Commit 23a90f4e authored by mtomasz@chromium.org's avatar mtomasz@chromium.org

Checks for Javascript errors in Files.app's tests.

This patch verifies if there are no Javascript errors at the end of each test. Along the way it removes callbackPass instances, which are not reliable and can cause false positives.

TEST=Run browser_tests --test_filter="*FileManagerBrowser*"
BUG=233142, 233141

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@195194 0039d316-1c4b-4281-b951-d872f2087c98
parent 84780b40
...@@ -42,6 +42,20 @@ test.util.openMainWindow = function(path, callback) { ...@@ -42,6 +42,20 @@ test.util.openMainWindow = function(path, callback) {
helper(); helper();
}; };
/**
* Gets total Javascript error count from each app window.
* @return {number} Error count.
*/
test.util.getErrorCount = function() {
var totalCount = 0;
for (var appId in appWindows) {
var contentWindow = appWindows[appId].contentWindow;
if (contentWindow.JSErrorCount)
totalCount += contentWindow.JSErrorCount;
}
return totalCount;
};
/** /**
* Returns an array with the files currently selected in the file manager. * Returns an array with the files currently selected in the file manager.
* *
...@@ -307,6 +321,9 @@ test.util.registerRemoteTestUtils = function() { ...@@ -307,6 +321,9 @@ test.util.registerRemoteTestUtils = function() {
case 'openMainWindow': case 'openMainWindow':
test.util.openMainWindow(request.args[0], sendResponse); test.util.openMainWindow(request.args[0], sendResponse);
return true; return true;
case 'getErrorCount':
sendResponse(test.util.getErrorCount());
return true;
default: default:
console.error('Global function ' + request.func + ' not found.'); console.error('Global function ' + request.func + ' not found.');
} }
......
...@@ -64,9 +64,21 @@ function setupAndWaitUntilReady(path, callback) { ...@@ -64,9 +64,21 @@ function setupAndWaitUntilReady(path, callback) {
}); });
} }
/**
* Verifies if there are no Javascript errors in any of the app windows.
* @param {function()} Completion callback.
*/
function checkIfNoErrorsOccured(callback) {
callRemoteTestUtil('getErrorCount', null, [], function(count) {
chrome.test.assertEq(0, count);
callback();
});
}
/** /**
* Expected files shown in "Recent". Directories (e.g. 'photos') are not in this * Expected files shown in "Recent". Directories (e.g. 'photos') are not in this
* list as they are not expected in "Recent". * list as they are not expected in "Recent".
*
* @type {Array.<Array.<string>>} * @type {Array.<Array.<string>>}
* @const * @const
*/ */
...@@ -128,10 +140,10 @@ testcase.intermediate.fileDisplay = function(path) { ...@@ -128,10 +140,10 @@ testcase.intermediate.fileDisplay = function(path) {
callRemoteTestUtil( callRemoteTestUtil(
'waitForFileListChange', 'waitForFileListChange',
appId, appId,
[expectedFilesBefore.length], [expectedFilesBefore.length], function(actualFilesAfter) {
chrome.test.callbackPass(function(actualFilesAfter) {
chrome.test.assertEq(expectedFilesAfter, actualFilesAfter); chrome.test.assertEq(expectedFilesAfter, actualFilesAfter);
})); checkIfNoErrorsOccured(chrome.test.succeed);
});
}); });
}); });
}; };
...@@ -142,14 +154,15 @@ testcase.intermediate.fileDisplay = function(path) { ...@@ -142,14 +154,15 @@ testcase.intermediate.fileDisplay = function(path) {
* *
* @param {string} path Directory path to be tested. * @param {string} path Directory path to be tested.
*/ */
testcase.intermediate.keyboardCopy = function(path) { testcase.intermediate.keyboardCopy = function(path, callback) {
setupAndWaitUntilReady(path, function(appId) { setupAndWaitUntilReady(path, function(appId) {
callRemoteTestUtil('copyFile', appId, ['world.mpeg'], function(result) { callRemoteTestUtil('copyFile', appId, ['world.mpeg'], function(result) {
chrome.test.assertFalse(!result); chrome.test.assertFalse(!result);
callRemoteTestUtil('waitForFileListChange', callRemoteTestUtil('waitForFileListChange',
appId, appId,
[getExpectedFilesBefore(path == '/drive/root').length], [getExpectedFilesBefore(path == '/drive/root').length],
chrome.test.succeed); checkIfNoErrorsOccured.bind(null,
chrome.test.succeed));
}); });
}); });
}; };
...@@ -167,7 +180,7 @@ testcase.intermediate.keyboardDelete = function(path) { ...@@ -167,7 +180,7 @@ testcase.intermediate.keyboardDelete = function(path) {
'waitForFileListChange', 'waitForFileListChange',
appId, appId,
[getExpectedFilesBefore(path == '/drive/root').length], [getExpectedFilesBefore(path == '/drive/root').length],
chrome.test.succeed); checkIfNoErrorsOccured.bind(null, chrome.test.succeed));
}); });
}); });
}); });
...@@ -204,9 +217,10 @@ testcase.keyboardDeleteDrive = function() { ...@@ -204,9 +217,10 @@ testcase.keyboardDeleteDrive = function() {
* Drive. * Drive.
*/ */
testcase.openSidebarRecent = function() { testcase.openSidebarRecent = function() {
var onFileListChange = chrome.test.callbackPass(function(actualFilesAfter) { var onFileListChange = function(actualFilesAfter) {
chrome.test.assertEq(EXPECTED_FILES_IN_RECENT, actualFilesAfter); chrome.test.assertEq(EXPECTED_FILES_IN_RECENT, actualFilesAfter);
}); checkIfNoErrorsOccured(chrome.test.succeed);
};
setupAndWaitUntilReady('/drive/root', function(appId) { setupAndWaitUntilReady('/drive/root', function(appId) {
// Use the icon for a click target. // Use the icon for a click target.
...@@ -230,9 +244,10 @@ testcase.openSidebarRecent = function() { ...@@ -230,9 +244,10 @@ testcase.openSidebarRecent = function() {
* entries cached by DriveCache. * entries cached by DriveCache.
*/ */
testcase.openSidebarOffline = function() { testcase.openSidebarOffline = function() {
var onFileListChange = chrome.test.callbackPass(function(actualFilesAfter) { var onFileListChange = function(actualFilesAfter) {
chrome.test.assertEq(EXPECTED_FILES_IN_OFFLINE, actualFilesAfter); chrome.test.assertEq(EXPECTED_FILES_IN_OFFLINE, actualFilesAfter);
}); checkIfNoErrorsOccured(chrome.test.succeed);
};
setupAndWaitUntilReady('/drive/root/', function(appId) { setupAndWaitUntilReady('/drive/root/', function(appId) {
// Use the icon for a click target. // Use the icon for a click target.
...@@ -284,10 +299,10 @@ testcase.autocomplete = function() { ...@@ -284,10 +299,10 @@ testcase.autocomplete = function() {
'hello.txt\n', 'hello.txt\n',
]; ];
var onAutocompleteListShown = chrome.test.callbackPass( var onAutocompleteListShown = function(autocompleteList) {
function(autocompleteList) { chrome.test.assertEq(EXPECTED_AUTOCOMPLETE_LIST, autocompleteList);
chrome.test.assertEq(EXPECTED_AUTOCOMPLETE_LIST, autocompleteList); checkIfNoErrorsOccured(chrome.test.succeed);
}); };
setupAndWaitUntilReady('/drive/root', function(appId, list) { setupAndWaitUntilReady('/drive/root', function(appId, list) {
callRemoteTestUtil('performAutocompleteAndWait', callRemoteTestUtil('performAutocompleteAndWait',
......
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