Thu, 15 Jan 2015 15:55:04 +0100
Back out 97036ab72558 which inappropriately compared turds to third parties.
michael@0 | 1 | var gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); |
michael@0 | 2 | var gTestBrowser = null; |
michael@0 | 3 | var gNextTest = null; |
michael@0 | 4 | |
michael@0 | 5 | Components.utils.import("resource://gre/modules/Services.jsm"); |
michael@0 | 6 | |
michael@0 | 7 | function test() { |
michael@0 | 8 | waitForExplicitFinish(); |
michael@0 | 9 | registerCleanupFunction(function() { |
michael@0 | 10 | Services.prefs.clearUserPref("plugins.click_to_play"); |
michael@0 | 11 | }); |
michael@0 | 12 | Services.prefs.setBoolPref("plugins.click_to_play", true); |
michael@0 | 13 | setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); |
michael@0 | 14 | |
michael@0 | 15 | var newTab = gBrowser.addTab(); |
michael@0 | 16 | gBrowser.selectedTab = newTab; |
michael@0 | 17 | gTestBrowser = gBrowser.selectedBrowser; |
michael@0 | 18 | gTestBrowser.addEventListener("load", pageLoad, true); |
michael@0 | 19 | setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml", |
michael@0 | 20 | function() { |
michael@0 | 21 | prepareTest(function() { |
michael@0 | 22 | // Due to layout being async, "PluginBindAttached" may trigger later. |
michael@0 | 23 | // This forces a layout flush, thus triggering it, and schedules the |
michael@0 | 24 | // test so it is definitely executed afterwards. |
michael@0 | 25 | gTestBrowser.contentDocument.getElementById('test').clientTop; |
michael@0 | 26 | testPart1(); |
michael@0 | 27 | }, |
michael@0 | 28 | gHttpTestRoot + "plugin_test.html"); |
michael@0 | 29 | }); |
michael@0 | 30 | } |
michael@0 | 31 | |
michael@0 | 32 | function finishTest() { |
michael@0 | 33 | gTestBrowser.removeEventListener("load", pageLoad, true); |
michael@0 | 34 | gBrowser.removeCurrentTab(); |
michael@0 | 35 | window.focus(); |
michael@0 | 36 | setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", |
michael@0 | 37 | function() { |
michael@0 | 38 | resetBlocklist(); |
michael@0 | 39 | finish(); |
michael@0 | 40 | }); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function pageLoad(aEvent) { |
michael@0 | 44 | // The plugin events are async dispatched and can come after the load event |
michael@0 | 45 | // This just allows the events to fire before we then go on to test the states |
michael@0 | 46 | if (gNextTest != null) |
michael@0 | 47 | executeSoon(gNextTest); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function prepareTest(nextTest, url) { |
michael@0 | 51 | gNextTest = nextTest; |
michael@0 | 52 | gTestBrowser.contentWindow.location = url; |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | // Tests that the going back will reshow the notification for click-to-play |
michael@0 | 56 | // blocklisted plugins (part 1/4) |
michael@0 | 57 | function testPart1() { |
michael@0 | 58 | var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
michael@0 | 59 | ok(popupNotification, "test part 1: Should have a click-to-play notification"); |
michael@0 | 60 | var plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 61 | var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 62 | is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "test part 1: plugin fallback type should be PLUGIN_VULNERABLE_UPDATABLE"); |
michael@0 | 63 | ok(!objLoadingContent.activated, "test part 1: plugin should not be activated"); |
michael@0 | 64 | |
michael@0 | 65 | prepareTest(testPart2, "about:blank"); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | function testPart2() { |
michael@0 | 69 | var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
michael@0 | 70 | ok(!popupNotification, "test part 2: Should not have a click-to-play notification"); |
michael@0 | 71 | var plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 72 | ok(!plugin, "test part 2: Should not have a plugin in this page"); |
michael@0 | 73 | |
michael@0 | 74 | Services.obs.addObserver(testPart3, "PopupNotifications-updateNotShowing", false); |
michael@0 | 75 | gTestBrowser.contentWindow.history.back(); |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function testPart3() { |
michael@0 | 79 | Services.obs.removeObserver(testPart3, "PopupNotifications-updateNotShowing"); |
michael@0 | 80 | var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
michael@0 | 81 | waitForCondition(condition, testPart4, "test part 3: waited too long for click-to-play-plugin notification"); |
michael@0 | 82 | } |
michael@0 | 83 | |
michael@0 | 84 | function testPart4() { |
michael@0 | 85 | var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); |
michael@0 | 86 | ok(popupNotification, "test part 4: Should have a click-to-play notification"); |
michael@0 | 87 | var plugin = gTestBrowser.contentDocument.getElementById("test"); |
michael@0 | 88 | var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); |
michael@0 | 89 | is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "test part 4: plugin fallback type should be PLUGIN_VULNERABLE_UPDATABLE"); |
michael@0 | 90 | ok(!objLoadingContent.activated, "test part 4: plugin should not be activated"); |
michael@0 | 91 | |
michael@0 | 92 | finishTest(); |
michael@0 | 93 | } |