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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/social/browser_social_perwindowPB.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +function openTab(win, url, callback) {
     1.9 +  let newTab = win.gBrowser.addTab(url);
    1.10 +  let tabBrowser = win.gBrowser.getBrowserForTab(newTab);
    1.11 +  tabBrowser.addEventListener("load", function tabLoadListener() {
    1.12 +    tabBrowser.removeEventListener("load", tabLoadListener, true);
    1.13 +    win.gBrowser.selectedTab = newTab;
    1.14 +    callback(newTab);
    1.15 +  }, true)
    1.16 +}
    1.17 +
    1.18 +// Tests for per-window private browsing.
    1.19 +function openPBWindow(callback) {
    1.20 +  let w = OpenBrowserWindow({private: true});
    1.21 +  w.addEventListener("load", function loadListener() {
    1.22 +    w.removeEventListener("load", loadListener);
    1.23 +    openTab(w, "http://example.com", function() {
    1.24 +      callback(w);
    1.25 +    });
    1.26 +  });
    1.27 +}
    1.28 +
    1.29 +function postAndReceive(port, postTopic, receiveTopic, callback) {
    1.30 +  port.onmessage = function(e) {
    1.31 +    if (e.data.topic == receiveTopic)
    1.32 +      callback();
    1.33 +  }
    1.34 +  port.postMessage({topic: postTopic});
    1.35 +}
    1.36 +
    1.37 +function test() {
    1.38 +  waitForExplicitFinish();
    1.39 +
    1.40 +  let manifest = { // normal provider
    1.41 +    name: "provider 1",
    1.42 +    origin: "https://example.com",
    1.43 +    sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
    1.44 +    statusURL: "https://example.com/browser/browser/base/content/test/social/social_panel.html",
    1.45 +    workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
    1.46 +    markURL: "https://example.com/browser/browser/base/content/test/social/social_mark.html?url=%{url}",
    1.47 +    iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png"
    1.48 +  };
    1.49 +  runSocialTestWithProvider(manifest, function (finishcb) {
    1.50 +    openTab(window, "http://example.com", function(newTab) {
    1.51 +      runSocialTests(tests, undefined, undefined, function() {
    1.52 +        window.gBrowser.removeTab(newTab);
    1.53 +        finishcb();
    1.54 +      });
    1.55 +    });
    1.56 +  });
    1.57 +}
    1.58 +
    1.59 +var tests = {
    1.60 +  testPrivateBrowsing: function(next) {
    1.61 +    let port = SocialSidebar.provider.getWorkerPort();
    1.62 +    ok(port, "provider has a port");
    1.63 +    postAndReceive(port, "test-init", "test-init-done", function() {
    1.64 +      // social features should all be enabled in the existing window.
    1.65 +      info("checking main window ui");
    1.66 +      ok(window.SocialUI.enabled, "social is enabled in normal window");
    1.67 +      checkSocialUI(window);
    1.68 +      // open a new private-window
    1.69 +      openPBWindow(function(pbwin) {
    1.70 +        // The provider should remain alive.
    1.71 +        postAndReceive(port, "ping", "pong", function() {
    1.72 +          // the new window should have no social features at all.
    1.73 +          info("checking private window ui");
    1.74 +          ok(!pbwin.SocialUI.enabled, "social is disabled in a PB window");
    1.75 +          checkSocialUI(pbwin);
    1.76 +
    1.77 +          // but they should all remain enabled in the initial window
    1.78 +          info("checking main window ui");
    1.79 +          ok(window.SocialUI.enabled, "social is still enabled in normal window");
    1.80 +          checkSocialUI(window);
    1.81 +
    1.82 +          // Check that the status button is disabled on the private
    1.83 +          // browsing window and not on the normal window.
    1.84 +          let id = SocialStatus._toolbarHelper.idFromOrigin("https://example.com");
    1.85 +          let widget = CustomizableUI.getWidget(id);
    1.86 +          ok(widget.forWindow(pbwin).node.disabled, "status button disabled on private window");
    1.87 +          ok(!widget.forWindow(window).node.disabled, "status button enabled on normal window");
    1.88 +
    1.89 +          // Check that the mark button is disabled on the private
    1.90 +          // browsing window and not on the normal window.
    1.91 +          id = SocialMarks._toolbarHelper.idFromOrigin("https://example.com");
    1.92 +          widget = CustomizableUI.getWidget(id);
    1.93 +          ok(widget.forWindow(pbwin).node.disabled, "mark button disabled on private window");
    1.94 +          ok(!widget.forWindow(window).node.disabled, "mark button enabled on normal window");
    1.95 +
    1.96 +          // that's all folks...
    1.97 +          pbwin.close();
    1.98 +          next();
    1.99 +        })
   1.100 +      });
   1.101 +    });
   1.102 +  },
   1.103 +}

mercurial