1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OK.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,96 @@ 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 a machine which exactly matches the blacklist entry is 1.9 +// successfully blocked. 1.10 +// Uses test_gfxBlacklist.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 checkBlacklist() 1.81 + { 1.82 + var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D); 1.83 + do_check_eq(status, Ci.nsIGfxInfo.FEATURE_BLOCKED_DRIVER_VERSION); 1.84 + 1.85 + // Make sure unrelated features aren't affected 1.86 + status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS); 1.87 + do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO); 1.88 + 1.89 + gTestserver.stop(do_test_finished); 1.90 + } 1.91 + 1.92 + Services.obs.addObserver(function(aSubject, aTopic, aData) { 1.93 + // If we wait until after we go through the event loop, gfxInfo is sure to 1.94 + // have processed the gfxItems event. 1.95 + do_execute_soon(checkBlacklist); 1.96 + }, "blocklist-data-gfxItems", false); 1.97 + 1.98 + load_blocklist("test_gfxBlacklist.xml"); 1.99 +}