Wed, 31 Dec 2014 06:09:35 +0100
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 | function gc() { |
michael@0 | 6 | Cu.forceGC(); |
michael@0 | 7 | let wu = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) |
michael@0 | 8 | .getInterface(Components.interfaces.nsIDOMWindowUtils); |
michael@0 | 9 | wu.garbageCollect(); |
michael@0 | 10 | } |
michael@0 | 11 | |
michael@0 | 12 | // Support for going on and offline. |
michael@0 | 13 | // (via browser/base/content/test/browser_bookmark_titles.js) |
michael@0 | 14 | let origProxyType = Services.prefs.getIntPref('network.proxy.type'); |
michael@0 | 15 | |
michael@0 | 16 | function goOffline() { |
michael@0 | 17 | // Simulate a network outage with offline mode. (Localhost is still |
michael@0 | 18 | // accessible in offline mode, so disable the test proxy as well.) |
michael@0 | 19 | if (!Services.io.offline) |
michael@0 | 20 | BrowserOffline.toggleOfflineStatus(); |
michael@0 | 21 | Services.prefs.setIntPref('network.proxy.type', 0); |
michael@0 | 22 | // LOAD_FLAGS_BYPASS_CACHE isn't good enough. So clear the cache. |
michael@0 | 23 | Services.cache2.clear(); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | function goOnline(callback) { |
michael@0 | 27 | Services.prefs.setIntPref('network.proxy.type', origProxyType); |
michael@0 | 28 | if (Services.io.offline) |
michael@0 | 29 | BrowserOffline.toggleOfflineStatus(); |
michael@0 | 30 | if (callback) |
michael@0 | 31 | callback(); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function openPanel(url, panelCallback, loadCallback) { |
michael@0 | 35 | // open a flyout |
michael@0 | 36 | SocialFlyout.open(url, 0, panelCallback); |
michael@0 | 37 | SocialFlyout.panel.firstChild.addEventListener("load", function panelLoad() { |
michael@0 | 38 | SocialFlyout.panel.firstChild.removeEventListener("load", panelLoad, true); |
michael@0 | 39 | loadCallback(); |
michael@0 | 40 | }, true); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function openChat(url, panelCallback, loadCallback) { |
michael@0 | 44 | // open a chat window |
michael@0 | 45 | SocialChatBar.openChat(SocialSidebar.provider, url, panelCallback); |
michael@0 | 46 | SocialChatBar.chatbar.firstChild.addEventListener("DOMContentLoaded", function panelLoad() { |
michael@0 | 47 | SocialChatBar.chatbar.firstChild.removeEventListener("DOMContentLoaded", panelLoad, true); |
michael@0 | 48 | loadCallback(); |
michael@0 | 49 | }, true); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function onSidebarLoad(callback) { |
michael@0 | 53 | let sbrowser = document.getElementById("social-sidebar-browser"); |
michael@0 | 54 | sbrowser.addEventListener("load", function load() { |
michael@0 | 55 | sbrowser.removeEventListener("load", load, true); |
michael@0 | 56 | callback(); |
michael@0 | 57 | }, true); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function ensureWorkerLoaded(provider, callback) { |
michael@0 | 61 | // once the worker responds to a ping we know it must be up. |
michael@0 | 62 | let port = provider.getWorkerPort(); |
michael@0 | 63 | port.onmessage = function(msg) { |
michael@0 | 64 | if (msg.data.topic == "pong") { |
michael@0 | 65 | port.close(); |
michael@0 | 66 | callback(); |
michael@0 | 67 | } |
michael@0 | 68 | } |
michael@0 | 69 | port.postMessage({topic: "ping"}) |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | let manifest = { // normal provider |
michael@0 | 73 | name: "provider 1", |
michael@0 | 74 | origin: "https://example.com", |
michael@0 | 75 | sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html", |
michael@0 | 76 | workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", |
michael@0 | 77 | iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png" |
michael@0 | 78 | }; |
michael@0 | 79 | |
michael@0 | 80 | function test() { |
michael@0 | 81 | waitForExplicitFinish(); |
michael@0 | 82 | |
michael@0 | 83 | runSocialTestWithProvider(manifest, function (finishcb) { |
michael@0 | 84 | runSocialTests(tests, undefined, goOnline, finishcb); |
michael@0 | 85 | }); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | var tests = { |
michael@0 | 89 | testSidebar: function(next) { |
michael@0 | 90 | let sbrowser = document.getElementById("social-sidebar-browser"); |
michael@0 | 91 | onSidebarLoad(function() { |
michael@0 | 92 | ok(sbrowser.contentDocument.location.href.indexOf("about:socialerror?")==0, "is on social error page"); |
michael@0 | 93 | gc(); |
michael@0 | 94 | // Add a new load listener, then find and click the "try again" button. |
michael@0 | 95 | onSidebarLoad(function() { |
michael@0 | 96 | // should still be on the error page. |
michael@0 | 97 | ok(sbrowser.contentDocument.location.href.indexOf("about:socialerror?")==0, "is still on social error page"); |
michael@0 | 98 | // go online and try again - this should work. |
michael@0 | 99 | goOnline(); |
michael@0 | 100 | onSidebarLoad(function() { |
michael@0 | 101 | // should now be on the correct page. |
michael@0 | 102 | is(sbrowser.contentDocument.location.href, manifest.sidebarURL, "is now on social sidebar page"); |
michael@0 | 103 | next(); |
michael@0 | 104 | }); |
michael@0 | 105 | sbrowser.contentDocument.getElementById("btnTryAgain").click(); |
michael@0 | 106 | }); |
michael@0 | 107 | sbrowser.contentDocument.getElementById("btnTryAgain").click(); |
michael@0 | 108 | }); |
michael@0 | 109 | // we want the worker to be fully loaded before going offline, otherwise |
michael@0 | 110 | // it might fail due to going offline. |
michael@0 | 111 | ensureWorkerLoaded(SocialSidebar.provider, function() { |
michael@0 | 112 | // go offline then attempt to load the sidebar - it should fail. |
michael@0 | 113 | goOffline(); |
michael@0 | 114 | SocialSidebar.show(); |
michael@0 | 115 | }); |
michael@0 | 116 | }, |
michael@0 | 117 | |
michael@0 | 118 | testFlyout: function(next) { |
michael@0 | 119 | let panelCallbackCount = 0; |
michael@0 | 120 | let panel = document.getElementById("social-flyout-panel"); |
michael@0 | 121 | // go offline and open a flyout. |
michael@0 | 122 | goOffline(); |
michael@0 | 123 | openPanel( |
michael@0 | 124 | "https://example.com/browser/browser/base/content/test/social/social_panel.html", |
michael@0 | 125 | function() { // the panel api callback |
michael@0 | 126 | panelCallbackCount++; |
michael@0 | 127 | }, |
michael@0 | 128 | function() { // the "load" callback. |
michael@0 | 129 | executeSoon(function() { |
michael@0 | 130 | todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads."); |
michael@0 | 131 | ok(panel.firstChild.contentDocument.location.href.indexOf("about:socialerror?")==0, "is on social error page"); |
michael@0 | 132 | // Bug 832943 - the listeners previously stopped working after a GC, so |
michael@0 | 133 | // force a GC now and try again. |
michael@0 | 134 | gc(); |
michael@0 | 135 | openPanel( |
michael@0 | 136 | "https://example.com/browser/browser/base/content/test/social/social_panel.html", |
michael@0 | 137 | function() { // the panel api callback |
michael@0 | 138 | panelCallbackCount++; |
michael@0 | 139 | }, |
michael@0 | 140 | function() { // the "load" callback. |
michael@0 | 141 | executeSoon(function() { |
michael@0 | 142 | todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads."); |
michael@0 | 143 | ok(panel.firstChild.contentDocument.location.href.indexOf("about:socialerror?")==0, "is on social error page"); |
michael@0 | 144 | gc(); |
michael@0 | 145 | SocialFlyout.unload(); |
michael@0 | 146 | next(); |
michael@0 | 147 | }); |
michael@0 | 148 | } |
michael@0 | 149 | ); |
michael@0 | 150 | }); |
michael@0 | 151 | } |
michael@0 | 152 | ); |
michael@0 | 153 | }, |
michael@0 | 154 | |
michael@0 | 155 | testChatWindow: function(next) { |
michael@0 | 156 | let panelCallbackCount = 0; |
michael@0 | 157 | // go offline and open a flyout. |
michael@0 | 158 | goOffline(); |
michael@0 | 159 | openChat( |
michael@0 | 160 | "https://example.com/browser/browser/base/content/test/social/social_chat.html", |
michael@0 | 161 | function() { // the panel api callback |
michael@0 | 162 | panelCallbackCount++; |
michael@0 | 163 | }, |
michael@0 | 164 | function() { // the "load" callback. |
michael@0 | 165 | executeSoon(function() { |
michael@0 | 166 | todo_is(panelCallbackCount, 0, "Bug 833207 - should be no callback when error page loads."); |
michael@0 | 167 | let chat = SocialChatBar.chatbar.selectedChat; |
michael@0 | 168 | waitForCondition(function() chat.contentDocument.location.href.indexOf("about:socialerror?")==0, |
michael@0 | 169 | function() { |
michael@0 | 170 | chat.close(); |
michael@0 | 171 | next(); |
michael@0 | 172 | }, |
michael@0 | 173 | "error page didn't appear"); |
michael@0 | 174 | }); |
michael@0 | 175 | } |
michael@0 | 176 | ); |
michael@0 | 177 | } |
michael@0 | 178 | } |