|
1 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
4 |
|
5 const Cc = Components.classes; |
|
6 const Ci = Components.interfaces; |
|
7 const Cu = Components.utils; |
|
8 const Cr = Components.results; |
|
9 |
|
10 Cu.import("resource://testing-common/httpd.js"); |
|
11 |
|
12 const nsIBLS = Ci.nsIBlocklistService; |
|
13 const URI_EXTENSION_BLOCKLIST_DIALOG = "chrome://mozapps/content/extensions/blocklist.xul"; |
|
14 |
|
15 var gBlocklist = null; |
|
16 var gPrefs = null; |
|
17 var gTestserver = null; |
|
18 |
|
19 var gNextTestPart = null; |
|
20 |
|
21 |
|
22 var PLUGINS = [{ |
|
23 // Tests a plugin whose state goes from not-blocked, to outdated |
|
24 name: "test_bug514327_outdated", |
|
25 version: "5", |
|
26 disabled: false, |
|
27 blocklisted: false |
|
28 }, { |
|
29 // Used to trigger the blocklist dialog, which indicates the blocklist has updated |
|
30 name: "test_bug514327_1", |
|
31 version: "5", |
|
32 disabled: false, |
|
33 blocklisted: false |
|
34 }, { |
|
35 // Used to trigger the blocklist dialog, which indicates the blocklist has updated |
|
36 name: "test_bug514327_2", |
|
37 version: "5", |
|
38 disabled: false, |
|
39 blocklisted: false |
|
40 } ]; |
|
41 |
|
42 |
|
43 // A fake plugin host for the blocklist service to use |
|
44 var PluginHost = { |
|
45 getPluginTags: function(countRef) { |
|
46 countRef.value = PLUGINS.length; |
|
47 return PLUGINS; |
|
48 }, |
|
49 |
|
50 QueryInterface: function(iid) { |
|
51 if (iid.equals(Ci.nsIPluginHost) |
|
52 || iid.equals(Ci.nsISupports)) |
|
53 return this; |
|
54 |
|
55 throw Components.results.NS_ERROR_NO_INTERFACE; |
|
56 } |
|
57 } |
|
58 |
|
59 var PluginHostFactory = { |
|
60 createInstance: function (outer, iid) { |
|
61 if (outer != null) |
|
62 throw Components.results.NS_ERROR_NO_AGGREGATION; |
|
63 return PluginHost.QueryInterface(iid); |
|
64 } |
|
65 }; |
|
66 |
|
67 // Don't need the full interface, attempts to call other methods will just |
|
68 // throw which is just fine |
|
69 var WindowWatcher = { |
|
70 openWindow: function(parent, url, name, features, arguments) { |
|
71 // Should be called to list the newly blocklisted items |
|
72 do_check_eq(url, URI_EXTENSION_BLOCKLIST_DIALOG); |
|
73 // Should only include one item |
|
74 do_check_eq(arguments.wrappedJSObject.list.length, 1); |
|
75 // And that item should be the blocked plugin, not the outdated one |
|
76 var item = arguments.wrappedJSObject.list[0]; |
|
77 do_check_true(item.item instanceof Ci.nsIPluginTag); |
|
78 do_check_neq(item.name, "test_bug514327_outdated"); |
|
79 |
|
80 // Call the next test after the blocklist has finished up |
|
81 do_timeout(0, gNextTestPart); |
|
82 }, |
|
83 |
|
84 QueryInterface: function(iid) { |
|
85 if (iid.equals(Ci.nsIWindowWatcher) |
|
86 || iid.equals(Ci.nsISupports)) |
|
87 return this; |
|
88 |
|
89 throw Cr.NS_ERROR_NO_INTERFACE; |
|
90 } |
|
91 } |
|
92 |
|
93 var WindowWatcherFactory = { |
|
94 createInstance: function createInstance(outer, iid) { |
|
95 if (outer != null) |
|
96 throw Components.results.NS_ERROR_NO_AGGREGATION; |
|
97 return WindowWatcher.QueryInterface(iid); |
|
98 } |
|
99 }; |
|
100 |
|
101 var registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar); |
|
102 registrar.registerFactory(Components.ID("{721c3e73-969e-474b-a6dc-059fd288c428}"), |
|
103 "Fake Plugin Host", |
|
104 "@mozilla.org/plugin/host;1", PluginHostFactory); |
|
105 registrar.registerFactory(Components.ID("{1dfeb90a-2193-45d5-9cb8-864928b2af55}"), |
|
106 "Fake Window Watcher", |
|
107 "@mozilla.org/embedcomp/window-watcher;1", WindowWatcherFactory); |
|
108 |
|
109 |
|
110 function do_update_blocklist(aDatafile, aNextPart) { |
|
111 gNextTestPart = aNextPart; |
|
112 |
|
113 gPrefs.setCharPref("extensions.blocklist.url", "http://localhost:" + gPort + "/data/" + aDatafile); |
|
114 gBlocklist.QueryInterface(Ci.nsITimerCallback).notify(null); |
|
115 } |
|
116 |
|
117 function run_test() { |
|
118 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); |
|
119 |
|
120 gTestserver = new HttpServer(); |
|
121 gTestserver.registerDirectory("/data/", do_get_file("data")); |
|
122 gTestserver.start(-1); |
|
123 gPort = gTestserver.identity.primaryPort; |
|
124 |
|
125 startupManager(); |
|
126 |
|
127 // initialize the blocklist with no entries |
|
128 copyBlocklistToProfile(do_get_file("data/test_bug514327_3_empty.xml")); |
|
129 |
|
130 gPrefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch); |
|
131 gBlocklist = Cc["@mozilla.org/extensions/blocklist;1"].getService(nsIBLS); |
|
132 |
|
133 // should NOT be marked as outdated by the blocklist |
|
134 do_check_true(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_NOT_BLOCKED); |
|
135 |
|
136 do_test_pending(); |
|
137 |
|
138 // update blocklist with data that marks the plugin as outdated |
|
139 do_update_blocklist("test_bug514327_3_outdated_1.xml", test_part_1); |
|
140 } |
|
141 |
|
142 function test_part_1() { |
|
143 // plugin should now be marked as outdated |
|
144 do_check_true(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_OUTDATED); |
|
145 // and the notifyUser pref should be set to true |
|
146 do_check_true(gPrefs.getBoolPref("plugins.update.notifyUser")); |
|
147 |
|
148 // preternd the user has been notified, reset the pref |
|
149 gPrefs.setBoolPref("plugins.update.notifyUser", false); |
|
150 |
|
151 // update blocklist with data that marks the plugin as outdated |
|
152 do_update_blocklist("test_bug514327_3_outdated_2.xml", test_part_2); |
|
153 } |
|
154 |
|
155 function test_part_2() { |
|
156 // plugin should still be marked as outdated |
|
157 do_check_true(gBlocklist.getPluginBlocklistState(PLUGINS[0], "1", "1.9") == nsIBLS.STATE_OUTDATED); |
|
158 // and the notifyUser pref should NOT be set to true, as the plugin was already outdated |
|
159 do_check_false(gPrefs.getBoolPref("plugins.update.notifyUser")); |
|
160 |
|
161 finish(); |
|
162 } |
|
163 |
|
164 function finish() { |
|
165 gTestserver.stop(do_test_finished); |
|
166 } |