|
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 let SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).SocialService; |
|
6 |
|
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 }; |
|
14 |
|
15 function test() { |
|
16 waitForExplicitFinish(); |
|
17 |
|
18 SocialService.addProvider(manifest, function() { |
|
19 // the test will remove the provider |
|
20 doTest(); |
|
21 }); |
|
22 } |
|
23 |
|
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(); |
|
28 |
|
29 let command = document.getElementById("Social:ToggleSidebar"); |
|
30 let sidebar = document.getElementById("social-sidebar-box"); |
|
31 let browser = sidebar.lastChild; |
|
32 |
|
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 } |
|
57 |
|
58 // First check the the sidebar is initially visible, and loaded |
|
59 ok(!command.hidden, "toggle command should be visible"); |
|
60 checkShown(true); |
|
61 |
|
62 browser.addEventListener("socialFrameHide", function sidebarhide() { |
|
63 browser.removeEventListener("socialFrameHide", sidebarhide); |
|
64 |
|
65 checkShown(false); |
|
66 |
|
67 browser.addEventListener("socialFrameShow", function sidebarshow() { |
|
68 browser.removeEventListener("socialFrameShow", sidebarshow); |
|
69 |
|
70 checkShown(true); |
|
71 |
|
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 }); |
|
81 |
|
82 // Toggle it back on |
|
83 info("Toggling sidebar back on"); |
|
84 SocialSidebar.toggleSidebar(); |
|
85 }); |
|
86 |
|
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 } |