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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/mozapps/extensions/test/xpcshell/test_gfxBlacklist_DriverNew.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,94 @@
     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 new-enough driver bypasses the blacklist, even if the rest of
     1.9 +// the attributes match the blacklist entry.
    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.2202");
    1.56 +      // Windows 7
    1.57 +      gfxInfo.spoofOSVersion(0x60001);
    1.58 +      break;
    1.59 +    case "Linux":
    1.60 +      // We don't support driver versions on Linux.
    1.61 +      do_test_finished();
    1.62 +      return;
    1.63 +    case "Darwin":
    1.64 +      // We don't support driver versions on Darwin.
    1.65 +      do_test_finished();
    1.66 +      return;
    1.67 +    case "Android":
    1.68 +      gfxInfo.spoofVendorID("abcd");
    1.69 +      gfxInfo.spoofDeviceID("wxyz");
    1.70 +      gfxInfo.spoofDriverVersion("6");
    1.71 +      break;
    1.72 +  }
    1.73 +
    1.74 +  createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "3", "8");
    1.75 +  startupManager();
    1.76 +
    1.77 +  do_test_pending();
    1.78 +
    1.79 +  function checkBlacklist()
    1.80 +  {
    1.81 +    var status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT2D);
    1.82 +    do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO);
    1.83 +
    1.84 +    status = gfxInfo.getFeatureStatus(Ci.nsIGfxInfo.FEATURE_DIRECT3D_9_LAYERS);
    1.85 +    do_check_eq(status, Ci.nsIGfxInfo.FEATURE_NO_INFO);
    1.86 +
    1.87 +    gTestserver.stop(do_test_finished);
    1.88 +  }
    1.89 +
    1.90 +  Services.obs.addObserver(function(aSubject, aTopic, aData) {
    1.91 +    // If we wait until after we go through the event loop, gfxInfo is sure to
    1.92 +    // have processed the gfxItems event.
    1.93 +    do_execute_soon(checkBlacklist);
    1.94 +  }, "blocklist-data-gfxItems", false);
    1.95 +
    1.96 +  load_blocklist("test_gfxBlacklist.xml");
    1.97 +}

mercurial