diff options
Diffstat (limited to 'chrome/test')
9 files changed, 163 insertions, 0 deletions
diff --git a/chrome/test/data/extensions/content_script_inject/js_test.js b/chrome/test/data/extensions/content_script_inject/js_test.js new file mode 100755 index 0000000..87a0930 --- /dev/null +++ b/chrome/test/data/extensions/content_script_inject/js_test.js @@ -0,0 +1,33 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// A quick and dirty JavaScript test runner.
+
+function assert(truth) {
+ if (!truth) {
+ throw new Error('Assertion failed');
+ }
+}
+
+function runAllTests() {
+ // If there was already an error, do nothing. We don't want to muddy
+ // up the results.
+ if (document.title.indexOf("Error: ") == 0) {
+ return;
+ }
+
+ for (var propName in window) {
+ if (typeof window[propName] == "function" &&
+ propName.indexOf("test") == 0) {
+ try {
+ window[propName]();
+ document.title += propName + ",";
+ } catch (e) {
+ // We use document.title to communicate results back to the browser.
+ document.title = "Error: " + propName + ': ' + e.message;
+ return;
+ }
+ }
+ }
+}
diff --git a/chrome/test/data/extensions/content_script_inject/manifest.json b/chrome/test/data/extensions/content_script_inject/manifest.json new file mode 100755 index 0000000..8214fb6 --- /dev/null +++ b/chrome/test/data/extensions/content_script_inject/manifest.json @@ -0,0 +1,21 @@ +{ + "id": "00123456789ABCDEF0123456789ABCDEF0123456", + "version": "1.0.0.0", + "name": "User script inject", + "content_scripts": [ + { + "matches": ["file://*/content_script_inject_page.html"], + "css": ["script1.css"], + "js": ["js_test.js", "script1a.js", "script1b.js"] + }, + { + "matches": ["file://*/content_script_inject_page.html"], + "js": ["js_test.js", "script2.js"] + }, + { + "matches": ["file://*/content_script_inject_page.html"], + "js": ["js_test.js", "script3.js"], + "run_at": "document_start" + } + ] +} diff --git a/chrome/test/data/extensions/content_script_inject/script1.css b/chrome/test/data/extensions/content_script_inject/script1.css new file mode 100644 index 0000000..521b501b --- /dev/null +++ b/chrome/test/data/extensions/content_script_inject/script1.css @@ -0,0 +1,10 @@ +/* +Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +Use of this source code is governed by a BSD-style license that can be +found in the LICENSE file. +*/ + +/* script1b.js tests that this rule was applied. */ +body { + background:red; +} diff --git a/chrome/test/data/extensions/content_script_inject/script1a.js b/chrome/test/data/extensions/content_script_inject/script1a.js new file mode 100755 index 0000000..87f4f55 --- /dev/null +++ b/chrome/test/data/extensions/content_script_inject/script1a.js @@ -0,0 +1,7 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// create a global variable. script1b.js tests to make sure it is visible and +// script2.js tests to make sure it is not. +var script1_var = 1; diff --git a/chrome/test/data/extensions/content_script_inject/script1b.js b/chrome/test/data/extensions/content_script_inject/script1b.js new file mode 100755 index 0000000..8e7e102 --- /dev/null +++ b/chrome/test/data/extensions/content_script_inject/script1b.js @@ -0,0 +1,27 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// This tests that we are running in the same global context as script1a.js. +function testScriptFilesRunInSameContext() { + assert(script1_var === 1); +} + +// This tests that our relationship to content is working correctly. +// a) We should not see content globals in our global scope. +// b) We should have a contentWindow object that looks like a DOM Window. +// c) We should be able to access content globals via contentWindow. +function testContentInteraction() { + assert(typeof content_var == "undefined"); + assert(typeof contentWindow != "undefined"); + assert(contentWindow.location.href.match(/content_script_inject_page.html$/)); + assert(contentWindow.content_var == "hello"); +} + +// Test that our css in script1.css was injected successfully. +function testCSSWasInjected() { + assert(document.defaultView.getComputedStyle( + document.body, null)["background-color"] == "rgb(255, 0, 0)"); +} + +runAllTests(); diff --git a/chrome/test/data/extensions/content_script_inject/script2.js b/chrome/test/data/extensions/content_script_inject/script2.js new file mode 100755 index 0000000..9133afa2 --- /dev/null +++ b/chrome/test/data/extensions/content_script_inject/script2.js @@ -0,0 +1,12 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Tests that we cannot see global variables defined in other content scripts. +// This var was defined in script1a.js. We run each content script in a separate +// context, so we shouldn't see globals across them. +function testCannotSeeOtherContentScriptGlobals() {
+ assert(typeof script1_var == "undefined");
+}
+
+runAllTests();
diff --git a/chrome/test/data/extensions/content_script_inject/script3.js b/chrome/test/data/extensions/content_script_inject/script3.js new file mode 100644 index 0000000..15bc225 --- /dev/null +++ b/chrome/test/data/extensions/content_script_inject/script3.js @@ -0,0 +1,31 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +var gotDOMContentLoadedEvent = false; + +// Test that at parse time, we have the document element. +// This basically tests that we don't get injected too early (before there is +// a document element). +var hasDocumentElement = (document.documentElement.tagName == "HTML"); + +// TODO(aa): We would like to add more tests here verifying that we aren't +// injected too late. For example, we could test that there are zero child +// nodes to the documentElement, but unfortunately run_at:document_start is +// currently buggy and doesn't guarantee that. + +window.addEventListener("DOMContentLoaded", function() { + gotDOMContentLoadedEvent = true; +}, false); + +// Don't run tests until onload so that we can test that DOMContentLoaded and +// onload happen after this script runs. +window.addEventListener("load", runAllTests, false); + +function testRunAtDocumentStart() { + assert(hasDocumentElement); +} + +function testGotLoadEvents() { + assert(gotDOMContentLoadedEvent); +} diff --git a/chrome/test/data/extensions/content_script_inject_page.html b/chrome/test/data/extensions/content_script_inject_page.html new file mode 100755 index 0000000..4412e19 --- /dev/null +++ b/chrome/test/data/extensions/content_script_inject_page.html @@ -0,0 +1,10 @@ +<html> +<head> +<title></title> +<script> +var content_var = "hello"; +</script> +</head> +<body> +</body> +</html> diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index d4e3864..0b2c1df 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -472,6 +472,10 @@ > </File> <File + RelativePath="..\..\browser\extensions\extension_content_script_inject_unittest.cc" + > + </File> + <File RelativePath="..\..\browser\extensions\extension_ui_unittest.cc" > </File> @@ -700,6 +704,14 @@ > </File> <File + RelativePath="..\..\browser\extensions\test_extension_loader.cc" + > + </File> + <File + RelativePath="..\..\browser\extensions\test_extension_loader.h" + > + </File> + <File RelativePath="..\..\browser\history\text_database_manager_unittest.cc" > </File> |