Commit eb6a392d authored by kevers@chromium.org's avatar kevers@chromium.org

Convert asynchronous closure test in cr.ui framework to a browser test.

BUG=249104
TEST=WebUIResourceBrowserTest

Review URL: https://chromiumcodereview.appspot.com/16831021

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207929 0039d316-1c4b-4281-b951-d872f2087c98
parent 83bcc96f
...@@ -2,21 +2,11 @@ ...@@ -2,21 +2,11 @@
<html> <html>
<head> <head>
<title>parseHtmlSubset test</title> <title>parseHtmlSubset test</title>
<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script> <script src="webui_resource_test.js"></script>
<script src="parse_html_subset.js"></script>
<script>
goog.require('goog.testing.AsyncTestCase');
goog.require('goog.testing.jsunit');
</script>
</head> </head>
<body> <body>
<script> <script>
var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall();
function parseAndAssertThrows() { function parseAndAssertThrows() {
var args = arguments; var args = arguments;
assertThrows(function() { assertThrows(function() {
...@@ -26,9 +16,7 @@ function parseAndAssertThrows() { ...@@ -26,9 +16,7 @@ function parseAndAssertThrows() {
function parseAndAssertNotThrows() { function parseAndAssertNotThrows() {
var args = arguments; var args = arguments;
assertNotThrows(function() {
parseHtmlSubset.apply(null, args); parseHtmlSubset.apply(null, args);
});
} }
function testText() { function testText() {
...@@ -113,17 +101,15 @@ function testInvalidCustomAttributes() { ...@@ -113,17 +101,15 @@ function testInvalidCustomAttributes() {
parseAndAssertThrows('<a class="fancy">I\'m fancy!</a>'); parseAndAssertThrows('<a class="fancy">I\'m fancy!</a>');
} }
function testOnError() { function testOnErrorAsync(testDoneCalback) {
window.called = false; window.called = false;
asyncTestCase.waitForAsync('Waiting for image error callbacks');
parseAndAssertThrows('<img onerror="window.called = true" src="_.png">'); parseAndAssertThrows('<img onerror="window.called = true" src="_.png">');
parseAndAssertThrows('<img src="_.png" onerror="window.called = true">'); parseAndAssertThrows('<img src="_.png" onerror="window.called = true">');
window.setTimeout(function() { window.setTimeout(function() {
asyncTestCase.continueTesting();
assertFalse(window.called); assertFalse(window.called);
testDoneCalback();
}); });
} }
......
...@@ -44,6 +44,9 @@ class WebUIResourceBrowserTest : public InProcessBrowserTest { ...@@ -44,6 +44,9 @@ class WebUIResourceBrowserTest : public InProcessBrowserTest {
std::string message; std::string message;
ExecuteJavascriptOnCurrentTab("runTests()"); ExecuteJavascriptOnCurrentTab("runTests()");
ASSERT_TRUE(message_queue.WaitForMessage(&message)); ASSERT_TRUE(message_queue.WaitForMessage(&message));
while (message.compare("\"PENDING\"") == 0) {
ASSERT_TRUE(message_queue.WaitForMessage(&message));
}
EXPECT_STREQ("\"SUCCESS\"", message.c_str()); EXPECT_STREQ("\"SUCCESS\"", message.c_str());
} }
...@@ -112,6 +115,11 @@ IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, LocalStringsTest) { ...@@ -112,6 +115,11 @@ IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, LocalStringsTest) {
RunTest(base::FilePath(FILE_PATH_LITERAL("local_strings_test.html"))); RunTest(base::FilePath(FILE_PATH_LITERAL("local_strings_test.html")));
} }
IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, ParseHtmlSubsetTest) {
AddLibrary(IDR_WEBUI_JS_PARSE_HTML_SUBSET);
RunTest(base::FilePath(FILE_PATH_LITERAL("parse_html_subset_test.html")));
}
IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, PositionUtilTest) { IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, PositionUtilTest) {
AddLibrary(IDR_WEBUI_JS_CR); AddLibrary(IDR_WEBUI_JS_CR);
AddLibrary(IDR_WEBUI_JS_CR_UI_POSITION_UTIL); AddLibrary(IDR_WEBUI_JS_CR_UI_POSITION_UTIL);
......
...@@ -96,35 +96,79 @@ function assertArrayEquals(expected, observed) { ...@@ -96,35 +96,79 @@ function assertArrayEquals(expected, observed) {
} }
/** /**
* Defines runTests.
*/
(function(exports) {
/**
* List of test cases.
* @type {Array.<string>} List of function names for tests to run.
*/
var testCases = [];
/**
* Indicates if all tests have run successfully.
* @type {boolean}
*/
var cleanTestRun = true;
/**
* Armed during setup of a test to call the matching tear down code.
* @type {Function}
*/
var pendingTearDown = null;
/**
* Runs all functions starting with test and reports success or * Runs all functions starting with test and reports success or
* failure of the test suite. * failure of the test suite.
*/ */
function runTests() { function runTests() {
var tests = [];
var success = true;
for (var name in window) { for (var name in window) {
if (typeof window[name] == 'function' && /^test/.test(name)) if (typeof window[name] == 'function' && /^test/.test(name))
tests.push(name); testCases.push(name);
}
if (!testCases.length) {
console.error('Failed to find test cases.');
cleanTestRun = false;
} }
if (!tests.length) { continueTesting();
console.error('\nFailed to find test cases.');
success = false;
} }
for (var i = 0; i < tests.length; i++) {
/**
* Runs the next test in the queue. Reports the test results if the queue is
* empty.
*/
function continueTesting() {
if (pendingTearDown) {
pendingTearDown();
pendingTearDown = null;
}
if (testCases.length > 0) {
var fn = testCases.pop();
var isAsyncTest = window[fn].length;
try { try {
if (window.setUp) if (window.setUp)
window.setUp(); window.setUp();
window[tests[i]](); pendingTearDown = window.tearDown;
} catch (err) { window[fn](continueTesting);
console.error('Failure in test ' + tests[i] + '\n' + err); } catch(err) {
console.error('Failure in test ' + fn + '\n' + err);
console.log(err.stack); console.log(err.stack);
success = false; cleanTestRun = false;
} }
if (window.tearDown) // Asynchronous tests must manually call continueTesting when complete.
window.tearDown(); if (!isAsyncTest)
continueTesting();
} else {
endTests(cleanTestRun);
} }
endTests(success); if (testCases.length) {
} domAutomationController.setAutomationId(1);
domAutomationController.send('PENDING');
}
};
exports.runTests = runTests;
})(this);
/** /**
* Signals completion of a test. * Signals completion of a test.
......
...@@ -506,6 +506,7 @@ bool DOMMessageQueue::WaitForMessage(std::string* message) { ...@@ -506,6 +506,7 @@ bool DOMMessageQueue::WaitForMessage(std::string* message) {
return false; return false;
if (message) if (message)
*message = message_queue_.front(); *message = message_queue_.front();
message_queue_.pop();
return true; return true;
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
tests --> tests -->
<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script> <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script>
<script src="../cr.js"></script> <script src="../cr.js"></script>
<script src="linkcontroller.js"></script> <script src="link_controller.js"></script>
<script> <script>
goog.require('goog.testing.MockControl'); goog.require('goog.testing.MockControl');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment