dom/tests/mochitest/bugs/test_toJSON.html

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:2b3b6bdfce98
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=760851
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 760851</title>
9 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 <script type="application/javascript">
12
13 /** Test for Bug 760851 **/
14 SimpleTest.waitForExplicitFinish();
15
16 // We need to skip all the interface constants.
17 var keysToSkip = ["TYPE_NAVIGATE", "TYPE_RELOAD", "TYPE_RESERVED",
18 "TYPE_BACK_FORWARD"];
19
20 // Testing window.performance is sufficient, because checkAttributesMatch is
21 // recursive, so window.performance.navigation and window.performance.timing
22 // get tested as well.
23 var toTest = [window.performance];
24
25 function checkAttributesMatch(obj, jsonObj) {
26 if (typeof(obj) !== "object") {
27 throw "Expected obj to be of type \"object\". Test failed.";
28 }
29 if (typeof(jsonObj) !== "object") {
30 is(false, "Expected object " + jsonObj + " to be of type object, but gotten otherwise");
31 }
32 for (key in obj) {
33 if (typeof(obj[key]) === "function" || keysToSkip.indexOf(key) > -1)
34 continue;
35 if (typeof(obj[key]) === "object") {
36 checkAttributesMatch(obj[key], jsonObj[key]);
37 continue;
38 }
39 is(jsonObj[key], obj[key], "values for " + obj + " key " + key + " should match");
40 }
41 }
42
43 function runTest() {
44 toTest.forEach(function(testObj) {
45 var jsonCopy = JSON.parse(JSON.stringify(testObj));
46 checkAttributesMatch(testObj, jsonCopy);
47 });
48 SimpleTest.finish();
49 }
50
51 </script>
52 </head>
53 <body onload="runTest();">
54 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=760851">Mozilla Bug 760851</a>
55 <p id="display"></p>
56 <div id="content" style="display: none">
57 <p></p>
58 <p></p>
59 <p></p>
60 </div>
61 <pre id="test">
62 </pre>
63 </body>
64 </html>

mercurial