parser/htmlparser/tests/mochitest/test_viewsource.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/parser/htmlparser/tests/mochitest/test_viewsource.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,50 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +  <head>
     1.7 +    <title>Test for view source</title>
     1.8 +    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
    1.10 +  </head>
    1.11 +
    1.12 +  <body>
    1.13 +
    1.14 +<!--
    1.15 +  this is a multi-line comment
    1.16 +-->
    1.17 +
    1.18 +    <script class="testbody" type="text/javascript">
    1.19 +
    1.20 +      SimpleTest.waitForExplicitFinish();
    1.21 +
    1.22 +      // Return the source text of the document at the given URL.
    1.23 +      function fetch(url) {
    1.24 +        var xhr = new XMLHttpRequest();
    1.25 +        xhr.open("GET", url, false);    // None of this async silliness,
    1.26 +        xhr.send();                     // we'll just wait.
    1.27 +        return xhr.responseText;
    1.28 +      }
    1.29 +
    1.30 +      // We will "view" the source of the document in a new window.
    1.31 +      // If everything is working correctly, the "source" will simply be the
    1.32 +      // text content of the new window's document's body element.
    1.33 +      // We have to use a window as view-source: is only allowed in top level,
    1.34 +      // see bug 624883.
    1.35 +
    1.36 +      // Open the new window.
    1.37 +      var windowWithSource = window.open("about:blank");
    1.38 +
    1.39 +      // The actual test will be carried out inside the window's onload handler.
    1.40 +      windowWithSource.onload = function () {
    1.41 +        var apparentSource = this.document.body.textContent;
    1.42 +        var actualSource = fetch(location.href);
    1.43 +        is(apparentSource, actualSource, "Sources should match");
    1.44 +
    1.45 +        windowWithSource.close()
    1.46 +        SimpleTest.finish();
    1.47 +      }
    1.48 +
    1.49 +      windowWithSource.location.href = "view-source:" + location.href;
    1.50 +    </script>
    1.51 +
    1.52 +  </body>
    1.53 +</html>

mercurial