toolkit/mozapps/extensions/test/xpcshell/test_pluginBlocklistCtp.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 /* 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 const nsIBLS = Components.interfaces.nsIBlocklistService;
michael@0 6 Components.utils.import("resource://testing-common/httpd.js");
michael@0 7
michael@0 8 var gBlocklistService = null;
michael@0 9 var gNotifier = null;
michael@0 10 var gNextTest = null;
michael@0 11 var gPluginHost = null;
michael@0 12
michael@0 13 var gServer = new HttpServer();
michael@0 14 gServer.start(-1);
michael@0 15 gPort = gServer.identity.primaryPort;
michael@0 16 mapFile("/data/test_pluginBlocklistCtp.xml", gServer);
michael@0 17 mapFile("/data/test_pluginBlocklistCtpUndo.xml", gServer);
michael@0 18
michael@0 19 var PLUGINS = [{
michael@0 20 // severity=0, vulnerabilitystatus=0 -> outdated
michael@0 21 name: "test_plugin_0",
michael@0 22 version: "5",
michael@0 23 disabled: false,
michael@0 24 blocklisted: false
michael@0 25 },
michael@0 26 {
michael@0 27 // severity=0, vulnerabilitystatus=1 -> update available
michael@0 28 name: "test_plugin_1",
michael@0 29 version: "5",
michael@0 30 disabled: false,
michael@0 31 blocklisted: false
michael@0 32 },
michael@0 33 {
michael@0 34 // severity=0, vulnerabilitystatus=2 -> no update
michael@0 35 name: "test_plugin_2",
michael@0 36 version: "5",
michael@0 37 disabled: false,
michael@0 38 blocklisted: false
michael@0 39 },
michael@0 40 {
michael@0 41 // no severity field -> severity=3 by default -> hardblock
michael@0 42 name: "test_plugin_3",
michael@0 43 version: "5",
michael@0 44 disabled: false,
michael@0 45 blocklisted: false
michael@0 46 },
michael@0 47 {
michael@0 48 // severity=1, vulnerabilitystatus=2 -> softblock
michael@0 49 name: "test_plugin_4",
michael@0 50 version: "5",
michael@0 51 disabled: false,
michael@0 52 blocklisted: false
michael@0 53 },
michael@0 54 {
michael@0 55 // not in the blocklist -> not blocked
michael@0 56 name: "test_plugin_5",
michael@0 57 version: "5",
michael@0 58 disabled: false,
michael@0 59 blocklisted: false
michael@0 60 }];
michael@0 61
michael@0 62 function test_basic() {
michael@0 63 var blocklist = Components.classes["@mozilla.org/extensions/blocklist;1"].getService(nsIBLS);
michael@0 64
michael@0 65 do_check_true(blocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_OUTDATED);
michael@0 66
michael@0 67 do_check_true(blocklist.getPluginBlocklistState(PLUGINS[1], "1", "1.9") == nsIBLS.STATE_VULNERABLE_UPDATE_AVAILABLE);
michael@0 68
michael@0 69 do_check_true(blocklist.getPluginBlocklistState(PLUGINS[2], "1", "1.9") == nsIBLS.STATE_VULNERABLE_NO_UPDATE);
michael@0 70
michael@0 71 do_check_true(blocklist.getPluginBlocklistState(PLUGINS[3], "1", "1.9") == nsIBLS.STATE_BLOCKED);
michael@0 72
michael@0 73 do_check_true(blocklist.getPluginBlocklistState(PLUGINS[4], "1", "1.9") == nsIBLS.STATE_SOFTBLOCKED);
michael@0 74
michael@0 75 do_check_true(blocklist.getPluginBlocklistState(PLUGINS[5], "1", "1.9") == nsIBLS.STATE_NOT_BLOCKED);
michael@0 76
michael@0 77 gNextTest = test_is_not_clicktoplay;
michael@0 78 do_execute_soon(gNextTest);
michael@0 79 }
michael@0 80
michael@0 81 function get_test_plugin() {
michael@0 82 var pluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
michael@0 83 for (var plugin of pluginHost.getPluginTags()) {
michael@0 84 if (plugin.name == "Test Plug-in")
michael@0 85 return plugin;
michael@0 86 }
michael@0 87 do_check_true(false);
michael@0 88 return null;
michael@0 89 }
michael@0 90
michael@0 91 // At this time, the blocklist does not have an entry for the test plugin,
michael@0 92 // so it shouldn't be click-to-play.
michael@0 93 function test_is_not_clicktoplay() {
michael@0 94 var plugin = get_test_plugin();
michael@0 95 var blocklistState = gBlocklistService.getPluginBlocklistState(plugin, "1", "1.9");
michael@0 96 do_check_neq(blocklistState, Components.interfaces.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE);
michael@0 97 do_check_neq(blocklistState, Components.interfaces.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE);
michael@0 98
michael@0 99 Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/test_pluginBlocklistCtpUndo.xml");
michael@0 100 gNextTest = test_is_clicktoplay;
michael@0 101 gNotifier.notify(null);
michael@0 102 }
michael@0 103
michael@0 104 // Here, we've updated the blocklist to have a block for the test plugin,
michael@0 105 // so it should be click-to-play.
michael@0 106 function test_is_clicktoplay() {
michael@0 107 var plugin = get_test_plugin();
michael@0 108 var blocklistState = gBlocklistService.getPluginBlocklistState(plugin, "1", "1.9");
michael@0 109 do_check_eq(blocklistState, Components.interfaces.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE);
michael@0 110
michael@0 111 Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/test_pluginBlocklistCtp.xml");
michael@0 112 gNextTest = test_is_not_clicktoplay2;
michael@0 113 gNotifier.notify(null);
michael@0 114 }
michael@0 115
michael@0 116 // But now we've removed that entry from the blocklist (really we've gone back
michael@0 117 // to the old one), so the plugin shouldn't be click-to-play any more.
michael@0 118 function test_is_not_clicktoplay2() {
michael@0 119 var plugin = get_test_plugin();
michael@0 120 var blocklistState = gBlocklistService.getPluginBlocklistState(plugin, "1", "1.9");
michael@0 121 do_check_neq(blocklistState, Components.interfaces.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE);
michael@0 122 do_check_neq(blocklistState, Components.interfaces.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE);
michael@0 123
michael@0 124 Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/test_pluginBlocklistCtpUndo.xml");
michael@0 125 gNextTest = test_disable_blocklist;
michael@0 126 gNotifier.notify(null);
michael@0 127 }
michael@0 128
michael@0 129 // Test that disabling the blocklist when a plugin is ctp-blocklisted will
michael@0 130 // result in the plugin not being click-to-play.
michael@0 131 function test_disable_blocklist() {
michael@0 132 var plugin = get_test_plugin();
michael@0 133 var blocklistState = gBlocklistService.getPluginBlocklistState(plugin, "1", "1.9");
michael@0 134 do_check_eq(blocklistState, Components.interfaces.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE);
michael@0 135
michael@0 136 gNextTest = null;
michael@0 137 Services.prefs.setBoolPref("extensions.blocklist.enabled", false);
michael@0 138 blocklistState = gBlocklistService.getPluginBlocklistState(plugin, "1", "1.9");
michael@0 139 do_check_neq(blocklistState, Components.interfaces.nsIBlocklistService.STATE_VULNERABLE_NO_UPDATE);
michael@0 140 do_check_neq(blocklistState, Components.interfaces.nsIBlocklistService.STATE_VULNERABLE_UPDATE_AVAILABLE);
michael@0 141
michael@0 142 // it should still be possible to make a plugin click-to-play via the pref
michael@0 143 // and setting that plugin's enabled state to click-to-play
michael@0 144 Services.prefs.setBoolPref("plugins.click_to_play", true);
michael@0 145 let previousEnabledState = plugin.enabledState;
michael@0 146 plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_CLICKTOPLAY;
michael@0 147 do_check_eq(gPluginHost.getStateForType("application/x-test"), Components.interfaces.nsIPluginTag.STATE_CLICKTOPLAY);
michael@0 148 // clean up plugin state
michael@0 149 plugin.enabledState = previousEnabledState;
michael@0 150
michael@0 151 gServer.stop(do_test_finished);
michael@0 152 }
michael@0 153
michael@0 154 // Observe "blocklist-updated" so we know when to advance to the next test
michael@0 155 function observer() {
michael@0 156 if (gNextTest)
michael@0 157 do_execute_soon(gNextTest);
michael@0 158 }
michael@0 159
michael@0 160 function run_test() {
michael@0 161 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9");
michael@0 162
michael@0 163 Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/test_pluginBlocklistCtp.xml");
michael@0 164 startupManager();
michael@0 165
michael@0 166 gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
michael@0 167 gBlocklistService = Components.classes["@mozilla.org/extensions/blocklist;1"].getService(Components.interfaces.nsIBlocklistService);
michael@0 168 gNotifier = Components.classes["@mozilla.org/extensions/blocklist;1"].getService(Components.interfaces.nsITimerCallback);
michael@0 169 Services.obs.addObserver(observer, "blocklist-updated", false);
michael@0 170
michael@0 171 do_register_cleanup(function() {
michael@0 172 Services.prefs.clearUserPref("extensions.blocklist.url");
michael@0 173 Services.prefs.clearUserPref("extensions.blocklist.enabled");
michael@0 174 Services.prefs.clearUserPref("plugins.click_to_play");
michael@0 175 Services.obs.removeObserver(observer, "blocklist-updated");
michael@0 176 });
michael@0 177
michael@0 178 gNextTest = test_basic;
michael@0 179 do_test_pending();
michael@0 180 gNotifier.notify(null);
michael@0 181 }

mercurial