Bug 1357517 - Remove Preferences.jsm usage from graphics sanity test. r=mchang
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Mon, 31 Jul 2017 19:36:32 +0200
changeset 423242 fa81cd2510dbadd71d657258c7e76de6d74775cc
parent 423241 45821738caeb0294b7fec3a00e51413124955110
child 423243 26e332a412c740da5803576bb30e665fc13d7143
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmchang
bugs1357517
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1357517 - Remove Preferences.jsm usage from graphics sanity test. r=mchang
toolkit/components/gfx/SanityTest.js
--- a/toolkit/components/gfx/SanityTest.js
+++ b/toolkit/components/gfx/SanityTest.js
@@ -2,17 +2,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const { utils: Cu, interfaces: Ci, classes: Cc, results: Cr } = Components;
 
 Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/Preferences.jsm");
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 
 const XUL_NS = "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul";
 const FRAME_SCRIPT_URL = "chrome://gfxsanity/content/gfxFrameScript.js";
 
 const PAGE_WIDTH = 92;
 const PAGE_HEIGHT = 166;
 const DRIVER_PREF = "sanity-test.driver-version";
@@ -61,17 +60,17 @@ function testPixel(ctx, x, y, r, g, b, a
 }
 
 function reportResult(val) {
   try {
     let histogram = Services.telemetry.getHistogramById("GRAPHICS_SANITY_TEST");
     histogram.add(val);
   } catch (e) {}
 
-  Preferences.set(RUNNING_PREF, false);
+  Services.prefs.setBoolPref(RUNNING_PREF, false);
   Services.prefs.savePrefFile(null);
 }
 
 function reportTestReason(val) {
   let histogram = Services.telemetry.getHistogramById("GRAPHICS_SANITY_TEST_REASON");
   histogram.add(val);
 }
 
@@ -126,31 +125,31 @@ function verifyLayersRendering(ctx) {
 }
 
 function testCompositor(test, win, ctx) {
   takeWindowSnapshot(win, ctx);
   var testPassed = true;
 
   if (!verifyVideoRendering(ctx)) {
     reportResult(TEST_FAILED_VIDEO);
-    Preferences.set(DISABLE_VIDEO_PREF, true);
+    Services.prefs.setBoolPref(DISABLE_VIDEO_PREF, true);
     testPassed = false;
   }
 
   if (!verifyLayersRendering(ctx)) {
     // Try disabling advanced layers if it was enabled. Also trgiger
     // a device reset so the screen redraws.
-    if (Preferences.get(AL_ENABLED_PREF, false)) {
-      Preferences.set(AL_TEST_FAILED_PREF, true);
+    if (Services.prefs.getBoolPref(AL_ENABLED_PREF, false)) {
+      Services.prefs.setBoolPref(AL_TEST_FAILED_PREF, true);
       test.utils.triggerDeviceReset();
     }
     reportResult(TEST_FAILED_RENDER);
     testPassed = false;
   } else {
-    Preferences.set(AL_TEST_FAILED_PREF, false);
+    Services.prefs.setBoolPref(AL_TEST_FAILED_PREF, false);
   }
 
   if (testPassed) {
     reportResult(TEST_PASSED);
   }
 
   return testPassed;
 }
@@ -254,55 +253,75 @@ SanityTest.prototype = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
                                          Ci.nsISupportsWeakReference]),
 
   shouldRunTest() {
     // Only test gfx features if firefox has updated, or if the user has a new
     // gpu or drivers.
     var buildId = Services.appinfo.platformBuildID;
     var gfxinfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
-    var hasAL = Preferences.get(AL_ENABLED_PREF, false);
+    var hasAL = Services.prefs.getBoolPref(AL_ENABLED_PREF, false);
 
-    if (Preferences.get(RUNNING_PREF, false)) {
-      Preferences.set(DISABLE_VIDEO_PREF, true);
+    if (Services.prefs.getBoolPref(RUNNING_PREF, false)) {
+      Services.prefs.setBoolPref(DISABLE_VIDEO_PREF, true);
       reportResult(TEST_CRASHED);
       return false;
     }
 
     function checkPref(pref, value, reason) {
-      var prefValue = Preferences.get(pref, undefined);
-      if (prefValue == value) {
-        return true;
+      let prefValue;
+      let prefType = Services.prefs.getPrefType(pref);
+
+      switch (prefType) {
+          case Ci.nsIPrefBranch.PREF_INVALID:
+              reportTestReason(REASON_FIRST_RUN);
+              return false;
+
+          case Ci.nsIPrefBranch.PREF_STRING:
+              prefValue = Services.prefs.getStringPref(pref);
+              break;
+
+          case Ci.nsIPrefBranch.PREF_BOOL:
+              prefValue = Services.prefs.getBoolPref(pref);
+              break;
+
+          case Ci.nsIPrefBranch.PREF_INT:
+              prefValue = Services.prefs.getIntPref(pref);
+              break;
+
+          default:
+              throw new Error("Unexpected preference type.");
       }
-      if (prefValue === undefined) {
-        reportTestReason(REASON_FIRST_RUN);
-      } else {
+
+      if (prefValue != value) {
         reportTestReason(reason);
+        return false;
       }
-      return false;
+
+      return true;
     }
 
     // TODO: Handle dual GPU setups
     if (checkPref(DRIVER_PREF, gfxinfo.adapterDriverVersion, REASON_DRIVER_CHANGED) &&
         checkPref(DEVICE_PREF, gfxinfo.adapterDeviceID, REASON_DEVICE_CHANGED) &&
         checkPref(VERSION_PREF, buildId, REASON_FIREFOX_CHANGED) &&
         checkPref(ADVANCED_LAYERS_PREF, hasAL, REASON_AL_CONFIG_CHANGED)) {
       return false;
     }
 
     // Enable hardware decoding so we can test again
     // and record the driver version to detect if the driver changes.
-    Preferences.set(DISABLE_VIDEO_PREF, false);
-    Preferences.set(DRIVER_PREF, gfxinfo.adapterDriverVersion);
-    Preferences.set(DEVICE_PREF, gfxinfo.adapterDeviceID);
-    Preferences.set(VERSION_PREF, buildId);
-    Preferences.set(ADVANCED_LAYERS_PREF, hasAL);
+    Services.prefs.setBoolPref(DISABLE_VIDEO_PREF, false);
+    Services.prefs.setStringPref(DRIVER_PREF, gfxinfo.adapterDriverVersion);
+    Services.prefs.setStringPref(DEVICE_PREF, gfxinfo.adapterDeviceID);
+    Services.prefs.setStringPref(VERSION_PREF, buildId);
+    Services.prefs.setBoolPref(ADVANCED_LAYERS_PREF, hasAL);
 
     // Update the prefs so that this test doesn't run again until the next update.
-    Preferences.set(RUNNING_PREF, true);
+    Services.prefs.setBoolPref(RUNNING_PREF, true);
     Services.prefs.savePrefFile(null);
     return true;
   },
 
   observe(subject, topic, data) {
     if (topic != "profile-after-change") return;
 
     // profile-after-change fires only at startup, so we won't need