Bug 1743148 - Call ensureCaptivePortalTab() directly from NetErrorParent instead of firing an obs notification. r=lyavor,valentin

Differential Revision: https://phabricator.services.mozilla.com/D132254
This commit is contained in:
Nihanth Subramanya 2021-12-03 19:16:48 +00:00
Родитель b34f3789ca
Коммит c80b5b3dfc
3 изменённых файлов: 14 добавлений и 6 удалений

Просмотреть файл

@ -276,7 +276,7 @@ class NetErrorParent extends JSWindowActorParent {
this.browser.reload();
break;
case "Browser:OpenCaptivePortalPage":
Services.obs.notifyObservers(null, "ensure-captive-portal-tab");
this.browser.ownerGlobal.CaptivePortalWatcher.ensureCaptivePortalTab();
break;
case "Browser:PrimeMitm":
this.primeMitm(this.browser);

Просмотреть файл

@ -44,7 +44,6 @@ var CaptivePortalWatcher = {
},
init() {
Services.obs.addObserver(this, "ensure-captive-portal-tab");
Services.obs.addObserver(this, "captive-portal-login");
Services.obs.addObserver(this, "captive-portal-login-abort");
Services.obs.addObserver(this, "captive-portal-login-success");
@ -79,7 +78,6 @@ var CaptivePortalWatcher = {
},
uninit() {
Services.obs.removeObserver(this, "ensure-captive-portal-tab");
Services.obs.removeObserver(this, "captive-portal-login");
Services.obs.removeObserver(this, "captive-portal-login-abort");
Services.obs.removeObserver(this, "captive-portal-login-success");
@ -96,9 +94,6 @@ var CaptivePortalWatcher = {
observe(aSubject, aTopic, aData) {
switch (aTopic) {
case "ensure-captive-portal-tab":
this.ensureCaptivePortalTab();
break;
case "captive-portal-login":
this._captivePortalDetected();
break;

Просмотреть файл

@ -18,6 +18,12 @@ add_task(async function checkCaptivePortalCertErrorUI() {
"Checking that the alternate cert error UI is shown when we are behind a captive portal"
);
// Open a second window in the background. Later, we'll check that
// when we click the button to open the captive portal tab, the tab
// only opens in the active window and not in the background one.
let secondWindow = await openWindowAndWaitForFocus();
await SimpleTest.promiseFocus(window);
await portalDetected();
let tab = await openCaptivePortalErrorTab();
let browser = tab.linkedBrowser;
@ -50,6 +56,9 @@ add_task(async function checkCaptivePortalCertErrorUI() {
"Login page should be open in a new foreground tab."
);
// Check that we didn't open anything in the background window.
ensureNoPortalTab(secondWindow);
// Make sure clicking the "Open Login Page" button again focuses the existing portal tab.
await BrowserTestUtils.switchTab(gBrowser, tab);
// Passing an empty function to BrowserTestUtils.switchTab lets us wait for an arbitrary
@ -67,6 +76,9 @@ add_task(async function checkCaptivePortalCertErrorUI() {
let portalTab2 = await portalTabPromise;
is(portalTab2, portalTab, "The existing portal tab should be focused.");
// Check that we didn't open anything in the background window.
ensureNoPortalTab(secondWindow);
let portalTabClosing = BrowserTestUtils.waitForTabClosing(portalTab);
let errorTabReloaded = BrowserTestUtils.waitForErrorPage(browser);
@ -86,6 +98,7 @@ add_task(async function checkCaptivePortalCertErrorUI() {
});
await BrowserTestUtils.removeTab(tab);
await BrowserTestUtils.closeWindow(secondWindow);
});
add_task(async function testCaptivePortalAdvancedPanel() {