toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_OK.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 a machine which exactly matches the blacklist entry is
michael@0 6 // successfully blocked.
michael@0 7 // Uses test_gfxBlacklist.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 checkBlacklist()
michael@0 78 {
michael@0 79 var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D);
michael@0 80 do_check_eq(status, Ci.nsIGfxInfo.FEATURE_BLOCKED_DRIVER_VERSION);
michael@0 81
michael@0 82 // Make sure unrelated features aren't affected
michael@0 83 status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS);
michael@0 84 do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO);
michael@0 85
michael@0 86 gTestserver.stop(do_test_finished);
michael@0 87 }
michael@0 88
michael@0 89 Services.obs.addObserver(function(aSubject, aTopic, aData) {
michael@0 90 // If we wait until after we go through the event loop, gfxInfo is sure to
michael@0 91 // have processed the gfxItems event.
michael@0 92 do_execute_soon(checkBlacklist);
michael@0 93 }, "blocklist-data-gfxItems", false);
michael@0 94
michael@0 95 load_blocklist("test_gfxBlacklist.xml");
michael@0 96 }

mercurial