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