summaryrefslogtreecommitdiffstats
path: root/chrome/test
diff options
context:
space:
mode:
authordtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-20 18:41:16 +0000
committerdtseng@chromium.org <dtseng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-20 18:41:16 +0000
commit82aff3f9755be6176092244cc76ced588076dcdb (patch)
treea7fdc5dd00ba5ec76a898cae57388af61a5cce4c /chrome/test
parent7edbf666d99d82ffe14daff4d38360f8636c4b6e (diff)
downloadchromium_src-82aff3f9755be6176092244cc76ced588076dcdb.zip
chromium_src-82aff3f9755be6176092244cc76ced588076dcdb.tar.gz
chromium_src-82aff3f9755be6176092244cc76ced588076dcdb.tar.bz2
Initial sketch of DOM UI test framework.
BUG=65911 TEST=manually run tests. Review URL: http://codereview.chromium.org/6231004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71972 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r--chrome/test/data/dom_ui/sample_downloads.js17
-rw-r--r--chrome/test/data/dom_ui/test_api.js84
2 files changed, 101 insertions, 0 deletions
diff --git a/chrome/test/data/dom_ui/sample_downloads.js b/chrome/test/data/dom_ui/sample_downloads.js
new file mode 100644
index 0000000..68ac9c0
--- /dev/null
+++ b/chrome/test/data/dom_ui/sample_downloads.js
@@ -0,0 +1,17 @@
+// Copyright (c) 2011 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.
+
+// Sample tests that exercise the test JS library and show how this framework
+// could be used to test the downloads page.
+// Call this method to run the tests.
+// The method takes an array of functions (your tests).
+runTests([
+ function testAssertFalse() {
+ assertFalse(false);
+ },
+
+ function testInitialFocus() {
+ assertTrue(document.activeElement.id == 'term', '');
+ }
+]);
diff --git a/chrome/test/data/dom_ui/test_api.js b/chrome/test/data/dom_ui/test_api.js
new file mode 100644
index 0000000..08140d0
--- /dev/null
+++ b/chrome/test/data/dom_ui/test_api.js
@@ -0,0 +1,84 @@
+// Copyright (c) 2011 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.
+
+// Library providing basic test framework functionality.
+
+(function() {
+ // Indicates a pass to the C++ backend.
+ function pass(message) {
+ chrome.send('Pass', []);
+ }
+
+ // Indicates a fail to the C++ backend.
+ function fail(message) {
+ chrome.send('Fail', []);
+ }
+
+ // Asserts.
+ // Use the following assertions to verify a condition within a test.
+ // If assertion fails, the C++ backend will be immediately notified.
+ // If assertion passes, no notification will be sent to the C++ backend.
+ function assertBool(test, expected, message) {
+ if (test !== expected) {
+ if (message)
+ message = test + '\n' + message;
+ else
+ message = test;
+ fail(message);
+ }
+ }
+
+ function assertTrue(test, message) {
+ assertBool(test, true, message);
+ }
+
+ function assertFalse(test, message) {
+ assertBool(test, false, message);
+ }
+
+ function assertEquals(expected, actual, message) {
+ if (expected !== actual) {
+ fail('Test Error in ' + testName(currentTest) +
+ '\nActual: ' + actual + '\nExpected: ' + expected + '\n' + message);
+ }
+ if (typeof expected != typeof actual) {
+ fail('Test Error in ' + testName(currentTest) +
+ ' (type mismatch)\nActual Type: ' + typeof actual +
+ '\nExpected Type:' + typeof expected + '\n' + message);
+ }
+ }
+
+ function assertNotReached(message) {
+ fail(message);
+ }
+
+ // Call this method within your test script file to begin tests.
+ // Takes an array of functions; each function is a test.
+ function runTests(tests) {
+ var currentTest = tests.shift();
+
+ while (currentTest) {
+ try {
+ console.log('Running test ' + currentTest.name);
+ currentTest.call();
+ currentTest = tests.shift();
+ } catch (e) {
+ console.log(
+ 'Failed: ' + currentTest.name + '\nwith exception: ' + e.message);
+
+ fail();
+ }
+ }
+
+ // All tests passed.
+ pass('');
+ }
+
+ // Exports.
+ window.assertTrue = assertTrue;
+ window.assertFalse = assertFalse;
+ window.assertEquals = assertEquals;
+ window.assertNotReached = assertNotReached;
+ window.runTests = runTests;
+})(); \ No newline at end of file