{"size": 2437, "ext": "js", "max_stars_repo_path": "B2G/gecko/browser/components/sessionstore/test/browser_463206.js", "max_stars_repo_name": "wilebeast/FireFox-OS", "max_stars_repo_stars_event_min_datetime": "2015-08-31T15:24:31.000Z", "max_stars_repo_stars_event_max_datetime": "2020-04-24T20:31:29.000Z", "max_issues_repo_path": "B2G/gecko/browser/components/sessionstore/test/browser_463206.js", "max_issues_repo_name": "wilebeast/FireFox-OS", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "B2G/gecko/browser/components/sessionstore/test/browser_463206.js", "max_forks_repo_name": "wilebeast/FireFox-OS", "max_forks_repo_forks_event_min_datetime": "2015-07-29T07:17:15.000Z", "max_forks_repo_forks_event_max_datetime": "2020-11-04T06:55:37.000Z"}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": 3, "avg_line_length": 37.4923076923, "max_line_length": 93, "alphanum_fraction": 0.657775954}
/* 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/. */

function test() {
  /** Test for Bug 463206 **/

  waitForExplicitFinish();

  let testURL = "http://mochi.test:8888/browser/" +
    "browser/components/sessionstore/test/browser_463206_sample.html";

  var frameCount = 0;
  let tab = gBrowser.addTab(testURL);
  tab.linkedBrowser.addEventListener("load", function(aEvent) {
    // wait for all frames to load completely
    if (frameCount++ < 5)
      return;
    tab.linkedBrowser.removeEventListener("load", arguments.callee, true);

    function typeText(aTextField, aValue) {
      aTextField.value = aValue;

      let event = aTextField.ownerDocument.createEvent("UIEvents");
      event.initUIEvent("input", true, true, aTextField.ownerDocument.defaultView, 0);
      aTextField.dispatchEvent(event);
    }

    let doc = tab.linkedBrowser.contentDocument;
    typeText(doc.getElementById("out1"), Date.now());
    typeText(doc.getElementsByName("1|#out2")[0], Math.random());
    typeText(doc.defaultView.frames[0].frames[1].document.getElementById("in1"), new Date());

    frameCount = 0;
    let tab2 = gBrowser.duplicateTab(tab);
    tab2.linkedBrowser.addEventListener("load", function(aEvent) {
      // wait for all frames to load completely
      if (frameCount++ < 5)
        return;
      tab2.linkedBrowser.removeEventListener("load", arguments.callee, true);

      let doc = tab2.linkedBrowser.contentDocument;
      let win = tab2.linkedBrowser.contentWindow;
      isnot(doc.getElementById("out1").value,
            win.frames[1].document.getElementById("out1").value,
            "text isn't reused for frames");
      isnot(doc.getElementsByName("1|#out2")[0].value, "",
            "text containing | and # is correctly restored");
      is(win.frames[1].document.getElementById("out2").value, "",
            "id prefixes can't be faked");
      // Disabled for now, Bug 588077
      // isnot(win.frames[0].frames[1].document.getElementById("in1").value, "",
      //       "id prefixes aren't mixed up");
      is(win.frames[1].frames[0].document.getElementById("in1").value, "",
            "id prefixes aren't mixed up");

      // clean up
      gBrowser.removeTab(tab2);
      gBrowser.removeTab(tab);

      finish();
    }, true);
  }, true);
}
