Bug 1541748 - Add tests to verify WebExtensions API compatibility around new tab index r=mixedpuppy
authorYUKI "Piro" Hiroshi <yuki@clear-code.com>
Mon, 22 Apr 2019 09:00:57 +0000
changeset 470338 fd7d4206ad5993616bd553ffaac2d1ddb90d9fce
parent 470337 64c05e3826cdcc90e96c55e83015cf9c0bd67f3f
child 470339 9b8441bd38535473b25f4d9926991423187a1dbc
push id112865
push usershindli@mozilla.com
push dateMon, 22 Apr 2019 15:52:44 +0000
treeherdermozilla-inbound@b4b482a09cf0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1541748
milestone68.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 1541748 - Add tests to verify WebExtensions API compatibility around new tab index r=mixedpuppy Differential Revision: https://phabricator.services.mozilla.com/D27226
browser/components/extensions/test/browser/browser_ext_sessions_restoreTab.js
browser/components/extensions/test/browser/browser_ext_tabs_create.js
--- a/browser/components/extensions/test/browser/browser_ext_sessions_restoreTab.js
+++ b/browser/components/extensions/test/browser/browser_ext_sessions_restoreTab.js
@@ -56,8 +56,61 @@ add_task(async function test_restoringMo
   is(restoredTab.linkedBrowser.currentURI.spec, contentScriptTabURL, "Got expected URL");
 
   await extension.unload();
   BrowserTestUtils.removeTab(restoredTab);
 
   // Close the window.
   await BrowserTestUtils.closeWindow(win);
 });
+
+add_task(async function test_restoringClosedTabWithTooLargeIndex() {
+  function background() {
+    browser.test.onMessage.addListener(async (msg, filter) => {
+      if (msg != "restoreTab") {
+        return;
+      }
+      const recentlyClosed = await browser.sessions.getRecentlyClosed({maxResults: 2});
+      let tabWithTooLargeIndex;
+      for (const info of recentlyClosed) {
+        if (info.tab && info.tab.index > 1) {
+          tabWithTooLargeIndex = info.tab;
+          break;
+        }
+      }
+      const onRestored = tab => {
+        browser.tabs.onCreated.removeListener(onRestored);
+        browser.test.sendMessage("restoredTab", tab);
+      };
+      browser.tabs.onCreated.addListener(onRestored);
+      browser.sessions.restore(tabWithTooLargeIndex.sessionId);
+    });
+  }
+  let extension = ExtensionTestUtils.loadExtension({
+    manifest: {
+      permissions: ["tabs", "sessions"],
+    },
+    background,
+  });
+
+  const win = await BrowserTestUtils.openNewBrowserWindow({});
+  const tabs = await Promise.all([
+    BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:blank?0"),
+    BrowserTestUtils.openNewForegroundTab(win.gBrowser, "about:blank?1"),
+  ]);
+  const promsiedSessionStored = Promise.all([
+    BrowserTestUtils.waitForSessionStoreUpdate(tabs[0]),
+    BrowserTestUtils.waitForSessionStoreUpdate(tabs[1]),
+  ]);
+  // Close the rightmost tab at first
+  BrowserTestUtils.removeTab(tabs[1]);
+  BrowserTestUtils.removeTab(tabs[0]);
+  await promsiedSessionStored;
+
+  await extension.startup();
+  const promisedRestoredTab = extension.awaitMessage("restoredTab");
+  extension.sendMessage("restoreTab");
+  const restoredTab = await promisedRestoredTab;
+  is(restoredTab.index, 1, "Got valid index");
+
+  await extension.unload();
+  await BrowserTestUtils.closeWindow(win);
+});
--- a/browser/components/extensions/test/browser/browser_ext_tabs_create.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_create.js
@@ -94,16 +94,20 @@ add_task(async function test_create_opti
             {
               create: {index: 1, active: false},
               result: {index: 1, active: false},
             },
             {
               create: {windowId: activeWindow},
               result: {windowId: activeWindow},
             },
+            {
+              create: {index: 9999},
+              result: {index: 2},
+            },
           ];
 
           async function nextTest() {
             if (!tests.length) {
               browser.test.notifyPass("tabs.create");
               return;
             }