B2G/gecko/browser/components/privatebrowsing/test/browser/browser_privatebrowsing_openlocation.js
// mode without leaving any trace of the URLs visited.
mode without leaving any trace of the URLs visited.
mode without leaving any trace of the URLs visited .
function test() {
  gPrefService.setBoolPref("browser.privatebrowsing.keep_current_session", true);
  let pb = Cc["@mozilla.org/privatebrowsing;1"].
           getService(Ci.nsIPrivateBrowsingService);
  waitForExplicitFinish();
  function openLocation(url, autofilled, callback) {
    function observer(aSubject, aTopic, aData) {
      switch (aTopic) {
        case "domwindowopened":
          let dialog = aSubject.QueryInterface(Ci.nsIDOMWindow);
          dialog.addEventListener("load", function () {
            dialog.removeEventListener("load", arguments.callee, false);
            let browser = gBrowser.selectedBrowser;
            browser.addEventListener("load", function() {
              browser.removeEventListener("load", arguments.callee, true);
              is(browser.currentURI.spec, url,
                 "The correct URL should be loaded via the open location dialog");
              executeSoon(callback);
            }, true);
            SimpleTest.waitForFocus(function() {
              let input = dialog.document.getElementById("dialog.input");
              is(input.value, autofilled, "The input field should be correctly auto-filled");
              input.focus();
              for (let i = 0; i < url.length; ++i)
                EventUtils.synthesizeKey(url[i], {}, dialog);
              EventUtils.synthesizeKey("VK_RETURN", {}, dialog);
            }, dialog);
          }, false);
          break;
        case "domwindowclosed":
          Services.ww.unregisterNotification(arguments.callee);
          break;
      }
    }
    Services.ww.registerNotification(observer);
    gPrefService.setIntPref("general.open_location.last_window_choice", 0);
    openDialog("chrome://browser/content/openLocation.xul", "_blank",
               "chrome,titlebar", window);
  }
  if (gPrefService.prefHasUserValue("general.open_location.last_url"))
    gPrefService.clearUserPref("general.open_location.last_url");
  openLocation("http://example.com/", "", function() {
    openLocation("http://example.org/", "http://example.com/", function() {
      pb.privateBrowsingEnabled = true;
      openLocation("about:logo", "", function() {
        openLocation("about:buildconfig", "about:logo", function() {
          pb.privateBrowsingEnabled = false;
          openLocation("about:blank", "http://example.org/", function() {
            gPrefService.clearUserPref("general.open_location.last_url");
            if (gPrefService.prefHasUserValue("general.open_location.last_window_choice"))
              gPrefService.clearUserPref("general.open_location.last_window_choice");
            gPrefService.clearUserPref("browser.privatebrowsing.keep_current_session");
            finish();
          });
        });
      });
    });
  });
}
function test ( ) { gPrefService . setBoolPref ( "browser.privatebrowsing.keep_current_session" , true ) ; let pb = Cc [ "@mozilla.org/privatebrowsing;1" ] . getService ( Ci . nsIPrivateBrowsingService ) ; waitForExplicitFinish ( ) ; function openLocation ( url , autofilled , callback ) { function observer ( aSubject , aTopic , aData ) { switch ( aTopic ) { case "domwindowopened" : let dialog = aSubject . QueryInterface ( Ci . nsIDOMWindow ) ; dialog . addEventListener ( "load" , function ( ) { dialog . removeEventListener ( "load" , arguments . callee , false ) ; let browser = gBrowser . selectedBrowser ; browser . addEventListener ( "load" , function ( ) { browser . removeEventListener ( "load" , arguments . callee , true ) ; is ( browser . currentURI . spec , url , "The correct URL should be loaded via the open location dialog" ) ; executeSoon ( callback ) ; } , true ) ; SimpleTest . waitForFocus ( function ( ) { let input = dialog . document . getElementById ( "dialog.input" ) ; is ( input . value , autofilled , "The input field should be correctly auto-filled" ) ; input . focus ( ) ; for ( let i = 0 ; i < url . length ; ++ i ) EventUtils . synthesizeKey ( url [ i ] , { } , dialog ) ; EventUtils . synthesizeKey ( "VK_RETURN" , { } , dialog ) ; } , dialog ) ; } , false ) ; break ; case "domwindowclosed" : Services . ww . unregisterNotification ( arguments . callee ) ; break ; } } Services . ww . registerNotification ( observer ) ; gPrefService . setIntPref ( "general.open_location.last_window_choice" , 0 ) ; openDialog ( "chrome://browser/content/openLocation.xul" , "_blank" , "chrome,titlebar" , window ) ; } if ( gPrefService . prefHasUserValue ( "general.open_location.last_url" ) ) gPrefService . clearUserPref ( "general.open_location.last_url" ) ; openLocation ( "http://example.com/" , "" , function ( ) { openLocation ( "http://example.org/" , "http://example.com/" , function ( ) { pb . privateBrowsingEnabled = true ; openLocation ( "about:logo" , "" , function ( ) { openLocation ( "about:buildconfig" , "about:logo" , function ( ) { pb . privateBrowsingEnabled = false ; openLocation ( "about:blank" , "http://example.org/" , function ( ) { gPrefService . clearUserPref ( "general.open_location.last_url" ) ; if ( gPrefService . prefHasUserValue ( "general.open_location.last_window_choice" ) ) gPrefService . clearUserPref ( "general.open_location.last_window_choice" ) ; gPrefService . clearUserPref ( "browser.privatebrowsing.keep_current_session" ) ; finish ( ) ; } ) ; } ) ; } ) ; } ) ; } ) ; }
mode without leaving any trace of the URLs visited.
mode without leaving any trace of the URLs visited .
// initialization // enter private browsing mode // exit private browsing mode