browser/base/content/test/social/browser_social_multiprovider.js

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

mercurial