From d4700cbcf933980fc414ad354528103253cb43c9 Mon Sep 17 00:00:00 2001 From: Andres Hernandez Date: Thu, 15 Nov 2012 18:33:31 -0600 Subject: [PATCH] Bug 811490 - Convert services/sync/tests/tps/test_privbrw_tabs.js to PB per window mode; r=ehsan,rnewman --- services/sync/tests/tps/test_privbrw_tabs.js | 4 +-- .../sync/tps/extensions/tps/modules/tps.jsm | 21 +++++++++++ .../tps/extensions/tps/modules/windows.jsm | 36 +++++++++++++++++++ 3 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 services/sync/tps/extensions/tps/modules/windows.jsm diff --git a/services/sync/tests/tps/test_privbrw_tabs.js b/services/sync/tests/tps/test_privbrw_tabs.js index d662131f2a4..e7c94e9db9a 100644 --- a/services/sync/tests/tps/test_privbrw_tabs.js +++ b/services/sync/tests/tps/test_privbrw_tabs.js @@ -58,7 +58,6 @@ var tabs3 = [ } ]; - /* * Test phases */ @@ -77,7 +76,7 @@ Phase('phase2', [ Phase('phase3', [ [Sync], - [SetPrivateBrowsing, true], + [Windows.add, { private: true }], [Tabs.add, tabs3], [Sync] ]); @@ -86,4 +85,3 @@ Phase('phase4', [ [Sync], [Tabs.verifyNot, tabs3] ]); - diff --git a/services/sync/tps/extensions/tps/modules/tps.jsm b/services/sync/tps/extensions/tps/modules/tps.jsm index 3045eb17853..f1122a397cb 100644 --- a/services/sync/tps/extensions/tps/modules/tps.jsm +++ b/services/sync/tps/extensions/tps/modules/tps.jsm @@ -25,6 +25,7 @@ CU.import("resource://tps/history.jsm"); CU.import("resource://tps/forms.jsm"); CU.import("resource://tps/prefs.jsm"); CU.import("resource://tps/tabs.jsm"); +CU.import("resource://tps/windows.jsm"); var hh = CC["@mozilla.org/network/protocol;1?name=http"] .getService(CI.nsIHttpProtocolHandler); @@ -163,6 +164,20 @@ let TPS = { this.goQuitApplication(); }, + HandleWindows: function (aWindow, action) { + Logger.logInfo("executing action " + action.toUpperCase() + + " on window " + JSON.stringify(aWindow)); + switch(action) { + case ACTION_ADD: + BrowserWindows.Add(aWindow.private, function(win) { + Logger.logInfo("window finished loading"); + this.FinishAsyncOperation(); + }.bind(this)); + break; + } + Logger.logPass("executing action " + action.toUpperCase() + " on windows"); + }, + HandleTabs: function (tabs, action) { this._tabsAdded = tabs.length; this._tabsFinished = 0; @@ -927,3 +942,9 @@ var Tabs = { } }; +var Windows = { + add: function Window__add(aWindow) { + TPS.StartAsyncOperation(); + TPS.HandleWindows(aWindow, ACTION_ADD); + }, +}; diff --git a/services/sync/tps/extensions/tps/modules/windows.jsm b/services/sync/tps/extensions/tps/modules/windows.jsm new file mode 100644 index 00000000000..62cc80d2cd4 --- /dev/null +++ b/services/sync/tps/extensions/tps/modules/windows.jsm @@ -0,0 +1,36 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +"use strict"; + + /* This is a JavaScript module (JSM) to be imported via + Components.utils.import() and acts as a singleton. + Only the following listed symbols will exposed on import, and only when + and where imported. */ + +const EXPORTED_SYMBOLS = ["BrowserWindows"]; + +const {classes: Cc, interfaces: Ci, utils: Cu} = Components; + +Cu.import("resource://services-sync/main.js"); + +let BrowserWindows = { + /** + * Add + * + * Opens a new window. Throws on error. + * + * @param aPrivate The private option. + * @return nothing + */ + Add: function(aPrivate, fn) { + let wm = Cc["@mozilla.org/appshell/window-mediator;1"] + .getService(Ci.nsIWindowMediator); + let mainWindow = wm.getMostRecentWindow("navigator:browser"); + let win = mainWindow.OpenBrowserWindow({private: aPrivate}); + win.addEventListener("load", function onLoad() { + win.removeEventListener("load", onLoad, false); + fn.call(win); + }, false); + } +};