browser/base/content/test/social/browser_social_perwindowPB.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 function openTab(win, url, callback) {
     6   let newTab = win.gBrowser.addTab(url);
     7   let tabBrowser = win.gBrowser.getBrowserForTab(newTab);
     8   tabBrowser.addEventListener("load", function tabLoadListener() {
     9     tabBrowser.removeEventListener("load", tabLoadListener, true);
    10     win.gBrowser.selectedTab = newTab;
    11     callback(newTab);
    12   }, true)
    13 }
    15 // Tests for per-window private browsing.
    16 function openPBWindow(callback) {
    17   let w = OpenBrowserWindow({private: true});
    18   w.addEventListener("load", function loadListener() {
    19     w.removeEventListener("load", loadListener);
    20     openTab(w, "http://example.com", function() {
    21       callback(w);
    22     });
    23   });
    24 }
    26 function postAndReceive(port, postTopic, receiveTopic, callback) {
    27   port.onmessage = function(e) {
    28     if (e.data.topic == receiveTopic)
    29       callback();
    30   }
    31   port.postMessage({topic: postTopic});
    32 }
    34 function test() {
    35   waitForExplicitFinish();
    37   let manifest = { // normal provider
    38     name: "provider 1",
    39     origin: "https://example.com",
    40     sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
    41     statusURL: "https://example.com/browser/browser/base/content/test/social/social_panel.html",
    42     workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
    43     markURL: "https://example.com/browser/browser/base/content/test/social/social_mark.html?url=%{url}",
    44     iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png"
    45   };
    46   runSocialTestWithProvider(manifest, function (finishcb) {
    47     openTab(window, "http://example.com", function(newTab) {
    48       runSocialTests(tests, undefined, undefined, function() {
    49         window.gBrowser.removeTab(newTab);
    50         finishcb();
    51       });
    52     });
    53   });
    54 }
    56 var tests = {
    57   testPrivateBrowsing: function(next) {
    58     let port = SocialSidebar.provider.getWorkerPort();
    59     ok(port, "provider has a port");
    60     postAndReceive(port, "test-init", "test-init-done", function() {
    61       // social features should all be enabled in the existing window.
    62       info("checking main window ui");
    63       ok(window.SocialUI.enabled, "social is enabled in normal window");
    64       checkSocialUI(window);
    65       // open a new private-window
    66       openPBWindow(function(pbwin) {
    67         // The provider should remain alive.
    68         postAndReceive(port, "ping", "pong", function() {
    69           // the new window should have no social features at all.
    70           info("checking private window ui");
    71           ok(!pbwin.SocialUI.enabled, "social is disabled in a PB window");
    72           checkSocialUI(pbwin);
    74           // but they should all remain enabled in the initial window
    75           info("checking main window ui");
    76           ok(window.SocialUI.enabled, "social is still enabled in normal window");
    77           checkSocialUI(window);
    79           // Check that the status button is disabled on the private
    80           // browsing window and not on the normal window.
    81           let id = SocialStatus._toolbarHelper.idFromOrigin("https://example.com");
    82           let widget = CustomizableUI.getWidget(id);
    83           ok(widget.forWindow(pbwin).node.disabled, "status button disabled on private window");
    84           ok(!widget.forWindow(window).node.disabled, "status button enabled on normal window");
    86           // Check that the mark button is disabled on the private
    87           // browsing window and not on the normal window.
    88           id = SocialMarks._toolbarHelper.idFromOrigin("https://example.com");
    89           widget = CustomizableUI.getWidget(id);
    90           ok(widget.forWindow(pbwin).node.disabled, "mark button disabled on private window");
    91           ok(!widget.forWindow(window).node.disabled, "mark button enabled on normal window");
    93           // that's all folks...
    94           pbwin.close();
    95           next();
    96         })
    97       });
    98     });
    99   },
   100 }

mercurial