forked from mozilla/gecko-dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1408708 - Fetch stylesheet content via stylesheet window instead …
…of top level content window. r=pbro MozReview-Commit-ID: AKXQLNAwy8t
- Loading branch information
Showing
7 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
devtools/client/styleeditor/test/browser_styleeditor_bug_1405342_serviceworker_iframes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* Any copyright is dedicated to the Public Domain. | ||
http://creativecommons.org/publicdomain/zero/1.0/ */ | ||
"use strict"; | ||
|
||
// Test that sheets inside cross origin iframes, served from a service worker | ||
// are correctly fetched via the service worker in the stylesheet editor. | ||
|
||
add_task(async function () { | ||
const TEST_URL = "https://test1.example.com/browser/devtools/client/styleeditor/test/bug_1405342_serviceworker_iframes.html"; | ||
let { ui } = await openStyleEditorForURL(TEST_URL); | ||
|
||
if (ui.editors.length != 1) { | ||
info("Stylesheet isn't available immediately, waiting for it"); | ||
await ui.once("editor-added"); | ||
} | ||
is(ui.editors.length, 1, "Got the iframe stylesheet"); | ||
|
||
await ui.selectStyleSheet(ui.editors[0].styleSheet); | ||
let editor = await ui.editors[0].getSourceEditor(); | ||
let text = editor.sourceEditor.getText(); | ||
is(text, "* { color: green; }", | ||
"stylesheet content is the one served by the service worker"); | ||
}); |
10 changes: 10 additions & 0 deletions
10
devtools/client/styleeditor/test/bug_1405342_serviceworker_iframes.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Bug 1405342</title> | ||
</head> | ||
<body> | ||
<iframe src="https://test2.example.com/browser/devtools/client/styleeditor/test/iframe_with_service_worker.html"><iframe> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
"use strict"; | ||
|
||
self.onfetch = function (event) { | ||
if (event.request.url.includes("sheet.css")) { | ||
return event.respondWith(new Response("* { color: green; }")); | ||
} | ||
return null; | ||
}; | ||
|
||
self.onactivate = function (event) { | ||
event.waitUntil(self.clients.claim()); | ||
}; |
33 changes: 33 additions & 0 deletions
33
devtools/client/styleeditor/test/iframe_with_service_worker.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
|
||
Iframe loading a stylesheet via a service worker | ||
<script> | ||
"use strict"; | ||
|
||
function waitForActive(swr) { | ||
let sw = swr.installing || swr.waiting || swr.active; | ||
return new Promise(resolve => { | ||
if (sw.state === "activated") { | ||
resolve(swr); | ||
return; | ||
} | ||
sw.addEventListener("statechange", function onStateChange(evt) { | ||
if (sw.state === "activated") { | ||
sw.removeEventListener("statechange", onStateChange); | ||
resolve(swr); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
navigator.serviceWorker.register("iframe_service_worker.js", {scope: "."}) | ||
.then(registration => waitForActive(registration)) | ||
.then(() => { | ||
let link = document.createElement("link"); | ||
link.setAttribute("rel", "stylesheet"); | ||
link.setAttribute("type", "text/css"); | ||
link.setAttribute("href", "sheet.css"); | ||
document.documentElement.appendChild(link); | ||
}); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters