summaryrefslogtreecommitdiffstats
path: root/dom/html/test/browser_containerLoadingContent.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /dom/html/test/browser_containerLoadingContent.js
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/html/test/browser_containerLoadingContent.js')
-rw-r--r--dom/html/test/browser_containerLoadingContent.js130
1 files changed, 130 insertions, 0 deletions
diff --git a/dom/html/test/browser_containerLoadingContent.js b/dom/html/test/browser_containerLoadingContent.js
new file mode 100644
index 0000000000..c0b52ffe8a
--- /dev/null
+++ b/dom/html/test/browser_containerLoadingContent.js
@@ -0,0 +1,130 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const syntheticBrowsingContexts = SpecialPowers.getBoolPref(
+ "browser.opaqueResponseBlocking.syntheticBrowsingContext",
+ false
+);
+
+const DIRPATH = getRootDirectory(gTestPath).replace(
+ "chrome://mochitests/content/",
+ ""
+);
+
+const ORIGIN = "https://example.com";
+const CROSSORIGIN = "https://example.org";
+
+const TABURL = `${ORIGIN}/${DIRPATH}dummy_page.html`;
+
+const IMAGEURL = `${ORIGIN}/${DIRPATH}image.png`;
+const CROSSIMAGEURL = `${CROSSORIGIN}/${DIRPATH}image.png`;
+
+const DOCUMENTURL = `${ORIGIN}/${DIRPATH}dummy_page.html`;
+const CROSSDOCUMENTURL = `${CROSSORIGIN}/${DIRPATH}dummy_page.html`;
+
+async function createElements({ element, attribute }, url1, url2) {
+ for (let url of [url1, url2]) {
+ const object = content.document.createElement(element);
+ object[attribute] = url;
+ const onloadPromise = new Promise(res => {
+ object.onload = res;
+ });
+ content.document.body.appendChild(object);
+ await onloadPromise;
+ return object;
+ }
+}
+
+function getPids(browser) {
+ return browser.browsingContext.children.map(
+ child => child.currentWindowContext.osPid
+ );
+}
+
+async function runTest(spec, tabUrl, imageurl, crossimageurl, check) {
+ await BrowserTestUtils.withNewTab(tabUrl, async browser => {
+ await SpecialPowers.spawn(
+ browser,
+ [spec, imageurl, crossimageurl],
+ async ({ element, attribute }, url1, url2) => {
+ for (let url of [url1, url2]) {
+ const object = content.document.createElement(element);
+ object[attribute] = url;
+ const onloadPromise = new Promise(res => {
+ object.onload = res;
+ });
+ content.document.body.appendChild(object);
+ await onloadPromise;
+ }
+ }
+ );
+
+ await check(browser);
+ });
+}
+
+let iframe = { element: "iframe", attribute: "src" };
+let embed = { element: "embed", attribute: "src" };
+let object = { element: "object", attribute: "data" };
+
+async function checkImage(browser) {
+ let pids = getPids(browser);
+ is(pids.length, 2, "There should be two browsing contexts");
+ ok(pids[0], "The first pid should have a sane value");
+ ok(pids[1], "The second pid should have a sane value");
+ isnot(pids[0], pids[1], "The two pids should be different");
+
+ let images = [];
+ for (let context of browser.browsingContext.children) {
+ images.push(
+ await SpecialPowers.spawn(context, [], async () => {
+ let img = new URL(content.document.querySelector("img").src);
+ is(
+ `${img.protocol}//${img.host}`,
+ `${content.location.protocol}//${content.location.host}`,
+ "Images should be loaded in the same domain as the document"
+ );
+ return img.href;
+ })
+ );
+ }
+ isnot(images[0], images[1], "The images should have different sources");
+}
+
+function checkDocument(browser) {
+ let pids = getPids(browser);
+ is(pids.length, 2, "There should be two browsing contexts");
+ ok(pids[0], "The first pid should have a sane value");
+ ok(pids[1], "The second pid should have a sane value");
+ isnot(pids[0], pids[1], "The two pids should be different");
+}
+
+add_task(async function test_iframeImageDocument() {
+ await runTest(iframe, TABURL, IMAGEURL, CROSSIMAGEURL, checkImage);
+});
+
+if (syntheticBrowsingContexts) {
+ add_task(async function test_embedImageDocument() {
+ await runTest(embed, TABURL, IMAGEURL, CROSSIMAGEURL, checkImage);
+ });
+
+ add_task(async function test_objectImageDocument() {
+ await runTest(object, TABURL, IMAGEURL, CROSSIMAGEURL, checkImage);
+ });
+}
+
+add_task(async function test_iframeDocument() {
+ await runTest(iframe, TABURL, DOCUMENTURL, CROSSDOCUMENTURL, checkDocument);
+});
+
+if (syntheticBrowsingContexts) {
+ add_task(async function test_embedDocument() {
+ await runTest(embed, TABURL, DOCUMENTURL, CROSSDOCUMENTURL, checkDocument);
+ });
+
+ add_task(async function test_objectDocument() {
+ await runTest(object, TABURL, DOCUMENTURL, CROSSDOCUMENTURL, checkDocument);
+ });
+}