B2G/gecko/toolkit/content/tests/browser/browser_save_resend_postdata.js
/**
 * Test for bug 471962 <https://bugzilla.mozilla.org/show_bug.cgi?id=471962>:
 * When saving an inner frame as file only, the POST data of the outer page is
 * sent to the address of the inner page.
 *
 * Test for bug 485196 <https://bugzilla.mozilla.org/show_bug.cgi?id=485196>:
 * Web page generated by POST is retried as GET when Save Frame As used, and the
 * page is no longer in the cache.
 */
Test for bug 471962 :
When saving an inner frame as file only, the POST data of the outer page is
sent to the address of the inner page.

Test for bug 485196 :
Web page generated by POST is retried as GET when Save Frame As used, and the
page is no longer in the cache.
Test for bug 471962 : When saving an inner frame as file only the POST data of the outer page is sent to the address of the inner page . Test for bug 485196 : Web page generated by POST is retried as GET when Save Frame As used and the page is no longer in the cache .
function test() {
  waitForExplicitFinish();
  gBrowser.loadURI("http://mochi.test:8888/browser/toolkit/content/tests/browser/data/post_form_outer.sjs");
  registerCleanupFunction(function () {
    gBrowser.addTab();
    gBrowser.removeCurrentTab();
  });
  gBrowser.addEventListener("pageshow", function pageShown(event) {
    if (event.target.location == "about:blank")
      return;
    gBrowser.removeEventListener("pageshow", pageShown);
    gBrowser.addEventListener("DOMContentLoaded", handleOuterSubmit);
    gBrowser.contentDocument.getElementById("postForm").submit();
  });
  var framesLoaded = 0;
  var innerFrame;
  function handleOuterSubmit() {
    if (++framesLoaded < 2)
      return;
    gBrowser.removeEventListener("DOMContentLoaded", handleOuterSubmit);
    innerFrame = gBrowser.contentDocument.getElementById("innerFrame");
    gBrowser.addEventListener("DOMContentLoaded", handleInnerSubmit);
    innerFrame.contentDocument.getElementById("postForm").submit();
  }
  function handleInnerSubmit() {
    gBrowser.removeEventListener("DOMContentLoaded", handleInnerSubmit);
    var destDir = createTemporarySaveDirectory();
    var file = destDir.clone();
    file.append("no_default_file_name");
    MockFilePicker.returnFiles = [file];
    MockFilePicker.showCallback = function(fp) {
      MockFilePicker.filterIndex = 1; 
    };
    mockTransferCallback = onTransferComplete;
    mockTransferRegisterer.register();
    registerCleanupFunction(function () {
      mockTransferRegisterer.unregister();
      MockFilePicker.cleanup();
      destDir.remove(true);
    });
    var docToSave = innerFrame.contentDocument;
    internalSave(docToSave.location.href, docToSave, null, null,
                 docToSave.contentType, false, null, null,
                 docToSave.referrer ? makeURI(docToSave.referrer) : null,
                 docToSave, false, null);
  }
  function onTransferComplete(downloadSuccess) {
    ok(downloadSuccess, "The inner frame should have been downloaded successfully");
    var file = MockFilePicker.returnFiles[0];
    var fileContents = readShortFile(file);
    is(fileContents.indexOf("inputfield=outer"), -1,
       "The saved inner frame does not contain outer POST data");
    isnot(fileContents.indexOf("inputfield=inner"), -1,
          "The saved inner frame was generated using the correct POST data");
    finish();
  }
}
function test ( ) { waitForExplicitFinish ( ) ; gBrowser . loadURI ( "http://mochi.test:8888/browser/toolkit/content/tests/browser/data/post_form_outer.sjs" ) ; registerCleanupFunction ( function ( ) { gBrowser . addTab ( ) ; gBrowser . removeCurrentTab ( ) ; } ) ; gBrowser . addEventListener ( "pageshow" , function pageShown ( event ) { if ( event . target . location == "about:blank" ) return ; gBrowser . removeEventListener ( "pageshow" , pageShown ) ; gBrowser . addEventListener ( "DOMContentLoaded" , handleOuterSubmit ) ; gBrowser . contentDocument . getElementById ( "postForm" ) . submit ( ) ; } ) ; var framesLoaded = 0 ; var innerFrame ; function handleOuterSubmit ( ) { if ( ++ framesLoaded < 2 ) return ; gBrowser . removeEventListener ( "DOMContentLoaded" , handleOuterSubmit ) ; innerFrame = gBrowser . contentDocument . getElementById ( "innerFrame" ) ; gBrowser . addEventListener ( "DOMContentLoaded" , handleInnerSubmit ) ; innerFrame . contentDocument . getElementById ( "postForm" ) . submit ( ) ; } function handleInnerSubmit ( ) { gBrowser . removeEventListener ( "DOMContentLoaded" , handleInnerSubmit ) ; var destDir = createTemporarySaveDirectory ( ) ; var file = destDir . clone ( ) ; file . append ( "no_default_file_name" ) ; MockFilePicker . returnFiles = [ file ] ; MockFilePicker . showCallback = function ( fp ) { MockFilePicker . filterIndex = 1 ; } ; mockTransferCallback = onTransferComplete ; mockTransferRegisterer . register ( ) ; registerCleanupFunction ( function ( ) { mockTransferRegisterer . unregister ( ) ; MockFilePicker . cleanup ( ) ; destDir . remove ( true ) ; } ) ; var docToSave = innerFrame . contentDocument ; internalSave ( docToSave . location . href , docToSave , null , null , docToSave . contentType , false , null , null , docToSave . referrer ? makeURI ( docToSave . referrer ) : null , docToSave , false , null ) ; } function onTransferComplete ( downloadSuccess ) { ok ( downloadSuccess , "The inner frame should have been downloaded successfully" ) ; var file = MockFilePicker . returnFiles [ 0 ] ; var fileContents = readShortFile ( file ) ; is ( fileContents . indexOf ( "inputfield=outer" ) , - 1 , "The saved inner frame does not contain outer POST data" ) ; isnot ( fileContents . indexOf ( "inputfield=inner" ) , - 1 , "The saved inner frame was generated using the correct POST data" ) ; finish ( ) ; } }
Test for bug 471962 <https://bugzilla.mozilla.org/show_bug.cgi?id=471962>:
 When saving an inner frame as file only, the POST data of the outer page is
 sent to the address of the inner page.
Test for bug 471962 <https : // bugzilla . mozilla . org / show_bug . cgi?id = 471962 > : When saving an inner frame as file only the POST data of the outer page is sent to the address of the inner page .
// Submit the form in the outer page, then wait for both the outer // document and the inner frame to be loaded again. // Submit the form in the inner page. // Create the folder the page will be saved into. // kSaveAsType_URL // We call internalSave instead of saveDocument to bypass the history // cache. // Read the entire saved file. // Check if outer POST data is found (bug 471962). // Check if inner POST data is found (bug 485196).