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

mercurial