browser/base/content/test/social/browser_social_sidebar.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_sidebar.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,99 @@
     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 +let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService;
     1.9 +
    1.10 +let manifest = { // normal provider
    1.11 +  name: "provider 1",
    1.12 +  origin: "https://example.com",
    1.13 +  sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
    1.14 +  workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
    1.15 +  iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png"
    1.16 +};
    1.17 +
    1.18 +function test() {
    1.19 +  waitForExplicitFinish();
    1.20 +
    1.21 +  SocialService.addProvider(manifest, function() {
    1.22 +    // the test will remove the provider
    1.23 +    doTest();
    1.24 +  });
    1.25 +}
    1.26 +
    1.27 +function doTest() {
    1.28 +  ok(SocialSidebar.canShow, "social sidebar should be able to be shown");
    1.29 +  ok(!SocialSidebar.opened, "social sidebar should not be open by default");
    1.30 +  SocialSidebar.show();
    1.31 +
    1.32 +  let command = document.getElementById("Social:ToggleSidebar");
    1.33 +  let sidebar = document.getElementById("social-sidebar-box");
    1.34 +  let browser = sidebar.lastChild;
    1.35 +
    1.36 +  function checkShown(shouldBeShown) {
    1.37 +    is(command.getAttribute("checked"), shouldBeShown ? "true" : "false",
    1.38 +       "toggle command should be " + (shouldBeShown ? "checked" : "unchecked"));
    1.39 +    is(sidebar.hidden, !shouldBeShown,
    1.40 +       "sidebar should be " + (shouldBeShown ? "visible" : "hidden"));
    1.41 +    if (shouldBeShown) {
    1.42 +      is(browser.getAttribute('src'), SocialSidebar.provider.sidebarURL, "sidebar url should be set");
    1.43 +      // We don't currently check docShellIsActive as this is only set
    1.44 +      // after load event fires, and the tests below explicitly wait for this
    1.45 +      // anyway.
    1.46 +    }
    1.47 +    else {
    1.48 +      ok(!browser.docShellIsActive, "sidebar should have an inactive docshell");
    1.49 +      // sidebar will only be immediately unloaded (and thus set to
    1.50 +      // about:blank) when canShow is false.
    1.51 +      if (SocialSidebar.canShow) {
    1.52 +        // should not have unloaded so will still be the provider URL.
    1.53 +        is(browser.getAttribute('src'), SocialSidebar.provider.sidebarURL, "sidebar url should be set");
    1.54 +      } else {
    1.55 +        // should have been an immediate unload.
    1.56 +        is(browser.getAttribute('src'), "about:blank", "sidebar url should be blank");
    1.57 +      }
    1.58 +    }
    1.59 +  }
    1.60 +
    1.61 +  // First check the the sidebar is initially visible, and loaded
    1.62 +  ok(!command.hidden, "toggle command should be visible");
    1.63 +  checkShown(true);
    1.64 +
    1.65 +  browser.addEventListener("socialFrameHide", function sidebarhide() {
    1.66 +    browser.removeEventListener("socialFrameHide", sidebarhide);
    1.67 +
    1.68 +    checkShown(false);
    1.69 +
    1.70 +    browser.addEventListener("socialFrameShow", function sidebarshow() {
    1.71 +      browser.removeEventListener("socialFrameShow", sidebarshow);
    1.72 +
    1.73 +      checkShown(true);
    1.74 +
    1.75 +      // disable social.
    1.76 +      SocialService.removeProvider(SocialSidebar.provider.origin, function() {
    1.77 +        checkShown(false);
    1.78 +        is(Social.providers.length, 0, "no providers left");
    1.79 +        defaultFinishChecks();
    1.80 +        // Finish the test
    1.81 +        executeSoon(finish);
    1.82 +      });
    1.83 +    });
    1.84 +
    1.85 +    // Toggle it back on
    1.86 +    info("Toggling sidebar back on");
    1.87 +    SocialSidebar.toggleSidebar();
    1.88 +  });
    1.89 +
    1.90 +  // use port messaging to ensure that the sidebar is both loaded and
    1.91 +  // ready before we run other tests
    1.92 +  let port = SocialSidebar.provider.getWorkerPort();
    1.93 +  port.postMessage({topic: "test-init"});
    1.94 +  port.onmessage = function (e) {
    1.95 +    let topic = e.data.topic;
    1.96 +    switch (topic) {
    1.97 +      case "got-sidebar-message":
    1.98 +        ok(true, "sidebar is loaded and ready");
    1.99 +        SocialSidebar.toggleSidebar();
   1.100 +    }
   1.101 +  };
   1.102 +}

mercurial