Bug 1602318 - Fix race in browser_ext_tabs_onUpdated by installing the listener before adding the new tab. r=zombie
authorMatt Woodrow <mwoodrow@mozilla.com>
Sun, 26 Apr 2020 00:51:25 +0000
changeset 526105 bf51916fa039c4dc2955116e149a8829fe98210d
parent 526104 18451f8ef984658f124389a1a9d10d9a8201755c
child 526106 34931634acb78a051ecd2ea115b9ad3d07531e44
push id37350
push usernbeleuzu@mozilla.com
push dateSun, 26 Apr 2020 09:43:12 +0000
treeherdermozilla-central@21659f178a12 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszombie
bugs1602318
milestone77.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1602318 - Fix race in browser_ext_tabs_onUpdated by installing the listener before adding the new tab. r=zombie Differential Revision: https://phabricator.services.mozilla.com/D70622
browser/components/extensions/test/browser/browser_ext_tabs_onUpdated.js
--- a/browser/components/extensions/test/browser/browser_ext_tabs_onUpdated.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_onUpdated.js
@@ -210,21 +210,25 @@ add_task(async function test_title() {
     });
   });
 });
 
 add_task(async function test_without_tabs_permission() {
   await do_test_update(async function background() {
     const url =
       "http://mochi.test:8888/browser/browser/components/extensions/test/browser/context_tabs_onUpdated_page.html";
-    const tab = await browser.tabs.create({ url });
+    let tab = null;
     let count = 0;
 
     browser.tabs.onUpdated.addListener(function onUpdated(tabId, changeInfo) {
-      browser.test.assertEq(tabId, tab.id, "Check tab id");
+      // An attention change can happen during tabs.create, so
+      // we can't compare against tab yet.
+      if (!("attention" in changeInfo)) {
+        browser.test.assertEq(tabId, tab.id, "Check tab id");
+      }
       browser.test.log(`onUpdated: ${JSON.stringify(changeInfo)}`);
 
       browser.test.assertFalse(
         "url" in changeInfo,
         "url should not be included without tabs permission"
       );
       browser.test.assertFalse(
         "favIconUrl" in changeInfo,
@@ -232,26 +236,28 @@ add_task(async function test_without_tab
       );
       browser.test.assertFalse(
         "title" in changeInfo,
         "title should not be included without tabs permission"
       );
 
       if (changeInfo.status == "complete") {
         count++;
-        if (count === 2) {
+        if (count === 1) {
+          browser.tabs.reload(tabId);
+        } else {
           browser.test.log("Reload complete");
           browser.tabs.onUpdated.removeListener(onUpdated);
           browser.tabs.remove(tabId);
           browser.test.notifyPass("finish");
         }
       }
     });
 
-    browser.tabs.reload(tab.id);
+    tab = await browser.tabs.create({ url });
   }, false /* withPermissions */);
 });
 
 add_task(async function test_onUpdated_after_onRemoved() {
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       permissions: ["tabs"],
     },