From a9417a719e356b4d40a052cb0239e2525acbac63 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Thu, 4 Mar 2021 22:03:57 +0000 Subject: [PATCH] Bug 1360715 - Part 2: Modify instanceofs in tests to non-cross-context r=edgar Differential Revision: https://phabricator.services.mozilla.com/D106662 --- dom/base/test/test_root_iframe.html | 2 +- dom/crypto/test/test_WebCrypto.html | 2 +- dom/events/test/test_bug328885.html | 10 +++++----- dom/html/test/test_bug277724.html | 13 ++++++++----- dom/tests/mochitest/fetch/common_readableStreams.js | 8 ++++---- .../test/mochitest/apz_test_native_event_utils.js | 4 ++-- js/xpconnect/tests/mochitest/test_bug829872.html | 2 +- layout/style/test/test_media_query_list.html | 2 +- .../org/mozilla/geckoview/test/AccessibilityTest.kt | 6 +++--- .../mozilla/geckoview/test/AutofillDelegateTest.kt | 6 +++--- .../the-object-element/object-events.html | 2 +- .../test/xpcshell/data/file_document_write.html | 3 ++- .../tests/widgets/test_ua_widget_sandbox.html | 4 ++-- 13 files changed, 34 insertions(+), 30 deletions(-) diff --git a/dom/base/test/test_root_iframe.html b/dom/base/test/test_root_iframe.html index 984009c47fff..2e19f19efc04 100644 --- a/dom/base/test/test_root_iframe.html +++ b/dom/base/test/test_root_iframe.html @@ -19,7 +19,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=511084 /** Test for Bug 511084 **/ var doc = frames[0].document; doc.replaceChild(doc.createElement("iframe"), doc.documentElement); - ok(frames[0][0] instanceof Window, + ok(frames[0][0] instanceof frames[0][0].Window, "Should have a subframe window for a root iframe"); diff --git a/dom/crypto/test/test_WebCrypto.html b/dom/crypto/test/test_WebCrypto.html index 972538e0d304..cee0b71505e1 100644 --- a/dom/crypto/test/test_WebCrypto.html +++ b/dom/crypto/test/test_WebCrypto.html @@ -1126,7 +1126,7 @@ TestArray.addTest( return Promise.all([p1, p2, p3]).then(complete(that, keys => { return keys.every(key => { - if (key instanceof CryptoKey) { + if (key instanceof frames[0].CryptoKey) { return checkPrototypes(key, "CryptoKey"); } diff --git a/dom/events/test/test_bug328885.html b/dom/events/test/test_bug328885.html index 1a41a305cfa1..aba639b8f87a 100644 --- a/dom/events/test/test_bug328885.html +++ b/dom/events/test/test_bug328885.html @@ -13,7 +13,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=328885 Mozilla Bug 328885

