B2G/gecko/browser/components/sessionstore/test/browser_454908.js
/* This Source Code Form is subject to the terms of the Mozilla Public
 * 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/. */
This Source Code Form is subject to the terms of the Mozilla Public
License, v.
This Source Code Form is subject to the terms of the Mozilla Public License v .
function test() {
  waitForExplicitFinish();
  let fieldValues = {
    username: "User " + Math.random(),
    passwd:   "pwd" + Date.now()
  };
  gPrefService.setIntPref("browser.sessionstore.privacy_level", 0);
  let rootDir = getRootDirectory(gTestPath);
  let testURL = rootDir + "browser_454908_sample.html";
  let tab = gBrowser.addTab(testURL);
  tab.linkedBrowser.addEventListener("load", function(aEvent) {
    tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
    let doc = tab.linkedBrowser.contentDocument;
    for (let id in fieldValues)
      doc.getElementById(id).value = fieldValues[id];
    gBrowser.removeTab(tab);
    tab = undoCloseTab();
    tab.linkedBrowser.addEventListener("load", function(aEvent) {
      tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
      let doc = tab.linkedBrowser.contentDocument;
      for (let id in fieldValues) {
        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");
      }
      if (gPrefService.prefHasUserValue("browser.sessionstore.privacy_level"))
        gPrefService.clearUserPref("browser.sessionstore.privacy_level");
      if (gBrowser.tabs.length == 1)
        gBrowser.addTab();
      gBrowser.removeTab(tab);
      finish();
    }, true);
  }, true);
}
function test ( ) { waitForExplicitFinish ( ) ; let fieldValues = { username : "User " + Math . random ( ) , passwd : "pwd" + Date . now ( ) } ; gPrefService . setIntPref ( "browser.sessionstore.privacy_level" , 0 ) ; let rootDir = getRootDirectory ( gTestPath ) ; let testURL = rootDir + "browser_454908_sample.html" ; let tab = gBrowser . addTab ( testURL ) ; tab . linkedBrowser . addEventListener ( "load" , function ( aEvent ) { tab . linkedBrowser . removeEventListener ( "load" , arguments . callee , true ) ; let doc = tab . linkedBrowser . contentDocument ; for ( let id in fieldValues ) doc . getElementById ( id ) . value = fieldValues [ id ] ; gBrowser . removeTab ( tab ) ; tab = undoCloseTab ( ) ; tab . linkedBrowser . addEventListener ( "load" , function ( aEvent ) { tab . linkedBrowser . removeEventListener ( "load" , arguments . callee , true ) ; let doc = tab . linkedBrowser . contentDocument ; for ( let id in fieldValues ) { 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" ) ; } if ( gPrefService . prefHasUserValue ( "browser.sessionstore.privacy_level" ) ) gPrefService . clearUserPref ( "browser.sessionstore.privacy_level" ) ; if ( gBrowser . tabs . length == 1 ) gBrowser . addTab ( ) ; gBrowser . removeTab ( tab ) ; finish ( ) ; } , true ) ; } , true ) ; }
This Source Code Form is subject to the terms of the Mozilla Public
 License, v. 2.0.
This Source Code Form is subject to the terms of the Mozilla Public License v . 2 . 0 .
/** Test for Bug 454908 **/ // make sure we do save form data // clean up // undoCloseTab can reuse a single blank tab, so we have to // make sure not to close the window when closing our last tab