Bug 1412873 - Disarm JSONFile when trying to discard changes in preferences tests r=aswan
authorMark Striemer <mstriemer@mozilla.com>
Mon, 12 Feb 2018 15:51:48 -0600
changeset 404029 ebc312ac3d390133cafbb1c5538055ed2a6c0d0e
parent 404028 c4b14a5665b439ab07b9b796bb18912870c8fdff
child 404030 302d513bcb404722f0488de5bb0fbb43017b28eb
push id99924
push userebalazs@mozilla.com
push dateThu, 15 Feb 2018 20:43:51 +0000
treeherdermozilla-inbound@a7d2a49f46fb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1412873
milestone60.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 1412873 - Disarm JSONFile when trying to discard changes in preferences tests r=aswan MozReview-Commit-ID: 5l0yRop3guh
browser/components/preferences/in-content/tests/browser_extension_controlled.js
toolkit/components/extensions/ExtensionSettingsStore.jsm
--- a/browser/components/preferences/in-content/tests/browser_extension_controlled.js
+++ b/browser/components/preferences/in-content/tests/browser_extension_controlled.js
@@ -439,16 +439,19 @@ add_task(async function testExtensionCon
 
   await ExtensionSettingsStore.initialize();
 
   // Verify the setting isn't reported as controlled and the inputs are enabled.
   is(ExtensionSettingsStore.getSetting("prefs", "homepage_override"), null,
      "The homepage_override is not set");
   await checkHomepageEnabled();
 
+  // Disarm any pending writes before we modify the JSONFile directly.
+  await ExtensionSettingsStore._reloadFile(false);
+
   // Write out a bad store file.
   let storeData = {
     prefs: {
       homepage_override: {
         initialValue: "",
         precedenceList: [{
           id: "bad@mochi.test",
           installDate: 1508802672,
--- a/toolkit/components/extensions/ExtensionSettingsStore.jsm
+++ b/toolkit/components/extensions/ExtensionSettingsStore.jsm
@@ -83,20 +83,22 @@ function initialize() {
       dataPostProcessor,
     });
     _initializePromise = _store.load();
   }
   return _initializePromise;
 }
 
 // Test-only method to force reloading of the JSON file.
-async function reloadFile(finalize) {
-  if (finalize) {
-    await _store.finalize();
+async function reloadFile(saveChanges) {
+  if (!saveChanges) {
+    // Disarm the saver so that the current changes are dropped.
+    _store._saver.disarm();
   }
+  await _store.finalize();
   _initializePromise = null;
   return initialize();
 }
 
 // Checks that the store is ready and that the requested type exists.
 function ensureType(type) {
   if (!_store.dataReady) {
     throw new Error(
@@ -504,17 +506,18 @@ this.ExtensionSettingsStore = {
   },
 
   /**
    * Test-only method to force reloading of the JSON file.
    *
    * Note that this method simply clears the local variable that stores the
    * file, so the next time the file is accessed it will be reloaded.
    *
-   * @param   {boolean} finalize
-   *          When false, skip finalizing the store (writing current state to file).
+   * @param   {boolean} saveChanges
+   *          When false, discard any changes that have been made since the last
+   *          time the store was saved.
    * @returns {Promise}
    *          A promise that resolves once the settings store has been cleared.
    */
-  _reloadFile(finalize = true) {
-    return reloadFile(finalize);
+  _reloadFile(saveChanges = true) {
+    return reloadFile(saveChanges);
   },
 };