gecko/browser/base/content/test/browser_social_mozSocial_API.js
Jared Wein 8ccee29469 Bug 779360 - Implement mozSocial.isVisible API for social sidebar window, r=felipe
--HG--
extra : transplant_source : %1FB%A6T%7B%9D%60T%E6%95%CD%A7%27%E5%00%60%A5%B8%84%F8
2012-08-20 14:18:50 -07:00

126 lines
4.4 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function test() {
waitForExplicitFinish();
let manifest = { // normal provider
name: "provider 1",
origin: "https://example.com",
sidebarURL: "https://example.com/browser/browser/base/content/test/social_sidebar.html",
workerURL: "https://example.com/browser/browser/base/content/test/social_worker.js",
iconURL: "chrome://branding/content/icon48.png"
};
runSocialTestWithProvider(manifest, function (finishcb) {
runSocialTests(tests, undefined, undefined, finishcb);
});
}
var tests = {
testStatusIcons: function(next) {
let iconsReady = false;
let gotSidebarMessage = false;
function checkNext() {
if (iconsReady && gotSidebarMessage)
triggerIconPanel();
}
function triggerIconPanel() {
let statusIcons = document.getElementById("social-status-iconbox");
ok(!statusIcons.firstChild.hidden, "status icon is visible");
// Click the button to trigger its contentPanel
let panel = document.getElementById("social-notification-panel");
EventUtils.synthesizeMouseAtCenter(statusIcons.firstChild, {});
}
let port = Social.provider.port;
ok(port, "provider has a port");
port.postMessage({topic: "test-init"});
Social.provider.port.onmessage = function (e) {
let topic = e.data.topic;
switch (topic) {
case "got-panel-message":
ok(true, "got panel message");
// Wait for the panel to close before ending the test
let panel = document.getElementById("social-notification-panel");
panel.addEventListener("popuphidden", function hiddenListener() {
panel.removeEventListener("popuphidden", hiddenListener);
next();
});
panel.hidePopup();
break;
case "got-sidebar-message":
// The sidebar message will always come first, since it loads by default
ok(true, "got sidebar message");
gotSidebarMessage = true;
checkNext();
break;
}
}
// Our worker sets up ambient notification at the same time as it responds to
// the workerAPI initialization. If it's already initialized, we can
// immediately check the icons, otherwise wait for initialization by
// observing the topic sent out by the social service.
if (Social.provider.workerAPI.initialized) {
iconsReady = true;
checkNext();
} else {
Services.obs.addObserver(function obs() {
Services.obs.removeObserver(obs, "social:ambient-notification-changed");
// Let the other observers (like the one that updates the UI) run before
// checking the icons.
executeSoon(function () {
iconsReady = true;
checkNext();
});
}, "social:ambient-notification-changed", false);
}
},
testServiceWindow: function(next) {
// our test provider was initialized in the test above, we just
// initiate our specific test now.
let port = Social.provider.port;
ok(port, "provider has a port");
port.postMessage({topic: "test-service-window"});
port.onmessage = function (e) {
let topic = e.data.topic;
switch (topic) {
case "got-service-window-message":
// The sidebar message will always come first, since it loads by default
ok(true, "got service window message");
port.postMessage({topic: "test-close-service-window"});
break;
case "got-service-window-closed-message":
ok(true, "got service window closed message");
next();
break;
}
}
},
testServiceWindowTwice: function(next) {
let port = Social.provider.port;
port.postMessage({topic: "test-service-window-twice"});
Social.provider.port.onmessage = function (e) {
let topic = e.data.topic;
switch (topic) {
case "test-service-window-twice-result":
is(e.data.result, "ok", "only one window should open when name is reused");
break;
case "got-service-window-message":
ok(true, "got service window message");
port.postMessage({topic: "test-close-service-window"});
break;
case "got-service-window-closed-message":
ok(true, "got service window closed message");
next();
break;
}
}
}
}