|
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 = { // builtin provider |
|
8 name: "provider example.com", |
|
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 let manifest2 = { // used for testing install |
|
15 name: "provider test1", |
|
16 origin: "https://test1.example.com", |
|
17 workerURL: "https://test1.example.com/browser/browser/base/content/test/social/social_worker.js", |
|
18 statusURL: "https://test1.example.com/browser/browser/base/content/test/social/social_panel.html", |
|
19 iconURL: "https://test1.example.com/browser/browser/base/content/test/general/moz.png", |
|
20 version: 1 |
|
21 }; |
|
22 let manifest3 = { // used for testing install |
|
23 name: "provider test2", |
|
24 origin: "https://test2.example.com", |
|
25 sidebarURL: "https://test2.example.com/browser/browser/base/content/test/social/social_sidebar.html", |
|
26 iconURL: "https://test2.example.com/browser/browser/base/content/test/general/moz.png", |
|
27 version: 1 |
|
28 }; |
|
29 |
|
30 |
|
31 function openWindowAndWaitForInit(callback) { |
|
32 let topic = "browser-delayed-startup-finished"; |
|
33 let w = OpenBrowserWindow(); |
|
34 Services.obs.addObserver(function providerSet(subject, topic, data) { |
|
35 Services.obs.removeObserver(providerSet, topic); |
|
36 executeSoon(() => callback(w)); |
|
37 }, topic, false); |
|
38 } |
|
39 |
|
40 function test() { |
|
41 waitForExplicitFinish(); |
|
42 |
|
43 runSocialTestWithProvider(manifest, function (finishcb) { |
|
44 runSocialTests(tests, undefined, undefined, function () { |
|
45 Services.prefs.clearUserPref("social.remote-install.enabled"); |
|
46 // just in case the tests failed, clear these here as well |
|
47 Services.prefs.clearUserPref("social.whitelist"); |
|
48 ok(CustomizableUI.inDefaultState, "Should be in the default state when we finish"); |
|
49 CustomizableUI.reset(); |
|
50 finishcb(); |
|
51 }); |
|
52 }); |
|
53 } |
|
54 |
|
55 var tests = { |
|
56 testNoButtonOnEnable: function(next) { |
|
57 // we expect the addon install dialog to appear, we need to accept the |
|
58 // install from the dialog. |
|
59 let panel = document.getElementById("servicesInstall-notification"); |
|
60 PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { |
|
61 PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); |
|
62 info("servicesInstall-notification panel opened"); |
|
63 panel.button.click(); |
|
64 }) |
|
65 |
|
66 let activationURL = manifest3.origin + "/browser/browser/base/content/test/social/social_activate.html" |
|
67 addTab(activationURL, function(tab) { |
|
68 let doc = tab.linkedBrowser.contentDocument; |
|
69 Social.installProvider(doc, manifest3, function(addonManifest) { |
|
70 // enable the provider so we know the button would have appeared |
|
71 SocialService.addBuiltinProvider(manifest3.origin, function(provider) { |
|
72 is(provider.origin, manifest3.origin, "provider is installed"); |
|
73 let id = SocialStatus._toolbarHelper.idFromOrigin(provider.origin); |
|
74 let widget = CustomizableUI.getWidget(id); |
|
75 ok(!widget || !widget.forWindow(window).node, "no button added to widget set"); |
|
76 Social.uninstallProvider(manifest3.origin, function() { |
|
77 gBrowser.removeTab(tab); |
|
78 next(); |
|
79 }); |
|
80 }); |
|
81 }); |
|
82 }); |
|
83 }, |
|
84 testButtonOnEnable: function(next) { |
|
85 let panel = document.getElementById("servicesInstall-notification"); |
|
86 PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { |
|
87 PopupNotifications.panel.removeEventListener("popupshown", onpopupshown); |
|
88 info("servicesInstall-notification panel opened"); |
|
89 panel.button.click(); |
|
90 }); |
|
91 |
|
92 // enable the provider now |
|
93 let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" |
|
94 addTab(activationURL, function(tab) { |
|
95 let doc = tab.linkedBrowser.contentDocument; |
|
96 Social.installProvider(doc, manifest2, function(addonManifest) { |
|
97 SocialService.addBuiltinProvider(manifest2.origin, function(provider) { |
|
98 is(provider.origin, manifest2.origin, "provider is installed"); |
|
99 let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin); |
|
100 let widget = CustomizableUI.getWidget(id).forWindow(window); |
|
101 ok(widget.node, "button added to widget set"); |
|
102 checkSocialUI(window); |
|
103 gBrowser.removeTab(tab); |
|
104 next(); |
|
105 }); |
|
106 }); |
|
107 }); |
|
108 }, |
|
109 testStatusPanel: function(next) { |
|
110 let icon = { |
|
111 name: "testIcon", |
|
112 iconURL: "chrome://browser/skin/Info.png", |
|
113 counter: 1 |
|
114 }; |
|
115 // click on panel to open and wait for visibility |
|
116 let provider = Social._getProviderFromOrigin(manifest2.origin); |
|
117 let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin); |
|
118 let widget = CustomizableUI.getWidget(id); |
|
119 let btn = widget.forWindow(window).node; |
|
120 ok(btn, "got a status button"); |
|
121 let port = provider.getWorkerPort(); |
|
122 |
|
123 port.onmessage = function (e) { |
|
124 let topic = e.data.topic; |
|
125 switch (topic) { |
|
126 case "test-init-done": |
|
127 ok(true, "test-init-done received"); |
|
128 ok(provider.profile.userName, "profile was set by test worker"); |
|
129 btn.click(); |
|
130 break; |
|
131 case "got-social-panel-visibility": |
|
132 ok(true, "got the panel message " + e.data.result); |
|
133 if (e.data.result == "shown") { |
|
134 let panel = document.getElementById("social-notification-panel"); |
|
135 panel.hidePopup(); |
|
136 } else { |
|
137 port.postMessage({topic: "test-ambient-notification", data: icon}); |
|
138 port.close(); |
|
139 waitForCondition(function() { return btn.getAttribute("badge"); }, |
|
140 function() { |
|
141 is(btn.style.listStyleImage, "url(\"" + icon.iconURL + "\")", "notification icon updated"); |
|
142 next(); |
|
143 }, "button updated by notification"); |
|
144 } |
|
145 break; |
|
146 } |
|
147 }; |
|
148 port.postMessage({topic: "test-init"}); |
|
149 }, |
|
150 testButtonOnDisable: function(next) { |
|
151 // enable the provider now |
|
152 let provider = Social._getProviderFromOrigin(manifest2.origin); |
|
153 ok(provider, "provider is installed"); |
|
154 SocialService.removeProvider(manifest2.origin, function() { |
|
155 let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin); |
|
156 waitForCondition(function() { return !document.getElementById(id) }, |
|
157 function() { |
|
158 Social.uninstallProvider(manifest2.origin, next); |
|
159 }, "button does not exist after disabling the provider"); |
|
160 }); |
|
161 } |
|
162 } |