diff options
24 files changed, 183 insertions, 333 deletions
diff --git a/chrome/browser/extensions/extension_test_api.cc b/chrome/browser/extensions/extension_test_api.cc index a381286..6c837dc 100644 --- a/chrome/browser/extensions/extension_test_api.cc +++ b/chrome/browser/extensions/extension_test_api.cc @@ -6,8 +6,8 @@ #include "chrome/common/notification_service.h" namespace extension_test_api_functions { -const char kPassFunction[] = "test.pass"; -const char kFailFunction[] = "test.fail"; +const char kPassFunction[] = "test.notifyPass"; +const char kFailFunction[] = "test.notifyFail"; }; // namespace extension_test_api_functions bool ExtensionTestPassFunction::RunImpl() { diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 81f13d7..d4fc821 100644 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -2765,6 +2765,7 @@ 'renderer/net/render_dns_queue.cc', 'renderer/net/render_dns_queue.h', 'renderer/resources/event_bindings.js', + 'renderer/resources/extension_apitest.js', 'renderer/resources/extension_process_bindings.js', 'renderer/resources/greasemonkey_api.js', 'renderer/resources/json_schema.js', diff --git a/chrome/common/common_resources.grd b/chrome/common/common_resources.grd index 5fc44f4..457cd27 100644 --- a/chrome/common/common_resources.grd +++ b/chrome/common/common_resources.grd @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- This comment is only here because changes to resources are not picked up -without changes to the corresponding grd file. rw --> +without changes to the corresponding grd file. --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/common_resources.h" type="rc_header"> diff --git a/chrome/common/extensions/api/extension_api.json b/chrome/common/extensions/api/extension_api.json index f0cca69..9b56818 100755 --- a/chrome/common/extensions/api/extension_api.json +++ b/chrome/common/extensions/api/extension_api.json @@ -932,7 +932,7 @@ "types": [], "functions": [ { - "name": "fail", + "name": "notifyFail", "type": "function", "description": "Notify the browser process that test code running in the extension failed. This is only used for internal unit testing.", "parameters": [ @@ -940,10 +940,12 @@ ] }, { - "name": "pass", + "name": "notifyPass", "type": "function", "description": "Notify the browser process that test code running in the extension passed. This is only used for internal unit testing.", - "parameters": [] + "parameters": [ + {"type": "string", "name": "message", "optional": true} + ] } ], "events": [] diff --git a/chrome/renderer/extensions/extension_process_bindings.cc b/chrome/renderer/extensions/extension_process_bindings.cc index 0b019ae..8aaa2f2 100644 --- a/chrome/renderer/extensions/extension_process_bindings.cc +++ b/chrome/renderer/extensions/extension_process_bindings.cc @@ -46,6 +46,7 @@ const char* kExtensionDeps[] = { EventBindings::kName, JsonSchemaJsV8Extension::kName, RendererExtensionBindings::kName, + ExtensionApiTestV8Extension::kName, }; struct SingletonData { diff --git a/chrome/renderer/extensions/js_only_v8_extensions.cc b/chrome/renderer/extensions/js_only_v8_extensions.cc index 986e656..94b12be 100644 --- a/chrome/renderer/extensions/js_only_v8_extensions.cc +++ b/chrome/renderer/extensions/js_only_v8_extensions.cc @@ -27,3 +27,12 @@ v8::Extension* JsonSchemaJsV8Extension::Get() { kName, GetStringResource<IDR_JSON_SCHEMA_JS>(), 0, NULL); return extension; } + +// ExtensionApiTestV8Extension +const char* ExtensionApiTestV8Extension::kName = "chrome/extensionapitest"; +v8::Extension* ExtensionApiTestV8Extension::Get() { + static v8::Extension* extension = + new bindings_utils::ExtensionBase( + kName, GetStringResource<IDR_EXTENSION_APITEST_JS>(), 0, NULL); + return extension; +} diff --git a/chrome/renderer/extensions/js_only_v8_extensions.h b/chrome/renderer/extensions/js_only_v8_extensions.h index 58f9861..79b6c30 100644 --- a/chrome/renderer/extensions/js_only_v8_extensions.h +++ b/chrome/renderer/extensions/js_only_v8_extensions.h @@ -22,4 +22,10 @@ class JsonSchemaJsV8Extension { static v8::Extension* Get(); }; +class ExtensionApiTestV8Extension { + public: + static const char* kName; + static v8::Extension* Get(); +}; + #endif // CHROME_RENDERER_JS_ONLY_V8_EXTENSIONS_H_ diff --git a/chrome/renderer/render_thread.cc b/chrome/renderer/render_thread.cc index 56b4215..fd076ba 100644 --- a/chrome/renderer/render_thread.cc +++ b/chrome/renderer/render_thread.cc @@ -433,6 +433,10 @@ void RenderThread::EnsureWebKitInitialized() { WebKit::registerExtension(RendererExtensionBindings::Get(), EXTENSION_GROUP_CONTENT_SCRIPTS); WebKit::registerExtension(RendererExtensionBindings::Get(), kExtensionScheme); + WebKit::registerExtension(ExtensionApiTestV8Extension::Get(), + kExtensionScheme); + WebKit::registerExtension(ExtensionApiTestV8Extension::Get(), + EXTENSION_GROUP_CONTENT_SCRIPTS); const CommandLine& command_line = *CommandLine::ForCurrentProcess(); diff --git a/chrome/renderer/renderer_resources.grd b/chrome/renderer/renderer_resources.grd index eb128c7..98e2092 100644 --- a/chrome/renderer/renderer_resources.grd +++ b/chrome/renderer/renderer_resources.grd @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <!-- This comment is only here because changes to resources are not picked up -without changes to the corresponding grd file. aa1 --> +without changes to the corresponding grd file. ek6 --> <grit latest_public_release="0" current_release="1"> <outputs> <output filename="grit/renderer_resources.h" type="rc_header"> @@ -20,6 +20,7 @@ without changes to the corresponding grd file. aa1 --> <include name="IDR_NET_ERROR_HTML" file="resources\neterror.html" type="BINDATA" /> <include name="IDR_RENDERER_EXTENSION_BINDINGS_JS" file="resources\renderer_extension_bindings.js" type="BINDATA" /> <include name="IDR_SAD_PLUGIN" file="resources\sadplugin.png" type="BINDATA" /> + <include name="IDR_EXTENSION_APITEST_JS" file="resources\extension_apitest.js" type="BINDATA" /> </includes> </release> </grit> diff --git a/chrome/renderer/resources/extension_apitest.js b/chrome/renderer/resources/extension_apitest.js new file mode 100644 index 0000000..41ef1ef --- /dev/null +++ b/chrome/renderer/resources/extension_apitest.js @@ -0,0 +1,120 @@ +// extension_apitest.js +// mini-framework for ExtensionApiTest browser tests + +var chrome = chrome || {}; +(function() { + chrome.test = chrome.test || {}; + + chrome.test.tests = chrome.test.tests || []; + + var completed = false; + var currentTest; + + function complete() { + completed = true; + + // Try to get the script to stop running immediately. + // This isn't an error, just an attempt at saying "done". + throw "completed"; + } + + chrome.test.fail = function(message) { + if (completed) throw "completed"; + + var stack; + try { + crash.me += 0; // An intentional exception to get the stack trace. + } catch (e) { + stack = e.stack.split("\n"); + stack = stack.slice(2); // Remove title and fail() lines. + stack = stack.join("\n"); + } + + if (!message) { + message = "FAIL (no message)"; + } + message += "\n" + stack; + console.log("[FAIL] " + currentTest.name + ": " + message); + chrome.test.notifyFail(message); + complete(); + } + + function allTestsSucceeded() { + console.log("All tests succeeded"); + if (completed) throw "completed"; + + chrome.test.notifyPass(); + complete(); + } + + chrome.test.runNextTest = function() { + currentTest = chrome.test.tests.shift(); + if (!currentTest) { + allTestsSucceeded(); + return; + } + try { + currentTest.call(); + } catch (e) { + message = e.stack; + console.log("[FAIL] " + currentTest.name + ": " + message); + chrome.test.notifyFail(message); + complete(); + } + } + + chrome.test.succeed = function() { + console.log("[SUCCESS] " + currentTest.name); + chrome.test.runNextTest(); + } + + chrome.test.assertTrue = function(test, message) { + if (test !== true) { + if (typeof(test) == "string") { + if (message) { + message = test + "\n" + message; + } else { + message = test; + } + } + chrome.test.fail(message); + } + } + + chrome.test.assertNoLastError = function() { + if (chrome.extension.lastError != undefined) { + chrome.test.fail("lastError.message == " + + chrome.extension.lastError.message); + } + } + + // Wrapper for generating test functions, that takes care of calling + // assertNoLastError() and succeed() for you. + chrome.test.testFunction = function(func) { + return function() { + chrome.test.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)"; + } + chrome.test.fail(msg); + } + chrome.test.succeed(); + }; + } + + chrome.test.runTests = function(tests) { + chrome.test.tests = tests; + chrome.test.runNextTest(); + } +})(); diff --git a/chrome/test/data/extensions/api_test/bookmarks/api_test.js b/chrome/test/data/extensions/api_test/bookmarks/api_test.js deleted file mode 100644 index 84d0bb1..0000000 --- a/chrome/test/data/extensions/api_test/bookmarks/api_test.js +++ /dev/null @@ -1,107 +0,0 @@ -// 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(); - }; -} diff --git a/chrome/test/data/extensions/api_test/bookmarks/test.html b/chrome/test/data/extensions/api_test/bookmarks/test.html index 0f02a821..3e7b4a4 100644 --- a/chrome/test/data/extensions/api_test/bookmarks/test.html +++ b/chrome/test/data/extensions/api_test/bookmarks/test.html @@ -1,2 +1 @@ -<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 bab0de2..7189296 100644 --- a/chrome/test/data/extensions/api_test/bookmarks/test.js +++ b/chrome/test/data/extensions/api_test/bookmarks/test.js @@ -50,48 +50,48 @@ function compareTrees(left, right) { return true; } -var tests = [ +chrome.test.runTests([ function getTree() { - chrome.bookmarks.getTree(testFunction(function(results) { - assertTrue(compareTrees(results, expected), + chrome.bookmarks.getTree(chrome.test.testFunction(function(results) { + chrome.test.assertTrue(compareTrees(results, expected), "getTree() result != expected"); expected = results; })); }, function get() { - chrome.bookmarks.get("1", testFunction(function(results) { - assertTrue(compareNode(results[0], expected[0].children[0])); + chrome.bookmarks.get("1", chrome.test.testFunction(function(results) { + chrome.test.assertTrue(compareNode(results[0], expected[0].children[0])); })); }, function getArray() { - chrome.bookmarks.get(["1", "2"], testFunction(function(results) { - assertTrue(compareNode(results[0], expected[0].children[0]), + chrome.bookmarks.get(["1", "2"], + chrome.test.testFunction(function(results) { + chrome.test.assertTrue(compareNode(results[0], expected[0].children[0]), "get() result != expected"); - assertTrue(compareNode(results[1], expected[0].children[1]), + chrome.test.assertTrue(compareNode(results[1], expected[0].children[1]), "get() result != expected"); })); }, function getChildren() { - chrome.bookmarks.getChildren("0", testFunction(function(results) { - assertTrue(compareNode(results[0], expected[0].children[0]), + chrome.bookmarks.getChildren("0", + chrome.test.testFunction(function(results) { + chrome.test.assertTrue(compareNode(results[0], expected[0].children[0]), "getChildren() result != expected"); - assertTrue(compareNode(results[1], expected[0].children[1]), + chrome.test.assertTrue(compareNode(results[1], expected[0].children[1]), "getChildren() result != expected"); })); }, function create() { var node = {parentId: "1", title:"google", url:"http://www.google.com/"}; - chrome.bookmarks.create(node, testFunction(function(results) { + chrome.bookmarks.create(node, chrome.test.testFunction(function(results) { node.id = results.id; // since we couldn't know this going in node.index = 0; - assertTrue(compareNode(node, results), + chrome.test.assertTrue(compareNode(node, results), "created node != source"); })); }, -]; - -runNextTest(); +]); diff --git a/chrome/test/data/extensions/api_test/override1/api_test.js b/chrome/test/data/extensions/api_test/override1/api_test.js deleted file mode 100755 index 84d0bb1..0000000 --- a/chrome/test/data/extensions/api_test/override1/api_test.js +++ /dev/null @@ -1,107 +0,0 @@ -// 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(); - }; -} diff --git a/chrome/test/data/extensions/api_test/override1/background.html b/chrome/test/data/extensions/api_test/override1/background.html index 0f02a821..3e7b4a4 100644 --- a/chrome/test/data/extensions/api_test/override1/background.html +++ b/chrome/test/data/extensions/api_test/override1/background.html @@ -1,2 +1 @@ -<script src="api_test.js"></script>
<script src="test.js"></script>
diff --git a/chrome/test/data/extensions/api_test/override1/downloads.html b/chrome/test/data/extensions/api_test/override1/downloads.html index 565343c..17927f2 100644 --- a/chrome/test/data/extensions/api_test/override1/downloads.html +++ b/chrome/test/data/extensions/api_test/override1/downloads.html @@ -1,6 +1,6 @@ <title>download1</title>
<script>
console.log("download1");
-chrome.test.pass();
+chrome.test.notifyPass();
</script>
Downloads Override
diff --git a/chrome/test/data/extensions/api_test/override1/history.html b/chrome/test/data/extensions/api_test/override1/history.html index ba1e65b..fedd7a0 100644 --- a/chrome/test/data/extensions/api_test/override1/history.html +++ b/chrome/test/data/extensions/api_test/override1/history.html @@ -1,4 +1,4 @@ <script>
-chrome.test.pass();
+chrome.test.notifyPass();
</script>
History Override
diff --git a/chrome/test/data/extensions/api_test/override1/newtab.html b/chrome/test/data/extensions/api_test/override1/newtab.html index a1028a2..20b8f82 100644 --- a/chrome/test/data/extensions/api_test/override1/newtab.html +++ b/chrome/test/data/extensions/api_test/override1/newtab.html @@ -1,4 +1,4 @@ <script>
-chrome.test.pass();
+chrome.test.notifyPass();
</script>
New Tab Override
diff --git a/chrome/test/data/extensions/api_test/override1/nonexistant.html b/chrome/test/data/extensions/api_test/override1/nonexistant.html index 66cfbd0..927f5ca 100644 --- a/chrome/test/data/extensions/api_test/override1/nonexistant.html +++ b/chrome/test/data/extensions/api_test/override1/nonexistant.html @@ -1,4 +1,4 @@ <script>
-chrome.test.pass();
+chrome.test.notifyPass();
</script>
Nonexistant Override
diff --git a/chrome/test/data/extensions/api_test/override1/test.js b/chrome/test/data/extensions/api_test/override1/test.js index 1684f2f..f70d85da 100644 --- a/chrome/test/data/extensions/api_test/override1/test.js +++ b/chrome/test/data/extensions/api_test/override1/test.js @@ -1,11 +1,8 @@ -var tests = [
+chrome.test.runTests([
function newtab() {
chrome.tabs.create({"url": "chrome://newtab/"},
- testFunction(function(response) {
- console.log("AFTER");
+ chrome.test.testFunction(function(response) {
}));
}
-];
-
-runNextTest();
+]);
diff --git a/chrome/test/data/extensions/api_test/storage/api_test.js b/chrome/test/data/extensions/api_test/storage/api_test.js deleted file mode 100755 index 985cff3..0000000 --- a/chrome/test/data/extensions/api_test/storage/api_test.js +++ /dev/null @@ -1,77 +0,0 @@ -// 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/storage/background.html b/chrome/test/data/extensions/api_test/storage/background.html index b704b2d..5373c7a 100644 --- a/chrome/test/data/extensions/api_test/storage/background.html +++ b/chrome/test/data/extensions/api_test/storage/background.html @@ -9,7 +9,7 @@ tx.executeSql("create table note (body text)", []);
tx.executeSql("insert into note values ('hotdog')", []);
}, function(error) {
- fail(error.message);
+ chrome.test.fail(error.message);
});
// Open a tab. This doesn't really prove we're writing to disk, but it is
diff --git a/chrome/test/data/extensions/api_test/storage/tab.html b/chrome/test/data/extensions/api_test/storage/tab.html index b52fdc3..ebed9ef 100644 --- a/chrome/test/data/extensions/api_test/storage/tab.html +++ b/chrome/test/data/extensions/api_test/storage/tab.html @@ -1,17 +1,18 @@ -<script src="api_test.js"></script>
<script>
+chrome.test.runTests([function tab() {
// Check that the localstorage stuff we stored is still there.
- expectTrue(localStorage.foo == "bar");
+ chrome.test.assertTrue(localStorage.foo == "bar");
// Check that the database stuff we stored is still there.
var db = window.openDatabase("mydb2", "1.0", "database test", 2048);
db.transaction(function(tx) {
tx.executeSql("select body from note", [], function(tx, results) {
- expectTrue(results.rows.length == 1);
- expectTrue(results.rows.item(0).body == "hotdog");
- allTestsSucceeded();
+ chrome.test.assertTrue(results.rows.length == 1);
+ chrome.test.assertTrue(results.rows.item(0).body == "hotdog");
+ chrome.test.succeed();
});
}, function(error) {
- fail(error.message);
+ chrome.test.fail(error.message);
});
+}]);
</script>
diff --git a/chrome/test/render_view_test.cc b/chrome/test/render_view_test.cc index cf3a90b..9cc0ecd 100644 --- a/chrome/test/render_view_test.cc +++ b/chrome/test/render_view_test.cc @@ -72,6 +72,7 @@ void RenderViewTest::SetUp() { WebKit::registerExtension(BaseJsV8Extension::Get()); WebKit::registerExtension(JsonSchemaJsV8Extension::Get()); WebKit::registerExtension(EventBindings::Get()); + WebKit::registerExtension(ExtensionApiTestV8Extension::Get()); WebKit::registerExtension(ExtensionProcessBindings::Get()); WebKit::registerExtension(RendererExtensionBindings::Get()); EventBindings::SetRenderThread(&render_thread_); |