summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rwxr-xr-xchrome/test/data/extensions/api_test/bookmarks/api_test.js77
-rw-r--r--chrome/test/data/extensions/api_test/bookmarks/test.html1
-rwxr-xr-xchrome/test/data/extensions/api_test/bookmarks/test.js132
3 files changed, 155 insertions, 55 deletions
diff --git a/chrome/test/data/extensions/api_test/bookmarks/api_test.js b/chrome/test/data/extensions/api_test/bookmarks/api_test.js
new file mode 100755
index 0000000..985cff3
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/bookmarks/api_test.js
@@ -0,0 +1,77 @@
+// api_test.js
+// mini-framework for ExtensionApiTest browser tests
+// TODO(erikkay) - figure out a way to share this code across extensions
+
+var completed = false;
+var tests;
+var currentTest;
+
+function complete() {
+ 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";
+
+ var stack;
+ try {
+ crash.me += 0; // intentional exception to get the stack trace
+ } catch (e) {
+ stack = e.stack.split("\n");
+ stack = stack.slice(2); // remove title and fail()
+ stack = stack.join("\n");
+ }
+
+ if (!message) {
+ message = "FAIL (no message)";
+ }
+ message += "\n" + stack;
+ console.log("[FAIL] " + currentTest.name + ": " + message);
+ chrome.test.fail(message);
+ complete();
+}
+
+function allTestsSucceeded() {
+ console.log("All tests succeeded");
+ if (completed) throw "completed";
+
+ chrome.test.pass();
+ complete();
+}
+
+function runNextTest() {
+ currentTest = tests.shift();
+ if (!currentTest) {
+ allTestsSucceeded();
+ return;
+ }
+ currentTest.call();
+}
+
+function succeed() {
+ console.log("[SUCCESS] " + currentTest.name);
+ runNextTest();
+}
+
+window.onerror = function(message, url, code) {
+ if (completed) return;
+
+ fail(message);
+};
+
+function expectTrue(test, message) {
+ if (test !== true) {
+ if (typeof(test) == "string") {
+ if (message) {
+ message = test + "\n" + message;
+ } else {
+ message = test;
+ }
+ }
+ fail(message);
+ }
+}
+
diff --git a/chrome/test/data/extensions/api_test/bookmarks/test.html b/chrome/test/data/extensions/api_test/bookmarks/test.html
index 3e7b4a4..0f02a821 100644
--- a/chrome/test/data/extensions/api_test/bookmarks/test.html
+++ b/chrome/test/data/extensions/api_test/bookmarks/test.html
@@ -1 +1,2 @@
+<script src="api_test.js"></script>
<script src="test.js"></script>
diff --git a/chrome/test/data/extensions/api_test/bookmarks/test.js b/chrome/test/data/extensions/api_test/bookmarks/test.js
index 13de9b5..ec7a90a 100755
--- a/chrome/test/data/extensions/api_test/bookmarks/test.js
+++ b/chrome/test/data/extensions/api_test/bookmarks/test.js
@@ -1,37 +1,5 @@
-var completed = false;
-
-function complete() {
- 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);
- }
-}
+// bookmarks api test
+// browser_tests.exe --gtest_filter=ExtensionApiTest.Bookmarks
var expected = [
{"children": [
@@ -42,35 +10,89 @@ var expected = [
}
];
-function compareTrees(left, right) {
- console.log("compare");
- console.log(JSON.stringify(right));
- console.log(JSON.stringify(left));
+function compareNode(left, right) {
+ //console.log(JSON.stringify(left));
+ //console.log(JSON.stringify(right));
// TODO(erikkay): do some comparison of dateAdded
+ if (left.id != right.id)
+ return "id mismatch: " + left.id + " != " + right.id;
+ if (left.title != right.title)
+ return "title mismatch: " + left.title + " != " + right.title;
+ if (left.url != right.url)
+ return "url mismatch: " + left.url + " != " + right.url;
+ if (left.index != right.index)
+ return "index mismatch: " + left.index + " != " + right.index;
+ return true;
+}
+
+function compareTrees(left, right) {
+ //console.log(JSON.stringify(left));
+ //console.log(JSON.stringify(right));
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;
+ return left + " !+ " + right;
+ if (left.length != right.length)
+ return "count mismatch: " + left.length + " != " + right.length;
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;
+ var result = compareNode(left[i], right[i]);
+ if (result !== true)
+ return result;
+ result = compareTrees(left[i].children, right[i].children);
+ if (result !== true)
+ return result;
}
return true;
}
-chrome.bookmarks.getTree(function(results) {
- expectTrue(compareTrees(results, expected),
- "getTree() result doesn't match expected");
- expected = results;
- console.log("done");
- succeed();
-});
+var tests = [
+ function getTree() {
+ chrome.bookmarks.getTree(function(results) {
+ expectTrue(compareTrees(results, expected),
+ "getTree() result != expected");
+ expected = results;
+ succeed();
+ });
+ },
+
+ function get() {
+ chrome.bookmarks.get("1", function(results) {
+ expectTrue(compareNode(results[0], expected[0].children[0]));
+ succeed();
+ });
+ },
+
+ function getArray() {
+ chrome.bookmarks.get(["1", "2"], function(results) {
+ expectTrue(compareNode(results[0], expected[0].children[0]),
+ "get() result != expected");
+ expectTrue(compareNode(results[1], expected[0].children[1]),
+ "get() result != expected");
+ succeed();
+ });
+ },
+
+ function getChildren() {
+ chrome.bookmarks.getChildren("0", function(results) {
+ expectTrue(compareNode(results[0], expected[0].children[0]),
+ "getChildren() result != expected");
+ expectTrue(compareNode(results[1], expected[0].children[1]),
+ "getChildren() result != expected");
+ succeed();
+ });
+ },
+
+ function create() {
+ var node = {parentId: "1", title:"google", url:"http://www.google.com/"};
+ chrome.bookmarks.create(node, function(results) {
+ node.id = results.id; // since we couldn't know this going in
+ expectTrue(compareNode(node, results),
+ "created node != source");
+ succeed();
+ });
+ },
+];
+
+runNextTest();