diff options
author | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-27 08:13:33 +0000 |
---|---|---|
committer | yoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-11-27 08:13:33 +0000 |
commit | 01f83530e6064ec0972055ad8d5a6aecb3945061 (patch) | |
tree | f82d76686cb191ea1843aec50256dc37a146c6f6 | |
parent | 413508215e6422c2d756e3fd063975cb84466330 (diff) | |
download | chromium_src-01f83530e6064ec0972055ad8d5a6aecb3945061.zip chromium_src-01f83530e6064ec0972055ad8d5a6aecb3945061.tar.gz chromium_src-01f83530e6064ec0972055ad8d5a6aecb3945061.tar.bz2 |
[Files.app] Add a test of default task execution.
This patch adds a test of executing the default task by double click on the file.
BUG=none
TEST=manually tested
Review URL: https://codereview.chromium.org/90563002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@237538 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 119 insertions, 2 deletions
diff --git a/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc b/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc index 3f7e292..2722de8 100644 --- a/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc +++ b/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc @@ -715,6 +715,12 @@ INSTANTIATE_TEST_CASE_P( ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "suggestAppDialog"))); INSTANTIATE_TEST_CASE_P( + FileTask, + FileManagerBrowserTest, + ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, "executeDefaultTask"), + TestParameter(IN_GUEST_MODE, "executeDefaultTask"))); + +INSTANTIATE_TEST_CASE_P( NavigationList, FileManagerBrowserTest, ::testing::Values(TestParameter(NOT_IN_GUEST_MODE, diff --git a/chrome/browser/resources/file_manager/background/js/test_util.js b/chrome/browser/resources/file_manager/background/js/test_util.js index e43569e..2960920 100644 --- a/chrome/browser/resources/file_manager/background/js/test_util.js +++ b/chrome/browser/resources/file_manager/background/js/test_util.js @@ -688,7 +688,7 @@ test.util.sync.deleteFile = function(contentWindow, filename) { * * @param {Window} contentWindow Window to be tested. * @param {Array.<object>} queries Queries that specifies the elements and - * expected styles. + * expected styles. * @param {function()} callback Callback function to be notified the change of * the styles. */ @@ -719,6 +719,56 @@ test.util.sync.execCommand = function(contentWindow, command) { }; /** + * Override the task-related methods in private api for test. + * + * @param {Window} contentWindow Window to be tested. + * @param {Array.<Object>} taskList List of tasks to be returned in + * fileBrowserPrivate.getFileTasks(). + * @return {boolean} Always return true. + */ +test.util.sync.overrideTasks = function(contentWindow, taskList) { + var getFileTasks = function(urls, mime, onTasks) { + // Call onTask asynchronously (same with original getFileTasks). + setTimeout(function() { + onTasks(taskList); + }); + }; + + var executeTask = function(taskId, url) { + test.util.executedTasks_.push(taskId); + }; + + test.util.executedTasks_ = []; + contentWindow.chrome.fileBrowserPrivate.getFileTasks = getFileTasks; + contentWindow.chrome.fileBrowserPrivate.executeTask = executeTask; + return true; +}; + +/** + * Check if Files.app has ordered to execute the given task or not yet. This + * method must be used with test.util.sync.overrideTasks(). + * + * @param {Window} contentWindow Window to be tested. + * @param {string} taskId Taskid of the task which should be executed. + * @param {function()} callback Callback function to be notified the order of + * the execution. + */ +test.util.async.waitUntilTaskExecutes = + function(contentWindow, taskId, callback) { + if (!test.util.executedTasks_) { + console.error('Please call overrideTasks() first.'); + return; + } + + test.util.repeatUntilTrue_(function() { + if (test.util.executedTasks_.indexOf(taskId) === -1) + return false; + callback(); + return true; + }); +}; + +/** * Registers message listener, which runs test utility functions. */ test.util.registerRemoteTestUtils = function() { diff --git a/chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js b/chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js index 729afee..1d97eba 100644 --- a/chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js +++ b/chrome/test/data/extensions/api_test/file_manager_browsertest/test_cases.js @@ -1174,6 +1174,68 @@ testcase.shareDirectory = function() { }; /** + * Tests executing the default task when there is only one task. + */ +testcase.executeDefaultTask = function() { + var appId; + StepsRunner.run([ + // Set up File Manager. + function() { + var appState = { + defaultPath: '/drive/root' + }; + setupAndWaitUntilReady(appState, this.next); + }, + // Override tasks list with a dummy task. + function(inAppId, inFileListBefore) { + appId = inAppId; + + callRemoteTestUtil( + 'overrideTasks', + appId, + [[ + { + driveApp: false, + iconUrl: 'chrome://theme/IDR_DEFAULT_FAVICON', // Dummy icon + isDefault: true, + taskId: 'dummytaskid|drive|open-with', + title: 'The dummy task for test' + } + ]], + this.next); + }, + // Select file. + function(result) { + chrome.test.assertTrue(result); + callRemoteTestUtil( + 'selectFile', appId, ['hello.txt'], this.next); + }, + // Double-click the file. + function(result) { + chrome.test.assertTrue(result); + callRemoteTestUtil( + 'fakeMouseDoubleClick', + appId, + ['#file-list li.table-row[selected] .filename-label span'], + this.next); + }, + // Wait until the task is executed. + function(result) { + chrome.test.assertTrue(!!result); + callRemoteTestUtil( + 'waitUntilTaskExecutes', + appId, + ['dummytaskid|drive|open-with'], + this.next); + }, + // Check the error. + function() { + checkIfNoErrorsOccured(this.next); + } + ]); +}; + +/** * Tests sharing a file on Drive */ testcase.suggestAppDialog = function() { @@ -1685,4 +1747,3 @@ testcase.thumbnailsDownloads = function() { } ]); }; - |