michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function openTab(win, url, callback) { michael@0: let newTab = win.gBrowser.addTab(url); michael@0: let tabBrowser = win.gBrowser.getBrowserForTab(newTab); michael@0: tabBrowser.addEventListener("load", function tabLoadListener() { michael@0: tabBrowser.removeEventListener("load", tabLoadListener, true); michael@0: win.gBrowser.selectedTab = newTab; michael@0: callback(newTab); michael@0: }, true) michael@0: } michael@0: michael@0: // Tests for per-window private browsing. michael@0: function openPBWindow(callback) { michael@0: let w = OpenBrowserWindow({private: true}); michael@0: w.addEventListener("load", function loadListener() { michael@0: w.removeEventListener("load", loadListener); michael@0: openTab(w, "http://example.com", function() { michael@0: callback(w); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function postAndReceive(port, postTopic, receiveTopic, callback) { michael@0: port.onmessage = function(e) { michael@0: if (e.data.topic == receiveTopic) michael@0: callback(); michael@0: } michael@0: port.postMessage({topic: postTopic}); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: let manifest = { // normal provider michael@0: name: "provider 1", michael@0: origin: "https://example.com", michael@0: sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html", michael@0: statusURL: "https://example.com/browser/browser/base/content/test/social/social_panel.html", michael@0: workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", michael@0: markURL: "https://example.com/browser/browser/base/content/test/social/social_mark.html?url=%{url}", michael@0: iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png" michael@0: }; michael@0: runSocialTestWithProvider(manifest, function (finishcb) { michael@0: openTab(window, "http://example.com", function(newTab) { michael@0: runSocialTests(tests, undefined, undefined, function() { michael@0: window.gBrowser.removeTab(newTab); michael@0: finishcb(); michael@0: }); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: var tests = { michael@0: testPrivateBrowsing: function(next) { michael@0: let port = SocialSidebar.provider.getWorkerPort(); michael@0: ok(port, "provider has a port"); michael@0: postAndReceive(port, "test-init", "test-init-done", function() { michael@0: // social features should all be enabled in the existing window. michael@0: info("checking main window ui"); michael@0: ok(window.SocialUI.enabled, "social is enabled in normal window"); michael@0: checkSocialUI(window); michael@0: // open a new private-window michael@0: openPBWindow(function(pbwin) { michael@0: // The provider should remain alive. michael@0: postAndReceive(port, "ping", "pong", function() { michael@0: // the new window should have no social features at all. michael@0: info("checking private window ui"); michael@0: ok(!pbwin.SocialUI.enabled, "social is disabled in a PB window"); michael@0: checkSocialUI(pbwin); michael@0: michael@0: // but they should all remain enabled in the initial window michael@0: info("checking main window ui"); michael@0: ok(window.SocialUI.enabled, "social is still enabled in normal window"); michael@0: checkSocialUI(window); michael@0: michael@0: // Check that the status button is disabled on the private michael@0: // browsing window and not on the normal window. michael@0: let id = SocialStatus._toolbarHelper.idFromOrigin("https://example.com"); michael@0: let widget = CustomizableUI.getWidget(id); michael@0: ok(widget.forWindow(pbwin).node.disabled, "status button disabled on private window"); michael@0: ok(!widget.forWindow(window).node.disabled, "status button enabled on normal window"); michael@0: michael@0: // Check that the mark button is disabled on the private michael@0: // browsing window and not on the normal window. michael@0: id = SocialMarks._toolbarHelper.idFromOrigin("https://example.com"); michael@0: widget = CustomizableUI.getWidget(id); michael@0: ok(widget.forWindow(pbwin).node.disabled, "mark button disabled on private window"); michael@0: ok(!widget.forWindow(window).node.disabled, "mark button enabled on normal window"); michael@0: michael@0: // that's all folks... michael@0: pbwin.close(); michael@0: next(); michael@0: }) michael@0: }); michael@0: }); michael@0: }, michael@0: }