B2G/gecko/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_popupmode.js
// browsing mode, even if it's disabled before that (see bug 495495).
browsing mode, even if it's disabled before that .
browsing mode even if it ' s disabled before that .
function test() {
  let pb = Cc["@mozilla.org/privatebrowsing;1"].
           getService(Ci.nsIPrivateBrowsingService);
  let ss = Cc["@mozilla.org/browser/sessionstore;1"].
           getService(Ci.nsISessionStore);
  while (ss.getClosedWindowCount())
    ss.forgetClosedWindow(0);
  let stateBackup = ss.getWindowState(window);
  function pretendToBeAPopup(whatToPretend) {
    let state = whatToPretend ?
      '{"windows":[{"tabs":[{"entries":[],"attributes":{}}],"isPopup":true,"hidden":"toolbar"}]}' :
      '{"windows":[{"tabs":[{"entries":[],"attributes":{}}],"isPopup":false}]}';
    ss.setWindowState(window, state, true);
    if (whatToPretend) {
      ok(gURLBar.readOnly, "pretendToBeAPopup correctly made the URL bar read-only");
      is(gURLBar.getAttribute("enablehistory"), "false",
         "pretendToBeAPopup correctly disabled autocomplete on the URL bar");
    }
    else {
      ok(!gURLBar.readOnly, "pretendToBeAPopup correctly made the URL bar read-write");
      is(gURLBar.getAttribute("enablehistory"), "true",
         "pretendToBeAPopup correctly enabled autocomplete on the URL bar");
    }
  }
  pretendToBeAPopup(true);
  pb.privateBrowsingEnabled = true;
  ok(!gURLBar.readOnly,
     "URL bar should not be read-only after entering the private browsing mode");
  is(gURLBar.getAttribute("enablehistory"), "true",
     "URL bar autocomplete should be enabled after entering the private browsing mode");
  pb.privateBrowsingEnabled = false;
  pretendToBeAPopup(false);
  pb.privateBrowsingEnabled = true;
  pretendToBeAPopup(true);
  pb.privateBrowsingEnabled = false;
  ok(!gURLBar.readOnly,
     "URL bar should not be read-only after leaving the private browsing mode");
  is(gURLBar.getAttribute("enablehistory"), "true",
     "URL bar autocomplete should be enabled after leaving the private browsing mode");
  ss.setWindowState(window, stateBackup, true);
}
function test ( ) { let pb = Cc [ "@mozilla.org/privatebrowsing;1" ] . getService ( Ci . nsIPrivateBrowsingService ) ; let ss = Cc [ "@mozilla.org/browser/sessionstore;1" ] . getService ( Ci . nsISessionStore ) ; while ( ss . getClosedWindowCount ( ) ) ss . forgetClosedWindow ( 0 ) ; let stateBackup = ss . getWindowState ( window ) ; function pretendToBeAPopup ( whatToPretend ) { let state = whatToPretend ? '{"windows":[{"tabs":[{"entries":[],"attributes":{}}],"isPopup":true,"hidden":"toolbar"}]}' : '{"windows":[{"tabs":[{"entries":[],"attributes":{}}],"isPopup":false}]}' ; ss . setWindowState ( window , state , true ) ; if ( whatToPretend ) { ok ( gURLBar . readOnly , "pretendToBeAPopup correctly made the URL bar read-only" ) ; is ( gURLBar . getAttribute ( "enablehistory" ) , "false" , "pretendToBeAPopup correctly disabled autocomplete on the URL bar" ) ; } else { ok ( ! gURLBar . readOnly , "pretendToBeAPopup correctly made the URL bar read-write" ) ; is ( gURLBar . getAttribute ( "enablehistory" ) , "true" , "pretendToBeAPopup correctly enabled autocomplete on the URL bar" ) ; } } pretendToBeAPopup ( true ) ; pb . privateBrowsingEnabled = true ; ok ( ! gURLBar . readOnly , "URL bar should not be read-only after entering the private browsing mode" ) ; is ( gURLBar . getAttribute ( "enablehistory" ) , "true" , "URL bar autocomplete should be enabled after entering the private browsing mode" ) ; pb . privateBrowsingEnabled = false ; pretendToBeAPopup ( false ) ; pb . privateBrowsingEnabled = true ; pretendToBeAPopup ( true ) ; pb . privateBrowsingEnabled = false ; ok ( ! gURLBar . readOnly , "URL bar should not be read-only after leaving the private browsing mode" ) ; is ( gURLBar . getAttribute ( "enablehistory" ) , "true" , "URL bar autocomplete should be enabled after leaving the private browsing mode" ) ; ss . setWindowState ( window , stateBackup , true ) ; }
browsing mode, even if it's disabled before that (see bug 495495).
browsing mode even if it ' s disabled before that ( see bug 495495 ) .
// initialization // clear the history of closed windows (that other tests have created) // to avoid the issue in bug 596592 // XXX remove this when bug 597071 is fixed // backup our state // first, test the case of entering the PB mode when a popup window is active // pretend we're a popup window // enter private browsing mode // make sure that the url bar status is correctly restored // leave private browsing mode // we're no longer a popup window // then, test the case of leaving the PB mode when a popup window is active // start from within the private browsing mode // pretend we're a popup window // leave private browsing mode // make sure that the url bar status is correctly restored // cleanup