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

mercurial