Bug 1219101 more updates to current infra for socialapi tests, fixes intermittent bug 1219101, r=markh

MozReview-Commit-ID: JOwtSkjIwQ1

--HG--
extra : rebase_source : 01187c73d6f6cc3126ce67f9bceb731074b0ea2b
This commit is contained in:
Shane Caraveo 2016-07-20 13:53:09 -07:00
Родитель 7b6a6a19d3
Коммит 5639861258
17 изменённых файлов: 346 добавлений и 476 удалений

Просмотреть файл

@ -24,6 +24,10 @@ var manifestUpgrade = { // used for testing install
function test() { function test() {
waitForExplicitFinish(); waitForExplicitFinish();
PopupNotifications.panel.setAttribute("animate", "false");
registerCleanupFunction(function () {
PopupNotifications.panel.removeAttribute("animate");
});
let prefname = getManifestPrefname(manifest); let prefname = getManifestPrefname(manifest);
// ensure that manifest2 is NOT showing as builtin // ensure that manifest2 is NOT showing as builtin
@ -189,7 +193,7 @@ var tests = {
testDirectoryInstall: function(next) { testDirectoryInstall: function(next) {
AddonManager.addAddonListener(installListener(next, manifest2)); AddonManager.addAddonListener(installListener(next, manifest2));
ensureEventFired(PopupNotifications.panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
let panel = document.getElementById("servicesInstall-notification"); let panel = document.getElementById("servicesInstall-notification");
info("servicesInstall-notification panel opened"); info("servicesInstall-notification panel opened");
panel.button.click(); panel.button.click();

Просмотреть файл

@ -22,6 +22,36 @@ var manifest_bad = { // normal provider
iconURL: "https://test1.example.com/browser/browser/base/content/test/general/moz.png" iconURL: "https://test1.example.com/browser/browser/base/content/test/general/moz.png"
}; };
// blocklist testing
function updateBlocklist() {
var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"]
.getService(Ci.nsITimerCallback);
let promise = promiseObserverNotified("blocklist-updated");
blocklistNotifier.notify(null);
return promise;
}
var _originalTestBlocklistURL = null;
function setAndUpdateBlocklist(aURL) {
if (!_originalTestBlocklistURL)
_originalTestBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url");
Services.prefs.setCharPref("extensions.blocklist.url", aURL);
return updateBlocklist();
}
function resetBlocklist() {
// XXX - this has "forked" from the head.js helpers in our parent directory :(
// But let's reuse their blockNoPlugins.xml. Later, we should arrange to
// use their head.js helpers directly
let noBlockedURL = "http://example.com/browser/browser/base/content/test/plugins/blockNoPlugins.xml";
return new Promise(resolve => {
setAndUpdateBlocklist(noBlockedURL).then(() => {
Services.prefs.setCharPref("extensions.blocklist.url", _originalTestBlocklistURL);
resolve();
});
});
}
function test() { function test() {
waitForExplicitFinish(); waitForExplicitFinish();
// turn on logging for nsBlocklistService.js // turn on logging for nsBlocklistService.js
@ -31,17 +61,17 @@ function test() {
}); });
runSocialTests(tests, undefined, undefined, function () { runSocialTests(tests, undefined, undefined, function () {
resetBlocklist(finish); //restore to original pref resetBlocklist().then(finish); //restore to original pref
}); });
} }
var tests = { var tests = {
testSimpleBlocklist: function(next) { testSimpleBlocklist: function(next) {
// this really just tests adding and clearing our blocklist for later tests // this really just tests adding and clearing our blocklist for later tests
setAndUpdateBlocklist(blocklistURL, function() { setAndUpdateBlocklist(blocklistURL).then(() => {
ok(Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest_bad)), "blocking 'blocked'"); ok(Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest_bad)), "blocking 'blocked'");
ok(!Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest)), "not blocking 'good'"); ok(!Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest)), "not blocking 'good'");
resetBlocklist(function() { resetBlocklist().then(() => {
ok(!Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest_bad)), "blocklist cleared"); ok(!Services.blocklist.isAddonBlocklisted(SocialService.createWrapper(manifest_bad)), "blocklist cleared");
next(); next();
}); });
@ -51,10 +81,10 @@ var tests = {
function finishTest(isgood) { function finishTest(isgood) {
ok(isgood, "adding non-blocked provider ok"); ok(isgood, "adding non-blocked provider ok");
Services.prefs.clearUserPref("social.manifest.good"); Services.prefs.clearUserPref("social.manifest.good");
resetBlocklist(next); resetBlocklist().then(next);
} }
setManifestPref("social.manifest.good", manifest); setManifestPref("social.manifest.good", manifest);
setAndUpdateBlocklist(blocklistURL, function() { setAndUpdateBlocklist(blocklistURL).then(() => {
try { try {
SocialService.addProvider(manifest, function(provider) { SocialService.addProvider(manifest, function(provider) {
try { try {
@ -77,10 +107,10 @@ var tests = {
function finishTest(good) { function finishTest(good) {
ok(good, "Unable to add blocklisted provider"); ok(good, "Unable to add blocklisted provider");
Services.prefs.clearUserPref("social.manifest.blocked"); Services.prefs.clearUserPref("social.manifest.blocked");
resetBlocklist(next); resetBlocklist().then(next);
} }
setManifestPref("social.manifest.blocked", manifest_bad); setManifestPref("social.manifest.blocked", manifest_bad);
setAndUpdateBlocklist(blocklistURL, function() { setAndUpdateBlocklist(blocklistURL).then(() => {
try { try {
SocialService.addProvider(manifest_bad, function(provider) { SocialService.addProvider(manifest_bad, function(provider) {
SocialService.disableProvider(provider.origin, function() { SocialService.disableProvider(provider.origin, function() {
@ -96,36 +126,26 @@ var tests = {
}, },
testInstallingBlockedProvider: function(next) { testInstallingBlockedProvider: function(next) {
function finishTest(good) { function finishTest(good) {
ok(good, "Unable to add blocklisted provider"); ok(good, "Unable to install blocklisted provider");
Services.prefs.clearUserPref("social.whitelist"); resetBlocklist().then(next);
resetBlocklist(next);
} }
let activationURL = manifest_bad.origin + "/browser/browser/base/content/test/social/social_activate.html" let activationURL = manifest_bad.origin + "/browser/browser/base/content/test/social/social_activate.html"
addTab(activationURL, function(tab) { setAndUpdateBlocklist(blocklistURL).then(() => {
let doc = tab.linkedBrowser.contentDocument; try {
let installFrom = doc.nodePrincipal.origin; // expecting an exception when attempting to install a hard blocked
// whitelist to avoid the 3rd party install dialog, we only want to test // provider
// the blocklist inside installProvider. let data = {
Services.prefs.setCharPref("social.whitelist", installFrom); origin: manifest_bad.origin,
setAndUpdateBlocklist(blocklistURL, function() { url: activationURL,
try { manifest: manifest_bad,
// expecting an exception when attempting to install a hard blocked window: window
// provider
let data = {
origin: doc.nodePrincipal.origin,
url: doc.location.href,
manifest: manifest_bad,
window: window
}
Social.installProvider(data, function(addonManifest) {
gBrowser.removeTab(tab);
finishTest(false);
});
} catch(e) {
gBrowser.removeTab(tab);
finishTest(true);
} }
}); Social.installProvider(data, function(addonManifest) {
finishTest(false);
});
} catch(e) {
finishTest(true);
}
}); });
}, },
testBlockingExistingProvider: function(next) { testBlockingExistingProvider: function(next) {

Просмотреть файл

@ -167,7 +167,7 @@ var tests = {
SocialUI.onCustomizeEnd(window); SocialUI.onCustomizeEnd(window);
let testData = corpus[0]; let testData = corpus[0];
addTab(testData.url, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, testData.url).then(tab => {
SocialService.addProvider(manifest, function(provider) { SocialService.addProvider(manifest, function(provider) {
is(SocialUI.enabled, true, "SocialUI is enabled"); is(SocialUI.enabled, true, "SocialUI is enabled");
checkSocialUI(); checkSocialUI();
@ -177,8 +177,7 @@ var tests = {
ok(!shareButton.hasAttribute("disabled"), "share button is enabled"); ok(!shareButton.hasAttribute("disabled"), "share button is enabled");
// button should be visible // button should be visible
is(shareButton.hidden, false, "share button is visible"); is(shareButton.hidden, false, "share button is visible");
gBrowser.removeTab(tab); BrowserTestUtils.removeTab(tab).then(next);
next();
}); });
}); });
}, },
@ -196,22 +195,23 @@ var tests = {
let mm = getGroupMessageManager("social"); let mm = getGroupMessageManager("social");
mm.addMessageListener("sharedata", function handler(msg) { mm.addMessageListener("sharedata", function handler(msg) {
gBrowser.removeTab(testTab); BrowserTestUtils.removeTab(testTab).then(() => {
hasoptions(testData.options, JSON.parse(msg.data)); hasoptions(testData.options, JSON.parse(msg.data));
testData = corpus[testIndex++]; testData = corpus[testIndex++];
BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; },"share panel closed").then(() => { BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; },"share panel closed").then(() => {
if (testData) { if (testData) {
runOneTest(); runOneTest();
} else { } else {
mm.removeMessageListener("sharedata", handler); mm.removeMessageListener("sharedata", handler);
SocialService.disableProvider(manifest.origin, next); SocialService.disableProvider(manifest.origin, next);
} }
});
SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
}); });
SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
}); });
function runOneTest() { function runOneTest() {
addTab(testData.url, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, testData.url).then(tab => {
testTab = tab; testTab = tab;
let shareButton = SocialShare.shareButton; let shareButton = SocialShare.shareButton;
@ -284,15 +284,16 @@ var tests = {
is(msg.data, expecting, "microformats data ok"); is(msg.data, expecting, "microformats data ok");
BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; }, BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; },
"share panel closed").then(() => { "share panel closed").then(() => {
gBrowser.removeTab(testTab);
mm.removeMessageListener("sharedata", handler); mm.removeMessageListener("sharedata", handler);
SocialService.disableProvider(manifest.origin, next); BrowserTestUtils.removeTab(testTab).then(() => {
SocialService.disableProvider(manifest.origin, next);
});
}); });
SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {}); SocialShare.iframe.messageManager.sendAsyncMessage("closeself", {});
}); });
let url = "https://example.com/browser/browser/base/content/test/social/microformats.html" let url = "https://example.com/browser/browser/base/content/test/social/microformats.html"
addTab(url, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, url).then(tab => {
testTab = tab; testTab = tab;
let shareButton = SocialShare.shareButton; let shareButton = SocialShare.shareButton;
@ -321,7 +322,7 @@ var tests = {
// ensure correct state // ensure correct state
SocialUI.onCustomizeEnd(window); SocialUI.onCustomizeEnd(window);
ensureEventFired(iframe, "load").then(() => { ensureFrameLoaded(iframe).then(() => {
let subframe = iframe.contentDocument.getElementById("activation-frame"); let subframe = iframe.contentDocument.getElementById("activation-frame");
ensureFrameLoaded(subframe, activationPage).then(() => { ensureFrameLoaded(subframe, activationPage).then(() => {
is(subframe.contentDocument.location.href, activationPage, "activation page loaded"); is(subframe.contentDocument.location.href, activationPage, "activation page loaded");
@ -332,7 +333,7 @@ var tests = {
BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; }, BrowserTestUtils.waitForCondition(() => { return SocialShare.currentShare == null; },
"share panel closed").then(() => { "share panel closed").then(() => {
ensureBrowserTabClosed(testTab).then(() => { BrowserTestUtils.removeTab(testTab).then(() => {
mm.removeMessageListener("sharedata", handler); mm.removeMessageListener("sharedata", handler);
SocialService.uninstallProvider(manifest.origin, next); SocialService.uninstallProvider(manifest.origin, next);
}); });
@ -343,7 +344,7 @@ var tests = {
sendActivationEvent(subframe); sendActivationEvent(subframe);
}); });
}); });
addTab(activationPage, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, activationPage).then(tab => {
let shareButton = SocialShare.shareButton; let shareButton = SocialShare.shareButton;
// verify the attribute for proper css // verify the attribute for proper css
ok(!shareButton.hasAttribute("disabled"), "share button is enabled"); ok(!shareButton.hasAttribute("disabled"), "share button is enabled");
@ -363,8 +364,8 @@ var tests = {
SocialShare._createFrame(); SocialShare._createFrame();
SocialService.addProvider(manifest, () => { SocialService.addProvider(manifest, () => {
addTab(activationPage, (tab) => { BrowserTestUtils.openNewForegroundTab(gBrowser, activationPage).then(tab => {
ensureEventFired(SocialShare.iframe, "load").then(() => { ensureFrameLoaded(SocialShare.iframe).then(() => {
// send keys to the input field. An unexpected failure will happen // send keys to the input field. An unexpected failure will happen
// if the onbeforeunload handler is fired. // if the onbeforeunload handler is fired.
EventUtils.sendKey("f"); EventUtils.sendKey("f");
@ -377,7 +378,7 @@ var tests = {
let topwin = Services.wm.getMostRecentWindow(null); let topwin = Services.wm.getMostRecentWindow(null);
is(topwin, window, "no dialog is open"); is(topwin, window, "no dialog is open");
ensureBrowserTabClosed(testTab).then(() => { BrowserTestUtils.removeTab(testTab).then(() => {
SocialService.disableProvider(manifest.origin, next); SocialService.disableProvider(manifest.origin, next);
}); });
}); });

Просмотреть файл

@ -14,49 +14,39 @@ var SocialService = Cu.import("resource://gre/modules/SocialService.jsm", {}).So
var tabsToRemove = []; var tabsToRemove = [];
function removeProvider(provider) {
function removeAllProviders(callback) { return new Promise(resolve => {
// all the providers may have been added.
function removeProviders() {
if (Social.providers.length < 1) {
executeSoon(function() {
is(Social.providers.length, 0, "all providers removed");
executeSoon(callback);
});
return;
}
// a full install sets the manifest into a pref, addProvider alone doesn't, // a full install sets the manifest into a pref, addProvider alone doesn't,
// make sure we uninstall if the manifest was added. // make sure we uninstall if the manifest was added.
if (Social.providers[0].manifest) { if (provider.manifest) {
SocialService.uninstallProvider(Social.providers[0].origin, removeProviders); SocialService.uninstallProvider(provider.origin, resolve);
} else { } else {
SocialService.disableProvider(Social.providers[0].origin, removeProviders); SocialService.disableProvider(provider.origin, resolve);
} }
} });
removeProviders();
} }
function postTestCleanup(callback) { function postTestCleanup(callback) {
// any tabs opened by the test. Task.spawn(function () {
for (let tab of tabsToRemove) // any tabs opened by the test.
gBrowser.removeTab(tab); for (let tab of tabsToRemove) {
tabsToRemove = []; yield BrowserTestUtils.removeTab(tab);
// theses tests use the notification panel but don't bother waiting for it }
// to fully open - the end result is that the panel might stay open tabsToRemove = [];
//SocialUI.activationPanel.hidePopup(); // all the providers may have been added.
while (Social.providers.length > 0) {
// all the providers may have been added. yield removeProvider(Social.providers[0]);
removeAllProviders(callback); }
}).then(callback);
} }
function addTab(url, callback) { function newTab(url) {
let tab = gBrowser.selectedTab = gBrowser.addTab(url, {skipAnimation: true}); return new Promise(resolve => {
tab.linkedBrowser.addEventListener("load", function tabLoad(event) { BrowserTestUtils.openNewForegroundTab(gBrowser, url).then(tab => {
tab.linkedBrowser.removeEventListener("load", tabLoad, true); tabsToRemove.push(tab);
tabsToRemove.push(tab); resolve(tab);
executeSoon(function() {callback(tab)}); });
}, true); });
} }
function sendActivationEvent(tab, callback, nullManifest) { function sendActivationEvent(tab, callback, nullManifest) {
@ -68,34 +58,25 @@ function sendActivationEvent(tab, callback, nullManifest) {
function activateProvider(domain, callback, nullManifest) { function activateProvider(domain, callback, nullManifest) {
let activationURL = domain+"/browser/browser/base/content/test/social/social_activate_basic.html" let activationURL = domain+"/browser/browser/base/content/test/social/social_activate_basic.html"
addTab(activationURL, function(tab) { newTab(activationURL).then(tab => {
sendActivationEvent(tab, callback, nullManifest); sendActivationEvent(tab, callback, nullManifest);
}); });
} }
function activateIFrameProvider(domain, callback) { function activateIFrameProvider(domain, callback) {
let activationURL = domain+"/browser/browser/base/content/test/social/social_activate_iframe.html" let activationURL = domain+"/browser/browser/base/content/test/social/social_activate_iframe.html"
addTab(activationURL, function(tab) { newTab(activationURL).then(tab => {
sendActivationEvent(tab, callback, false); sendActivationEvent(tab, callback, false);
}); });
} }
function waitForProviderLoad(cb) { function waitForProviderLoad(origin) {
waitForCondition(function() { return Promise.all([
let sbrowser = document.getElementById("social-sidebar-browser"); ensureFrameLoaded(gBrowser, origin + "/browser/browser/base/content/test/social/social_postActivation.html"),
let provider = SocialSidebar.provider; ensureFrameLoaded(SocialSidebar.browser)
let postActivation = provider && gBrowser.currentURI && ]);
gBrowser.currentURI.spec == provider.origin + "/browser/browser/base/content/test/social/social_postActivation.html";
return postActivation && sbrowser.docShellIsActive;
}, function() {
// executeSoon to let the browser UI observers run first
executeSoon(cb);
},
"waitForProviderLoad: provider was not loaded");
} }
function getAddonItemInList(aId, aList) { function getAddonItemInList(aId, aList) {
var item = aList.firstChild; var item = aList.firstChild;
while (item) { while (item) {
@ -133,22 +114,20 @@ function clickAddonRemoveButton(tab, aCallback) {
function activateOneProvider(manifest, finishActivation, aCallback) { function activateOneProvider(manifest, finishActivation, aCallback) {
let panel = document.getElementById("servicesInstall-notification"); let panel = document.getElementById("servicesInstall-notification");
PopupNotifications.panel.addEventListener("popupshown", function onpopupshown() { BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
PopupNotifications.panel.removeEventListener("popupshown", onpopupshown);
ok(!panel.hidden, "servicesInstall-notification panel opened"); ok(!panel.hidden, "servicesInstall-notification panel opened");
if (finishActivation) if (finishActivation)
panel.button.click(); panel.button.click();
else else
panel.closebutton.click(); panel.closebutton.click();
}); });
PopupNotifications.panel.addEventListener("popuphidden", function _hidden() { BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popuphidden").then(() => {
PopupNotifications.panel.removeEventListener("popuphidden", _hidden);
ok(panel.hidden, "servicesInstall-notification panel hidden"); ok(panel.hidden, "servicesInstall-notification panel hidden");
if (!finishActivation) { if (!finishActivation) {
ok(panel.hidden, "activation panel is not showing"); ok(panel.hidden, "activation panel is not showing");
executeSoon(aCallback); executeSoon(aCallback);
} else { } else {
waitForProviderLoad(function() { waitForProviderLoad(manifest.origin).then(() => {
is(SocialSidebar.provider.origin, manifest.origin, "new provider is active"); is(SocialSidebar.provider.origin, manifest.origin, "new provider is active");
ok(SocialSidebar.opened, "sidebar is open"); ok(SocialSidebar.opened, "sidebar is open");
checkSocialUI(); checkSocialUI();
@ -187,6 +166,10 @@ var gProviders = [
function test() { function test() {
PopupNotifications.panel.setAttribute("animate", "false");
registerCleanupFunction(function () {
PopupNotifications.panel.removeAttribute("animate");
});
waitForExplicitFinish(); waitForExplicitFinish();
runSocialTests(tests, undefined, postTestCleanup); runSocialTests(tests, undefined, postTestCleanup);
} }
@ -201,7 +184,7 @@ var tests = {
ok(panel.hidden, "activation panel still hidden"); ok(panel.hidden, "activation panel still hidden");
checkSocialUI(); checkSocialUI();
Services.prefs.clearUserPref("social.remote-install.enabled"); Services.prefs.clearUserPref("social.remote-install.enabled");
removeAllProviders(next); next();
}); });
}, },
@ -212,7 +195,7 @@ var tests = {
let panel = document.getElementById("servicesInstall-notification"); let panel = document.getElementById("servicesInstall-notification");
ok(panel.hidden, "activation panel still hidden"); ok(panel.hidden, "activation panel still hidden");
checkSocialUI(); checkSocialUI();
removeAllProviders(next); next();
}); });
}, },
@ -222,7 +205,7 @@ var tests = {
// we deactivated leaving no providers left, so Social is disabled. // we deactivated leaving no providers left, so Social is disabled.
ok(!SocialSidebar.provider, "should be no provider left after disabling"); ok(!SocialSidebar.provider, "should be no provider left after disabling");
checkSocialUI(); checkSocialUI();
removeAllProviders(next); next();
}); });
}, },
@ -240,7 +223,7 @@ var tests = {
// we deactivated - the first provider should be enabled. // we deactivated - the first provider should be enabled.
is(SocialSidebar.provider.origin, Social.providers[1].origin, "original provider should have been reactivated"); is(SocialSidebar.provider.origin, Social.providers[1].origin, "original provider should have been reactivated");
checkSocialUI(); checkSocialUI();
removeAllProviders(next); next();
}); });
}); });
}); });
@ -248,52 +231,41 @@ var tests = {
testAddonManagerDoubleInstall: function(next) { testAddonManagerDoubleInstall: function(next) {
// Create a new tab and load about:addons // Create a new tab and load about:addons
let blanktab = gBrowser.addTab(); let addonsTab = gBrowser.addTab();
gBrowser.selectedTab = blanktab; gBrowser.selectedTab = addonsTab;
BrowserOpenAddonsMgr('addons://list/service'); BrowserOpenAddonsMgr('addons://list/service');
is(blanktab, gBrowser.selectedTab, "Current tab should be blank tab");
gBrowser.selectedBrowser.addEventListener("load", function tabLoad() { gBrowser.selectedBrowser.addEventListener("load", function tabLoad() {
gBrowser.selectedBrowser.removeEventListener("load", tabLoad, true); gBrowser.selectedBrowser.removeEventListener("load", tabLoad, true);
let browser = blanktab.linkedBrowser; is(addonsTab.linkedBrowser.currentURI.spec, "about:addons", "about:addons should load into blank tab.");
is(browser.currentURI.spec, "about:addons", "about:addons should load into blank tab.");
activateOneProvider(gProviders[0], true, function() { activateOneProvider(gProviders[0], true, function() {
info("first activation completed"); info("first activation completed");
is(gBrowser.contentDocument.location.href, gProviders[0].origin + "/browser/browser/base/content/test/social/social_postActivation.html", "postActivationURL loaded"); is(gBrowser.contentDocument.location.href, gProviders[0].origin + "/browser/browser/base/content/test/social/social_postActivation.html", "postActivationURL loaded");
gBrowser.removeTab(gBrowser.selectedTab); BrowserTestUtils.removeTab(gBrowser.selectedTab).then(() => {
is(gBrowser.contentDocument.location.href, gProviders[0].origin + "/browser/browser/base/content/test/social/social_activate_basic.html", "activation page selected"); is(gBrowser.contentDocument.location.href, gProviders[0].origin + "/browser/browser/base/content/test/social/social_activate_basic.html", "activation page selected");
gBrowser.removeTab(gBrowser.selectedTab); BrowserTestUtils.removeTab(gBrowser.selectedTab).then(() => {
tabsToRemove.pop(); tabsToRemove.pop();
// uninstall the provider // uninstall the provider
clickAddonRemoveButton(blanktab, function(addon) { clickAddonRemoveButton(addonsTab, function(addon) {
checkSocialUI(); checkSocialUI();
activateOneProvider(gProviders[0], true, function() { activateOneProvider(gProviders[0], true, function() {
info("second activation completed"); info("second activation completed");
is(gBrowser.contentDocument.location.href, gProviders[0].origin + "/browser/browser/base/content/test/social/social_postActivation.html", "postActivationURL loaded"); is(gBrowser.contentDocument.location.href, gProviders[0].origin + "/browser/browser/base/content/test/social/social_postActivation.html", "postActivationURL loaded");
gBrowser.removeTab(gBrowser.selectedTab); BrowserTestUtils.removeTab(gBrowser.selectedTab).then(() => {
// after closing the addons tab, verify provider is still installed // after closing the addons tab, verify provider is still installed
gBrowser.tabContainer.addEventListener("TabClose", function onTabClose() { AddonManager.getAddonsByTypes(["service"], function(aAddons) {
gBrowser.tabContainer.removeEventListener("TabClose", onTabClose); is(aAddons.length, 1, "there can be only one");
AddonManager.getAddonsByTypes(["service"], function(aAddons) {
is(aAddons.length, 1, "there can be only one"); let doc = addonsTab.linkedBrowser.contentDocument;
removeAllProviders(next); let list = doc.getElementById("addon-list");
is(list.childNodes.length, 1, "only one addon is displayed");
BrowserTestUtils.removeTab(addonsTab).then(next);
});
});
}); });
}); });
// verify only one provider in list
AddonManager.getAddonsByTypes(["service"], function(aAddons) {
is(aAddons.length, 1, "there can be only one");
let doc = blanktab.linkedBrowser.contentDocument;
let list = doc.getElementById("addon-list");
is(list.childNodes.length, 1, "only one addon is displayed");
gBrowser.removeTab(blanktab);
});
}); });
}); });
}); });

Просмотреть файл

@ -27,12 +27,12 @@ var manifests = [
var chatId = 0; var chatId = 0;
function openChat(provider) { function openChat(provider) {
let deferred = Promise.defer(); return new Promise(resolve => {
SocialSidebar.provider = provider; SocialSidebar.provider = provider;
let chatUrl = provider.origin + "/browser/browser/base/content/test/social/social_chat.html"; let chatUrl = provider.origin + "/browser/browser/base/content/test/social/social_chat.html";
let url = chatUrl + "?id=" + (chatId++); let url = chatUrl + "?id=" + (chatId++);
makeChat("normal", "chat " + chatId, (cb) => { deferred.resolve(cb); }); makeChat("normal", "chat " + chatId, (cb) => { resolve(cb); });
return deferred.promise; });
} }
function windowHasChats(win) { function windowHasChats(win) {
@ -74,23 +74,19 @@ function test() {
var tests = { var tests = {
testOpenCloseChat: function(next) { testOpenCloseChat: function(next) {
openChat(SocialSidebar.provider).then((cb) => { openChat(SocialSidebar.provider).then((cb) => {
waitForCondition(function() { BrowserTestUtils.waitForCondition(() => { return cb.minimized; },
return cb.minimized; "chatbox is minimized").then(() => {
}, function() {
ok(cb.minimized, "chat is minimized after toggle"); ok(cb.minimized, "chat is minimized after toggle");
waitForCondition(function() { BrowserTestUtils.waitForCondition(() => { return !cb.minimized; },
return !cb.minimized; "chatbox is not minimized").then(() => {
}, function() {
ok(!cb.minimized, "chat is not minimized after toggle"); ok(!cb.minimized, "chat is not minimized after toggle");
promiseNodeRemoved(cb).then(next); promiseNodeRemoved(cb).then(next);
let mm = cb.content.messageManager; let mm = cb.content.messageManager;
mm.sendAsyncMessage("socialTest-CloseSelf", {}); mm.sendAsyncMessage("socialTest-CloseSelf", {});
info("close chat window requested"); info("close chat window requested");
}, });
"chatbox is not minimized");
cb.toggle(); cb.toggle();
}, });
"chatbox is minimized");
ok(!cb.minimized, "chat is not minimized on open"); ok(!cb.minimized, "chat is not minimized on open");
// toggle to minimize chat // toggle to minimize chat

Просмотреть файл

@ -42,7 +42,7 @@ function test() {
runSocialTestWithProvider(manifest, function (finishcb) { runSocialTestWithProvider(manifest, function (finishcb) {
SocialSidebar.show(); SocialSidebar.show();
runSocialTests(tests, preSubTest, postSubTest, function () { runSocialTests(tests, preSubTest, postSubTest, function () {
ensureBrowserTabClosed(tab).then(finishcb); BrowserTestUtils.removeTab(tab).then(finishcb);
}); });
}); });
}, true); }, true);
@ -56,10 +56,11 @@ var tests = {
let chatbar = getChatBar(); let chatbar = getChatBar();
openChatViaUser(); openChatViaUser();
ok(chatbar.firstElementChild, "chat opened"); ok(chatbar.firstElementChild, "chat opened");
waitForCondition(() => isChatFocused(chatbar.selectedChat), function() { BrowserTestUtils.waitForCondition(() => isChatFocused(chatbar.selectedChat),
"chat should be focused").then(() => {
is(chatbar.selectedChat, chatbar.firstElementChild, "chat is selected"); is(chatbar.selectedChat, chatbar.firstElementChild, "chat is selected");
next(); next();
}, "chat should be focused"); });
}); });
}, },
}; };

Просмотреть файл

@ -58,14 +58,13 @@ var tests = {
let mm = getGroupMessageManager("social"); let mm = getGroupMessageManager("social");
mm.addMessageListener("sharedata", function handler(msg) { mm.addMessageListener("sharedata", function handler(msg) {
gBrowser.removeTab(testTab);
is(msg.data, expecting, "microformats data ok"); is(msg.data, expecting, "microformats data ok");
mm.removeMessageListener("sharedata", handler); mm.removeMessageListener("sharedata", handler);
next(); BrowserTestUtils.removeTab(testTab).then(next);
}); });
let url = "https://example.com/browser/browser/base/content/test/social/microformats.html" let url = "https://example.com/browser/browser/base/content/test/social/microformats.html"
addTab(url, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, url).then(tab => {
testTab = tab; testTab = tab;
let doc = tab.linkedBrowser.contentDocument; let doc = tab.linkedBrowser.contentDocument;
target = doc.getElementById("test-review"); target = doc.getElementById("test-review");

Просмотреть файл

@ -17,12 +17,10 @@ function openPanel(url, panelCallback, loadCallback) {
// wait for both open and loaded before callback. Since the test doesn't close // wait for both open and loaded before callback. Since the test doesn't close
// the panel between opens, we cannot rely on events here. We need to ensure // the panel between opens, we cannot rely on events here. We need to ensure
// popupshown happens before we finish out the tests. // popupshown happens before we finish out the tests.
waitForCondition(function() { BrowserTestUtils.waitForCondition(function() {
return SocialFlyout.panel.state == "open" && return SocialFlyout.panel.state == "open" &&
SocialFlyout.iframe.contentDocument.readyState == "complete"; SocialFlyout.iframe.contentDocument.readyState == "complete";
}, },"flyout is open and loaded").then(() => { executeSoon(loadCallback) });
function () { executeSoon(loadCallback) },
"flyout is open and loaded");
} }
function openChat(url, panelCallback, loadCallback) { function openChat(url, panelCallback, loadCallback) {
@ -138,12 +136,11 @@ var tests = {
function() { // the "load" callback. function() { // the "load" callback.
todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads."); todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads.");
let chat = getChatBar().selectedChat; let chat = getChatBar().selectedChat;
waitForCondition(() => chat.content != null && chat.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly")==0, BrowserTestUtils.waitForCondition(() => chat.content != null && chat.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly")==0,
function() { "error page didn't appear").then(() => {
chat.close(); chat.close();
next(); next();
}, });
"error page didn't appear");
} }
); );
}); });
@ -167,26 +164,23 @@ var tests = {
let chat = getChatBar().selectedChat; let chat = getChatBar().selectedChat;
is(chat.contentDocument.documentURI, url, "correct url loaded"); is(chat.contentDocument.documentURI, url, "correct url loaded");
// toggle to a detached window. // toggle to a detached window.
chat.swapWindows().then( chat.swapWindows().then(chat => {
chat => { ok(!!chat.content, "we have chat content 1");
ok(!!chat.content, "we have chat content 1"); BrowserTestUtils.waitForCondition(() => chat.content != null && chat.contentDocument.readyState == "complete",
waitForCondition(() => chat.content != null && chat.contentDocument.readyState == "complete", "swapped window loaded").then(() => {
function() { // now go offline and reload the chat - about:socialerror should be loaded.
// now go offline and reload the chat - about:socialerror should be loaded. goOffline().then(() => {
goOffline().then(function() { ok(!!chat.content, "we have chat content 2");
ok(!!chat.content, "we have chat content 2"); chat.contentDocument.location.reload();
chat.contentDocument.location.reload(); info("chat reload called");
info("chat reload called"); BrowserTestUtils.waitForCondition(() => chat.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly")==0,
waitForCondition(() => chat.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly")==0, "error page didn't appear").then(() => {
function() { chat.close();
chat.close(); next();
next();
},
"error page didn't appear");
}); });
}, "swapped window loaded"); });
} });
); });
} }
); );
} }

Просмотреть файл

@ -8,9 +8,6 @@ function test() {
addMessageListener("socialTest-CloseSelf", function(e) { addMessageListener("socialTest-CloseSelf", function(e) {
content.close(); content.close();
}); });
addEventListener("visibilitychange", function() {
sendAsyncMessage("social-visibility", content.document.hidden ? "hidden" : "shown");
});
addMessageListener("socialTest-sendEvent", function(msg) { addMessageListener("socialTest-sendEvent", function(msg) {
let data = msg.data; let data = msg.data;
let evt = content.document.createEvent("CustomEvent"); let evt = content.document.createEvent("CustomEvent");
@ -30,41 +27,22 @@ function test() {
}; };
runSocialTestWithProvider(manifest, function (finishcb) { runSocialTestWithProvider(manifest, function (finishcb) {
SocialSidebar.show(); SocialSidebar.show();
ensureFrameLoaded(document.getElementById("social-sidebar-browser")).then(() => { ensureFrameLoaded(SocialSidebar.browser, manifest.sidebarURL).then(() => {
// disable transitions for the test // disable transitions for the test
let panel = document.getElementById("social-flyout-panel");
registerCleanupFunction(function () { registerCleanupFunction(function () {
panel.removeAttribute("animate"); SocialFlyout.panel.removeAttribute("animate");
}); });
panel.setAttribute("animate", "false"); SocialFlyout.panel.setAttribute("animate", "false");
runSocialTests(tests, undefined, undefined, finishcb); runSocialTests(tests, undefined, undefined, finishcb);
}); });
}); });
} }
var tests = { var tests = {
testOpenCloseFlyout: function(next) {
let panel = document.getElementById("social-flyout-panel");
ensureEventFired(panel, "popupshown").then(() => {
is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing");
});
let sidebar = document.getElementById("social-sidebar-browser")
let mm = getGroupMessageManager("social");
mm.addMessageListener("social-visibility", function handler(msg) {
if (msg.data == "shown") {
sidebar.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-close", data: {} });
} else if (msg.data == "hidden") {
mm.removeMessageListener("social-visibility", handler);
next();
}
});
sidebar.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
},
testResizeFlyout: function(next) { testResizeFlyout: function(next) {
let panel = document.getElementById("social-flyout-panel"); let panel = document.getElementById("social-flyout-panel");
ensureEventFired(panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(panel, "popupshown").then(() => {
is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing"); is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing");
// The width of the flyout should be 400px initially // The width of the flyout should be 400px initially
let iframe = panel.firstChild; let iframe = panel.firstChild;
@ -76,54 +54,49 @@ var tests = {
is(cs.height, "400px", "should be 400px high"); is(cs.height, "400px", "should be 400px high");
is(iframe.boxObject.height, 400, "iframe should now be 400px high"); is(iframe.boxObject.height, 400, "iframe should now be 400px high");
ensureEventFired(iframe.contentWindow, "resize").then(() => { BrowserTestUtils.waitForEvent(iframe.contentWindow, "resize").then(() => {
cs = iframe.contentWindow.getComputedStyle(body); cs = iframe.contentWindow.getComputedStyle(body);
is(cs.width, "500px", "should now be 500px wide"); is(cs.width, "500px", "should now be 500px wide");
is(iframe.boxObject.width, 500, "iframe should now be 500px wide"); is(iframe.boxObject.width, 500, "iframe should now be 500px wide");
is(cs.height, "500px", "should now be 500px high"); is(cs.height, "500px", "should now be 500px high");
is(iframe.boxObject.height, 500, "iframe should now be 500px high"); is(iframe.boxObject.height, 500, "iframe should now be 500px high");
ensureEventFired(panel, "popuphidden").then(next); BrowserTestUtils.waitForEvent(panel, "popuphidden").then(next);
panel.hidePopup(); panel.hidePopup();
}); });
SocialFlyout.dispatchPanelEvent("socialTest-MakeWider"); SocialFlyout.dispatchPanelEvent("socialTest-MakeWider");
}); });
let sidebar = document.getElementById("social-sidebar-browser"); SocialSidebar.browser.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
sidebar.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
}, },
testCloseSelf: function(next) { testCloseSelf: function(next) {
let panel = document.getElementById("social-flyout-panel"); let panel = document.getElementById("social-flyout-panel");
ensureEventFired(panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(panel, "popupshown").then(() => {
is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing"); is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing");
ensureEventFired(panel, "popuphidden").then(next); BrowserTestUtils.waitForEvent(panel, "popuphidden").then(next);
let mm = panel.firstChild.messageManager; let mm = panel.firstChild.messageManager;
mm.sendAsyncMessage("socialTest-CloseSelf", {}); mm.sendAsyncMessage("socialTest-CloseSelf", {});
}); });
let sidebar = document.getElementById("social-sidebar-browser"); SocialSidebar.browser.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
sidebar.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
}, },
testCloseOnLinkTraversal: function(next) { testCloseOnLinkTraversal: function(next) {
function onTabOpen(event) { BrowserTestUtils.waitForEvent(gBrowser.tabContainer, "TabOpen", true).then(event => {
gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true); BrowserTestUtils.waitForCondition(function() { return panel.state == "closed" },
waitForCondition(function() { return panel.state == "closed" }, function() { "panel should close after tab open").then(() => {
gBrowser.removeTab(event.target); BrowserTestUtils.removeTab(event.target).then(next);
next(); });
}, "panel should close after tab open"); });
}
let panel = document.getElementById("social-flyout-panel"); let panel = document.getElementById("social-flyout-panel");
ensureEventFired(panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(panel, "popupshown").then(() => {
is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing"); is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing");
is(panel.state, "open", "flyout should be open"); is(panel.state, "open", "flyout should be open");
gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true);
let iframe = panel.firstChild; let iframe = panel.firstChild;
iframe.contentDocument.getElementById('traversal').click(); iframe.contentDocument.getElementById('traversal').click();
}); });
let sidebar = document.getElementById("social-sidebar-browser"); SocialSidebar.browser.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
sidebar.messageManager.sendAsyncMessage("socialTest-sendEvent", { name: "test-flyout-open", data: {} });
} }
} }

Просмотреть файл

@ -33,7 +33,9 @@ function test() {
let mm = getGroupMessageManager("social"); let mm = getGroupMessageManager("social");
mm.loadFrameScript(frameScript, true); mm.loadFrameScript(frameScript, true);
PopupNotifications.panel.setAttribute("animate", "false");
registerCleanupFunction(function () { registerCleanupFunction(function () {
PopupNotifications.panel.removeAttribute("animate");
mm.removeDelayedFrameScript(frameScript); mm.removeDelayedFrameScript(frameScript);
}); });
@ -67,13 +69,13 @@ var tests = {
// we expect the addon install dialog to appear, we need to accept the // we expect the addon install dialog to appear, we need to accept the
// install from the dialog. // install from the dialog.
let panel = document.getElementById("servicesInstall-notification"); let panel = document.getElementById("servicesInstall-notification");
ensureEventFired(PopupNotifications.panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
info("servicesInstall-notification panel opened"); info("servicesInstall-notification panel opened");
panel.button.click(); panel.button.click();
}); });
let activationURL = manifest3.origin + "/browser/browser/base/content/test/social/social_activate.html" let activationURL = manifest3.origin + "/browser/browser/base/content/test/social/social_activate.html"
addTab(activationURL, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
let doc = tab.linkedBrowser.contentDocument; let doc = tab.linkedBrowser.contentDocument;
let data = { let data = {
origin: doc.nodePrincipal.origin, origin: doc.nodePrincipal.origin,
@ -90,7 +92,7 @@ var tests = {
let widget = CustomizableUI.getWidget(id); let widget = CustomizableUI.getWidget(id);
ok(!widget || !widget.forWindow(window).node, "no button added to widget set"); ok(!widget || !widget.forWindow(window).node, "no button added to widget set");
Social.uninstallProvider(manifest3.origin, function() { Social.uninstallProvider(manifest3.origin, function() {
ensureBrowserTabClosed(tab).then(next); BrowserTestUtils.removeTab(tab).then(next);
}); });
}); });
}); });
@ -99,14 +101,14 @@ var tests = {
testButtonOnEnable: function(next) { testButtonOnEnable: function(next) {
let panel = document.getElementById("servicesInstall-notification"); let panel = document.getElementById("servicesInstall-notification");
ensureEventFired(PopupNotifications.panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
info("servicesInstall-notification panel opened"); info("servicesInstall-notification panel opened");
panel.button.click(); panel.button.click();
}); });
// enable the provider now // enable the provider now
let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
addTab(activationURL, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
let doc = tab.linkedBrowser.contentDocument; let doc = tab.linkedBrowser.contentDocument;
let data = { let data = {
origin: doc.nodePrincipal.origin, origin: doc.nodePrincipal.origin,
@ -131,7 +133,7 @@ var tests = {
is(button.hidden, false, "mark button is visible"); is(button.hidden, false, "mark button is visible");
checkSocialUI(window); checkSocialUI(window);
ensureBrowserTabClosed(tab).then(next); BrowserTestUtils.removeTab(tab).then(next);
}); });
}); });
}); });
@ -147,7 +149,7 @@ var tests = {
ok(btn, "got a mark button"); ok(btn, "got a mark button");
let ourTab; let ourTab;
ensureEventFired(btn.panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(btn.panel, "popupshown").then(() => {
info("marks panel shown"); info("marks panel shown");
let doc = btn.contentDocument; let doc = btn.contentDocument;
let unmarkBtn = doc.getElementById("unmark"); let unmarkBtn = doc.getElementById("unmark");
@ -155,8 +157,8 @@ var tests = {
EventUtils.sendMouseEvent({type: "click"}, unmarkBtn, btn.contentWindow); EventUtils.sendMouseEvent({type: "click"}, unmarkBtn, btn.contentWindow);
}); });
ensureEventFired(btn.panel, "popuphidden").then(() => { BrowserTestUtils.waitForEvent(btn.panel, "popuphidden").then(() => {
ensureBrowserTabClosed(ourTab).then(() => { BrowserTestUtils.removeTab(ourTab).then(() => {
ok(btn.disabled, "button is disabled"); ok(btn.disabled, "button is disabled");
next(); next();
}); });
@ -165,7 +167,7 @@ var tests = {
// verify markbutton is disabled when there is no browser url // verify markbutton is disabled when there is no browser url
ok(btn.disabled, "button is disabled"); ok(btn.disabled, "button is disabled");
let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
addTab(activationURL, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
ourTab = tab; ourTab = tab;
ok(!btn.disabled, "button is enabled"); ok(!btn.disabled, "button is enabled");
// first click marks the page, second click opens the page. We have to // first click marks the page, second click opens the page. We have to
@ -173,9 +175,9 @@ var tests = {
EventUtils.synthesizeMouseAtCenter(btn, {}); EventUtils.synthesizeMouseAtCenter(btn, {});
// wait for the button to be marked, click to open panel // wait for the button to be marked, click to open panel
is(btn.panel.state, "closed", "panel should not be visible yet"); is(btn.panel.state, "closed", "panel should not be visible yet");
waitForCondition(() => btn.isMarked, function() { BrowserTestUtils.waitForCondition(() => btn.isMarked, "button is marked").then(() => {
EventUtils.synthesizeMouseAtCenter(btn, {}); EventUtils.synthesizeMouseAtCenter(btn, {});
}, "button is marked"); });
}); });
}, },
@ -190,18 +192,18 @@ var tests = {
// verify markbutton is disabled when there is no browser url // verify markbutton is disabled when there is no browser url
ok(btn.disabled, "button is disabled"); ok(btn.disabled, "button is disabled");
let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html";
addTab(activationURL, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
ok(!btn.disabled, "button is enabled"); ok(!btn.disabled, "button is enabled");
goOffline().then(function() { goOffline().then(function() {
info("testing offline error page"); info("testing offline error page");
// wait for popupshown // wait for popupshown
ensureEventFired(btn.panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(btn.panel, "popupshown").then(() => {
info("marks panel is open"); info("marks panel is open");
ensureFrameLoaded(btn.content).then(() => { ensureFrameLoaded(btn.content).then(() => {
is(btn.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly"), 0, "social error page is showing "+btn.contentDocument.documentURI); is(btn.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly"), 0, "social error page is showing "+btn.contentDocument.documentURI);
// cleanup after the page has been unmarked // cleanup after the page has been unmarked
ensureBrowserTabClosed(tab).then(() => { BrowserTestUtils.removeTab(tab).then(() => {
ok(btn.disabled, "button is disabled"); ok(btn.disabled, "button is disabled");
goOnline().then(next); goOnline().then(next);
}); });
@ -218,14 +220,13 @@ var tests = {
ok(provider, "provider is installed"); ok(provider, "provider is installed");
SocialService.disableProvider(manifest2.origin, function() { SocialService.disableProvider(manifest2.origin, function() {
let id = SocialMarks._toolbarHelper.idFromOrigin(manifest2.origin); let id = SocialMarks._toolbarHelper.idFromOrigin(manifest2.origin);
waitForCondition(function() { BrowserTestUtils.waitForCondition(() => {
// getWidget now returns null since we've destroyed the widget // getWidget now returns null since we've destroyed the widget
return !CustomizableUI.getWidget(id) return !CustomizableUI.getWidget(id)
}, }, "button does not exist after disabling the provider").then(() => {
function() {
checkSocialUI(window); checkSocialUI(window);
Social.uninstallProvider(manifest2.origin, next); Social.uninstallProvider(manifest2.origin, next);
}, "button does not exist after disabling the provider"); });
}); });
} }
} }

Просмотреть файл

@ -14,6 +14,10 @@ function makeMarkProvider(origin) {
function test() { function test() {
waitForExplicitFinish(); waitForExplicitFinish();
PopupNotifications.panel.setAttribute("animate", "false");
registerCleanupFunction(function () {
PopupNotifications.panel.removeAttribute("animate");
});
runSocialTests(tests, undefined, undefined, finish); runSocialTests(tests, undefined, undefined, finish);
} }
@ -40,7 +44,7 @@ var tests = {
} }
info("INSTALLING " + manifest.origin); info("INSTALLING " + manifest.origin);
let panel = document.getElementById("servicesInstall-notification"); let panel = document.getElementById("servicesInstall-notification");
ensureEventFired(PopupNotifications.panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
info("servicesInstall-notification panel opened"); info("servicesInstall-notification panel opened");
panel.button.click(); panel.button.click();
}); });
@ -48,7 +52,7 @@ var tests = {
let activationURL = manifest.origin + "/browser/browser/base/content/test/social/social_activate.html" let activationURL = manifest.origin + "/browser/browser/base/content/test/social/social_activate.html"
let id = SocialMarks._toolbarHelper.idFromOrigin(manifest.origin); let id = SocialMarks._toolbarHelper.idFromOrigin(manifest.origin);
let toolbar = document.getElementById("nav-bar"); let toolbar = document.getElementById("nav-bar");
addTab(activationURL, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
let doc = tab.linkedBrowser.contentDocument; let doc = tab.linkedBrowser.contentDocument;
let data = { let data = {
origin: doc.nodePrincipal.origin, origin: doc.nodePrincipal.origin,
@ -60,16 +64,17 @@ var tests = {
Social.installProvider(data, function(addonManifest) { Social.installProvider(data, function(addonManifest) {
// enable the provider so we know the button would have appeared // enable the provider so we know the button would have appeared
SocialService.enableProvider(manifest.origin, function(provider) { SocialService.enableProvider(manifest.origin, function(provider) {
waitForCondition(function() { return CustomizableUI.getWidget(id) }, BrowserTestUtils.waitForCondition(() => { return CustomizableUI.getWidget(id) },
function() { "button exists after enabling social").then(() => {
gBrowser.removeTab(tab); BrowserTestUtils.removeTab(tab).then(() => {
installed.push(manifest.origin); installed.push(manifest.origin);
// checkSocialUI will properly check where the menus are located // checkSocialUI will properly check where the menus are located
checkSocialUI(window); checkSocialUI(window);
executeSoon(function() { executeSoon(function() {
addProviders(callback); addProviders(callback);
});
}); });
}, "button exists after enabling social"); });
}); });
}); });
}); });

Просмотреть файл

@ -42,23 +42,23 @@ var tests = {
} }
// the menu is not populated until onpopupshowing, so wait for popupshown // the menu is not populated until onpopupshowing, so wait for popupshown
ensureEventFired(menu, "popupshown").then(()=>{ BrowserTestUtils.waitForEvent(menu, "popupshown", true).then(()=>{
menu.hidePopup(); // doesn't need visibility menu.hidePopup(); // doesn't need visibility
// first provider should already be visible in the sidebar // first provider should already be visible in the sidebar
is(Social.providers[0].origin, SocialSidebar.provider.origin, "selected provider in sidebar"); is(Social.providers[0].origin, SocialSidebar.provider.origin, "selected provider in sidebar");
checkProviderMenu(Social.providers[0]); checkProviderMenu(Social.providers[0]);
// Now activate "provider 2" // Now activate "provider 2"
ensureEventFired(sbrowser, "load").then(()=>{ BrowserTestUtils.waitForEvent(sbrowser, "load", true).then(()=>{
checkUIStateMatchesProvider(Social.providers[1]); checkUIStateMatchesProvider(Social.providers[1]);
ensureEventFired(sbrowser, "load").then(()=>{ BrowserTestUtils.waitForEvent(sbrowser, "load", true).then(()=>{
checkUIStateMatchesProvider(Social.providers[0]); checkUIStateMatchesProvider(Social.providers[0]);
next(); next();
}); });
// show the menu again so the menu is updated with the correct commands // show the menu again so the menu is updated with the correct commands
ensureEventFired(menu, "popupshown").then(()=>{ BrowserTestUtils.waitForEvent(menu, "popupshown", true).then(()=>{
// click on the provider menuitem to switch providers // click on the provider menuitem to switch providers
let el = menu.getElementsByAttribute("origin", Social.providers[0].origin); let el = menu.getElementsByAttribute("origin", Social.providers[0].origin);
is(el.length, 1, "selected provider menu item exists"); is(el.length, 1, "selected provider menu item exists");

Просмотреть файл

@ -68,7 +68,7 @@ function doTest() {
} }
} }
} }
ensureEventFired(browser, "load").then(() => { ensureFrameLoaded(browser).then(() => {
// First check the the sidebar is initially visible, and loaded // First check the the sidebar is initially visible, and loaded
ok(!command.hidden, "toggle command should be visible"); ok(!command.hidden, "toggle command should be visible");
let mm = getGroupMessageManager("social"); let mm = getGroupMessageManager("social");

Просмотреть файл

@ -49,7 +49,9 @@ function test() {
let mm = getGroupMessageManager("social"); let mm = getGroupMessageManager("social");
mm.loadFrameScript(frameScript, true); mm.loadFrameScript(frameScript, true);
PopupNotifications.panel.setAttribute("animate", "false");
registerCleanupFunction(function () { registerCleanupFunction(function () {
PopupNotifications.panel.removeAttribute("animate");
mm.removeDelayedFrameScript(frameScript); mm.removeDelayedFrameScript(frameScript);
}); });
@ -69,13 +71,13 @@ var tests = {
// we expect the addon install dialog to appear, we need to accept the // we expect the addon install dialog to appear, we need to accept the
// install from the dialog. // install from the dialog.
let panel = document.getElementById("servicesInstall-notification"); let panel = document.getElementById("servicesInstall-notification");
ensureEventFired(PopupNotifications.panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
info("servicesInstall-notification panel opened"); info("servicesInstall-notification panel opened");
panel.button.click(); panel.button.click();
}) })
let activationURL = manifest3.origin + "/browser/browser/base/content/test/social/social_activate.html" let activationURL = manifest3.origin + "/browser/browser/base/content/test/social/social_activate.html"
addTab(activationURL, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
let doc = tab.linkedBrowser.contentDocument; let doc = tab.linkedBrowser.contentDocument;
let data = { let data = {
origin: doc.nodePrincipal.origin, origin: doc.nodePrincipal.origin,
@ -91,8 +93,7 @@ var tests = {
let widget = CustomizableUI.getWidget(id); let widget = CustomizableUI.getWidget(id);
ok(!widget || !widget.forWindow(window).node, "no button added to widget set"); ok(!widget || !widget.forWindow(window).node, "no button added to widget set");
Social.uninstallProvider(manifest3.origin, function() { Social.uninstallProvider(manifest3.origin, function() {
gBrowser.removeTab(tab); BrowserTestUtils.removeTab(tab).then(next);
next();
}); });
}); });
}); });
@ -100,14 +101,14 @@ var tests = {
}, },
testButtonOnEnable: function(next) { testButtonOnEnable: function(next) {
let panel = document.getElementById("servicesInstall-notification"); let panel = document.getElementById("servicesInstall-notification");
ensureEventFired(PopupNotifications.panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(PopupNotifications.panel, "popupshown").then(() => {
info("servicesInstall-notification panel opened"); info("servicesInstall-notification panel opened");
panel.button.click(); panel.button.click();
}); });
// enable the provider now // enable the provider now
let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html" let activationURL = manifest2.origin + "/browser/browser/base/content/test/social/social_activate.html"
addTab(activationURL, function(tab) { BrowserTestUtils.openNewForegroundTab(gBrowser, activationURL).then(tab => {
let doc = tab.linkedBrowser.contentDocument; let doc = tab.linkedBrowser.contentDocument;
let data = { let data = {
origin: doc.nodePrincipal.origin, origin: doc.nodePrincipal.origin,
@ -123,8 +124,7 @@ var tests = {
let widget = CustomizableUI.getWidget(id).forWindow(window); let widget = CustomizableUI.getWidget(id).forWindow(window);
ok(widget.node, "button added to widget set"); ok(widget.node, "button added to widget set");
checkSocialUI(window); checkSocialUI(window);
gBrowser.removeTab(tab); BrowserTestUtils.removeTab(tab).then(next);
next();
}); });
}); });
}); });
@ -145,18 +145,18 @@ var tests = {
// Disable the transition // Disable the transition
let panel = document.getElementById("social-notification-panel"); let panel = document.getElementById("social-notification-panel");
panel.setAttribute("animate", "false"); panel.setAttribute("animate", "false");
ensureEventFired(panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(panel, "popupshown").then(() => {
ensureFrameLoaded(panel.firstChild).then(() => { ensureFrameLoaded(panel.firstChild).then(() => {
let mm = panel.firstChild.messageManager; let mm = panel.firstChild.messageManager;
mm.sendAsyncMessage("socialTest-sendEvent", { name: "Social:Notification", data: icon }); mm.sendAsyncMessage("socialTest-sendEvent", { name: "Social:Notification", data: icon });
waitForCondition(function() { return btn.getAttribute("badge"); }, BrowserTestUtils.waitForCondition(
function() { () => { return btn.getAttribute("badge"); }, "button updated by notification").then(() => {
is(btn.style.listStyleImage, "url(\"" + icon.iconURL + "\")", "notification icon updated"); is(btn.style.listStyleImage, "url(\"" + icon.iconURL + "\")", "notification icon updated");
panel.hidePopup(); panel.hidePopup();
}, "button updated by notification"); });
}); });
}); });
ensureEventFired(panel, "popuphidden").then(() => { BrowserTestUtils.waitForEvent(panel, "popuphidden").then(() => {
panel.removeAttribute("animate"); panel.removeAttribute("animate");
next(); next();
}); });
@ -178,13 +178,13 @@ var tests = {
info("testing offline error page"); info("testing offline error page");
// wait for popupshown // wait for popupshown
let panel = document.getElementById("social-notification-panel"); let panel = document.getElementById("social-notification-panel");
ensureEventFired(panel, "popupshown").then(() => { BrowserTestUtils.waitForEvent(panel, "popupshown").then(() => {
ensureFrameLoaded(frame).then(() => { ensureFrameLoaded(frame).then(() => {
is(frame.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly"), 0, "social error page is showing "+frame.contentDocument.documentURI); is(frame.contentDocument.documentURI.indexOf("about:socialerror?mode=tryAgainOnly"), 0, "social error page is showing "+frame.contentDocument.documentURI);
// We got our error page, reset to avoid test leak. // We got our error page, reset to avoid test leak.
ensureEventFired(frame, "load").then(() => { BrowserTestUtils.waitForEvent(frame, "load", true).then(() => {
is(frame.contentDocument.documentURI, "about:blank", "closing error panel"); is(frame.contentDocument.documentURI, "about:blank", "closing error panel");
ensureEventFired(panel, "popuphidden").then(next); BrowserTestUtils.waitForEvent(panel, "popuphidden").then(next);
panel.hidePopup(); panel.hidePopup();
}); });
goOnline().then(() => { goOnline().then(() => {
@ -194,7 +194,7 @@ var tests = {
}); });
}); });
// reload after going offline, wait for unload to open panel // reload after going offline, wait for unload to open panel
ensureEventFired(frame, "unload").then(() => { BrowserTestUtils.waitForEvent(frame, "unload", true).then(() => {
btn.click(); btn.click();
}); });
frame.contentDocument.location.reload(); frame.contentDocument.location.reload();
@ -207,10 +207,10 @@ var tests = {
ok(provider, "provider is installed"); ok(provider, "provider is installed");
SocialService.disableProvider(manifest2.origin, function() { SocialService.disableProvider(manifest2.origin, function() {
let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin); let id = SocialStatus._toolbarHelper.idFromOrigin(manifest2.origin);
waitForCondition(function() { return !document.getElementById(id) }, BrowserTestUtils.waitForCondition(() => { return !document.getElementById(id) },
function() { "button does not exist after disabling the provider").then(() => {
Social.uninstallProvider(manifest2.origin, next); Social.uninstallProvider(manifest2.origin, next);
}, "button does not exist after disabling the provider"); });
}); });
} }
} }

Просмотреть файл

@ -94,8 +94,8 @@ var tests = {
SocialService.addProvider(manifest, function() { SocialService.addProvider(manifest, function() {
SocialService.addProvider(manifest2, function (provider) { SocialService.addProvider(manifest2, function (provider) {
SocialSidebar.show(); SocialSidebar.show();
waitForCondition(() => SocialSidebar.opened, BrowserTestUtils.waitForCondition(
function() { () => SocialSidebar.opened, "sidebar did not open").then(() => {
ok(SocialSidebar.opened, "first window sidebar is open"); ok(SocialSidebar.opened, "first window sidebar is open");
openWindowAndWaitForInit(window, function(w1) { openWindowAndWaitForInit(window, function(w1) {
ok(w1.SocialSidebar.opened, "new window sidebar is open"); ok(w1.SocialSidebar.opened, "new window sidebar is open");
@ -123,7 +123,7 @@ var tests = {
}); });
}); });
}); });
}, "sidebar did not open"); });
}, cbnext); }, cbnext);
}, cbnext); }, cbnext);
}, },
@ -138,8 +138,7 @@ var tests = {
SocialService.addProvider(manifest, function() { SocialService.addProvider(manifest, function() {
openWindowAndWaitForInit(window, function(w1) { openWindowAndWaitForInit(window, function(w1) {
w1.SocialSidebar.show(); w1.SocialSidebar.show();
waitForCondition(() => w1.SocialSidebar.opened, BrowserTestUtils.waitForCondition(() => w1.SocialSidebar.opened, "sidebar opened").then(() => {
function() {
ok(Services.prefs.prefHasUserValue("social.sidebar.provider"), "global state set"); ok(Services.prefs.prefHasUserValue("social.sidebar.provider"), "global state set");
ok(!SocialSidebar.opened, "1. main sidebar is still closed"); ok(!SocialSidebar.opened, "1. main sidebar is still closed");
ok(w1.SocialSidebar.opened, "1. window sidebar is open"); ok(w1.SocialSidebar.opened, "1. window sidebar is open");

Просмотреть файл

@ -4,55 +4,32 @@
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
"resource://gre/modules/Promise.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "Task", XPCOMUtils.defineLazyModuleGetter(this, "Task",
"resource://gre/modules/Task.jsm"); "resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils", XPCOMUtils.defineLazyModuleGetter(this, "PlacesUtils",
"resource://gre/modules/PlacesUtils.jsm"); "resource://gre/modules/PlacesUtils.jsm");
function waitForCondition(condition, nextTest, errorMsg, numTries = 30) {
var tries = 0;
var interval = setInterval(function() {
if (tries >= numTries) {
ok(false, errorMsg);
moveOn();
}
var conditionPassed;
try {
conditionPassed = condition();
} catch (e) {
ok(false, e + "\n" + e.stack);
conditionPassed = false;
}
if (conditionPassed) {
moveOn();
}
tries++;
}, 100);
var moveOn = function() { clearInterval(interval); nextTest(); };
}
function promiseObserverNotified(aTopic) { function promiseObserverNotified(aTopic) {
let deferred = Promise.defer(); return new Promise(resolve => {
Services.obs.addObserver(function onNotification(aSubject, aTopic, aData) { Services.obs.addObserver(function onNotification(aSubject, aTopic, aData) {
Services.obs.removeObserver(onNotification, aTopic); dump("notification promised "+aTopic);
deferred.resolve({subject: aSubject, data: aData}); Services.obs.removeObserver(onNotification, aTopic);
TestUtils.executeSoon(() => resolve({subject: aSubject, data: aData}));
}, aTopic, false); }, aTopic, false);
return deferred.promise; });
} }
// Check that a specified (string) URL hasn't been "remembered" (ie, is not // Check that a specified (string) URL hasn't been "remembered" (ie, is not
// in history, will not appear in about:newtab or auto-complete, etc.) // in history, will not appear in about:newtab or auto-complete, etc.)
function promiseSocialUrlNotRemembered(url) { function promiseSocialUrlNotRemembered(url) {
let deferred = Promise.defer(); return new Promise(resolve => {
let uri = Services.io.newURI(url, null, null); let uri = Services.io.newURI(url, null, null);
PlacesUtils.asyncHistory.isURIVisited(uri, function(aURI, aIsVisited) { PlacesUtils.asyncHistory.isURIVisited(uri, function(aURI, aIsVisited) {
ok(!aIsVisited, "social URL " + url + " should not be in global history"); ok(!aIsVisited, "social URL " + url + " should not be in global history");
deferred.resolve(); resolve();
});
}); });
return deferred.promise;
} }
var gURLsNotRemembered = []; var gURLsNotRemembered = [];
@ -154,11 +131,11 @@ function runSocialTestWithProvider(manifest, callback, finishcallback) {
registerCleanupFunction(function () { registerCleanupFunction(function () {
finishSocialTest(true); finishSocialTest(true);
}); });
waitForCondition(() => provider.enabled, BrowserTestUtils.waitForCondition(() => provider.enabled,
function() { "providers added and enabled").then(() => {
info("provider has been enabled"); info("provider has been enabled");
callback(finishSocialTest); callback(finishSocialTest);
}, "providers added and enabled"); });
} }
}); });
}); });
@ -307,39 +284,6 @@ function waitForNotification(topic, cb) {
Services.obs.addObserver(observer, topic, false); Services.obs.addObserver(observer, topic, false);
} }
// blocklist testing
function updateBlocklist(aCallback) {
var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"]
.getService(Ci.nsITimerCallback);
var observer = function() {
Services.obs.removeObserver(observer, "blocklist-updated");
if (aCallback)
executeSoon(aCallback);
};
Services.obs.addObserver(observer, "blocklist-updated", false);
blocklistNotifier.notify(null);
}
var _originalTestBlocklistURL = null;
function setAndUpdateBlocklist(aURL, aCallback) {
if (!_originalTestBlocklistURL)
_originalTestBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url");
Services.prefs.setCharPref("extensions.blocklist.url", aURL);
updateBlocklist(aCallback);
}
function resetBlocklist(aCallback) {
// XXX - this has "forked" from the head.js helpers in our parent directory :(
// But let's reuse their blockNoPlugins.xml. Later, we should arrange to
// use their head.js helpers directly
let noBlockedURL = "http://example.com/browser/browser/base/content/test/plugins/blockNoPlugins.xml";
setAndUpdateBlocklist(noBlockedURL, function() {
Services.prefs.setCharPref("extensions.blocklist.url", _originalTestBlocklistURL);
if (aCallback)
aCallback();
});
}
function setManifestPref(name, manifest) { function setManifestPref(name, manifest) {
let string = Cc["@mozilla.org/supports-string;1"]. let string = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString); createInstance(Ci.nsISupportsString);
@ -375,64 +319,24 @@ function resetBuiltinManifestPref(name) {
Services.prefs.PREF_INVALID, "default manifest removed"); Services.prefs.PREF_INVALID, "default manifest removed");
} }
function addTab(url, callback) {
let tab = gBrowser.selectedTab = gBrowser.addTab(url, {skipAnimation: true});
tab.linkedBrowser.addEventListener("load", function tabLoad(event) {
tab.linkedBrowser.removeEventListener("load", tabLoad, true);
executeSoon(function() {callback(tab)});
}, true);
}
function selectBrowserTab(tab, callback) {
if (gBrowser.selectedTab == tab) {
executeSoon(function() {callback(tab)});
return;
}
gBrowser.tabContainer.addEventListener("TabSelect", function onTabSelect() {
gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect, false);
is(gBrowser.selectedTab, tab, "browser tab is selected");
executeSoon(function() {callback(tab)});
});
gBrowser.selectedTab = tab;
}
function ensureEventFired(elem, event) { function ensureEventFired(elem, event) {
let deferred = Promise.defer(); return BrowserTestUtils.waitForEvent(elem, event, true);
elem.addEventListener(event, function handler() {
elem.removeEventListener(event, handler, true);
deferred.resolve()
}, true);
return deferred.promise;
}
function loadIntoTab(tab, url, callback) {
tab.linkedBrowser.addEventListener("load", function tabLoad(event) {
tab.linkedBrowser.removeEventListener("load", tabLoad, true);
executeSoon(function() {callback(tab)});
}, true);
tab.linkedBrowser.loadURI(url);
}
function ensureBrowserTabClosed(tab) {
let promise = ensureEventFired(gBrowser.tabContainer, "TabClose");
gBrowser.removeTab(tab);
return promise;
} }
function ensureFrameLoaded(frame, uri) { function ensureFrameLoaded(frame, uri) {
let deferred = Promise.defer(); return new Promise(resolve => {
if (frame.contentDocument && frame.contentDocument.readyState == "complete" && if (frame.contentDocument && frame.contentDocument.readyState == "complete" &&
(!uri || frame.contentDocument.location.href == uri)) { (!uri || frame.contentDocument.location.href == uri)) {
deferred.resolve(); resolve();
} else { } else {
frame.addEventListener("load", function handler() { frame.addEventListener("load", function handler() {
if (uri && frame.contentDocument.location.href != uri) if (uri && frame.contentDocument.location.href != uri)
return; return;
frame.removeEventListener("load", handler, true); frame.removeEventListener("load", handler, true);
deferred.resolve() resolve()
}, true); }, true);
} }
return deferred.promise; });
} }
// chat test help functions // chat test help functions
@ -630,23 +534,23 @@ function getPopupWidth() {
} }
function promiseNodeRemoved(aNode) { function promiseNodeRemoved(aNode) {
let deferred = Promise.defer(); return new Promise(resolve => {
let parent = aNode.parentNode; let parent = aNode.parentNode;
let observer = new MutationObserver(function onMutatations(mutations) { let observer = new MutationObserver(function onMutatations(mutations) {
for (let mutation of mutations) { for (let mutation of mutations) {
for (let i = 0; i < mutation.removedNodes.length; i++) { for (let i = 0; i < mutation.removedNodes.length; i++) {
let node = mutation.removedNodes.item(i); let node = mutation.removedNodes.item(i);
if (node != aNode) { if (node != aNode) {
continue; continue;
}
observer.disconnect();
resolve();
} }
observer.disconnect();
deferred.resolve();
} }
} });
observer.observe(parent, {childList: true});
}); });
observer.observe(parent, {childList: true});
return deferred.promise;
} }
function promiseCloseChat(chat) { function promiseCloseChat(chat) {
@ -678,29 +582,29 @@ var origProxyType = Services.prefs.getIntPref('network.proxy.type');
function toggleOfflineStatus(goOffline) { function toggleOfflineStatus(goOffline) {
// Bug 968887 fix. when going on/offline, wait for notification before continuing // Bug 968887 fix. when going on/offline, wait for notification before continuing
let deferred = Promise.defer(); return new Promise(resolve => {
if (!goOffline) { if (!goOffline) {
Services.prefs.setIntPref('network.proxy.type', origProxyType); Services.prefs.setIntPref('network.proxy.type', origProxyType);
} }
if (goOffline != Services.io.offline) { if (goOffline != Services.io.offline) {
info("initial offline state " + Services.io.offline); info("initial offline state " + Services.io.offline);
let expect = !Services.io.offline; let expect = !Services.io.offline;
Services.obs.addObserver(function offlineChange(subject, topic, data) { Services.obs.addObserver(function offlineChange(subject, topic, data) {
Services.obs.removeObserver(offlineChange, "network:offline-status-changed"); Services.obs.removeObserver(offlineChange, "network:offline-status-changed");
info("offline state changed to " + Services.io.offline); info("offline state changed to " + Services.io.offline);
is(expect, Services.io.offline, "network:offline-status-changed successful toggle"); is(expect, Services.io.offline, "network:offline-status-changed successful toggle");
deferred.resolve(); resolve();
}, "network:offline-status-changed", false); }, "network:offline-status-changed", false);
BrowserOffline.toggleOfflineStatus(); BrowserOffline.toggleOfflineStatus();
} else { } else {
deferred.resolve(); resolve();
} }
if (goOffline) { if (goOffline) {
Services.prefs.setIntPref('network.proxy.type', 0); Services.prefs.setIntPref('network.proxy.type', 0);
// LOAD_FLAGS_BYPASS_CACHE isn't good enough. So clear the cache. // LOAD_FLAGS_BYPASS_CACHE isn't good enough. So clear the cache.
Services.cache2.clear(); Services.cache2.clear();
} }
return deferred.promise; });
} }
function goOffline() { function goOffline() {

Просмотреть файл

@ -1,6 +1,7 @@
<html> <html>
<head> <head>
<title>Activation test</title> <meta charset="utf-8">
<title>Activation test</title>
</head> </head>
<script> <script>
// icons from http://findicons.com/icon/158311/firefox?id=356182 by ipapun // icons from http://findicons.com/icon/158311/firefox?id=356182 by ipapun