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 test() { |
michael@0 | 6 | waitForExplicitFinish(); |
michael@0 | 7 | |
michael@0 | 8 | let manifest = { // normal provider |
michael@0 | 9 | name: "provider 1", |
michael@0 | 10 | origin: "https://example.com", |
michael@0 | 11 | sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html", |
michael@0 | 12 | workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js", |
michael@0 | 13 | iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png" |
michael@0 | 14 | }; |
michael@0 | 15 | runSocialTestWithProvider(manifest, function (finishcb) { |
michael@0 | 16 | SocialSidebar.show(); |
michael@0 | 17 | runSocialTests(tests, undefined, undefined, finishcb); |
michael@0 | 18 | }); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | var tests = { |
michael@0 | 22 | testOpenCloseFlyout: function(next) { |
michael@0 | 23 | let panel = document.getElementById("social-flyout-panel"); |
michael@0 | 24 | panel.addEventListener("popupshowing", function onShowing() { |
michael@0 | 25 | panel.removeEventListener("popupshowing", onShowing); |
michael@0 | 26 | is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing"); |
michael@0 | 27 | }); |
michael@0 | 28 | let port = SocialSidebar.provider.getWorkerPort(); |
michael@0 | 29 | ok(port, "provider has a port"); |
michael@0 | 30 | port.onmessage = function (e) { |
michael@0 | 31 | let topic = e.data.topic; |
michael@0 | 32 | switch (topic) { |
michael@0 | 33 | case "got-sidebar-message": |
michael@0 | 34 | port.postMessage({topic: "test-flyout-open"}); |
michael@0 | 35 | break; |
michael@0 | 36 | case "got-flyout-visibility": |
michael@0 | 37 | if (e.data.result == "hidden") { |
michael@0 | 38 | ok(true, "flyout visibility is 'hidden'"); |
michael@0 | 39 | is(panel.state, "closed", "panel really is closed"); |
michael@0 | 40 | port.close(); |
michael@0 | 41 | next(); |
michael@0 | 42 | } else if (e.data.result == "shown") { |
michael@0 | 43 | ok(true, "flyout visibility is 'shown"); |
michael@0 | 44 | port.postMessage({topic: "test-flyout-close"}); |
michael@0 | 45 | } |
michael@0 | 46 | break; |
michael@0 | 47 | case "got-flyout-message": |
michael@0 | 48 | ok(e.data.result == "ok", "got flyout message"); |
michael@0 | 49 | break; |
michael@0 | 50 | } |
michael@0 | 51 | } |
michael@0 | 52 | port.postMessage({topic: "test-init"}); |
michael@0 | 53 | }, |
michael@0 | 54 | |
michael@0 | 55 | testResizeFlyout: function(next) { |
michael@0 | 56 | let panel = document.getElementById("social-flyout-panel"); |
michael@0 | 57 | let port = SocialSidebar.provider.getWorkerPort(); |
michael@0 | 58 | ok(port, "provider has a port"); |
michael@0 | 59 | port.onmessage = function (e) { |
michael@0 | 60 | let topic = e.data.topic; |
michael@0 | 61 | switch (topic) { |
michael@0 | 62 | case "test-init-done": |
michael@0 | 63 | port.postMessage({topic: "test-flyout-open"}); |
michael@0 | 64 | break; |
michael@0 | 65 | case "got-flyout-visibility": |
michael@0 | 66 | if (e.data.result != "shown") |
michael@0 | 67 | return; |
michael@0 | 68 | // The width of the flyout should be 400px initially |
michael@0 | 69 | let iframe = panel.firstChild; |
michael@0 | 70 | let body = iframe.contentDocument.body; |
michael@0 | 71 | let cs = iframe.contentWindow.getComputedStyle(body); |
michael@0 | 72 | |
michael@0 | 73 | is(cs.width, "400px", "should be 400px wide"); |
michael@0 | 74 | is(iframe.boxObject.width, 400, "iframe should now be 400px wide"); |
michael@0 | 75 | is(cs.height, "400px", "should be 400px high"); |
michael@0 | 76 | is(iframe.boxObject.height, 400, "iframe should now be 400px high"); |
michael@0 | 77 | |
michael@0 | 78 | iframe.contentWindow.addEventListener("resize", function _doneHandler() { |
michael@0 | 79 | iframe.contentWindow.removeEventListener("resize", _doneHandler, false); |
michael@0 | 80 | cs = iframe.contentWindow.getComputedStyle(body); |
michael@0 | 81 | |
michael@0 | 82 | is(cs.width, "500px", "should now be 500px wide"); |
michael@0 | 83 | is(iframe.boxObject.width, 500, "iframe should now be 500px wide"); |
michael@0 | 84 | is(cs.height, "500px", "should now be 500px high"); |
michael@0 | 85 | is(iframe.boxObject.height, 500, "iframe should now be 500px high"); |
michael@0 | 86 | panel.hidePopup(); |
michael@0 | 87 | port.close(); |
michael@0 | 88 | next(); |
michael@0 | 89 | }, false); |
michael@0 | 90 | SocialFlyout.dispatchPanelEvent("socialTest-MakeWider"); |
michael@0 | 91 | break; |
michael@0 | 92 | } |
michael@0 | 93 | } |
michael@0 | 94 | port.postMessage({topic: "test-init"}); |
michael@0 | 95 | }, |
michael@0 | 96 | |
michael@0 | 97 | testCloseSelf: function(next) { |
michael@0 | 98 | // window.close is affected by the pref dom.allow_scripts_to_close_windows, |
michael@0 | 99 | // which defaults to false, but is set to true by the test harness. |
michael@0 | 100 | // so temporarily set it back. |
michael@0 | 101 | const ALLOW_SCRIPTS_TO_CLOSE_PREF = "dom.allow_scripts_to_close_windows"; |
michael@0 | 102 | // note clearUserPref doesn't do what we expect, as the test harness itself |
michael@0 | 103 | // changes the pref value - so clearUserPref resets it to false rather than |
michael@0 | 104 | // the true setup by the test harness. |
michael@0 | 105 | let oldAllowScriptsToClose = Services.prefs.getBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF); |
michael@0 | 106 | Services.prefs.setBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF, false); |
michael@0 | 107 | let panel = document.getElementById("social-flyout-panel"); |
michael@0 | 108 | let port = SocialSidebar.provider.getWorkerPort(); |
michael@0 | 109 | ok(port, "provider has a port"); |
michael@0 | 110 | port.onmessage = function (e) { |
michael@0 | 111 | let topic = e.data.topic; |
michael@0 | 112 | switch (topic) { |
michael@0 | 113 | case "test-init-done": |
michael@0 | 114 | port.postMessage({topic: "test-flyout-open"}); |
michael@0 | 115 | break; |
michael@0 | 116 | case "got-flyout-visibility": |
michael@0 | 117 | if (e.data.result != "shown") |
michael@0 | 118 | return; |
michael@0 | 119 | let iframe = panel.firstChild; |
michael@0 | 120 | iframe.contentDocument.addEventListener("SocialTest-DoneCloseSelf", function _doneHandler() { |
michael@0 | 121 | iframe.contentDocument.removeEventListener("SocialTest-DoneCloseSelf", _doneHandler, false); |
michael@0 | 122 | port.close(); |
michael@0 | 123 | is(panel.state, "closed", "flyout should have closed itself"); |
michael@0 | 124 | Services.prefs.setBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF, oldAllowScriptsToClose); |
michael@0 | 125 | next(); |
michael@0 | 126 | }, false); |
michael@0 | 127 | is(panel.state, "open", "flyout should be open"); |
michael@0 | 128 | SocialFlyout.dispatchPanelEvent("socialTest-CloseSelf"); |
michael@0 | 129 | break; |
michael@0 | 130 | } |
michael@0 | 131 | } |
michael@0 | 132 | port.postMessage({topic: "test-init"}); |
michael@0 | 133 | }, |
michael@0 | 134 | |
michael@0 | 135 | testCloseOnLinkTraversal: function(next) { |
michael@0 | 136 | |
michael@0 | 137 | function onTabOpen(event) { |
michael@0 | 138 | gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true); |
michael@0 | 139 | waitForCondition(function() { return panel.state == "closed" }, function() { |
michael@0 | 140 | gBrowser.removeTab(event.target); |
michael@0 | 141 | next(); |
michael@0 | 142 | }, "panel should close after tab open"); |
michael@0 | 143 | } |
michael@0 | 144 | |
michael@0 | 145 | let panel = document.getElementById("social-flyout-panel"); |
michael@0 | 146 | let port = SocialSidebar.provider.getWorkerPort(); |
michael@0 | 147 | ok(port, "provider has a port"); |
michael@0 | 148 | port.onmessage = function (e) { |
michael@0 | 149 | let topic = e.data.topic; |
michael@0 | 150 | switch (topic) { |
michael@0 | 151 | case "test-init-done": |
michael@0 | 152 | port.postMessage({topic: "test-flyout-open"}); |
michael@0 | 153 | break; |
michael@0 | 154 | case "got-flyout-visibility": |
michael@0 | 155 | if (e.data.result == "shown") { |
michael@0 | 156 | // click on our test link |
michael@0 | 157 | is(panel.state, "open", "flyout should be open"); |
michael@0 | 158 | gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true); |
michael@0 | 159 | let iframe = panel.firstChild; |
michael@0 | 160 | iframe.contentDocument.getElementById('traversal').click(); |
michael@0 | 161 | } |
michael@0 | 162 | break; |
michael@0 | 163 | } |
michael@0 | 164 | } |
michael@0 | 165 | port.postMessage({topic: "test-init"}); |
michael@0 | 166 | } |
michael@0 | 167 | } |