Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7361)

Unified Diff: chrome/test/data/extensions/api_test/bookmarks/test.js

Issue 171032: end-to-end extension API tests (Closed)
Patch Set: a bit of refactoring and review feedback Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/bookmarks/test.js
diff --git a/chrome/test/data/extensions/api_test/bookmarks/test.js b/chrome/test/data/extensions/api_test/bookmarks/test.js
new file mode 100755
index 0000000000000000000000000000000000000000..13de9b5ef308c673b3e801802480b942345d6deb
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/bookmarks/test.js
@@ -0,0 +1,76 @@
+var completed = false;
+
+function complete() {
Aaron Boodman 2009/08/17 17:31:03 It would be nice if this light infrastructure were
+ completed = true;
+ // a bit of a hack just to try to get the script to stop running at this point
+ throw "completed";
+}
+
+function fail(message) {
+ if (completed) throw "completed";
+
+ console.log("FAIL: " + message);
+ chrome.test.fail(message);
+ complete();
+}
+
+function succeed() {
+ if (completed) throw "completed";
+
+ chrome.test.pass();
+ complete();
+}
+
+window.onerror = function(message, url, code) {
+ if (completed) return;
+
+ fail(message);
+};
+
+function expectTrue(test, message) {
+ if (!test) {
+ fail(message);
+ }
+}
+
+var expected = [
+ {"children": [
+ {"children": [], "id": "1", "parentId": "0", "title":"Bookmarks bar"},
+ {"children": [], "id": "2", "parentId": "0", "title":"Other bookmarks"}
+ ],
+ "id": "0", "title": ""
+ }
+];
+
+function compareTrees(left, right) {
+ console.log("compare");
+ console.log(JSON.stringify(right));
+ console.log(JSON.stringify(left));
+ // TODO(erikkay): do some comparison of dateAdded
+ if (left == null && right == null) {
+ console.log("both left and right are NULL");
+ return true;
+ }
+ if (left == null || right == null)
+ return false;
+ if (left.length < right.length)
+ return false;
+ for (var i = 0; i < left.length; i++) {
+ if (left[i].id != right[i].id)
+ return false;
+ console.log(left[i].title + " ? " + right[i].title);
+ if (left[i].title != right[i].title)
+ return false;
+ if (!compareTrees(left[i].children, right[i].children))
+ return false;
+ }
+ return true;
+}
+
+chrome.bookmarks.getTree(function(results) {
+ expectTrue(compareTrees(results, expected),
+ "getTree() result doesn't match expected");
+ expected = results;
+ console.log("done");
+ succeed();
+});
« chrome/chrome.gyp ('K') | « chrome/test/data/extensions/api_test/bookmarks/test.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698