1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_prefs.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,132 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +// Test whether the blacklist succesfully adds and removes the prefs that store 1.9 +// its decisions when the remote blacklist is changed. 1.10 +// Uses test_gfxBlacklist.xml and test_gfxBlacklist2.xml 1.11 + 1.12 +Components.utils.import("resource://testing-common/httpd.js"); 1.13 + 1.14 +var gTestserver = new HttpServer(); 1.15 +gTestserver.start(-1); 1.16 +gPort = gTestserver.identity.primaryPort; 1.17 +mapFile("/data/test_gfxBlacklist.xml", gTestserver); 1.18 + 1.19 +function get_platform() { 1.20 + var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"] 1.21 + .getService(Components.interfaces.nsIXULRuntime); 1.22 + return xulRuntime.OS; 1.23 +} 1.24 + 1.25 +function load_blocklist(file) { 1.26 + Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + 1.27 + gPort + "/data/" + file); 1.28 + var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]. 1.29 + getService(Ci.nsITimerCallback); 1.30 + blocklist.notify(null); 1.31 +} 1.32 + 1.33 +// Performs the initial setup 1.34 +function run_test() { 1.35 + try { 1.36 + var gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo); 1.37 + } catch (e) { 1.38 + do_test_finished(); 1.39 + return; 1.40 + } 1.41 + 1.42 + // We can't do anything if we can't spoof the stuff we need. 1.43 + if (!(gfxInfo instanceof Ci.nsIGfxInfoDebug)) { 1.44 + do_test_finished(); 1.45 + return; 1.46 + } 1.47 + 1.48 + gfxInfo.QueryInterface(Ci.nsIGfxInfoDebug); 1.49 + 1.50 + // Set the vendor/device ID, etc, to match the test file. 1.51 + switch (get_platform()) { 1.52 + case "WINNT": 1.53 + gfxInfo.spoofVendorID("0xabcd"); 1.54 + gfxInfo.spoofDeviceID("0x1234"); 1.55 + gfxInfo.spoofDriverVersion("8.52.322.2201"); 1.56 + // Windows 7 1.57 + gfxInfo.spoofOSVersion(0x60001); 1.58 + break; 1.59 + case "Linux": 1.60 + gfxInfo.spoofVendorID("0xabcd"); 1.61 + gfxInfo.spoofDeviceID("0x1234"); 1.62 + break; 1.63 + case "Darwin": 1.64 + gfxInfo.spoofVendorID("0xabcd"); 1.65 + gfxInfo.spoofDeviceID("0x1234"); 1.66 + gfxInfo.spoofOSVersion(0x1050); 1.67 + break; 1.68 + case "Android": 1.69 + gfxInfo.spoofVendorID("abcd"); 1.70 + gfxInfo.spoofDeviceID("asdf"); 1.71 + gfxInfo.spoofDriverVersion("5"); 1.72 + break; 1.73 + } 1.74 + 1.75 + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8"); 1.76 + startupManager(); 1.77 + 1.78 + do_test_pending(); 1.79 + 1.80 + function blacklistAdded(aSubject, aTopic, aData) 1.81 + { 1.82 + // If we wait until after we go through the event loop, gfxInfo is sure to 1.83 + // have processed the gfxItems event. 1.84 + do_execute_soon(ensureBlacklistSet); 1.85 + } 1.86 + function ensureBlacklistSet() 1.87 + { 1.88 + var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D); 1.89 + do_check_eq(status, Ci.nsIGfxInfo.FEATURE_BLOCKED_DRIVER_VERSION); 1.90 + 1.91 + // Make sure unrelated features aren't affected 1.92 + status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS); 1.93 + do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO); 1.94 + 1.95 + var prefs = Cc["@mozilla.org/preferences-service;1"]. 1.96 + getService(Ci.nsIPrefBranch); 1.97 + do_check_eq(prefs.getIntPref("gfx.blacklist.direct2d"), 1.98 + Ci.nsIGfxInfo.FEATURE_BLOCKED_DRIVER_VERSION); 1.99 + 1.100 + Services.obs.removeObserver(blacklistAdded, "blocklist-data-gfxItems"); 1.101 + Services.obs.addObserver(blacklistRemoved, "blocklist-data-gfxItems", false); 1.102 + load_blocklist("test_gfxBlacklist2.xml"); 1.103 + } 1.104 + 1.105 + function blacklistRemoved(aSubject, aTopic, aData) 1.106 + { 1.107 + // If we wait until after we go through the event loop, gfxInfo is sure to 1.108 + // have processed the gfxItems event. 1.109 + do_execute_soon(ensureBlacklistUnset); 1.110 + } 1.111 + function ensureBlacklistUnset() 1.112 + { 1.113 + var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D); 1.114 + do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO); 1.115 + 1.116 + // Make sure unrelated features aren't affected 1.117 + status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS); 1.118 + do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO); 1.119 + 1.120 + var prefs = Cc["@mozilla.org/preferences-service;1"]. 1.121 + getService(Ci.nsIPrefBranch); 1.122 + var exists = false; 1.123 + try { 1.124 + prefs.getIntPref("gfx.blacklist.direct2d"); 1.125 + exists = true; 1.126 + } catch(e) {} 1.127 + 1.128 + do_check_false(exists); 1.129 + 1.130 + gTestserver.stop(do_test_finished); 1.131 + } 1.132 + 1.133 + Services.obs.addObserver(blacklistAdded, "blocklist-data-gfxItems", false); 1.134 + load_blocklist("test_gfxBlacklist.xml"); 1.135 +}