diff options
author | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-10 09:44:36 +0000 |
---|---|---|
committer | pfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-10 09:44:36 +0000 |
commit | ff7a8f6f83c9569dae22cbab612c7201b2990731 (patch) | |
tree | 077be1de69146ad797caa7ba6f5f9bcd501b2437 /webkit/glue/devtools | |
parent | 1c67ccc3ab473fd54db8aa1d93b5e216edbe1d01 (diff) | |
download | chromium_src-ff7a8f6f83c9569dae22cbab612c7201b2990731.zip chromium_src-ff7a8f6f83c9569dae22cbab612c7201b2990731.tar.gz chromium_src-ff7a8f6f83c9569dae22cbab612c7201b2990731.tar.bz2 |
DevTools: migrate sanity tests to javascript.
Review URL: http://codereview.chromium.org/119368
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18047 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/devtools')
-rw-r--r-- | webkit/glue/devtools/js/devtools.html | 1 | ||||
-rw-r--r-- | webkit/glue/devtools/js/devtools_host_stub.js | 7 | ||||
-rw-r--r-- | webkit/glue/devtools/js/tests.js | 124 |
3 files changed, 132 insertions, 0 deletions
diff --git a/webkit/glue/devtools/js/devtools.html b/webkit/glue/devtools/js/devtools.html index b10e208..018573d 100644 --- a/webkit/glue/devtools/js/devtools.html +++ b/webkit/glue/devtools/js/devtools.html @@ -105,6 +105,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. <script type="text/javascript" src="TopDownProfileDataGridTree.js"></script> <script type="text/javascript" src="devtools.js"></script> <script type="text/javascript" src="devtools_host_stub.js"></script> + <script type="text/javascript" src="tests.js"></script> </head> <body class="detached"> <div id="toolbar"> diff --git a/webkit/glue/devtools/js/devtools_host_stub.js b/webkit/glue/devtools/js/devtools_host_stub.js index 5948abe..bfa7304 100644 --- a/webkit/glue/devtools/js/devtools_host_stub.js +++ b/webkit/glue/devtools/js/devtools_host_stub.js @@ -276,6 +276,12 @@ RemoteDebuggerCommandExecutorStub.prototype.DebuggerCommand = function(cmd) { * @constructor */ DevToolsHostStub = function() { + this.isStub = true; + window.domAutomationController = { + send: function(text) { + debugPrint(text); + } + }; }; @@ -285,6 +291,7 @@ DevToolsHostStub.prototype.loaded = function() { RemoteDomAgentStub.sendChildNodes_(2); devtools.tools.updateFocusedNode_(4); devtools.tools.addMessageToConsole_('message', 'source', 3); + uiTests.runAllTests(); }; diff --git a/webkit/glue/devtools/js/tests.js b/webkit/glue/devtools/js/tests.js new file mode 100644 index 0000000..a2d5a28 --- /dev/null +++ b/webkit/glue/devtools/js/tests.js @@ -0,0 +1,124 @@ +// 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. + + +/** + * @fileoverview This file contains small testing framework along with the + * test suite for the frontend. These tests are a part of the continues build + * and are executed by the devtools_sanity_unittest.cc as a part of the + * Interactive UI Test suite. + */ + +if (window.domAutomationController) { + + +/** + * Test suite for interactive UI tests. + * @constructor + */ +TestSuite = function() { +}; + + +/** + * Reports test failure. + * @param {string} message Failure description. + */ +TestSuite.prototype.fail = function(message) { + throw message; +} + + +/** + * Equals assertion tests that expected == actual. + * @param {Object} expected Expected object. + * @param {Object} actual Actual object. + */ +TestSuite.prototype.assertEquals = function(expected, actual) { + if (expected != actual) { + this.fail('Expected: "' + expected + '", but was "' + actual + '"'); + } +} + + +/** + * True assertion tests that value == true. + * @param {Object} expected Expected object. + * @param {Object} value Actual object. + */ +TestSuite.prototype.assertTrue = function(value) { + this.assertEquals(true, value); +} + + +/** + * Runs all global functions starting with 'test' as unit tests. + */ +TestSuite.prototype.runAllTests = function() { + // For debugging purposes. + for (var name in this) { + if (name.substring(0, 4) == 'test' && + typeof this[name] == 'function') { + this.runTest(name); + } + } +} + + +/** + * Runs all global functions starting with 'test' as unit tests. + */ +TestSuite.prototype.runTest = function(testName) { + try { + this[testName](); + window.domAutomationController.send('[OK]'); + } catch (e) { + window.domAutomationController.send('[FAILED] ' + testName + ': ' + e); + } +} + + +// UI Tests + + +/** + * Tests that the real injected host is present in the context. + */ +TestSuite.prototype.testHostIsPresent = function() { + var domAgent = devtools.tools.getDomAgent(); + var doc = domAgent.getDocument(); + this.assertTrue(typeof DevToolsHost == 'object' && !DevToolsHost.isStub); + this.assertTrue(!!doc.documentElement); +} + + +/** + * Tests elements tree has an 'HTML' root. + */ +TestSuite.prototype.testElementsTreeRoot = function() { + var domAgent = devtools.tools.getDomAgent(); + var doc = domAgent.getDocument(); + this.assertEquals('HTML', doc.documentElement.nodeName); + this.assertTrue(doc.documentElement.hasChildNodes()); +} + + +/** + * Tests that main resource is present in the system and that it is + * the only resource. + */ +TestSuite.prototype.testMainResource = function() { + var tokens = []; + var resources = WebInspector.resources; + for (var id in resources) { + tokens.push(resources[id].lastPathComponent); + } + this.assertEquals('simple_page.html', tokens.join(',')); +} + + +var uiTests = new TestSuite(); + + +} |