Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 var completed = false; | |
| 2 | |
| 3 function complete() { | |
|
Aaron Boodman
2009/08/17 17:31:03
It would be nice if this light infrastructure were
| |
| 4 completed = true; | |
| 5 // a bit of a hack just to try to get the script to stop running at this point | |
| 6 throw "completed"; | |
| 7 } | |
| 8 | |
| 9 function fail(message) { | |
| 10 if (completed) throw "completed"; | |
| 11 | |
| 12 console.log("FAIL: " + message); | |
| 13 chrome.test.fail(message); | |
| 14 complete(); | |
| 15 } | |
| 16 | |
| 17 function succeed() { | |
| 18 if (completed) throw "completed"; | |
| 19 | |
| 20 chrome.test.pass(); | |
| 21 complete(); | |
| 22 } | |
| 23 | |
| 24 window.onerror = function(message, url, code) { | |
| 25 if (completed) return; | |
| 26 | |
| 27 fail(message); | |
| 28 }; | |
| 29 | |
| 30 function expectTrue(test, message) { | |
| 31 if (!test) { | |
| 32 fail(message); | |
| 33 } | |
| 34 } | |
| 35 | |
| 36 var expected = [ | |
| 37 {"children": [ | |
| 38 {"children": [], "id": "1", "parentId": "0", "title":"Bookmarks bar"}, | |
| 39 {"children": [], "id": "2", "parentId": "0", "title":"Other bookmarks"} | |
| 40 ], | |
| 41 "id": "0", "title": "" | |
| 42 } | |
| 43 ]; | |
| 44 | |
| 45 function compareTrees(left, right) { | |
| 46 console.log("compare"); | |
| 47 console.log(JSON.stringify(right)); | |
| 48 console.log(JSON.stringify(left)); | |
| 49 // TODO(erikkay): do some comparison of dateAdded | |
| 50 if (left == null && right == null) { | |
| 51 console.log("both left and right are NULL"); | |
| 52 return true; | |
| 53 } | |
| 54 if (left == null || right == null) | |
| 55 return false; | |
| 56 if (left.length < right.length) | |
| 57 return false; | |
| 58 for (var i = 0; i < left.length; i++) { | |
| 59 if (left[i].id != right[i].id) | |
| 60 return false; | |
| 61 console.log(left[i].title + " ? " + right[i].title); | |
| 62 if (left[i].title != right[i].title) | |
| 63 return false; | |
| 64 if (!compareTrees(left[i].children, right[i].children)) | |
| 65 return false; | |
| 66 } | |
| 67 return true; | |
| 68 } | |
| 69 | |
| 70 chrome.bookmarks.getTree(function(results) { | |
| 71 expectTrue(compareTrees(results, expected), | |
| 72 "getTree() result doesn't match expected"); | |
| 73 expected = results; | |
| 74 console.log("done"); | |
| 75 succeed(); | |
| 76 }); | |
| OLD | NEW |