@@ -37,11 +37,11 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=328885 inputelement.addEventListener("DOMNodeInsertedIntoDocument", mutationListener); inputelement.addEventListener("DOMAttrModified", mutationListener); inputelement.addEventListener("DOMCharacterDataModified", mutationListener); - - inputelement.addEventListener('click', + + inputelement.addEventListener('click', function(event) { var evt = SpecialPowers.wrap(event); - ok(SpecialPowers.unwrap(evt.originalTarget) instanceof HTMLDivElement, + ok(SpecialPowers.call_Instanceof(evt.originalTarget, HTMLDivElement), "(1) Wrong originalTarget!"); is(SpecialPowers.unwrap(evt.originalTarget.parentNode), inputelement, "(2) Wront parent node!"); @@ -92,7 +92,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=328885 ok(mutationCount == 12, "(16) Mutation listener should have been called! ["+ mutationCount + "]"); // Then try some mixed mutations. The mutation handler of non-native-a - inputelement.addEventListener("DOMAttrModified", + inputelement.addEventListener("DOMAttrModified", function (evt2) { evt.originalTarget.setAttribute("foo", "bar" + mutationCount); ok(evt.originalTarget.getAttribute("foo") == "bar" + mutationCount, diff --git a/dom/html/test/test_bug277724.html b/dom/html/test/test_bug277724.html index 32fe0a7e9953..0732a4cf9a92 100644 --- a/dom/html/test/test_bug277724.html +++ b/dom/html/test/test_bug277724.html @@ -44,12 +44,13 @@ function startTest(frameid) { is(childUnloaded, false, "Child not unloaded yet"); var doc = $(frameid).contentDocument; - ok(doc instanceof Document, "doc should be a document"); + var win = $(frameid).contentWindow; + ok(doc instanceof win.Document, "doc should be a document"); for (var i = 0; i < nodes.length; ++i) { var id = nodes[i][0]; var node = doc.getElementById(id); - ok(node instanceof nodes[i][1], id + " should be a " + nodes[i][1]); + ok(node instanceof win[nodes[i][1].name], id + " should be a " + nodes[i][1]); is(node.disabled, false, "check for " + id + " state"); node.disabled = true; is(node.disabled, true, "check for " + id + " state change"); @@ -67,7 +68,8 @@ function startTest(frameid) { function continueTest(frameid) { is(childUnloaded, true, "Unload handler should have fired"); var doc = $(frameid).contentDocument; - ok(doc instanceof Document, "doc should be a document"); + var win = $(frameid).contentWindow; + ok(doc instanceof win.Document, "doc should be a document"); for (var i = 0; i < nodes.length; ++i) { var id = nodes[i][0]; @@ -100,12 +102,13 @@ function flipper(a, b, c) { function finishTest(frameid) { var doc = $(frameid).contentDocument; - ok(doc instanceof Document, "doc should be a document"); + var win = $(frameid).contentWindow; + ok(doc instanceof win.Document, "doc should be a document"); for (var i = 0; i < nodes.length; ++i) { var id = nodes[i][0]; var node = doc.getElementById(id); - ok(node instanceof nodes[i][1], id + " should be a " + nodes[i][1]); + ok(node instanceof win[nodes[i][1].name], id + " should be a " + nodes[i][1]); //testIs(node.disabled, true, "check for " + id + " state restore"); } diff --git a/dom/tests/mochitest/fetch/common_readableStreams.js b/dom/tests/mochitest/fetch/common_readableStreams.js index 7152af9a41ff..2b4c1700fa78 100644 --- a/dom/tests/mochitest/fetch/common_readableStreams.js +++ b/dom/tests/mochitest/fetch/common_readableStreams.js @@ -52,13 +52,13 @@ async function test_nativeStream_continue(r, that) { let blob = await r.blob(); - that.ok(blob instanceof Blob, "We have a blob"); + that.ok(blob instanceof that.Blob, "We have a blob"); let d = await a.body.getReader().read(); that.ok(!d.done, "We have read something!"); blob = await b.blob(); - that.ok(blob instanceof Blob, "We have a blob"); + that.ok(blob instanceof that.Blob, "We have a blob"); } async function test_timeout(compartment) { @@ -123,13 +123,13 @@ async function test_nonNativeStream_continue(data, that) { let blob = await data.r.blob(); - that.ok(blob instanceof Blob, "We have a blob"); + that.ok(blob instanceof that.Blob, "We have a blob"); let d = await a.body.getReader().read(); that.ok(!d.done, "We have read something!"); blob = await b.blob(); - that.ok(blob instanceof Blob, "We have a blob"); + that.ok(blob instanceof that.Blob, "We have a blob"); that.is(blob.size, data.buffer.byteLength, "Blob size matches"); } diff --git a/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js b/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js index 35ad1ea3f754..a9e17af3c4ed 100644 --- a/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js +++ b/gfx/layers/apz/test/mochitest/apz_test_native_event_utils.js @@ -65,7 +65,7 @@ function nativeHorizontalWheelEventMsg() { // Given an event target which may be a window or an element, get the associated window. function windowForTarget(aTarget) { - if (aTarget instanceof Window) { + if (aTarget.Window && aTarget instanceof aTarget.Window) { return aTarget; } return aTarget.ownerDocument.defaultView; @@ -73,7 +73,7 @@ function windowForTarget(aTarget) { // Given an event target which may be a window or an element, get the associated element. function elementForTarget(aTarget) { - if (aTarget instanceof Window) { + if (aTarget.Window && aTarget instanceof aTarget.Window) { return aTarget.document.documentElement; } return aTarget; diff --git a/js/xpconnect/tests/mochitest/test_bug829872.html b/js/xpconnect/tests/mochitest/test_bug829872.html index c880033fffa3..07e2a4ca7782 100644 --- a/js/xpconnect/tests/mochitest/test_bug829872.html +++ b/js/xpconnect/tests/mochitest/test_bug829872.html @@ -23,7 +23,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=829872 is(elem.contentDocument, null, "null cross-origin contentDocument for " + desc); ok(await SpecialPowers.spawn(elem, [], () => this.content.eval('frameElement === null;')), "null cross-origin frameElement for " + desc); - if (!(elem instanceof HTMLFrameElement)) + if (!(elem instanceof elem.ownerDocument.defaultView.HTMLFrameElement)) is(elem.getSVGDocument(), null, "null cross-origin getSVGDocument() for " + desc); } diff --git a/layout/style/test/test_media_query_list.html b/layout/style/test/test_media_query_list.html index ea8ea1c14cd8..017d2e660362 100644 --- a/layout/style/test/test_media_query_list.html +++ b/layout/style/test/test_media_query_list.html @@ -42,7 +42,7 @@ function run() { mql: subwin.matchMedia(str), notifyCount: 0, listener: function(event) { - ok(event instanceof MediaQueryListEvent, + ok(event instanceof subwin.MediaQueryListEvent, "correct argument to listener: " + obj.str); is(event.media, obj.mql.media, "correct media in the event: " + obj.str); diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AccessibilityTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AccessibilityTest.kt index f2d2a42fa16e..6fcf1f12ea6e 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AccessibilityTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AccessibilityTest.kt @@ -1106,9 +1106,9 @@ class AccessibilityTest : BaseSessionTest() { $doc.querySelector('${entry.key}').addEventListener( 'input', event => { let eventInterface = - event instanceof InputEvent ? "InputEvent" : - event instanceof UIEvent ? "UIEvent" : - event instanceof Event ? "Event" : "Unknown"; + event instanceof $doc.defaultView.InputEvent ? "InputEvent" : + event instanceof $doc.defaultView.UIEvent ? "UIEvent" : + event instanceof $doc.defaultView.Event ? "Event" : "Unknown"; resolve([event.target.value, '${entry.value}', eventInterface]); }, { once: true }))""") } diff --git a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutofillDelegateTest.kt b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutofillDelegateTest.kt index 22e6f27c856f..92d10a49f4bb 100644 --- a/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutofillDelegateTest.kt +++ b/mobile/android/geckoview/src/androidTest/java/org/mozilla/geckoview/test/AutofillDelegateTest.kt @@ -172,9 +172,9 @@ class AutofillDelegateTest : BaseSessionTest() { $doc.querySelector('${entry.key}').addEventListener( 'input', event => { let eventInterface = - event instanceof InputEvent ? "InputEvent" : - event instanceof UIEvent ? "UIEvent" : - event instanceof Event ? "Event" : "Unknown"; + event instanceof $doc.defaultView.InputEvent ? "InputEvent" : + event instanceof $doc.defaultView.UIEvent ? "UIEvent" : + event instanceof $doc.defaultView.Event ? "Event" : "Unknown"; resolve([ '${entry.key}', event.target.value, diff --git a/testing/web-platform/tests/html/semantics/embedded-content/the-object-element/object-events.html b/testing/web-platform/tests/html/semantics/embedded-content/the-object-element/object-events.html index 151923ac2fdd..38f92c3d356c 100644 --- a/testing/web-platform/tests/html/semantics/embedded-content/the-object-element/object-events.html +++ b/testing/web-platform/tests/html/semantics/embedded-content/the-object-element/object-events.html @@ -62,7 +62,7 @@ async_test(function(t) { async_test(function(t) { var obj = document.createElement("object"); obj.onload = t.step_func_done(function(e){ - assert_true(obj.contentWindow instanceof Window, "The object element should represent a nested browsing context.") + assert_true(obj.contentWindow instanceof obj.contentWindow.Window, "The object element should represent a nested browsing context.") assert_equals(Object.getPrototypeOf(e).constructor, Event, "The load event should use the Event interface."); assert_true(e.isTrusted, "The load event should be a trusted event."); assert_false(e.cancelable, "The load event should not be a cancelable event."); diff --git a/toolkit/components/extensions/test/xpcshell/data/file_document_write.html b/toolkit/components/extensions/test/xpcshell/data/file_document_write.html index fbae3d6d763a..f8369ae5743e 100644 --- a/toolkit/components/extensions/test/xpcshell/data/file_document_write.html +++ b/toolkit/components/extensions/test/xpcshell/data/file_document_write.html @@ -16,6 +16,7 @@ let iframe = document.getElementById("iframe"); let doc = iframe.contentDocument; + let win = iframe.contentWindow; doc.open("text/html"); // We need to do two writes here. The first creates the document element, // which normally triggers parser blocking. The second triggers the @@ -25,7 +26,7 @@ doc.write("
"); let elem = doc.getElementById("beer"); - top.postMessage(elem instanceof HTMLDivElement ? "ok" : "fail", + top.postMessage(elem instanceof win.HTMLDivElement ? "ok" : "fail", "*"); doc.close(); diff --git a/toolkit/content/tests/widgets/test_ua_widget_sandbox.html b/toolkit/content/tests/widgets/test_ua_widget_sandbox.html index 134892619b2b..b391372cfdb5 100644 --- a/toolkit/content/tests/widgets/test_ua_widget_sandbox.html +++ b/toolkit/content/tests/widgets/test_ua_widget_sandbox.html @@ -78,8 +78,8 @@ const sandboxScript = function(shadowRoot) { SpecialPowers.Cu.evalInSandbox("this.script = " + sandboxScript.toString(), sandbox); sandbox.script(div.shadowRoot); -ok(window.spanElementFromUAWidget instanceof HTMLSpanElement, " exposed"); -ok(window.divElementFromUAWidget instanceof HTMLDivElement, "
exposed"); +ok(SpecialPowers.call_Instanceof(window.spanElementFromUAWidget, HTMLSpanElement), " exposed"); +ok(SpecialPowers.call_Instanceof(window.divElementFromUAWidget, HTMLDivElement), "
exposed"); try { window.spanElementFromUAWidget.textContent;