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 @@
<html>
<head>
<title>parseHtmlSubset test</title>
<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script>
<script src="parse_html_subset.js"></script>
<script>
goog.require('goog.testing.AsyncTestCase');
goog.require('goog.testing.jsunit');
</script>
<script src="webui_resource_test.js"></script>
</head>
<body>
<script>
var asyncTestCase = goog.testing.AsyncTestCase.createAndInstall();
function parseAndAssertThrows() {
var args = arguments;
assertThrows(function() {
......@@ -26,9 +16,7 @@ function parseAndAssertThrows() {
function parseAndAssertNotThrows() {
var args = arguments;
assertNotThrows(function() {
parseHtmlSubset.apply(null, args);
});
}
function testText() {
......@@ -113,17 +101,15 @@ function testInvalidCustomAttributes() {
parseAndAssertThrows('<a class="fancy">I\'m fancy!</a>');
}
function testOnError() {
function testOnErrorAsync(testDoneCalback) {
window.called = false;
asyncTestCase.waitForAsync('Waiting for image error callbacks');
parseAndAssertThrows('<img onerror="window.called = true" src="_.png">');
parseAndAssertThrows('<img src="_.png" onerror="window.called = true">');
window.setTimeout(function() {
asyncTestCase.continueTesting();
assertFalse(window.called);
testDoneCalback();
});
}
......
......@@ -44,6 +44,9 @@ class WebUIResourceBrowserTest : public InProcessBrowserTest {
std::string message;
ExecuteJavascriptOnCurrentTab("runTests()");
ASSERT_TRUE(message_queue.WaitForMessage(&message));
while (message.compare("\"PENDING\"") == 0) {
ASSERT_TRUE(message_queue.WaitForMessage(&message));
}
EXPECT_STREQ("\"SUCCESS\"", message.c_str());
}
......@@ -112,6 +115,11 @@ IN_PROC_BROWSER_TEST_F(WebUIResourceBrowserTest, LocalStringsTest) {
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) {
AddLibrary(IDR_WEBUI_JS_CR);
AddLibrary(IDR_WEBUI_JS_CR_UI_POSITION_UTIL);
......
......@@ -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
* failure of the test suite.
*/
function runTests() {
var tests = [];
var success = true;
function runTests() {
for (var name in window) {
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) {
console.error('\nFailed to find test cases.');
success = false;
continueTesting();
}
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 {
if (window.setUp)
window.setUp();
window[tests[i]]();
} catch (err) {
console.error('Failure in test ' + tests[i] + '\n' + err);
pendingTearDown = window.tearDown;
window[fn](continueTesting);
} catch(err) {
console.error('Failure in test ' + fn + '\n' + err);
console.log(err.stack);
success = false;
cleanTestRun = false;
}
if (window.tearDown)
window.tearDown();
// Asynchronous tests must manually call continueTesting when complete.
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.
......
......@@ -506,6 +506,7 @@ bool DOMMessageQueue::WaitForMessage(std::string* message) {
return false;
if (message)
*message = message_queue_.front();
message_queue_.pop();
return true;
}
......
......@@ -5,7 +5,7 @@
tests -->
<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script>
<script src="../cr.js"></script>
<script src="linkcontroller.js"></script>
<script src="link_controller.js"></script>
<script>
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