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

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

Issue 174277: override chrome:// URLs via extensions. (Closed)
Patch Set: fix linux errors 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
« no previous file with comments | « chrome/common/notification_type.h ('k') | chrome/test/data/extensions/api_test/override1/background.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/extensions/api_test/override1/api_test.js
diff --git a/chrome/test/data/extensions/api_test/override1/api_test.js b/chrome/test/data/extensions/api_test/override1/api_test.js
new file mode 100755
index 0000000000000000000000000000000000000000..84d0bb129bec7e85597a88d63594b1fe8bea7b00
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/override1/api_test.js
@@ -0,0 +1,107 @@
+// 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 assertTrue(test, message) {
+ if (test !== true) {
+ if (typeof(test) == "string") {
+ if (message) {
+ message = test + "\n" + message;
+ } else {
+ message = test;
+ }
+ }
+ fail(message);
+ }
+}
+
+function assertNoLastError() {
+ if (chrome.extension.lastError != undefined) {
+ fail("lastError.message == " + chrome.extension.lastError.message);
+ }
+}
+
+// Wrapper for generating test functions, that takes care of calling
+// assertNoLastError() and succeed() for you.
+function testFunction(func) {
+ return function() {
+ assertNoLastError();
+ try {
+ func.apply(null, arguments);
+ } catch (e) {
+ var stack = null;
+ if (typeof(e.stack) != "undefined") {
+ stack = e.stack.toString()
+ }
+ var msg = "Exception during execution of testFunction in " +
+ currentTest.name;
+ if (stack) {
+ msg += "\n" + stack;
+ } else {
+ msg += "\n(no stack available)";
+ }
+ fail(msg);
+ }
+ succeed();
+ };
+}
« no previous file with comments | « chrome/common/notification_type.h ('k') | chrome/test/data/extensions/api_test/override1/background.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698