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