Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Bug 246620 - Simple view-source test; r=ehsan

  • Loading branch information...
commit 5c31f17312bae7dc08f8f4f71312e1483ad6014c 1 parent 561df56
authored December 26, 2011
1  parser/htmlparser/tests/mochitest/Makefile.in
@@ -92,6 +92,7 @@ _TEST_FILES =	parser_datreader.js \
92 92
 		test_bug645115.html \
93 93
 		test_bug655682.html \
94 94
 		file_bug655682.sjs \
  95
+		test_viewsource.html \
95 96
 		$(NULL)
96 97
 
97 98
 # Disabled test due to orange on Linux
63  parser/htmlparser/tests/mochitest/test_viewsource.html
... ...
@@ -0,0 +1,63 @@
  1
+<!DOCTYPE HTML>
  2
+<html>
  3
+  <head>
  4
+    <title>Test for view source</title>
  5
+    <script type="text/javascript" src="/MochiKit/packed.js"></script>
  6
+    <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  7
+    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
  8
+  </head>
  9
+
  10
+  <body>
  11
+
  12
+<!--
  13
+  this is a multi-line comment
  14
+-->
  15
+
  16
+    <script class="testbody" type="text/javascript">
  17
+
  18
+      SimpleTest.waitForExplicitFinish();
  19
+
  20
+      // Return the source text of the document at the given URL.
  21
+      function fetch(url) {
  22
+        var xhr = new XMLHttpRequest();
  23
+        xhr.open("GET", url, false);    // None of this async silliness,
  24
+        xhr.send();                     // we'll just wait.
  25
+        return xhr.responseText;
  26
+      }
  27
+
  28
+      // Start a "view source" test using the document at "testUrl".  Note that
  29
+      // the test will actually complete asynchronously.
  30
+      function startViewSourceTest(testUrl) {
  31
+        
  32
+        // We will "view" the source of the document in an IFRAME.
  33
+        // If everything is working correctly, the "source" will simply be the
  34
+        // text content of the IFRAME document's top element.
  35
+
  36
+        // Create the IFRAME.
  37
+        var iframe = document.createElement('iframe');
  38
+        iframe.src = "view-source:" + testUrl;
  39
+
  40
+        // The actual test will be carried out inside the IFRAME's onload handler.
  41
+        iframe.onload = function () {
  42
+
  43
+          var apparentSource = this.contentDocument.body.textContent;
  44
+          var actualSource = fetch(testUrl);
  45
+
  46
+          // OK, verify that the apparent source and the actual source agree.
  47
+          ok(apparentSource == actualSource, "Sources should match");
  48
+
  49
+          SimpleTest.finish();
  50
+        }
  51
+        
  52
+        // Our test IFRAME is ready to go.  However, it will not load until we
  53
+        // actually append it to the document.  Do that now.  Note that the test
  54
+        // itself will run asynchronously some time after this function returns.
  55
+        document.body.appendChild(iframe);
  56
+      }
  57
+
  58
+      // Start a test using this document as the test document.
  59
+      startViewSourceTest(document.location.href);
  60
+    </script>
  61
+
  62
+  </body>
  63
+</html>

0 notes on commit 5c31f17

Please sign in to comment.
Something went wrong with that request. Please try again.