Bug 485088 - use clearUserPref to set a userPref to default value in Session Restore tests. r=zeniko
authorMichael Kohler <michaelkohler@live.com>
Sat, 11 Apr 2009 10:43:59 +0200
changeset 27207 50a692b9e8973998286aab6dfa62440cdddb6117
parent 27206 25f74e0b80a6d6d7e109ede7856f638931f7e065
child 27208 cee7968e5bebaa51ff6290662d99c1a143f69242
push idunknown
push userunknown
push dateunknown
reviewerszeniko
bugs485088
milestone1.9.2a1pre
Bug 485088 - use clearUserPref to set a userPref to default value in Session Restore tests. r=zeniko
browser/components/sessionstore/test/browser/browser_248970_a.js
browser/components/sessionstore/test/browser/browser_346337.js
browser/components/sessionstore/test/browser/browser_350525.js
browser/components/sessionstore/test/browser/browser_367052.js
browser/components/sessionstore/test/browser/browser_448741.js
browser/components/sessionstore/test/browser/browser_454908.js
browser/components/sessionstore/test/browser/browser_456342.js
browser/components/sessionstore/test/browser/browser_464199.js
--- a/browser/components/sessionstore/test/browser/browser_248970_a.js
+++ b/browser/components/sessionstore/test/browser/browser_248970_a.js
@@ -62,17 +62,16 @@ function test() {
       return file.lastModifiedTime;
     else
       return -1;
   }
 
   // sessionstore service
   let ss = Cc["@mozilla.org/browser/sessionstore;1"].
            getService(Ci.nsISessionStore);
-  let ss_interval = gPrefService.getIntPref("browser.sessionstore.interval");
   // Remove the sessionstore.js file before setting the interval to 0
   let sessionStoreJS = profilePath.clone();
   sessionStoreJS.append("sessionstore.js");
   if (sessionStoreJS.exists())
     sessionStoreJS.remove(false);
   // Make sure that sessionstore.js can be forced to be created by setting
   // the interval pref to 0
   gPrefService.setIntPref("browser.sessionstore.interval", 0);
@@ -133,28 +132,28 @@ function test() {
 
         // private browsing session, close tab: (B)
         gBrowser.removeTab(tab_B);
 
         // private browsing session, close tab: (A)
         gBrowser.removeTab(tab_A);
 
         // record the timestamp of sessionstore.js at the end of the private session
-        gPrefService.setIntPref("browser.sessionstore.interval", ss_interval);
+        gPrefService.clearUserPref("browser.sessionstore.interval");
         gPrefService.setIntPref("browser.sessionstore.interval", 0);
         let endPBModeTimeStamp = getSessionstorejsModificationTime();
 
         // exit private browsing mode
         pb.privateBrowsingEnabled = false;
         ok(!pb.privateBrowsingEnabled, "private browsing disabled");
 
         // compare timestamps: pre and post private browsing session
         is(startPBModeTimeStamp, endPBModeTimeStamp,
           "outside private browsing - sessionStore.js timestamp has not changed");
 
         // cleanup
-        gPrefService.setIntPref("browser.sessionstore.interval", ss_interval);
+        gPrefService.clearUserPref("browser.sessionstore.interval");
         gPrefService.clearUserPref("browser.privatebrowsing.keep_current_session");
         finish();
       }, true);
     }, true);
   }, true);
 }
--- a/browser/components/sessionstore/test/browser/browser_346337.js
+++ b/browser/components/sessionstore/test/browser/browser_346337.js
@@ -88,17 +88,16 @@ function test() {
                                        (aValue.indexOf(aIx) > -1) == aOpt.selected);
   }
   
   // test setup
   let tabbrowser = getBrowser();
   waitForExplicitFinish();
   
   // make sure we don't save form data at all (except for tab duplication)
