From f105a0c763549379ab8dd2de23687f5f627f4bf3 Mon Sep 17 00:00:00 2001 From: Anny Gakhokidze Date: Thu, 28 Jan 2021 00:19:23 +0000 Subject: [PATCH] Bug 1688767 - Change layout/base/tests/test_bug607529.html to use BroadcastChannel, r=smaug Differential Revision: https://phabricator.services.mozilla.com/D103189 --- layout/base/tests/file_bug607529-1.html | 13 ++++++- layout/base/tests/file_bug607529.html | 33 ++++++++++------ layout/base/tests/test_bug607529.html | 52 +++++++++++++------------ 3 files changed, 62 insertions(+), 36 deletions(-) diff --git a/layout/base/tests/file_bug607529-1.html b/layout/base/tests/file_bug607529-1.html index dbe54ebf3073..506b7092c540 100644 --- a/layout/base/tests/file_bug607529-1.html +++ b/layout/base/tests/file_bug607529-1.html @@ -1 +1,12 @@ - + diff --git a/layout/base/tests/file_bug607529.html b/layout/base/tests/file_bug607529.html index 9fbd7f3931b7..bebcd09de95e 100644 --- a/layout/base/tests/file_bug607529.html +++ b/layout/base/tests/file_bug607529.html @@ -1,40 +1,51 @@ diff --git a/layout/base/tests/test_bug607529.html b/layout/base/tests/test_bug607529.html index 40b8c2cf8fcb..0b42a57da7f5 100644 --- a/layout/base/tests/test_bug607529.html +++ b/layout/base/tests/test_bug607529.html @@ -26,20 +26,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=607529 var done = false; /** Test for Bug 607529 **/ - - function closeWindowAndFinish() { - w.close(); - window.onmessage = null; - SimpleTest.finish(); - } - - window.onmessage = function(e) { - isnot(e.data, "notcached", "Should never end up not being cached"); - - if (e.data == "loaded") { + var bc = new BroadcastChannel("bug607529"); + var bc_1 = new BroadcastChannel("bug607529_1"); + bc.onmessage = (msgEvent) => { + var msg = msgEvent.data; + isnot(msg, "notcached", "Should never end up not being cached"); + if (msg == "loaded") { if (!doneOneLoad) { doneOneLoad = true; - w.location = "file_bug607529-1.html"; + bc.postMessage("navigateToPage"); } else { // This is unexpected, but it can happen on Android, probably when // bfcache gets purged due to memory pressure. Hence, "soft fail" there. @@ -53,13 +48,10 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=607529 closeWindowAndFinish(); } } - else if (e.data == "goback") { - w.history.back(); + else if (msg == "revived") { + bc.postMessage("report"); } - else if (e.data == "revived") { - w.postMessage("report", "*"); - } - else if (e.data == "callbackHappened") { + else if (msg == "callbackHappened") { // We might get this message more than once, if the other page queues up // more than one callbackHappened message before we manage to close it. // Protect against calling SimpleTest.finish() more than once. @@ -67,22 +59,34 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=607529 closeWindowAndFinish(); done = true; } + } else if (msg == "closed") { + bc.close(); + bc_1.close(); + SimpleTest.finish(); } else { try { - var msg = JSON.parse(e.data); + var jsonMsg = JSON.parse(msg); } catch (ex) { // In case JSON.parse throws, we pause to print the string that it // choked on, and then resume throwing the exception. - ok(false, "JSON.parse threw, when passed string '" + e.data + "'"); + ok(false, "JSON.parse threw, when passed string '" + jsonMsg + "'"); throw ex; } - if (msg.error) { - window.onerror(msg.msg, msg.url, msg.line); + if (jsonMsg.error) { + window.onerror(jsonMsg.msg, jsonMsg.url, jsonMsg.line); } } - }; + } + bc_1.onmessage = (msgEvent) => { + if (msgEvent.data == "goback") { + bc_1.postMessage("navigateBack"); + } + } + function closeWindowAndFinish() { + bc.postMessage("close"); + } - var w = window.open("file_bug607529.html"); + window.open("file_bug607529.html", "", "noopener");