michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Test whether a machine which exactly matches the blacklist entry is michael@0: // successfully blocked. michael@0: // Uses test_gfxBlacklist.xml michael@0: michael@0: Components.utils.import("resource://testing-common/httpd.js"); michael@0: michael@0: var gTestserver = new HttpServer(); michael@0: gTestserver.start(-1); michael@0: gPort = gTestserver.identity.primaryPort; michael@0: mapFile("/data/test_gfxBlacklist.xml", gTestserver); michael@0: michael@0: function get_platform() { michael@0: var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"] michael@0: .getService(Components.interfaces.nsIXULRuntime); michael@0: return xulRuntime.OS; michael@0: } michael@0: michael@0: function load_blocklist(file) { michael@0: Services.prefs.setCharPref("extensions.blocklist.url", "http://localhost:" + michael@0: gPort + "/data/" + file); michael@0: var blocklist = Cc["@mozilla.org/extensions/blocklist;1"]. michael@0: getService(Ci.nsITimerCallback); michael@0: blocklist.notify(null); michael@0: } michael@0: michael@0: // Performs the initial setup michael@0: function run_test() { michael@0: try { michael@0: var gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo); michael@0: } catch (e) { michael@0: do_test_finished(); michael@0: return; michael@0: } michael@0: michael@0: // We can't do anything if we can't spoof the stuff we need. michael@0: if (!(gfxInfo instanceof Ci.nsIGfxInfoDebug)) { michael@0: do_test_finished(); michael@0: return; michael@0: } michael@0: michael@0: gfxInfo.QueryInterface(Ci.nsIGfxInfoDebug); michael@0: michael@0: // Set the vendor/device ID, etc, to match the test file. michael@0: switch (get_platform()) { michael@0: case "WINNT": michael@0: gfxInfo.spoofVendorID("0xabcd"); michael@0: gfxInfo.spoofDeviceID("0x1234"); michael@0: gfxInfo.spoofDriverVersion("8.52.322.2201"); michael@0: // Windows 7 michael@0: gfxInfo.spoofOSVersion(0x60001); michael@0: break; michael@0: case "Linux": michael@0: gfxInfo.spoofVendorID("0xabcd"); michael@0: gfxInfo.spoofDeviceID("0x1234"); michael@0: break; michael@0: case "Darwin": michael@0: gfxInfo.spoofVendorID("0xabcd"); michael@0: gfxInfo.spoofDeviceID("0x1234"); michael@0: gfxInfo.spoofOSVersion(0x1050); michael@0: break; michael@0: case "Android": michael@0: gfxInfo.spoofVendorID("abcd"); michael@0: gfxInfo.spoofDeviceID("asdf"); michael@0: gfxInfo.spoofDriverVersion("5"); michael@0: break; michael@0: } michael@0: michael@0: createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8"); michael@0: startupManager(); michael@0: michael@0: do_test_pending(); michael@0: michael@0: function checkBlacklist() michael@0: { michael@0: var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D); michael@0: do_check_eq(status, Ci.nsIGfxInfo.FEATURE_BLOCKED_DRIVER_VERSION); michael@0: michael@0: // Make sure unrelated features aren't affected michael@0: status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS); michael@0: do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO); michael@0: michael@0: gTestserver.stop(do_test_finished); michael@0: } michael@0: michael@0: Services.obs.addObserver(function(aSubject, aTopic, aData) { michael@0: // If we wait until after we go through the event loop, gfxInfo is sure to michael@0: // have processed the gfxItems event. michael@0: do_execute_soon(checkBlacklist); michael@0: }, "blocklist-data-gfxItems", false); michael@0: michael@0: load_blocklist("test_gfxBlacklist.xml"); michael@0: }