diff --git a/remote/shared/listeners/test/browser/browser.toml b/remote/shared/listeners/test/browser/browser.toml index 4747ef29c2a9c..0d2ff54b6a1e1 100644 --- a/remote/shared/listeners/test/browser/browser.toml +++ b/remote/shared/listeners/test/browser/browser.toml @@ -22,20 +22,9 @@ head js " " -style +cached_style . -css -" -" -test -- -page -- -with -- -css -. -html +sjs " ] prefs diff --git a/remote/shared/listeners/test/browser/browser_CachedResourceListener.js b/remote/shared/listeners/test/browser/browser_CachedResourceListener.js index b07385c2cd698..a57a4b3c0c351 100644 --- a/remote/shared/listeners/test/browser/browser_CachedResourceListener.js +++ b/remote/shared/listeners/test/browser/browser_CachedResourceListener.js @@ -57,7 +57,7 @@ MPL * / const -PAGE +STYLESHEET_URL = " https @@ -80,15 +80,9 @@ test / browser / -test -- -page -- -with -- -css +cached_style . -html +sjs " ; add_task @@ -99,9 +93,28 @@ test_only_for_observed_context ( ) { +/ +/ +Clear +the +cache +. +Services +. +cache2 +. +clear +( +) +; const tab = +( +gBrowser +. +selectedTab += BrowserTestUtils . addTab @@ -124,9 +137,10 @@ sjs ? html = -test +cached_css_testpage " ) +) ; await BrowserTestUtils @@ -138,13 +152,419 @@ tab linkedBrowser ) ; -await -loadURL +const +topContext += +tab +. +linkedBrowser +. +browsingContext +; +/ +/ +Setup +the +cached +resource +listener +and +load +a +stylesheet +in +a +link +tag +no +/ +/ +event +should +be +received +. +await +setupCachedListener +( +topContext +) +; +await +loadStylesheet +( +topContext +STYLESHEET_URL +) +; +let +cachedEventCount += +await +getCachedResourceEventCount +( +topContext +) +; +is +( +cachedEventCount +0 +" +No +cached +event +received +for +the +initial +load +" +) +; +/ +/ +Destroy +listener +before +reloading +. +await +destroyCachedListener +( +topContext +) +; +/ +/ +Reload +prepare +the +cached +resource +listener +and +load +the +same +stylesheet +/ +/ +again +. +await +BrowserTestUtils +. +reloadTab +( +tab +) +; +await +setupCachedListener +( +topContext +) +; +await +loadStylesheet +( +topContext +STYLESHEET_URL +) +; +cachedEventCount += +await +getCachedResourceEventCount +( +topContext +) +; +is +( +cachedEventCount +1 +" +1 +cached +event +received +for +the +second +load +" +) +; +const +iframeContext += +await +createIframeContext +( +topContext +) +; +await +setupCachedListener +( +iframeContext +) +; +await +loadStylesheet +( +iframeContext +STYLESHEET_URL +) +; +cachedEventCount += +await +getCachedResourceEventCount +( +topContext +) +; +is +( +cachedEventCount +1 +" +No +new +event +for +the +top +context +" +) +; +let +iframeCachedEventCount += +await +getCachedResourceEventCount +( +iframeContext +) +; +is +( +iframeCachedEventCount +1 +" +1 +event +received +for +the +frame +context +" +) +; +/ +/ +Destroy +listeners +. +await +destroyCachedListener +( +topContext +) +; +await +destroyCachedListener +( +iframeContext +) +; +gBrowser +. +removeTab +( +tab +) +; +} +) +; +async +function +loadStylesheet +( +browsingContext +url +) +{ +info +( +Load +stylesheet +for +browsingContext +{ +browsingContext +. +id +} +) +; +await +SpecialPowers +. +spawn +( +browsingContext +[ +url +] +async +_url += +> +{ +const +head += +content +. +document +. +getElementsByTagName +( +" +HEAD +" +) +[ +0 +] +; +const +link += +content +. +document +. +createElement +( +" +link +" +) +; +link +. +rel += +" +stylesheet +" +; +link +. +type += +" +text +/ +css +" +; +link +. +href += +_url +; +head +. +appendChild +( +link +) +; +info +( +" +Wait +until +the +stylesheet +has +been +loaded +and +applied +" +) +; +await +ContentTaskUtils +. +waitForCondition +( +( +) += +> +content +. +getComputedStyle +( +content +. +document +. +body +) +[ +" +background +- +color +" +] += += +" +rgb +( +0 +0 +0 +) +" +) +; +} +) +; +} +async +function +setupCachedListener ( -tab +browsingContext +) +{ +info +( +Setup +cachedResourcelistener +for +browsingContext +{ +browsingContext . -linkedBrowser -PAGE +id +} ) ; await @@ -152,22 +572,12 @@ SpecialPowers . spawn ( -tab -. -linkedBrowser +browsingContext [ -PAGE -tab -. -linkedBrowser -. browsingContext ] async -( -url -browsingContext -) +_browsingContext = > { @@ -201,8 +611,11 @@ mjs " ) ; -const -events +content +. +wrappedJSObject +. +cachedResourceEvents = [ ] @@ -216,20 +629,27 @@ data ) = > -events +{ +content +. +wrappedJSObject +. +cachedResourceEvents . push ( data ) ; +} +; const listener = new CachedResourceListener ( -browsingContext +_browsingContext ) ; listener @@ -252,109 +672,166 @@ startListening ( ) ; -const -head -= content . -document +wrappedJSObject . -getElementsByTagName +cachedResourcelistener += +listener +; +} +) +; +} +async +function +destroyCachedListener ( -" -HEAD -" +browsingContext +) +{ +info +( +Destroy +cachedResourcelistener +for +browsingContext +{ +browsingContext +. +id +} ) +; +return +SpecialPowers +. +spawn +( +browsingContext [ -0 ] -; -const -link +async +( +) = +> +{ +/ +/ +Cleanup +the +listener +. content . -document +wrappedJSObject . -createElement +cachedResourcelistener +. +stopListening ( -" -link -" ) ; -link -. -rel -= -" -stylesheet -" -; -link +content . -type -= -" -text -/ -css -" -; -link +wrappedJSObject . -href -= -" -style +cachedResourcelistener . -css -" +destroy +( +) ; -head -. -appendChild +} +) +; +} +async +function +getCachedResourceEventCount ( -link +browsingContext +) +{ +info +( +Retrieve +cached +resource +events +count +for +browsingContext +{ +browsingContext +. +id +} ) ; -await -ContentTaskUtils +return +SpecialPowers . -waitForCondition +spawn ( +browsingContext +[ +] +async ( ) = > -events +{ +return +content +. +wrappedJSObject +. +cachedResourceEvents . length -= -= -1 +; +} ) ; -Assert -. -equal +} +async +function +createIframeContext ( -events +browsingContext +) +{ +info +( +Create +iframe +in +browsingContext +{ +browsingContext . -length -1 -" -An -event -for -the -cached -stylesheet -is -received -" +id +} ) ; +return +SpecialPowers +. +spawn +( +browsingContext +[ +] +async +( +) += +> +{ const iframe = @@ -373,7 +850,25 @@ iframe . src = -url +" +https +: +/ +/ +example +. +com +/ +document +- +builder +. +sjs +? +html += +cached_css_frame +" ; content . @@ -397,45 +892,12 @@ load " ) ; -Assert -. -equal -( -events -. -length -1 -" -No -new -events -are -received -" -) -; -listener -. -stopListening -( -) -; -listener +return +iframe . -destroy -( -) +browsingContext ; } ) ; -gBrowser -. -removeTab -( -tab -) -; } -) -; diff --git a/remote/shared/listeners/test/browser/cached_style.sjs b/remote/shared/listeners/test/browser/cached_style.sjs new file mode 100644 index 0000000000000..8dbccdaed5e7c --- /dev/null +++ b/remote/shared/listeners/test/browser/cached_style.sjs @@ -0,0 +1,124 @@ +/ +* +Any +copyright +is +dedicated +to +the +Public +Domain +. +http +: +/ +/ +creativecommons +. +org +/ +publicdomain +/ +zero +/ +1 +. +0 +/ +* +/ +" +use +strict +" +; +function +handleRequest +( +request +response +) +{ +response +. +setHeader +( +" +Cache +- +Control +" +" +no +- +transform +public +max +- +age += +300 +s +- +maxage += +900 +" +) +; +response +. +setHeader +( +" +Expires +" +" +Thu +01 +Dec +2100 +20 +: +00 +: +00 +GMT +" +) +; +response +. +setHeader +( +" +Content +- +Type +" +" +text +/ +css +" +false +) +; +response +. +write +( +" +body +{ +background +- +color +: +black +; +} +" +) +; +} diff --git a/remote/shared/listeners/test/browser/style.css b/remote/shared/listeners/test/browser/style.css deleted file mode 100644 index b3c91da80f6c4..0000000000000 --- a/remote/shared/listeners/test/browser/style.css +++ /dev/null @@ -1,9 +0,0 @@ -body -{ -background -- -color -: -black -; -} diff --git a/remote/shared/listeners/test/browser/test-page-with-css.html b/remote/shared/listeners/test/browser/test-page-with-css.html deleted file mode 100644 index 0860e3d0ecc95..0000000000000 --- a/remote/shared/listeners/test/browser/test-page-with-css.html +++ /dev/null @@ -1,50 +0,0 @@ -< -! -DOCTYPE -html -> -< -html -> -< -head -> -< -link -rel -= -" -stylesheet -" -type -= -" -text -/ -css -" -href -= -" -style -. -css -" -> -< -/ -head -> -< -body -> -TEST -PAGE -< -/ -body -> -< -/ -html ->