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 | var rootDir = getRootDirectory(gTestPath); |
michael@0 | 6 | const gTestRoot = rootDir; |
michael@0 | 7 | |
michael@0 | 8 | var gTestBrowser = null; |
michael@0 | 9 | var gNextTest = null; |
michael@0 | 10 | var gNextTestSkip = 0; |
michael@0 | 11 | var gPlayPreviewPluginActualEvents = 0; |
michael@0 | 12 | var gPlayPreviewPluginExpectedEvents = 1; |
michael@0 | 13 | |
michael@0 | 14 | var gPlayPreviewRegistration = null; |
michael@0 | 15 | |
michael@0 | 16 | function registerPlayPreview(mimeType, targetUrl) { |
michael@0 | 17 | var ph = Cc["@mozilla.org/plugin/host;1"].getService(Ci.nsIPluginHost); |
michael@0 | 18 | ph.registerPlayPreviewMimeType(mimeType, false, targetUrl); |
michael@0 | 19 | |
michael@0 | 20 | return (gPlayPreviewRegistration = { |
michael@0 | 21 | unregister: function() { |
michael@0 | 22 | ph.unregisterPlayPreviewMimeType(mimeType); |
michael@0 | 23 | gPlayPreviewRegistration = null; |
michael@0 | 24 | } |
michael@0 | 25 | }); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | function unregisterPlayPreview() { |
michael@0 | 29 | gPlayPreviewRegistration.unregister(); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | Components.utils.import('resource://gre/modules/XPCOMUtils.jsm'); |
michael@0 | 33 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 34 | |
michael@0 | 35 | |
michael@0 | 36 | function test() { |
michael@0 | 37 | waitForExplicitFinish(); |
michael@0 | 38 | registerCleanupFunction(function() { |
michael@0 | 39 | if (gPlayPreviewRegistration) |
michael@0 | 40 | gPlayPreviewRegistration.unregister(); |
michael@0 | 41 | Services.prefs.clearUserPref("plugins.click_to_play"); |
michael@0 | 42 | }); |
michael@0 | 43 | |
michael@0 | 44 | var newTab = gBrowser.addTab(); |
michael@0 | 45 | gBrowser.selectedTab = newTab; |
michael@0 | 46 | gTestBrowser = gBrowser.selectedBrowser; |
michael@0 | 47 | gTestBrowser.addEventListener("load", pageLoad, true); |
michael@0 | 48 | gTestBrowser.addEventListener("PluginBindingAttached", handleBindingAttached, true, true); |
michael@0 | 49 | |
michael@0 | 50 | Services.prefs.setBoolPref("plugins.click_to_play", true); |
michael@0 | 51 | setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); |
michael@0 | 52 | |
michael@0 | 53 | registerPlayPreview('application/x-test', 'about:'); |
michael@0 | 54 | prepareTest(test1a, gTestRoot + "plugin_test.html", 1); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | function finishTest() { |
michael@0 | 58 | gTestBrowser.removeEventListener("load", pageLoad, true); |
michael@0 | 59 | gTestBrowser.removeEventListener("PluginBindingAttached", handleBindingAttached, true, true); |
michael@0 | 60 | gBrowser.removeCurrentTab(); |
michael@0 | 61 | window.focus(); |
michael@0 | 62 | finish(); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | function handleBindingAttached(evt) { |
michael@0 | 66 | if (evt.target instanceof Ci.nsIObjectLoadingContent && |
michael@0 | 67 | evt.target.pluginFallbackType == Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW) |
michael@0 | 68 | gPlayPreviewPluginActualEvents++; |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | function pageLoad() { |
michael@0 | 72 | // The plugin events are async dispatched and can come after the load event |
michael@0 | 73 | // This just allows the events to fire before we then go on to test the states |
michael@0 | 74 | |
michael@0 | 75 | // iframe might triggers load event as well, making sure we skip some to let |
michael@0 | 76 | // all iframes on the page be loaded as well |
michael@0 | 77 | if (gNextTestSkip) { |
michael@0 | 78 | gNextTestSkip--; |
michael@0 | 79 | return; |
michael@0 | 80 | } |
michael@0 | 81 | executeSoon(gNextTest); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | function prepareTest(nextTest, url, skip) { |
michael@0 | 85 | gNextTest = nextTest; |
michael@0 | 86 | gNextTestSkip = skip; |
michael@0 | 87 | gTestBrowser.contentWindow.location = url; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | // Tests a page with normal play preview registration (1/2) |
michael@0 | 91 | function test1a() { |
michael@0 | 92 | var notificationBox = gBrowser.getNotificationBox(gTestBrowser); |
michael@0 | 93 | ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 1a, Should not have displayed the missing plugin notification"); |
michael@0 | 94 | ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 1a, Should not have displayed the blocked plugin notification"); |
michael@0 | 95 | |
michael@0 | 96 | var pluginInfo = getTestPlugin(); |
michael@0 | 97 | ok(pluginInfo, "Should have a test plugin"); |
michael@0 | 98 | |
michael@0 | 99 | var doc = gTestBrowser.contentDocument; |
michael@0 | 100 | var plugin = doc.getElementById("test"); |
michael@0 | 101 | var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 102 | is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW, "Test 1a, plugin fallback type should be PLUGIN_PLAY_PREVIEW"); |
michael@0 | 103 | ok(!objLoadingContent.activated, "Test 1a, Plugin should not be activated"); |
michael@0 | 104 | |
michael@0 | 105 | var overlay = doc.getAnonymousElementByAttribute(plugin, "class", "previewPluginContent"); |
michael@0 | 106 | ok(overlay, "Test 1a, the overlay div is expected"); |
michael@0 | 107 | |
michael@0 | 108 | var iframe = overlay.getElementsByClassName("previewPluginContentFrame")[0]; |
michael@0 | 109 | ok(iframe && iframe.localName == "iframe", "Test 1a, the overlay iframe is expected"); |
michael@0 | 110 | var iframeHref = iframe.contentWindow.location.href; |
michael@0 | 111 | ok(iframeHref == "about:", "Test 1a, the overlay about: content is expected"); |
michael@0 | 112 | |
michael@0 | 113 | var rect = iframe.getBoundingClientRect(); |
michael@0 | 114 | ok(rect.width == 200, "Test 1a, Plugin with id=" + plugin.id + " overlay rect should have 200px width before being replaced by actual plugin"); |
michael@0 | 115 | ok(rect.height == 200, "Test 1a, Plugin with id=" + plugin.id + " overlay rect should have 200px height before being replaced by actual plugin"); |
michael@0 | 116 | |
michael@0 | 117 | var e = overlay.ownerDocument.createEvent("CustomEvent"); |
michael@0 | 118 | e.initCustomEvent("MozPlayPlugin", true, true, null); |
michael@0 | 119 | overlay.dispatchEvent(e); |
michael@0 | 120 | var condition = function() objLoadingContent.activated; |
michael@0 | 121 | waitForCondition(condition, test1b, "Test 1a, Waited too long for plugin to stop play preview"); |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | // Tests that activating via MozPlayPlugin through the notification works (part 2/2) |
michael@0 | 125 | function test1b() { |
michael@0 | 126 | var plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 127 | var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 128 | ok(objLoadingContent.activated, "Test 1b, Plugin should be activated"); |
michael@0 | 129 | |
michael@0 | 130 | is(gPlayPreviewPluginActualEvents, gPlayPreviewPluginExpectedEvents, |
michael@0 | 131 | "There should be exactly one PluginPlayPreview event"); |
michael@0 | 132 | |
michael@0 | 133 | unregisterPlayPreview(); |
michael@0 | 134 | |
michael@0 | 135 | prepareTest(test2, gTestRoot + "plugin_test.html"); |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | // Tests a page with a working plugin in it -- the mime type was just unregistered. |
michael@0 | 139 | function test2() { |
michael@0 | 140 | var doc = gTestBrowser.contentDocument; |
michael@0 | 141 | var plugin = doc.getElementById("test"); |
michael@0 | 142 | var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 143 | ok(objLoadingContent.pluginFallbackType != Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW, "Test 2, plugin fallback type should not be PLUGIN_PLAY_PREVIEW"); |
michael@0 | 144 | ok(!objLoadingContent.activated, "Test 2, Plugin should not be activated"); |
michael@0 | 145 | |
michael@0 | 146 | registerPlayPreview('application/x-unknown', 'about:'); |
michael@0 | 147 | |
michael@0 | 148 | prepareTest(test3, gTestRoot + "plugin_test.html"); |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | // Tests a page with a working plugin in it -- diffent play preview type is reserved. |
michael@0 | 152 | function test3() { |
michael@0 | 153 | var doc = gTestBrowser.contentDocument; |
michael@0 | 154 | var plugin = doc.getElementById("test"); |
michael@0 | 155 | var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 156 | ok(objLoadingContent.pluginFallbackType != Ci.nsIObjectLoadingContent.PLUGIN_PLAY_PREVIEW, "Test 3, plugin fallback type should not be PLUGIN_PLAY_PREVIEW"); |
michael@0 | 157 | ok(!objLoadingContent.activated, "Test 3, Plugin should not be activated"); |
michael@0 | 158 | |
michael@0 | 159 | unregisterPlayPreview(); |
michael@0 | 160 | |
michael@0 | 161 | registerPlayPreview('application/x-test', 'about:'); |
michael@0 | 162 | Services.prefs.setBoolPref("plugins.click_to_play", false); |
michael@0 | 163 | var plugin = getTestPlugin(); |
michael@0 | 164 | plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED; |
michael@0 | 165 | prepareTest(test4, gTestRoot + "plugin_test.html"); |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | // Tests a page with a working plugin in it -- click-to-play is off |
michael@0 | 169 | function test4() { |
michael@0 | 170 | var plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 171 | var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 172 | ok(objLoadingContent.activated, "Test 4, Plugin should be activated"); |
michael@0 | 173 | |
michael@0 | 174 | finishTest(); |
michael@0 | 175 | } |
michael@0 | 176 |