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 | let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; |
michael@0 | 6 | |
michael@0 | 7 | let manifest = { // normal provider |
michael@0 | 8 | name: "provider 1", |
michael@0 | 9 | origin: "https://example.com", |
michael@0 | 10 | sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html", |
michael@0 | 11 | workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", |
michael@0 | 12 | iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png" |
michael@0 | 13 | }; |
michael@0 | 14 | |
michael@0 | 15 | function test() { |
michael@0 | 16 | waitForExplicitFinish(); |
michael@0 | 17 | |
michael@0 | 18 | SocialService.addProvider(manifest, function() { |
michael@0 | 19 | // the test will remove the provider |
michael@0 | 20 | doTest(); |
michael@0 | 21 | }); |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | function doTest() { |
michael@0 | 25 | ok(SocialSidebar.canShow, "social sidebar should be able to be shown"); |
michael@0 | 26 | ok(!SocialSidebar.opened, "social sidebar should not be open by default"); |
michael@0 | 27 | SocialSidebar.show(); |
michael@0 | 28 | |
michael@0 | 29 | let command = document.getElementById("Social:ToggleSidebar"); |
michael@0 | 30 | let sidebar = document.getElementById("social-sidebar-box"); |
michael@0 | 31 | let browser = sidebar.lastChild; |
michael@0 | 32 | |
michael@0 | 33 | function checkShown(shouldBeShown) { |
michael@0 | 34 | is(command.getAttribute("checked"), shouldBeShown ? "true" : "false", |
michael@0 | 35 | "toggle command should be " + (shouldBeShown ? "checked" : "unchecked")); |
michael@0 | 36 | is(sidebar.hidden, !shouldBeShown, |
michael@0 | 37 | "sidebar should be " + (shouldBeShown ? "visible" : "hidden")); |
michael@0 | 38 | if (shouldBeShown) { |
michael@0 | 39 | is(browser.getAttribute('src'), SocialSidebar.provider.sidebarURL, "sidebar url should be set"); |
michael@0 | 40 | // We don't currently check docShellIsActive as this is only set |
michael@0 | 41 | // after load event fires, and the tests below explicitly wait for this |
michael@0 | 42 | // anyway. |
michael@0 | 43 | } |
michael@0 | 44 | else { |
michael@0 | 45 | ok(!browser.docShellIsActive, "sidebar should have an inactive docshell"); |
michael@0 | 46 | // sidebar will only be immediately unloaded (and thus set to |
michael@0 | 47 | // about:blank) when canShow is false. |
michael@0 | 48 | if (SocialSidebar.canShow) { |
michael@0 | 49 | // should not have unloaded so will still be the provider URL. |
michael@0 | 50 | is(browser.getAttribute('src'), SocialSidebar.provider.sidebarURL, "sidebar url should be set"); |
michael@0 | 51 | } else { |
michael@0 | 52 | // should have been an immediate unload. |
michael@0 | 53 | is(browser.getAttribute('src'), "about:blank", "sidebar url should be blank"); |
michael@0 | 54 | } |
michael@0 | 55 | } |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | // First check the the sidebar is initially visible, and loaded |
michael@0 | 59 | ok(!command.hidden, "toggle command should be visible"); |
michael@0 | 60 | checkShown(true); |
michael@0 | 61 | |
michael@0 | 62 | browser.addEventListener("socialFrameHide", function sidebarhide() { |
michael@0 | 63 | browser.removeEventListener("socialFrameHide", sidebarhide); |
michael@0 | 64 | |
michael@0 | 65 | checkShown(false); |
michael@0 | 66 | |
michael@0 | 67 | browser.addEventListener("socialFrameShow", function sidebarshow() { |
michael@0 | 68 | browser.removeEventListener("socialFrameShow", sidebarshow); |
michael@0 | 69 | |
michael@0 | 70 | checkShown(true); |
michael@0 | 71 | |
michael@0 | 72 | // disable social. |
michael@0 | 73 | SocialService.removeProvider(SocialSidebar.provider.origin, function() { |
michael@0 | 74 | checkShown(false); |
michael@0 | 75 | is(Social.providers.length, 0, "no providers left"); |
michael@0 | 76 | defaultFinishChecks(); |
michael@0 | 77 | // Finish the test |
michael@0 | 78 | executeSoon(finish); |
michael@0 | 79 | }); |
michael@0 | 80 | }); |
michael@0 | 81 | |
michael@0 | 82 | // Toggle it back on |
michael@0 | 83 | info("Toggling sidebar back on"); |
michael@0 | 84 | SocialSidebar.toggleSidebar(); |
michael@0 | 85 | }); |
michael@0 | 86 | |
michael@0 | 87 | // use port messaging to ensure that the sidebar is both loaded and |
michael@0 | 88 | // ready before we run other tests |
michael@0 | 89 | let port = SocialSidebar.provider.getWorkerPort(); |
michael@0 | 90 | port.postMessage({topic: "test-init"}); |
michael@0 | 91 | port.onmessage = function (e) { |
michael@0 | 92 | let topic = e.data.topic; |
michael@0 | 93 | switch (topic) { |
michael@0 | 94 | case "got-sidebar-message": |
michael@0 | 95 | ok(true, "sidebar is loaded and ready"); |
michael@0 | 96 | SocialSidebar.toggleSidebar(); |
michael@0 | 97 | } |
michael@0 | 98 | }; |
michael@0 | 99 | } |