summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/file_manager/file_manager_browsertest.cc20
-rw-r--r--chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/execute_default_task.js66
-rw-r--r--chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/tasks.js213
-rw-r--r--chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager_test_manifest.json2
-rw-r--r--ui/file_manager/file_manager/background/js/test_util.js25
5 files changed, 255 insertions, 71 deletions
diff --git a/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc b/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc
index f987875..07120a4 100644
--- a/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc
+++ b/chrome/browser/chromeos/file_manager/file_manager_browsertest.cc
@@ -953,6 +953,12 @@ WRAPPED_INSTANTIATE_TEST_CASE_P(
TestParameter(NOT_IN_GUEST_MODE, "executeDefaultTaskOnDownloads"),
TestParameter(IN_GUEST_MODE, "executeDefaultTaskOnDownloads")));
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
+#define MAYBE_ExecuteDefaultTaskOnDrive DISABLED_ExecuteDefaultTaskOnDrive
+#else
+#define MAYBE_ExecuteDefaultTaskOnDrive ExecuteDefaultTaskOnDrive
+#endif
INSTANTIATE_TEST_CASE_P(
ExecuteDefaultTaskOnDrive,
FileManagerBrowserTest,
@@ -961,6 +967,20 @@ INSTANTIATE_TEST_CASE_P(
// Slow tests are disabled on debug build. http://crbug.com/327719
#if !defined(NDEBUG)
+#define MAYBE_DefaultActionDialog DISABLED_DefaultActionDialog
+#else
+#define MAYBE_DefaultActionDialog DefaultActionDialog
+#endif
+WRAPPED_INSTANTIATE_TEST_CASE_P(
+ MAYBE_DefaultActionDialog,
+ FileManagerBrowserTest,
+ ::testing::Values(
+ TestParameter(NOT_IN_GUEST_MODE, "defaultActionDialogOnDownloads"),
+ TestParameter(IN_GUEST_MODE, "defaultActionDialogOnDownloads"),
+ TestParameter(NOT_IN_GUEST_MODE, "defaultActionDialogOnDrive")));
+
+// Slow tests are disabled on debug build. http://crbug.com/327719
+#if !defined(NDEBUG)
#define MAYBE_NavigationList DISABLED_NavigationList
#else
#define MAYBE_NavigationList NavigationList
diff --git a/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/execute_default_task.js b/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/execute_default_task.js
deleted file mode 100644
index 9ae400a..0000000
--- a/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/execute_default_task.js
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2014 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.
-
-'use strict';
-
-/**
- * Tests executing the default task when there is only one task.
- * @param {boolean} drive Whether to test Drive or Downloads.
- */
-function executeDefaultTask(drive) {
- var path = drive ? RootPath.DRIVE : RootPath.DOWNLOADS;
- var taskId = drive ? 'dummytaskid|drive|open-with' : 'dummytaskid|open-with';
- var appId;
- StepsRunner.run([
- // Set up File Manager.
- function() {
- setupAndWaitUntilReady(null, path, 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: taskId,
- 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);
- waitUntilTaskExecutes(appId, taskId).then(this.next);
- },
- // Check the error.
- function() {
- checkIfNoErrorsOccured(this.next);
- }
- ]);
-}
-
-testcase.executeDefaultTaskOnDrive = executeDefaultTask.bind(null, true);
-testcase.executeDefaultTaskOnDownloads = executeDefaultTask.bind(null, false);
diff --git a/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/tasks.js b/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/tasks.js
new file mode 100644
index 0000000..b91f93e
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/tasks.js
@@ -0,0 +1,213 @@
+// Copyright 2014 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.
+
+'use strict';
+
+/**
+ * Fake task.
+ *
+ * @param {boolean} isDefault Whether the task is default or not.
+ * @param {string} taskId Task ID.
+ * @param {string} title Title of the task.
+ * @constructor
+ */
+function FakeTask(isDefault, taskId, title) {
+ this.driveApp = false;
+ this.iconUrl = 'chrome://theme/IDR_DEFAULT_FAVICON'; // Dummy icon
+ this.isDefault = isDefault;
+ this.taskId = taskId;
+ this.title = title;
+ Object.freeze(this);
+}
+
+/**
+ * Fake tasks for a local volume.
+ *
+ * @type {Array.<FakeTask>}
+ * @const
+ */
+var DOWNLOADS_FAKE_TASKS = [
+ new FakeTask(true, 'dummytaskid|open-with', 'DummyAction1'),
+ new FakeTask(false, 'dummytaskid-2|open-with', 'DummyAction2')
+];
+
+/**
+ * Fake tasks for a drive volume.
+ *
+ * @type {Array.<FakeTask>}
+ * @const
+ */
+var DRIVE_FAKE_TASKS = [
+ new FakeTask(true, 'dummytaskid|drive|open-with', 'DummyAction1'),
+ new FakeTask(false, 'dummytaskid-2|drive|open-with', 'DummyAction2')
+];
+
+/**
+ * Sets up task tests.
+ *
+ * @param {string} rootPath Root path.
+ * @param {Array.<FakeTask>} fakeTasks Fake tasks.
+ */
+function setupTaskTest(rootPath, fakeTasks) {
+ return setupAndWaitUntilReady(null, rootPath).then(function(windowId) {
+ return callRemoteTestUtil(
+ 'overrideTasks',
+ windowId,
+ [fakeTasks]).then(function() {
+ return windowId;
+ });
+ });
+}
+
+/**
+ * Tests executing the default task when there is only one task.
+ *
+ * @param {string} expectedTaskId Task ID expected to execute.
+ * @param {string} windowId Window ID.
+ */
+function executeDefaultTask(expectedTaskId, windowId) {
+ // Select file.
+ var selectFilePromise =
+ callRemoteTestUtil('selectFile', windowId, ['hello.txt']);
+
+ // Double-click the file.
+ var doubleClickPromise = selectFilePromise.then(function(result) {
+ chrome.test.assertTrue(result);
+ return callRemoteTestUtil(
+ 'fakeMouseDoubleClick',
+ windowId,
+ ['#file-list li.table-row[selected] .filename-label span']);
+ });
+
+ // Wait until the task is executed.
+ return doubleClickPromise.then(function(result) {
+ chrome.test.assertTrue(!!result);
+ return waitUntilTaskExecutes(windowId, expectedTaskId);
+ });
+}
+
+/**
+ * Tests to specify default action via the default action dialog.
+ *
+ * @param {string} expectedTaskId Task ID to be expected to newly specify as
+ * default.
+ * @param {string} windowId Window ID.
+ * @return {Promise} Promise to be fulfilled/rejected depends on the test
+ * result.
+ */
+function defaultActionDialog(expectedTaskId, windowId) {
+ // Prepare expected labels.
+ var expectedLabels = [
+ 'DummyAction1 (default)',
+ 'DummyAction2'
+ ];
+
+ // Select file.
+ var selectFilePromise =
+ callRemoteTestUtil('selectFile', windowId, ['hello.txt']);
+
+ // Click the change default menu.
+ var menuClickedPromise = selectFilePromise.
+ then(function() {
+ return waitForElement(windowId, '#tasks[multiple]');
+ }).
+ then(function() {
+ return waitForElement(windowId, '#tasks-menu .change-default');
+ }).
+ then(function() {
+ return callRemoteTestUtil(
+ 'fakeEvent', windowId, ['#tasks', 'select', {item: {}}]);
+ }).
+ then(function(result) {
+ chrome.test.assertTrue(result);
+ });
+
+ // Wait for the list of menu item is added as expected.
+ var menuPreparedPromise = menuClickedPromise.then(function() {
+ return repeatUntil(function() {
+ // Obtains menu items.
+ var menuItemsPromise = callRemoteTestUtil(
+ 'queryAllElements',
+ windowId,
+ ['#default-action-dialog #default-actions-list li']);
+
+ // Compare the contents of items.
+ return menuItemsPromise.then(function(items) {
+ var actualLabels = items.map(function(item) { return item.text; });
+ if (chrome.test.checkDeepEq(expectedLabels, actualLabels)) {
+ return true;
+ } else {
+ return pending('Tasks do not match, expected: %j, actual: %j.',
+ expectedLabels,
+ actualLabels);
+ }
+ });
+ });
+ });
+
+ // Click the non default item.
+ var itemClickedPromise = menuPreparedPromise.
+ then(function() {
+ return callRemoteTestUtil(
+ 'fakeEvent',
+ windowId,
+ [
+ '#default-action-dialog #default-actions-list li:nth-of-type(2)',
+ 'mousedown',
+ {bubbles: true, button: 0}
+ ]);
+ }).
+ then(function() {
+ return callRemoteTestUtil(
+ 'fakeEvent',
+ windowId,
+ [
+ '#default-action-dialog #default-actions-list li:nth-of-type(2)',
+ 'click',
+ {bubbles: true}
+ ]);
+ }).
+ then(function(result) {
+ chrome.test.assertTrue(result);
+ });
+
+ // Wait for the dialog hidden, and the task is executed.
+ var dialogHiddenPromise = itemClickedPromise.then(function() {
+ return waitForElement.bind(null, windowId, '#default-action-dialog', null);
+ });
+
+ // Execute the new default task.
+ var taskButtonClicked = dialogHiddenPromise.
+ then(function() {
+ return callRemoteTestUtil('fakeEvent', windowId, ['#tasks', 'click']);
+ }).
+ then(function(result) {
+ chrome.test.assertTrue(result);
+ });
+
+ // Check the executed tasks.
+ return dialogHiddenPromise.then(function() {
+ return waitUntilTaskExecutes(windowId, expectedTaskId);
+ });
+}
+
+testcase.executeDefaultTaskOnDrive = function() {
+ testPromise(setupTaskTest(RootPath.DRIVE, DRIVE_FAKE_TASKS).then(
+ executeDefaultTask.bind(null, 'dummytaskid|drive|open-with')));
+};
+
+testcase.executeDefaultTaskOnDownloads = function() {
+ testPromise(setupTaskTest(RootPath.DOWNLOADS, DOWNLOADS_FAKE_TASKS).then(
+ executeDefaultTask.bind(null, 'dummytaskid|open-with')));
+};
+
+testcase.defaultActionDialogOnDrive = function() {
+ testPromise(setupTaskTest(RootPath.DRIVE, DRIVE_FAKE_TASKS).then(
+ defaultActionDialog.bind(null, 'dummytaskid-2|drive|open-with')));
+};
+
+testcase.defaultActionDialogOnDownloads = function() {
+ testPromise(setupTaskTest(RootPath.DOWNLOADS, DOWNLOADS_FAKE_TASKS).then(
+ defaultActionDialog.bind(null, 'dummytaskid-2|open-with')));
+};
diff --git a/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager_test_manifest.json b/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager_test_manifest.json
index e1cdf03..dc095ea 100644
--- a/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager_test_manifest.json
+++ b/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager_test_manifest.json
@@ -14,7 +14,6 @@
"file_manager/copy_between_windows.js",
"file_manager/create_new_folder.js",
"file_manager/drive_specific.js",
- "file_manager/execute_default_task.js",
"file_manager/file_display.js",
"file_manager/folder_shortcuts.js",
"file_manager/grid_view.js",
@@ -29,6 +28,7 @@
"file_manager/share_dialog.js",
"file_manager/suggest_app_dialog.js",
"file_manager/tab_index.js",
+ "file_manager/tasks.js",
"file_manager/thumbnails.js",
"file_manager/transfer.js",
"file_manager/traverse.js"
diff --git a/ui/file_manager/file_manager/background/js/test_util.js b/ui/file_manager/file_manager/background/js/test_util.js
index 62aec6e..9d5e7ed 100644
--- a/ui/file_manager/file_manager/background/js/test_util.js
+++ b/ui/file_manager/file_manager/background/js/test_util.js
@@ -352,12 +352,22 @@ test.util.sync.sendEvent = function(
*
* @param {Window} contentWindow Window to be tested.
* @param {string} targetQuery Query to specify the element.
- * @param {string} event Type of event.
+ * @param {string} eventType Type of event.
+ * @param {Object=} opt_additionalProperties Object contaning additional
+ * properties.
* @return {boolean} True if the event is sent to the target, false otherwise.
*/
-test.util.sync.fakeEvent = function(contentWindow, targetQuery, event) {
- return test.util.sync.sendEvent(
- contentWindow, targetQuery, new Event(event));
+test.util.sync.fakeEvent = function(contentWindow,
+ targetQuery,
+ eventType,
+ opt_additionalProperties) {
+ var event = new Event(eventType, opt_additionalProperties || {});
+ if (opt_additionalProperties) {
+ for (var name in opt_additionalProperties) {
+ event[name] = opt_additionalProperties[name];
+ }
+ }
+ return test.util.sync.sendEvent(contentWindow, targetQuery, event);
};
/**
@@ -591,9 +601,16 @@ test.util.sync.overrideTasks = function(contentWindow, taskList) {
test.util.executedTasks_.push(taskId);
};
+ var setDefaultTask = function(taskId) {
+ for (var i = 0; i < taskList.length; i++) {
+ taskList[i].isDefault = taskList[i].taskId === taskId;
+ }
+ };
+
test.util.executedTasks_ = [];
contentWindow.chrome.fileBrowserPrivate.getFileTasks = getFileTasks;
contentWindow.chrome.fileBrowserPrivate.executeTask = executeTask;
+ contentWindow.chrome.fileBrowserPrivate.setDefaultTask = setDefaultTask;
return true;
};