summaryrefslogtreecommitdiffstats
path: root/browser/components/sessionstore/test/browser_461743_sample.html
blob: 80c9e612af61288355e50f714ad68f9d3bb76c1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<!-- Testcase originally by <moz_bug_r_a4@yahoo.com> -->

<!DOCTYPE html>
<title>Test for bug 461743</title>

<body>
<iframe src="data:text/html;charset=utf-8,empty"></iframe>
<iframe></iframe>

<script type="application/javascript">
  var chromeUrl = "chrome://global/content/mozilla.xhtml";
  var exploitUrl = "javascript:try { document.body.innerHTML = Components.utils.reportError; } catch (ex) { }";

  var loadCount = 0;
  frames[0].addEventListener("DOMContentLoaded", handleLoad, false);
  frames[1].addEventListener("DOMContentLoaded", handleLoad, false);
  function handleLoad() {
    if (++loadCount < 2)
      return;
    frames[0].removeEventListener("DOMContentLoaded", handleLoad, false);
    frames[1].removeEventListener("DOMContentLoaded", handleLoad, false);

    var flip = 0;
    MutationEvent.prototype.toString = function() {
      return flip++ == 0 ? chromeUrl : exploitUrl;
    };

    var href = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(frames[1].location), "href").get;
    var loadChrome = { handleEvent: href };
    var loadExploit = { handleEvent: href };

    function delay() {
      var xhr = new XMLHttpRequest();
      xhr.open("GET", location.href, false);
      xhr.send(null);
    }
    function done() {
      var event = new MessageEvent('461743', { bubbles: true, cancelable: false,
                                               data: "done", origin: location.href,
                                               source: window });
      document.dispatchEvent(event);
      frames[0].document.removeEventListener("DOMNodeInserted", loadChrome, true);
      frames[0].document.removeEventListener("DOMNodeInserted", delay, true);
      frames[0].document.removeEventListener("DOMNodeInserted", loadExploit, true);
      frames[0].document.removeEventListener("DOMNodeInserted", done, true);
    }

    frames[0].document.addEventListener("DOMNodeInserted", loadChrome, true);
    frames[0].document.addEventListener("DOMNodeInserted", delay, true);
    frames[0].document.addEventListener("DOMNodeInserted", loadExploit, true);
    frames[0].document.addEventListener("DOMNodeInserted", done, true);

    frames[0].document.designMode = "on";
  };
</script>
</body>