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