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 the blacklist succesfully adds and removes the prefs that store michael@0: // its decisions when the remote blacklist is changed. michael@0: // Uses test_gfxBlacklist.xml and test_gfxBlacklist2.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 blacklistAdded(aSubject, aTopic, aData) michael@0: { 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(ensureBlacklistSet); michael@0: } michael@0: function ensureBlacklistSet() 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: var prefs = Cc["@mozilla.org/preferences-service;1"]. michael@0: getService(Ci.nsIPrefBranch); michael@0: do_check_eq(prefs.getIntPref("gfx.blacklist.direct2d"), michael@0: Ci.nsIGfxInfo.FEATURE_BLOCKED_DRIVER_VERSION); michael@0: michael@0: Services.obs.removeObserver(blacklistAdded, "blocklist-data-gfxItems"); michael@0: Services.obs.addObserver(blacklistRemoved, "blocklist-data-gfxItems", false); michael@0: load_blocklist("test_gfxBlacklist2.xml"); michael@0: } michael@0: michael@0: function blacklistRemoved(aSubject, aTopic, aData) michael@0: { 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(ensureBlacklistUnset); michael@0: } michael@0: function ensureBlacklistUnset() michael@0: { michael@0: var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D); michael@0: do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO); 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: var prefs = Cc["@mozilla.org/preferences-service;1"]. michael@0: getService(Ci.nsIPrefBranch); michael@0: var exists = false; michael@0: try { michael@0: prefs.getIntPref("gfx.blacklist.direct2d"); michael@0: exists = true; michael@0: } catch(e) {} michael@0: michael@0: do_check_false(exists); michael@0: michael@0: gTestserver.stop(do_test_finished); michael@0: } michael@0: michael@0: Services.obs.addObserver(blacklistAdded, "blocklist-data-gfxItems", false); michael@0: load_blocklist("test_gfxBlacklist.xml"); michael@0: }