1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/bugs/test_toJSON.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,64 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=760851 1.8 +--> 1.9 +<head> 1.10 + <meta charset="utf-8"> 1.11 + <title>Test for Bug 760851</title> 1.12 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.13 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.14 + <script type="application/javascript"> 1.15 + 1.16 + /** Test for Bug 760851 **/ 1.17 + SimpleTest.waitForExplicitFinish(); 1.18 + 1.19 + // We need to skip all the interface constants. 1.20 + var keysToSkip = ["TYPE_NAVIGATE", "TYPE_RELOAD", "TYPE_RESERVED", 1.21 + "TYPE_BACK_FORWARD"]; 1.22 + 1.23 + // Testing window.performance is sufficient, because checkAttributesMatch is 1.24 + // recursive, so window.performance.navigation and window.performance.timing 1.25 + // get tested as well. 1.26 + var toTest = [window.performance]; 1.27 + 1.28 + function checkAttributesMatch(obj, jsonObj) { 1.29 + if (typeof(obj) !== "object") { 1.30 + throw "Expected obj to be of type \"object\". Test failed."; 1.31 + } 1.32 + if (typeof(jsonObj) !== "object") { 1.33 + is(false, "Expected object " + jsonObj + " to be of type object, but gotten otherwise"); 1.34 + } 1.35 + for (key in obj) { 1.36 + if (typeof(obj[key]) === "function" || keysToSkip.indexOf(key) > -1) 1.37 + continue; 1.38 + if (typeof(obj[key]) === "object") { 1.39 + checkAttributesMatch(obj[key], jsonObj[key]); 1.40 + continue; 1.41 + } 1.42 + is(jsonObj[key], obj[key], "values for " + obj + " key " + key + " should match"); 1.43 + } 1.44 + } 1.45 + 1.46 + function runTest() { 1.47 + toTest.forEach(function(testObj) { 1.48 + var jsonCopy = JSON.parse(JSON.stringify(testObj)); 1.49 + checkAttributesMatch(testObj, jsonCopy); 1.50 + }); 1.51 + SimpleTest.finish(); 1.52 + } 1.53 + 1.54 + </script> 1.55 +</head> 1.56 +<body onload="runTest();"> 1.57 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=760851">Mozilla Bug 760851</a> 1.58 +<p id="display"></p> 1.59 +<div id="content" style="display: none"> 1.60 + <p></p> 1.61 + <p></p> 1.62 + <p></p> 1.63 +</div> 1.64 +<pre id="test"> 1.65 +</pre> 1.66 +</body> 1.67 +</html>