browser/base/content/test/plugins/browser_bug743421.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 var rootDir = getRootDirectory(gTestPath);
michael@0 2 const gTestRoot = rootDir.replace("chrome://mochitests/content/", "http://mochi.test:8888/");
michael@0 3
michael@0 4 var gTestBrowser = null;
michael@0 5 var gNextTest = null;
michael@0 6
michael@0 7 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 8
michael@0 9 function test() {
michael@0 10 waitForExplicitFinish();
michael@0 11 registerCleanupFunction(function() {
michael@0 12 clearAllPluginPermissions();
michael@0 13 Services.prefs.clearUserPref("plugins.click_to_play");
michael@0 14 });
michael@0 15 Services.prefs.setBoolPref("plugins.click_to_play", true);
michael@0 16 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
michael@0 17
michael@0 18 var newTab = gBrowser.addTab();
michael@0 19 gBrowser.selectedTab = newTab;
michael@0 20 gTestBrowser = gBrowser.selectedBrowser;
michael@0 21 gTestBrowser.addEventListener("load", pageLoad, true);
michael@0 22 prepareTest(test1a, gTestRoot + "plugin_add_dynamically.html");
michael@0 23 }
michael@0 24
michael@0 25 function finishTest() {
michael@0 26 gTestBrowser.removeEventListener("load", pageLoad, true);
michael@0 27 gBrowser.removeCurrentTab();
michael@0 28 window.focus();
michael@0 29 finish();
michael@0 30 }
michael@0 31
michael@0 32 function pageLoad() {
michael@0 33 // The plugin events are async dispatched and can come after the load event
michael@0 34 // This just allows the events to fire before we then go on to test the states
michael@0 35 executeSoon(gNextTest);
michael@0 36 }
michael@0 37
michael@0 38 function prepareTest(nextTest, url) {
michael@0 39 gNextTest = nextTest;
michael@0 40 gTestBrowser.contentWindow.location = url;
michael@0 41 }
michael@0 42
michael@0 43 // Tests that navigation within the page and the window.history API doesn't break click-to-play state.
michael@0 44 function test1a() {
michael@0 45 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 46 ok(!popupNotification, "Test 1a, Should not have a click-to-play notification");
michael@0 47 var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
michael@0 48
michael@0 49 var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 50 waitForCondition(condition, test1b, "Test 1a, Waited too long for plugin notification");
michael@0 51 }
michael@0 52
michael@0 53 function test1b() {
michael@0 54 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 55 ok(popupNotification, "Test 1b, Should have a click-to-play notification");
michael@0 56 var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
michael@0 57 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 58 ok(!objLoadingContent.activated, "Test 1b, Plugin should not be activated");
michael@0 59
michael@0 60 // Click the activate button on doorhanger to make sure it works
michael@0 61 popupNotification.reshow();
michael@0 62 PopupNotifications.panel.firstChild._primaryButton.click();
michael@0 63
michael@0 64 ok(objLoadingContent.activated, "Test 1b, Doorhanger should activate plugin");
michael@0 65
michael@0 66 test1c();
michael@0 67 }
michael@0 68
michael@0 69 function test1c() {
michael@0 70 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 71 ok(popupNotification, "Test 1c, Should still have a click-to-play notification");
michael@0 72 var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
michael@0 73
michael@0 74 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 75 var condition = function() objLoadingContent.activated;
michael@0 76 waitForCondition(condition, test1d, "Test 1c, Waited too long for plugin activation");
michael@0 77 }
michael@0 78
michael@0 79 function test1d() {
michael@0 80 var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[1];
michael@0 81 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 82 ok(objLoadingContent.activated, "Test 1d, Plugin should be activated");
michael@0 83
michael@0 84 gNextTest = test1e;
michael@0 85 gTestBrowser.contentWindow.addEventListener("hashchange", test1e, false);
michael@0 86 gTestBrowser.contentWindow.location += "#anchorNavigation";
michael@0 87 }
michael@0 88
michael@0 89 function test1e() {
michael@0 90 gTestBrowser.contentWindow.removeEventListener("hashchange", test1e, false);
michael@0 91
michael@0 92 var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
michael@0 93
michael@0 94 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 95 var condition = function() objLoadingContent.activated;
michael@0 96 waitForCondition(condition, test1f, "Test 1e, Waited too long for plugin activation");
michael@0 97 }
michael@0 98
michael@0 99 function test1f() {
michael@0 100 var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[2];
michael@0 101 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 102 ok(objLoadingContent.activated, "Test 1f, Plugin should be activated");
michael@0 103
michael@0 104 gTestBrowser.contentWindow.history.replaceState({}, "", "replacedState");
michael@0 105 var plugin = new XPCNativeWrapper(XPCNativeWrapper.unwrap(gTestBrowser.contentWindow).addPlugin());
michael@0 106 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 107 var condition = function() objLoadingContent.activated;
michael@0 108 waitForCondition(condition, test1g, "Test 1f, Waited too long for plugin activation");
michael@0 109 }
michael@0 110
michael@0 111 function test1g() {
michael@0 112 var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[3];
michael@0 113 var objLoadingContent2 = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 114 ok(objLoadingContent2.activated, "Test 1g, Plugin should be activated");
michael@0 115 finishTest();
michael@0 116 }

mercurial