parser/htmlparser/tests/mochitest/test_viewsource.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test for view source</title>
michael@0 5 <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
michael@0 7 </head>
michael@0 8
michael@0 9 <body>
michael@0 10
michael@0 11 <!--
michael@0 12 this is a multi-line comment
michael@0 13 -->
michael@0 14
michael@0 15 <script class="testbody" type="text/javascript">
michael@0 16
michael@0 17 SimpleTest.waitForExplicitFinish();
michael@0 18
michael@0 19 // Return the source text of the document at the given URL.
michael@0 20 function fetch(url) {
michael@0 21 var xhr = new XMLHttpRequest();
michael@0 22 xhr.open("GET", url, false); // None of this async silliness,
michael@0 23 xhr.send(); // we'll just wait.
michael@0 24 return xhr.responseText;
michael@0 25 }
michael@0 26
michael@0 27 // We will "view" the source of the document in a new window.
michael@0 28 // If everything is working correctly, the "source" will simply be the
michael@0 29 // text content of the new window's document's body element.
michael@0 30 // We have to use a window as view-source: is only allowed in top level,
michael@0 31 // see bug 624883.
michael@0 32
michael@0 33 // Open the new window.
michael@0 34 var windowWithSource = window.open("about:blank");
michael@0 35
michael@0 36 // The actual test will be carried out inside the window's onload handler.
michael@0 37 windowWithSource.onload = function () {
michael@0 38 var apparentSource = this.document.body.textContent;
michael@0 39 var actualSource = fetch(location.href);
michael@0 40 is(apparentSource, actualSource, "Sources should match");
michael@0 41
michael@0 42 windowWithSource.close()
michael@0 43 SimpleTest.finish();
michael@0 44 }
michael@0 45
michael@0 46 windowWithSource.location.href = "view-source:" + location.href;
michael@0 47 </script>
michael@0 48
michael@0 49 </body>
michael@0 50 </html>

mercurial