test_toJSON.html (2200B)
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 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 // The event handler has to be initialized or else jsonObj will be undefined 26 window.performance.onresourcetimingbufferfull = function() {}; 27 28 function checkAttributesMatch(obj, jsonObj) { 29 // EventCounts isn't going to converted to a JSON string 30 if ('EventCounts' in window && obj instanceof EventCounts) { 31 return; 32 } 33 if (typeof(obj) !== "object") { 34 throw "Expected obj to be of type \"object\". Test failed."; 35 } 36 if (typeof(jsonObj) !== "object") { 37 is(false, "Expected object " + jsonObj + " to be of type object, but gotten otherwise"); 38 } 39 for (key in obj) { 40 if (typeof(obj[key]) === "function" || keysToSkip.indexOf(key) > -1) 41 continue; 42 if (typeof(obj[key]) === "object") { 43 checkAttributesMatch(obj[key], jsonObj[key]); 44 continue; 45 } 46 is(jsonObj[key], obj[key], "values for " + obj + " key " + key + " should match"); 47 } 48 } 49 50 function runTest() { 51 toTest.forEach(function(testObj) { 52 var jsonCopy = JSON.parse(JSON.stringify(testObj)); 53 checkAttributesMatch(testObj, jsonCopy); 54 }); 55 SimpleTest.finish(); 56 } 57 58 </script> 59 </head> 60 <body onload="runTest();"> 61 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=760851">Mozilla Bug 760851</a> 62 <p id="display"></p> 63 <div id="content" style="display: none"> 64 <p></p> 65 <p></p> 66 <p></p> 67 </div> 68 <pre id="test"> 69 </pre> 70 </body> 71 </html>