B2G/gecko/docshell/test/chrome/docshell_helpers.js
/**
 * The event listener which listens for expectedEvents.
 */
The event listener which listens for expectedEvents.
The event listener which listens for expectedEvents .
function pageEventListener(event) {
  try {
    dump("TEST: eventListener received a " + event.type + " event for page " +
      event.originalTarget.title + ", persisted=" + event.persisted + "\n");
  } catch(e) {
  }
  if ( (event.type == "pageshow") && 
    (gNavType == NAV_BACK || gNavType == NAV_FORWARD) ) {
    let uri = TestWindow.getBrowser().currentURI.spec;
    if (uri in gUrisNotInBFCache) {
      ok(!event.persisted, "pageshow event has .persisted = false, even " +
       "though it was loaded with .preventBFCache previously\n");
    }
  }
  if (typeof(gUnexpectedEvents) != "undefined") {
    is(gUnexpectedEvents.indexOf(event.type), -1,
       "Should not get unexpected event " + event.type);
  }  
  if ((typeof(gExpectedEvents) == "undefined") && event.type == "pageshow")
  {
    setTimeout(function() { gFinalEvent = true; }, 0);
    return;
  }
  if (gExpectedEvents.length == 0) {
    ok(false, "Unexpected event (" + event.type + ") occurred");
    return;
  }
  let expected = gExpectedEvents.shift();
  is(event.type, expected.type, 
    "A " + expected.type + " event was expected, but a " +
    event.type + " event occurred");
  if (typeof(expected.title) != "undefined") {
    ok(event.originalTarget instanceof HTMLDocument,
       "originalTarget for last " + event.type + 
       " event not an HTMLDocument");
    is(event.originalTarget.title, expected.title, 
      "A " + event.type + " event was expected for page " +
      expected.title + ", but was fired for page " + 
      event.originalTarget.title);
  }  
  if (typeof(expected.persisted) != "undefined") {
    is(event.persisted, expected.persisted, 
      "The persisted property of the " + event.type + " event on page " +
      event.originalTarget.location + " had an unexpected value"); 
  }
  if ("visibilityState" in expected) {
    is(event.originalTarget.mozVisibilityState, expected.visibilityState,
       "The visibilityState property of the document on page " +
       event.originalTarget.location + " had an unexpected value");
  }
  if ("hidden" in expected) {
    is(event.originalTarget.mozHidden, expected.hidden,
       "The hidden property of the document on page " +
       event.originalTarget.location + " had an unexpected value");
  }
  if (gExpectedEvents.length == 0)
    setTimeout(function() { gFinalEvent = true; }, 0);
}
function pageEventListener ( event ) { try { dump ( "TEST: eventListener received a " + event . type + " event for page " + event . originalTarget . title + ", persisted=" + event . persisted + "\n" ) ; } catch ( e ) { } if ( ( event . type == "pageshow" ) && ( gNavType == NAV_BACK || gNavType == NAV_FORWARD ) ) { let uri = TestWindow . getBrowser ( ) . currentURI . spec ; if ( uri in gUrisNotInBFCache ) { ok ( ! event . persisted , "pageshow event has .persisted = false, even " + "though it was loaded with .preventBFCache previously\n" ) ; } } if ( typeof ( gUnexpectedEvents ) != "undefined" ) { is ( gUnexpectedEvents . indexOf ( event . type ) , - 1 , "Should not get unexpected event " + event . type ) ; } if ( ( typeof ( gExpectedEvents ) == "undefined" ) && event . type == "pageshow" ) { setTimeout ( function ( ) { gFinalEvent = true ; } , 0 ) ; return ; } if ( gExpectedEvents . length == 0 ) { ok ( false , "Unexpected event (" + event . type + ") occurred" ) ; return ; } let expected = gExpectedEvents . shift ( ) ; is ( event . type , expected . type , "A " + expected . type + " event was expected, but a " + event . type + " event occurred" ) ; if ( typeof ( expected . title ) != "undefined" ) { ok ( event . originalTarget instanceof HTMLDocument , "originalTarget for last " + event . type + " event not an HTMLDocument" ) ; is ( event . originalTarget . title , expected . title , "A " + event . type + " event was expected for page " + expected . title + ", but was fired for page " + event . originalTarget . title ) ; } if ( typeof ( expected . persisted ) != "undefined" ) { is ( event . persisted , expected . persisted , "The persisted property of the " + event . type + " event on page " + event . originalTarget . location + " had an unexpected value" ) ; } if ( "visibilityState" in expected ) { is ( event . originalTarget . mozVisibilityState , expected . visibilityState , "The visibilityState property of the document on page " + event . originalTarget . location + " had an unexpected value" ) ; } if ( "hidden" in expected ) { is ( event . originalTarget . mozHidden , expected . hidden , "The hidden property of the document on page " + event . originalTarget . location + " had an unexpected value" ) ; } if ( gExpectedEvents . length == 0 ) setTimeout ( function ( ) { gFinalEvent = true ; } , 0 ) ; }
The event listener which listens for expectedEvents.
The event listener which listens for expectedEvents .
// Ignore any exception. // If this page shouldn't be in the bfcache because it was previously // loaded with .preventBFCache, make sure that its pageshow event // has .persisted = false, even if the test doesn't explicitly test // for .persisted. // If no expected events were specified, mark the final event as having been  // triggered when a pageshow event is fired; this will allow  // doPageNavigation() to return. // If there are explicitly no expected events, but we receive one, it's an  // error. // Grab the next expected event, and compare its attributes against the  // actual event. // If we're out of expected events, let doPageNavigation() return.