Bug 1512353 skip moving windows between pb and non-pb windows r=zombie
authorShane Caraveo <scaraveo@mozilla.com>
Mon, 25 Feb 2019 18:38:49 +0000
changeset 518858 e42ba4e47d6520db2794e5195ac9979749d437f4
parent 518857 293617cdb29dcd04a178f83dd33f130b91c834c9
child 518859 43862dc87e0bebd357c300843bc9f2f3eeb0ae41
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerszombie
bugs1512353
milestone67.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 1512353 skip moving windows between pb and non-pb windows r=zombie Differential Revision: https://phabricator.services.mozilla.com/D20557
browser/components/extensions/parent/ext-tabs.js
browser/components/extensions/test/browser/browser_ext_tabs_move_window.js
--- a/browser/components/extensions/parent/ext-tabs.js
+++ b/browser/components/extensions/parent/ext-tabs.js
@@ -864,16 +864,23 @@ this.tabs = class extends ExtensionAPI {
             let window = destinationWindow || nativeTab.ownerGlobal;
             let gBrowser = window.gBrowser;
 
             // If we are not moving the tab to a different window, and the window
             // only has one tab, do nothing.
             if (nativeTab.ownerGlobal == window && gBrowser.tabs.length === 1) {
               continue;
             }
+            // If moving between windows, be sure privacy matches.  While gBrowser
+            // prevents this, we want to silently ignore it.
+            if (nativeTab.ownerGlobal != window &&
+                PrivateBrowsingUtils.isBrowserPrivate(window.gBrowser) !=
+                PrivateBrowsingUtils.isBrowserPrivate(nativeTab.ownerGlobal.gBrowser)) {
+              continue;
+            }
 
             let insertionPoint = indexMap.get(window) || moveProperties.index;
             // If the index is -1 it should go to the end of the tabs.
             if (insertionPoint == -1) {
               insertionPoint = gBrowser.tabs.length;
             }
 
             // We can only move pinned tabs to a point within, or just after,
--- a/browser/components/extensions/test/browser/browser_ext_tabs_move_window.js
+++ b/browser/components/extensions/test/browser/browser_ext_tabs_move_window.js
@@ -1,37 +1,55 @@
 /* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */
 /* vim: set sts=2 sw=2 et tw=80: */
 "use strict";
 
 add_task(async function() {
   await BrowserTestUtils.openNewForegroundTab(gBrowser, "http://example.net/");
   let window1 = await BrowserTestUtils.openNewBrowserWindow();
   await BrowserTestUtils.openNewForegroundTab(window1.gBrowser, "http://example.com/");
+  let window2 = await BrowserTestUtils.openNewBrowserWindow({private: true});
+  await BrowserTestUtils.openNewForegroundTab(window2.gBrowser, "http://example.com/");
 
   let extension = ExtensionTestUtils.loadExtension({
     manifest: {
       "permissions": ["tabs"],
     },
-
+    incognitoOverride: "spanning",
     async background() {
       let tabs = await browser.tabs.query({url: "<all_urls>"});
       let destination = tabs[0];
       let source = tabs[1]; // skip over about:blank in window1
+      let privateTab = tabs[2];
+      browser.test.assertTrue(privateTab.incognito, "have a private tab.");
 
       browser.tabs.onUpdated.addListener(() => {
         // Bug 1398272: Adding onUpdated listener broke tab IDs across windows.
       });
 
       // Assuming that this windowId does not exist.
       await browser.test.assertRejects(
         browser.tabs.move(source.id, {windowId: 123144576, index: 0}),
         /Invalid window/,
         "Should receive invalid window error");
 
+      // Test that a tab cannot be moved to a private window.
+      let moved = await browser.tabs.move(source.id, {windowId: privateTab.windowId, index: 0});
+      browser.test.assertEq(moved.length, 0, "tab was not moved to private window");
+      // Test that a private tab cannot be moved to a non-private window.
+      moved = await browser.tabs.move(privateTab.id, {windowId: source.windowId, index: 0});
+      browser.test.assertEq(moved.length, 0, "tab was not moved from private window");
+
+      // Verify tabs did not move between windows via another query.
+      let tabs2 = await browser.tabs.query({url: "<all_urls>"});
+      for (let i = 0; i < 3; i++) {
+        browser.test.assertEq(tabs2[i].windowId, tabs[i].windowId, "tab was not moved to another window");
+        browser.test.assertEq(tabs2[i].incognito, tabs[i].incognito, "tab privateness matches.");
+      }
+
       browser.tabs.move(source.id, {windowId: destination.windowId, index: 0});
 
       tabs = await browser.tabs.query({url: "<all_urls>"});
       browser.test.assertEq(tabs[0].url, "http://example.com/");
       browser.test.assertEq(tabs[0].windowId, destination.windowId);
       browser.test.assertEq(tabs[0].id, source.id);
 
       browser.test.notifyPass("tabs.move.window");
@@ -41,16 +59,17 @@ add_task(async function() {
   await extension.startup();
   await extension.awaitFinish("tabs.move.window");
   await extension.unload();
 
   for (let tab of window.gBrowser.tabs) {
     BrowserTestUtils.removeTab(tab);
   }
   await BrowserTestUtils.closeWindow(window1);
+  await BrowserTestUtils.closeWindow(window2);
 });
 
 add_task(async function test_currentWindowAfterTabMoved() {
   const files = {
     "current.html": "<meta charset=utf-8><script src=current.js></script>",
     "current.js": function() {
       browser.test.onMessage.addListener(msg => {
         if (msg === "current") {