browser/base/content/test/social/browser_social_multiprovider.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.

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 test() {
michael@0 6 waitForExplicitFinish();
michael@0 7 runSocialTestWithProvider(gProviders, function (finishcb) {
michael@0 8 SocialSidebar.provider = Social.providers[0];
michael@0 9 SocialSidebar.show();
michael@0 10 is(Social.providers[0].origin, SocialSidebar.provider.origin, "selected provider in sidebar");
michael@0 11 runSocialTests(tests, undefined, undefined, finishcb);
michael@0 12 });
michael@0 13 }
michael@0 14
michael@0 15 let gProviders = [
michael@0 16 {
michael@0 17 name: "provider 1",
michael@0 18 origin: "https://test1.example.com",
michael@0 19 sidebarURL: "https://test1.example.com/browser/browser/base/content/test/social/social_sidebar.html?provider1",
michael@0 20 workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js",
michael@0 21 iconURL: "chrome://branding/content/icon48.png"
michael@0 22 },
michael@0 23 {
michael@0 24 name: "provider 2",
michael@0 25 origin: "https://test2.example.com",
michael@0 26 sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html?provider2",
michael@0 27 workerURL: "https://test2.example.com/browser/browser/base/content/test/social/social_worker.js",
michael@0 28 iconURL: "chrome://branding/content/icon48.png"
michael@0 29 }
michael@0 30 ];
michael@0 31
michael@0 32 var tests = {
michael@0 33 testProviderSwitch: function(next) {
michael@0 34 let menu = document.getElementById("social-statusarea-popup");
michael@0 35 let button = document.getElementById("social-sidebar-button");
michael@0 36 function checkProviderMenu(selectedProvider) {
michael@0 37 let menuProviders = menu.querySelectorAll(".social-provider-menuitem");
michael@0 38 is(menuProviders.length, gProviders.length, "correct number of providers listed in the menu");
michael@0 39 // Find the selectedProvider's menu item
michael@0 40 let el = menu.getElementsByAttribute("origin", selectedProvider.origin);
michael@0 41 is(el.length, 1, "selected provider menu item exists");
michael@0 42 is(el[0].getAttribute("checked"), "true", "selected provider menu item is checked");
michael@0 43 }
michael@0 44
michael@0 45 // the menu is not populated until onpopupshowing, so wait for popupshown
michael@0 46 function theTest() {
michael@0 47 menu.removeEventListener("popupshown", theTest, true);
michael@0 48 menu.hidePopup(); // doesn't need visibility
michael@0 49 // first provider should already be visible in the sidebar
michael@0 50 is(Social.providers[0].origin, SocialSidebar.provider.origin, "selected provider in sidebar");
michael@0 51 checkProviderMenu(Social.providers[0]);
michael@0 52
michael@0 53 // Now activate "provider 2"
michael@0 54 onSidebarLoad(function() {
michael@0 55 checkUIStateMatchesProvider(Social.providers[1]);
michael@0 56
michael@0 57 onSidebarLoad(function() {
michael@0 58 checkUIStateMatchesProvider(Social.providers[0]);
michael@0 59 next();
michael@0 60 });
michael@0 61
michael@0 62 // show the menu again so the menu is updated with the correct commands
michael@0 63 function doClick() {
michael@0 64 // click on the provider menuitem to switch providers
michael@0 65 let el = menu.getElementsByAttribute("origin", Social.providers[0].origin);
michael@0 66 is(el.length, 1, "selected provider menu item exists");
michael@0 67 EventUtils.synthesizeMouseAtCenter(el[0], {});
michael@0 68 }
michael@0 69 menu.addEventListener("popupshown", doClick, true);
michael@0 70 EventUtils.synthesizeMouseAtCenter(button, {});
michael@0 71
michael@0 72 });
michael@0 73 SocialSidebar.provider = Social.providers[1];
michael@0 74 };
michael@0 75 menu.addEventListener("popupshown", theTest, true);
michael@0 76 EventUtils.synthesizeMouseAtCenter(button, {});
michael@0 77 }
michael@0 78 }
michael@0 79
michael@0 80 function checkUIStateMatchesProvider(provider) {
michael@0 81 // Sidebar
michael@0 82 is(document.getElementById("social-sidebar-browser").getAttribute("src"), provider.sidebarURL, "side bar URL is set");
michael@0 83 }
michael@0 84
michael@0 85 function onSidebarLoad(callback) {
michael@0 86 let sbrowser = document.getElementById("social-sidebar-browser");
michael@0 87 sbrowser.addEventListener("load", function load() {
michael@0 88 sbrowser.removeEventListener("load", load, true);
michael@0 89 // give the load a chance to finish before pulling the rug (ie. calling
michael@0 90 // next)
michael@0 91 executeSoon(callback);
michael@0 92 }, true);
michael@0 93 }

mercurial