|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Test whether the blacklist succesfully adds and removes the prefs that store |
|
6 // its decisions when the remote blacklist is changed. |
|
7 // Uses test_gfxBlacklist.xml and test_gfxBlacklist2.xml |
|
8 |
|
9 Components.utils.import("resource://testing-common/httpd.js"); |
|
10 |
|
11 var gTestserver = new HttpServer(); |
|
12 gTestserver.start(-1); |
|
13 gPort = gTestserver.identity.primaryPort; |
|
14 mapFile("/data/test_gfxBlacklist.xml", gTestserver); |
|
15 |
|
16 function get_platform() { |
|
17 var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"] |
|
18 .getService(Components.interfaces.nsIXULRuntime); |
|
19 return xulRuntime.OS; |
|
20 } |
|
21 |
|
22 function load_blocklist(file) { |
|
23 Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + |
|
24 gPort + "/data/" + file); |
|
25 var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]. |
|
26 getService(Ci.nsITimerCallback); |
|
27 blocklist.notify(null); |
|
28 } |
|
29 |
|
30 // Performs the initial setup |
|
31 function run_test() { |
|
32 try { |
|
33 var gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo); |
|
34 } catch (e) { |
|
35 do_test_finished(); |
|
36 return; |
|
37 } |
|
38 |
|
39 // We can't do anything if we can't spoof the stuff we need. |
|
40 if (!(gfxInfo instanceof Ci.nsIGfxInfoDebug)) { |
|
41 do_test_finished(); |
|
42 return; |
|
43 } |
|
44 |
|
45 gfxInfo.QueryInterface(Ci.nsIGfxInfoDebug); |
|
46 |
|
47 // Set the vendor/device ID, etc, to match the test file. |
|
48 switch (get_platform()) { |
|
49 case "WINNT": |
|
50 gfxInfo.spoofVendorID("0xabcd"); |
|
51 gfxInfo.spoofDeviceID("0x1234"); |
|
52 gfxInfo.spoofDriverVersion("8.52.322.2201"); |
|
53 // Windows 7 |
|
54 gfxInfo.spoofOSVersion(0x60001); |
|
55 break; |
|
56 case "Linux": |
|
57 gfxInfo.spoofVendorID("0xabcd"); |
|
58 gfxInfo.spoofDeviceID("0x1234"); |
|
59 break; |
|
60 case "Darwin": |
|
61 gfxInfo.spoofVendorID("0xabcd"); |
|
62 gfxInfo.spoofDeviceID("0x1234"); |
|
63 gfxInfo.spoofOSVersion(0x1050); |
|
64 break; |
|
65 case "Android": |
|
66 gfxInfo.spoofVendorID("abcd"); |
|
67 gfxInfo.spoofDeviceID("asdf"); |
|
68 gfxInfo.spoofDriverVersion("5"); |
|
69 break; |
|
70 } |
|
71 |
|
72 createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8"); |
|
73 startupManager(); |
|
74 |
|
75 do_test_pending(); |
|
76 |
|
77 function blacklistAdded(aSubject, aTopic, aData) |
|
78 { |
|
79 // If we wait until after we go through the event loop, gfxInfo is sure to |
|
80 // have processed the gfxItems event. |
|
81 do_execute_soon(ensureBlacklistSet); |
|
82 } |
|
83 function ensureBlacklistSet() |
|
84 { |
|
85 var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D); |
|
86 do_check_eq(status, Ci.nsIGfxInfo.FEATURE_BLOCKED_DRIVER_VERSION); |
|
87 |
|
88 // Make sure unrelated features aren't affected |
|
89 status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS); |
|
90 do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO); |
|
91 |
|
92 var prefs = Cc["@mozilla.org/preferences-service;1"]. |
|
93 getService(Ci.nsIPrefBranch); |
|
94 do_check_eq(prefs.getIntPref("gfx.blacklist.direct2d"), |
|
95 Ci.nsIGfxInfo.FEATURE_BLOCKED_DRIVER_VERSION); |
|
96 |
|
97 Services.obs.removeObserver(blacklistAdded, "blocklist-data-gfxItems"); |
|
98 Services.obs.addObserver(blacklistRemoved, "blocklist-data-gfxItems", false); |
|
99 load_blocklist("test_gfxBlacklist2.xml"); |
|
100 } |
|
101 |
|
102 function blacklistRemoved(aSubject, aTopic, aData) |
|
103 { |
|
104 // If we wait until after we go through the event loop, gfxInfo is sure to |
|
105 // have processed the gfxItems event. |
|
106 do_execute_soon(ensureBlacklistUnset); |
|
107 } |
|
108 function ensureBlacklistUnset() |
|
109 { |
|
110 var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D); |
|
111 do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO); |
|
112 |
|
113 // Make sure unrelated features aren't affected |
|
114 status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS); |
|
115 do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO); |
|
116 |
|
117 var prefs = Cc["@mozilla.org/preferences-service;1"]. |
|
118 getService(Ci.nsIPrefBranch); |
|
119 var exists = false; |
|
120 try { |
|
121 prefs.getIntPref("gfx.blacklist.direct2d"); |
|
122 exists = true; |
|
123 } catch(e) {} |
|
124 |
|
125 do_check_false(exists); |
|
126 |
|
127 gTestserver.stop(do_test_finished); |
|
128 } |
|
129 |
|
130 Services.obs.addObserver(blacklistAdded, "blocklist-data-gfxItems", false); |
|
131 load_blocklist("test_gfxBlacklist.xml"); |
|
132 } |