browser/base/content/test/social/browser_social_multiprovider.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_multiprovider.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     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 +function test() {
     1.9 +  waitForExplicitFinish();
    1.10 +  runSocialTestWithProvider(gProviders, function (finishcb) {
    1.11 +    SocialSidebar.provider = Social.providers[0];
    1.12 +    SocialSidebar.show();
    1.13 +    is(Social.providers[0].origin, SocialSidebar.provider.origin, "selected provider in sidebar");
    1.14 +    runSocialTests(tests, undefined, undefined, finishcb);
    1.15 +  });
    1.16 +}
    1.17 +
    1.18 +let gProviders = [
    1.19 +  {
    1.20 +    name: "provider 1",
    1.21 +    origin: "https://test1.example.com",
    1.22 +    sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html?provider1",
    1.23 +    workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js",
    1.24 +    iconURL: "chrome://branding/content/icon48.png"
    1.25 +  },
    1.26 +  {
    1.27 +    name: "provider 2",
    1.28 +    origin: "https://test2.example.com",
    1.29 +    sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html?provider2",
    1.30 +    workerURL: "https://test2.example.com/browser/browser/base/content/test/social/social_worker.js",
    1.31 +    iconURL: "chrome://branding/content/icon48.png"
    1.32 +  }
    1.33 +];
    1.34 +
    1.35 +var tests = {
    1.36 +  testProviderSwitch: function(next) {
    1.37 +    let menu = document.getElementById("social-statusarea-popup");
    1.38 +    let button = document.getElementById("social-sidebar-button");
    1.39 +    function checkProviderMenu(selectedProvider) {
    1.40 +      let menuProviders = menu.querySelectorAll(".social-provider-menuitem");
    1.41 +      is(menuProviders.length, gProviders.length, "correct number of providers listed in the menu");
    1.42 +      // Find the selectedProvider's menu item
    1.43 +      let el = menu.getElementsByAttribute("origin", selectedProvider.origin);
    1.44 +      is(el.length, 1, "selected provider menu item exists");
    1.45 +      is(el[0].getAttribute("checked"), "true", "selected provider menu item is checked");
    1.46 +    }
    1.47 +
    1.48 +    // the menu is not populated until onpopupshowing, so wait for popupshown
    1.49 +    function theTest() {
    1.50 +      menu.removeEventListener("popupshown", theTest, true);
    1.51 +      menu.hidePopup(); // doesn't need visibility
    1.52 +      // first provider should already be visible in the sidebar
    1.53 +      is(Social.providers[0].origin, SocialSidebar.provider.origin, "selected provider in sidebar");
    1.54 +      checkProviderMenu(Social.providers[0]);
    1.55 +
    1.56 +      // Now activate "provider 2"
    1.57 +      onSidebarLoad(function() {
    1.58 +        checkUIStateMatchesProvider(Social.providers[1]);
    1.59 +
    1.60 +        onSidebarLoad(function() {
    1.61 +          checkUIStateMatchesProvider(Social.providers[0]);
    1.62 +          next();
    1.63 +        });
    1.64 +
    1.65 +        // show the menu again so the menu is updated with the correct commands
    1.66 +        function doClick() {
    1.67 +          // click on the provider menuitem to switch providers
    1.68 +          let el = menu.getElementsByAttribute("origin", Social.providers[0].origin);
    1.69 +          is(el.length, 1, "selected provider menu item exists");
    1.70 +          EventUtils.synthesizeMouseAtCenter(el[0], {});
    1.71 +        }
    1.72 +        menu.addEventListener("popupshown", doClick, true);
    1.73 +        EventUtils.synthesizeMouseAtCenter(button, {});
    1.74 +
    1.75 +      });
    1.76 +      SocialSidebar.provider = Social.providers[1];
    1.77 +    };
    1.78 +    menu.addEventListener("popupshown", theTest, true);
    1.79 +    EventUtils.synthesizeMouseAtCenter(button, {});
    1.80 +  }
    1.81 +}
    1.82 +
    1.83 +function checkUIStateMatchesProvider(provider) {
    1.84 +  // Sidebar
    1.85 +  is(document.getElementById("social-sidebar-browser").getAttribute("src"), provider.sidebarURL, "side bar URL is set");
    1.86 +}
    1.87 +
    1.88 +function onSidebarLoad(callback) {
    1.89 +  let sbrowser = document.getElementById("social-sidebar-browser");
    1.90 +  sbrowser.addEventListener("load", function load() {
    1.91 +    sbrowser.removeEventListener("load", load, true);
    1.92 +    // give the load a chance to finish before pulling the rug (ie. calling
    1.93 +    // next)
    1.94 +    executeSoon(callback);
    1.95 +  }, true);
    1.96 +}

mercurial