michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: function gc() { michael@0: Cu.forceGC(); michael@0: let wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) michael@0: .getInterface(Components.interfaces.nsIDOMWindowUtils); michael@0: wu.garbageCollect(); michael@0: } michael@0: michael@0: // Support for going on and offline. michael@0: // (via browser/base/content/test/browser_bookmark_titles.js) michael@0: let origProxyType = Services.prefs.getIntPref('network.proxy.type'); michael@0: michael@0: function goOffline() { michael@0: // Simulate a network outage with offline mode. (Localhost is still michael@0: // accessible in offline mode, so disable the test proxy as well.) michael@0: if (!Services.io.offline) michael@0: BrowserOffline.toggleOfflineStatus(); michael@0: Services.prefs.setIntPref('network.proxy.type', 0); michael@0: // LOAD_FLAGS_BYPASS_CACHE isn't good enough. So clear the cache. michael@0: Services.cache2.clear(); michael@0: } michael@0: michael@0: function goOnline(callback) { michael@0: Services.prefs.setIntPref('network.proxy.type', origProxyType); michael@0: if (Services.io.offline) michael@0: BrowserOffline.toggleOfflineStatus(); michael@0: if (callback) michael@0: callback(); michael@0: } michael@0: michael@0: function openPanel(url, panelCallback, loadCallback) { michael@0: // open a flyout michael@0: SocialFlyout.open(url, 0, panelCallback); michael@0: SocialFlyout.panel.firstChild.addEventListener("load", function panelLoad() { michael@0: SocialFlyout.panel.firstChild.removeEventListener("load", panelLoad, true); michael@0: loadCallback(); michael@0: }, true); michael@0: } michael@0: michael@0: function openChat(url, panelCallback, loadCallback) { michael@0: // open a chat window michael@0: SocialChatBar.openChat(SocialSidebar.provider, url, panelCallback); michael@0: SocialChatBar.chatbar.firstChild.addEventListener("DOMContentLoaded", function panelLoad() { michael@0: SocialChatBar.chatbar.firstChild.removeEventListener("DOMContentLoaded", panelLoad, true); michael@0: loadCallback(); michael@0: }, true); michael@0: } michael@0: michael@0: function onSidebarLoad(callback) { michael@0: let sbrowser = document.getElementById("social-sidebar-browser"); michael@0: sbrowser.addEventListener("load", function load() { michael@0: sbrowser.removeEventListener("load", load, true); michael@0: callback(); michael@0: }, true); michael@0: } michael@0: michael@0: function ensureWorkerLoaded(provider, callback) { michael@0: // once the worker responds to a ping we know it must be up. michael@0: let port = provider.getWorkerPort(); michael@0: port.onmessage = function(msg) { michael@0: if (msg.data.topic == "pong") { michael@0: port.close(); michael@0: callback(); michael@0: } michael@0: } michael@0: port.postMessage({topic: "ping"}) michael@0: } michael@0: michael@0: let manifest = { // normal provider michael@0: name: "provider 1", michael@0: origin: "https://example.com", michael@0: sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html", michael@0: workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", michael@0: iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png" michael@0: }; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: runSocialTestWithProvider(manifest, function (finishcb) { michael@0: runSocialTests(tests, undefined, goOnline, finishcb); michael@0: }); michael@0: } michael@0: michael@0: var tests = { michael@0: testSidebar: function(next) { michael@0: let sbrowser = document.getElementById("social-sidebar-browser"); michael@0: onSidebarLoad(function() { michael@0: ok(sbrowser.contentDocument.location.href.indexOf("about:socialerror?")==0, "is on social error page"); michael@0: gc(); michael@0: // Add a new load listener, then find and click the "try again" button. michael@0: onSidebarLoad(function() { michael@0: // should still be on the error page. michael@0: ok(sbrowser.contentDocument.location.href.indexOf("about:socialerror?")==0, "is still on social error page"); michael@0: // go online and try again - this should work. michael@0: goOnline(); michael@0: onSidebarLoad(function() { michael@0: // should now be on the correct page. michael@0: is(sbrowser.contentDocument.location.href, manifest.sidebarURL, "is now on social sidebar page"); michael@0: next(); michael@0: }); michael@0: sbrowser.contentDocument.getElementById("btnTryAgain").click(); michael@0: }); michael@0: sbrowser.contentDocument.getElementById("btnTryAgain").click(); michael@0: }); michael@0: // we want the worker to be fully loaded before going offline, otherwise michael@0: // it might fail due to going offline. michael@0: ensureWorkerLoaded(SocialSidebar.provider, function() { michael@0: // go offline then attempt to load the sidebar - it should fail. michael@0: goOffline(); michael@0: SocialSidebar.show(); michael@0: }); michael@0: }, michael@0: michael@0: testFlyout: function(next) { michael@0: let panelCallbackCount = 0; michael@0: let panel = document.getElementById("social-flyout-panel"); michael@0: // go offline and open a flyout. michael@0: goOffline(); michael@0: openPanel( michael@0: "https://example.com/browser/browser/base/content/test/social/social_panel.html", michael@0: function() { // the panel api callback michael@0: panelCallbackCount++; michael@0: }, michael@0: function() { // the "load" callback. michael@0: executeSoon(function() { michael@0: todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads."); michael@0: ok(panel.firstChild.contentDocument.location.href.indexOf("about:socialerror?")==0, "is on social error page"); michael@0: // Bug 832943 - the listeners previously stopped working after a GC, so michael@0: // force a GC now and try again. michael@0: gc(); michael@0: openPanel( michael@0: "https://example.com/browser/browser/base/content/test/social/social_panel.html", michael@0: function() { // the panel api callback michael@0: panelCallbackCount++; michael@0: }, michael@0: function() { // the "load" callback. michael@0: executeSoon(function() { michael@0: todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads."); michael@0: ok(panel.firstChild.contentDocument.location.href.indexOf("about:socialerror?")==0, "is on social error page"); michael@0: gc(); michael@0: SocialFlyout.unload(); michael@0: next(); michael@0: }); michael@0: } michael@0: ); michael@0: }); michael@0: } michael@0: ); michael@0: }, michael@0: michael@0: testChatWindow: function(next) { michael@0: let panelCallbackCount = 0; michael@0: // go offline and open a flyout. michael@0: goOffline(); michael@0: openChat( michael@0: "https://example.com/browser/browser/base/content/test/social/social_chat.html", michael@0: function() { // the panel api callback michael@0: panelCallbackCount++; michael@0: }, michael@0: function() { // the "load" callback. michael@0: executeSoon(function() { michael@0: todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads."); michael@0: let chat = SocialChatBar.chatbar.selectedChat; michael@0: waitForCondition(function() chat.contentDocument.location.href.indexOf("about:socialerror?")==0, michael@0: function() { michael@0: chat.close(); michael@0: next(); michael@0: }, michael@0: "error page didn't appear"); michael@0: }); michael@0: } michael@0: ); michael@0: } michael@0: }