-  let privacy_level = gPrefService.getIntPref("browser.sessionstore.privacy_level");
   gPrefService.setIntPref("browser.sessionstore.privacy_level", 2);
   
   let testURL = "chrome://mochikit/content/browser/" +
     "browser/components/sessionstore/test/browser/browser_346337_sample.html";
   let tab = tabbrowser.addTab(testURL);
   tab.linkedBrowser.addEventListener("load", function(aEvent) {
     for (let xpath in fieldList)
       setFormValue(tab, xpath, fieldList[xpath]);
@@ -115,17 +114,17 @@ function test() {
       
       tab = undoCloseTab();
       tab.linkedBrowser.addEventListener("load", function(aEvent) {
         for (let xpath in fieldList)
           if (fieldList[xpath])
             ok(!compareFormValue(tab, xpath, fieldList[xpath]),
                "The value for \"" + xpath + "\" was correctly discarded");
         
-        gPrefService.setIntPref("browser.sessionstore.privacy_level", privacy_level);
+        gPrefService.clearUserPref("browser.sessionstore.privacy_level");
         // undoCloseTab can reuse a single blank tab, so we have to
         // make sure not to close the window when closing our last tab
         if (tabbrowser.tabContainer.childNodes.length == 1)
           tabbrowser.addTab();
         tabbrowser.removeTab(tab);
         finish();
       }, true);
     }, true);
--- a/browser/components/sessionstore/test/browser/browser_350525.js
+++ b/browser/components/sessionstore/test/browser/browser_350525.js
@@ -87,14 +87,14 @@ function test() {
     // undoCloseTab
     tab = test(function() ss.undoCloseTab(window, 0));
     ok(tab, "undoCloseTab doesn't throw")
     
     tab.linkedBrowser.addEventListener("load", function(aEvent) {
       is(this.currentURI.spec, testURL, "correct tab was reopened");
       
       // clean up
-      gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo);
+      gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
       tabbrowser.removeTab(tab);
       finish();
     }, true);
   }, true);
 }
--- a/browser/components/sessionstore/test/browser/browser_367052.js
+++ b/browser/components/sessionstore/test/browser/browser_367052.js
@@ -60,13 +60,13 @@ function test() {
     tab.linkedBrowser.addEventListener("load", function(aEvent) {
       ok(history.count == 0, "the tab was restored without any history whatsoever");
       
       tabbrowser.removeTab(tab);
       ok(ss.getClosedTabCount(window) == closedTabCount,
          "The closed blank tab wasn't added to Recently Closed Tabs");
       
       // clean up
-      gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo);
+      gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
       finish();
     }, true);
   }, true);
 }
--- a/browser/components/sessionstore/test/browser/browser_448741.js
+++ b/browser/components/sessionstore/test/browser/browser_448741.js
@@ -40,17 +40,16 @@ function test() {
   // test setup
   let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
   let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
   let tabbrowser = getBrowser();
   waitForExplicitFinish();
   
   let uniqueName = "bug 448741";
   let uniqueValue = "as good as unique: " + Date.now();
-  let interval = gPrefService.getIntPref("browser.sessionstore.interval");
   
   // set a unique value on a new, blank tab
   var tab = tabbrowser.addTab();
   ss.setTabValue(tab, uniqueName, uniqueValue);
   let valueWasCleaned = false;
   
   // prevent our value from being written to disk
   let cleaningObserver = {
@@ -82,17 +81,17 @@ function test() {
     observe: function(aSubject, aTopic, aData) {
       ok(valueWasCleaned && aSubject instanceof Ci.nsISupportsString,
          "ready to check the cleaned state?");
       ok(aSubject.data.indexOf(uniqueValue) == -1, "data no longer contains our value?");
       
       // clean up
       tabbrowser.removeTab(tab);
       os.removeObserver(this, aTopic, false);
-      gPrefService.setIntPref("browser.sessionstore.interval", interval);
+      gPrefService.clearUserPref("browser.sessionstore.interval");
       finish();
     }
   };
   
   // last added observers are invoked first
   os.addObserver(checkingObserver, "sessionstore-state-write", false);
   os.addObserver(cleaningObserver, "sessionstore-state-write", false);
   
--- a/browser/components/sessionstore/test/browser/browser_454908.js
+++ b/browser/components/sessionstore/test/browser/browser_454908.js
@@ -40,17 +40,16 @@ function test() {
   waitForExplicitFinish();
   
   let fieldValues = {
     username: "User " + Math.random(),
     passwd:   "pwd" + Date.now()
   };
   
   // make sure we do save form data
-  let privacy_level = gPrefService.getIntPref("browser.sessionstore.privacy_level");
   gPrefService.setIntPref("browser.sessionstore.privacy_level", 0);
   
   let testURL = "chrome://mochikit/content/browser/" +
     "browser/components/sessionstore/test/browser/browser_454908_sample.html";
   let tab = gBrowser.addTab(testURL);
   tab.linkedBrowser.addEventListener("load", function(aEvent) {
     let doc = tab.linkedBrowser.contentDocument;
     for (let id in fieldValues)
@@ -65,17 +64,17 @@ function test() {
         let node = doc.getElementById(id);
         if (node.type == "password")
           is(node.value, "", "password wasn't saved/restored");
         else
           is(node.value, fieldValues[id], "username was saved/restored");
       }
       
       // clean up
-      gPrefService.setIntPref("browser.sessionstore.privacy_level", privacy_level);
+      gPrefService.clearUserPref("browser.sessionstore.privacy_level");
       // undoCloseTab can reuse a single blank tab, so we have to
       // make sure not to close the window when closing our last tab
       if (gBrowser.tabContainer.childNodes.length == 1)
         gBrowser.addTab();
       gBrowser.removeTab(tab);
       finish();
     }, true);
   }, true);
--- a/browser/components/sessionstore/test/browser/browser_456342.js
+++ b/browser/components/sessionstore/test/browser/browser_456342.js
@@ -35,17 +35,16 @@
  * ***** END LICENSE BLOCK ***** */
 
 function test() {
   /** Test for Bug 456342 **/
   
   waitForExplicitFinish();
   
   // make sure we do save form data
-  let privacy_level = gPrefService.getIntPref("browser.sessionstore.privacy_level");
   gPrefService.setIntPref("browser.sessionstore.privacy_level", 0);
   
   let testURL = "chrome://mochikit/content/browser/" +
     "browser/components/sessionstore/test/browser/browser_456342_sample.xhtml";
   let tab = gBrowser.addTab(testURL);
   tab.linkedBrowser.addEventListener("load", function(aEvent) {
     gBrowser.removeTab(tab);
     
@@ -61,12 +60,12 @@ function test() {
       else
         countBad++;
     }
     
     is(countGood, 4, "Saved text for non-standard input fields");
     is(countBad,  0, "Didn't save text for ignored field types");
     
     // clean up
-    gPrefService.setIntPref("browser.sessionstore.privacy_level", privacy_level);
+    gPrefService.clearUserPref("browser.sessionstore.privacy_level");
     finish();
   }, true);
 }
--- a/browser/components/sessionstore/test/browser/browser_464199.js
+++ b/browser/components/sessionstore/test/browser/browser_464199.js
@@ -70,17 +70,16 @@ function test() {
   let remember_count = 5;
   
   function countByTitle(aClosedTabList, aTitle)
     aClosedTabList.filter(function(aData) aData.title == aTitle).length;
   
   // open a window and add the above closed tab list
   let newWin = openDialog(location, "_blank", "chrome,all,dialog=no");
   newWin.addEventListener("load", function(aEvent) {
-    let max_tabs_undo = gPrefService.getIntPref("browser.sessionstore.max_tabs_undo");
     gPrefService.setIntPref("browser.sessionstore.max_tabs_undo",
                             test_state.windows[0]._closedTabs.length);
     ss.setWindowState(newWin, JSON.stringify(test_state), true);
     
     let closedTabs = eval("(" + ss.getClosedTabData(newWin) + ")");
     is(closedTabs.length, test_state.windows[0]._closedTabs.length,
        "Closed tab list has the expected length");
     is(countByTitle(closedTabs, FORGET),
@@ -98,12 +97,12 @@ function test() {
        "The correct amout of tabs was removed");
     is(countByTitle(closedTabs, FORGET), 0,
        "All tabs to be forgotten were indeed removed");
     is(countByTitle(closedTabs, REMEMBER), remember_count,
        "... and tabs to be remembered weren't.");
     
     // clean up
     newWin.close();
-    gPrefService.setIntPref("browser.sessionstore.max_tabs_undo", max_tabs_undo);
+    gPrefService.clearUserPref("browser.sessionstore.max_tabs_undo");
     finish();
   }, false);
 }