Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6941)

Unified Diff: chrome/test/data/extensions/api_test/file_manager_browsertest/folder_shortcuts.js

Issue 303503004: Change directory if the active list item on navigation list is changed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add browser tests for folder shortcuts. Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/test/data/extensions/api_test/file_manager_browsertest/folder_shortcuts.js
diff --git a/chrome/test/data/extensions/api_test/file_manager_browsertest/folder_shortcuts.js b/chrome/test/data/extensions/api_test/file_manager_browsertest/folder_shortcuts.js
new file mode 100644
index 0000000000000000000000000000000000000000..890cf95b337c92975fa8dd00b79d1faf83bd3d35
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/file_manager_browsertest/folder_shortcuts.js
@@ -0,0 +1,403 @@
+// Copyright (c) 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';
+
+/**
+ * Constants for selectors.
+ */
+var TREEITEM_DRIVE = '#directory-tree > div:nth-child(1) ';
+var TREEITEM_A = TREEITEM_DRIVE + '> .tree-children > div:nth-child(1) ';
+var TREEITEM_B = TREEITEM_A + '> .tree-children > div:nth-child(1) ';
+var TREEITEM_C = TREEITEM_B + '> .tree-children > div:nth-child(1) ';
+var TREEITEM_D = TREEITEM_DRIVE + '> .tree-children > div:nth-child(2) ';
+var TREEITEM_E = TREEITEM_D + '> .tree-children > div:nth-child(1) ';
+var EXPAND_ICON = '> .tree-row > .expand-icon';
+var VOLUME_ICON = '> .tree-row > .volume-icon';
+var EXPANDED_SUBTREE = '> .tree-children[expanded]';
+
+/**
+ * Entry set which is used for this test.
yoshiki 2014/05/29 04:24:44 Please add @type annotation.
fukino 2014/05/29 04:46:59 Done.
+ */
+var ENTRY_SET = [
+ ENTRIES.directoryA,
+ ENTRIES.directoryB,
+ ENTRIES.directoryC,
+ ENTRIES.directoryD,
+ ENTRIES.directoryE,
+ ENTRIES.directoryF
+];
+
+/**
+ * Constants for each folders.
yoshiki 2014/05/29 04:24:44 Please add @type annotation.
fukino 2014/05/29 04:46:59 Done.
+ */
+var DIR = {
yoshiki 2014/05/29 04:24:44 nit: DIRECTORIES
fukino 2014/05/29 04:46:59 Done.
+ Drive: {
+ contents: [ENTRIES.directoryA.getExpectedRow(),
+ ENTRIES.directoryD.getExpectedRow()],
+ navItem: '#navigation-list-1',
+ treeItem: TREEITEM_DRIVE
+ },
+ A: {
+ contents: [ENTRIES.directoryB.getExpectedRow()],
+ name: 'A',
+ navItem: '#navigation-list-5',
+ treeItem: TREEITEM_A
+ },
+ B: {
+ contents: [ENTRIES.directoryC.getExpectedRow()],
+ name: 'B',
+ treeItem: TREEITEM_B
+ },
+ C: {
+ contents: [],
+ name: 'C',
+ navItem: '#navigation-list-3',
+ treeItem: TREEITEM_C
+ },
+ D: {
+ contents: [ENTRIES.directoryE.getExpectedRow()],
+ name: 'D',
+ navItem: '#navigation-list-4',
+ treeItem: TREEITEM_D
+ },
+ E: {
+ contents: [ENTRIES.directoryF.getExpectedRow()],
+ name: 'E',
+ treeItem: TREEITEM_E
+ }
+};
+
+/**
+ * Open two file manager windows.
+ * @return {Promise} Promise fulfilled with an array containing twi window IDs.
yoshiki 2014/05/29 04:24:44 s/twi/two/
fukino 2014/05/29 04:46:59 Done.
+ */
+function openWindows() {
+ return Promise.all([
+ openNewWindow(null, RootPath.DRIVE),
+ openNewWindow(null, RootPath.DRIVE)
+ ]).then(function(windowIds) {
+ return Promise.all([
+ waitForElement(windowIds[0], '#detail-table'),
+ waitForElement(windowIds[1], '#detail-table')
+ ]).then(function() {
+ return windowIds;
+ });
+ });
+};
+
+/**
+ * Expand tree item on the directory tree by clicking expand icon.
+ * @param {string} windowId ID of target window.
+ * @param {Object} directory Directory whose tree item should be expanded.
+ * @return {Promise} Promise fulfilled on success.
+ */
+function expandTreeItem(windowId, directory) {
+ return callRemoteTestUtil(
+ 'fakeMouseClick',
+ windowId,
+ [directory.treeItem + EXPAND_ICON]).then(function(result) {
+ chrome.test.assertTrue(result);
+ return waitForElement(windowId, directory.treeItem + EXPANDED_SUBTREE);
+ });
+}
+
+/**
+ * Expand whole directory tree.
+ * @param {string} windowId ID of target window.
+ * @return {Promise} Promise fulfilled on success.
+ */
+function expandDirectoryTree(windowId) {
+ return expandTreeItem(windowId, DIR.Drive).then(function() {
+ return expandTreeItem(windowId, DIR.A);
+ }).then(function() {
+ return expandTreeItem(windowId, DIR.B);
+ }).then(function() {
+ return expandTreeItem(windowId, DIR.D);
+ });
+};
+
+/**
+ * Make |directory| the current directory.
+ * @param {string} windowId ID of target window.
+ * @param {Object} directory Directory which should be a current directory.
+ * @return {Promise} Promise fulfilled on success.
+ */
+function navigateToDirectory(windowId, directory) {
+ return callRemoteTestUtil(
+ 'fakeMouseClick',
+ windowId,
+ [directory.treeItem + VOLUME_ICON]).then(function(result) {
+ chrome.test.assertTrue(result);
+ return waitForFiles(windowId, directory.contents);
+ });
+}
+
+/**
+ * Create folder shortcut to |directory|.
+ * The current directory must be a parent of the |directory|.
+ * @param {string} windowId ID of target window.
+ * @param {Object} directory Directory of shortcut to be created.
+ * @return {Promise} Promise fulfilled on success.
+ */
+function createShortcut(windowId, directory) {
+ return callRemoteTestUtil(
+ 'selectFile', windowId, [directory.name]).then(function(result) {
+ chrome.test.assertTrue(result);
+ return callRemoteTestUtil(
+ 'fakeMouseRightClick', windowId, ['.table-row[selected]']);
+ }).then(function(result) {
+ chrome.test.assertTrue(result);
+ return waitForElement(windowId, '#file-context-menu:not([hidden])');
+ }).then(function() {
+ return callRemoteTestUtil(
+ 'fakeMouseClick', windowId, ['[command="#create-folder-shortcut"]']);
+ }).then(function(result) {
+ chrome.test.assertTrue(result);
+ return waitForElement(windowId, directory.navItem);
+ });
+}
+
+/**
+ * Remove folder shortcut to |directory|.
+ * The current directory must be a parent of the |directory|.
+ * @param {string} windowId ID of target window.
+ * @param {Object} directory Directory of shortcut ot be removed.
+ * @return {Promise} Promise fullfilled on success.
+ */
+function removeShortcut(windowId, directory) {
+ return callRemoteTestUtil(
+ 'fakeMouseRightClick',
+ windowId,
+ [directory.navItem]).then(function(result) {
+ chrome.test.assertTrue(result);
+ return waitForElement(windowId, '#roots-context-menu:not([hidden])');
+ }).then(function() {
+ return callRemoteTestUtil(
+ 'fakeMouseClick', windowId, ['[command="#remove-folder-shortcut"]']);
+ }).then(function(result) {
+ chrome.test.assertTrue(result);
+ return waitForElementLost(windowId, directory.navItem);
+ });
+}
+
+/**
+ * Wait until the current directory become |currentDir| and folder shortcut to
+ * |shortcutDir| is selected.
+ * @param {string} windowId ID of target window.
+ * @param {Object} currentDir Directory which should be a current directory.
+ * @param {Object} shortcutDir Directory whose shortcut should be selected.
+ * @param {Promise} Promise fullfilled on success.
yoshiki 2014/05/29 04:24:44 s/param/return/
fukino 2014/05/29 04:46:59 Done.
+ */
+function expectSelection(windowId, currentDir, shortcutDir) {
+ return waitForFiles(windowId, currentDir.contents).then(function() {
+ return waitForElement(windowId, shortcutDir.navItem + '[selected]');
+ });
+}
+
+/**
+ * Click folder shortcut to |directory|.
+ * @param {string} windowId ID of target window.
+ * @param {Object} directory Directory whose shortcut will be clicked.
+ * @param {Promise} Promise fullfilled with result of fakeMouseClick.
yoshiki 2014/05/29 04:24:44 s/param/return/
fukino 2014/05/29 04:46:59 Done.
+ */
+function clickShortcut(windowId, directory) {
+ return callRemoteTestUtil('fakeMouseClick', windowId, [directory.navItem]);
+}
+
+testcase.traverseFolderShortcuts = function() {
+ var windowId1;
+ var windowId2;
+ StepsRunner.run([
+ // Set up each window.
+ function() {
+ addEntries(['drive'], ENTRY_SET, this.next);
+ },
+ function(result) {
+ chrome.test.assertTrue(result);
+ openWindows().then(this.next);
+ },
+ function(windowIds) {
+ windowId1 = windowIds[0];
+ windowId2 = windowIds[1];
+ waitForFiles(windowId1, DIR.Drive.contents).then(this.next);
+ },
+ function() {
+ expandDirectoryTree(windowId1).then(this.next);
+ },
+ function() {
+ expandDirectoryTree(windowId2).then(this.next);
+ },
+
+ // Create sortcut to C
+ function() {
+ navigateToDirectory(windowId1, DIR.B).then(this.next);
+ },
+ function() {
+ createShortcut(windowId1, DIR.C).then(this.next);
+ },
+
+ // Create shortcut to D
+ function() {
+ navigateToDirectory(windowId1, DIR.Drive).then(this.next);
+ },
+ function() {
+ createShortcut(windowId1, DIR.D).then(this.next);
+ },
+
+ // Navigate to E.
+ // Current directory should be E.
+ // Shortcut to D should be selected.
+ function() {
+ navigateToDirectory(windowId1, DIR.E).then(this.next);
+ },
+ function() {
+ expectSelection(windowId1, DIR.E, DIR.D).then(this.next);
+ },
+
+ // Navigate to Drive root.
+ // Current directory should be Drive root.
+ // Shortcut to Drive root should be selected.
+ function() {
+ navigateToDirectory(windowId1, DIR.Drive).then(this.next);
+ },
+ function() {
+ expectSelection(windowId1, DIR.Drive, DIR.Drive).then(this.next);
+ },
+
+ // Navigate to E.
+ // Current directory should be E.
+ // Shortcut to E should be selected.
+ function() {
+ navigateToDirectory(windowId1, DIR.E).then(this.next);
+ },
+ function() {
+ expectSelection(windowId1, DIR.E, DIR.D).then(this.next);
+ },
+
+ // Create shortcut to A in another file manager window.
+ function() {
+ navigateToDirectory(windowId2, DIR.Drive).then(this.next);
+ },
+ function() {
+ createShortcut(windowId2, DIR.A).then(this.next);
+ },
+
+ // The index of shortcut to D is changed.
+ // Current directory should remain E.
+ // Shortcut to D should keep selected.
+ function() {
+ expectSelection(windowId1, DIR.E, DIR.D).then(this.next);
+ },
+
+ // Click shortcut to D which is ascendant of current directory.
+ // Current directory should be D.
+ // Shortcut to D should keep selected.
+ function() {
+ clickShortcut(windowId1, DIR.D).then(this.next);
+ },
+ function(result) {
+ chrome.test.assertTrue(result);
+ expectSelection(windowId1, DIR.D, DIR.D).then(this.next);
+ },
+
+ // Click shortcut to C which don't have ascendant-descentant relation with
+ // current directory.
+ // Current directory should be C.
+ // Shortcut to C should be selected.
+ function() {
+ clickShortcut(windowId1, DIR.C).then(this.next);
+ },
+ function(result) {
+ chrome.test.assertTrue(result);
+ expectSelection(windowId1, DIR.C, DIR.C).then(this.next);
+ },
+
+ // Navigate to B which is ascendant of C and descendant of A.
+ // Current directory should be B.
+ // Shortcut to A should be selected.
+ function() {
+ navigateToDirectory(windowId1, DIR.B).then(this.next);
+ },
+ function() {
+ expectSelection(windowId1, DIR.B, DIR.A).then(this.next);
+ },
+
+ // Navigate to A which is ascendant of B and C.
+ // Current directory should be A.
+ // Shortcut to A should be selected.
+ function() {
+ navigateToDirectory(windowId1, DIR.A).then(this.next);
+ },
+ function() {
+ expectSelection(windowId1, DIR.A, DIR.A).then(this.next);
+ },
+
+ // Remove shortcut to A in another window.
+ function() {
+ navigateToDirectory(windowId2, DIR.Drive).then(this.next);
+ },
+ function() {
+ removeShortcut(windowId2, DIR.A).then(this.next);
+ },
+
+ // Current directory should remain A.
+ // Shortcut to Drive root should be selected.
+ function() {
+ expectSelection(windowId1, DIR.A, DIR.Drive).then(this.next);
+ },
+
+ // Press Ctrl+1 to select 1st shortcut.
+ // Current directory should be Drive root.
+ // Shortcut to Drive root should be selected.
+ function() {
+ callRemoteTestUtil('fakeKeyDown', windowId1,
+ ['#file-list', 'U+0031', true], this.next);
+ },
+ function(result) {
+ chrome.test.assertTrue(result);
+ expectSelection(windowId1, DIR.Drive, DIR.Drive).then(this.next);
+ },
+
+ // Press Ctrl+4 to select 4th shortcut.
+ // Current directory should be D.
+ // Shortcut to C should be selected.
+ function() {
+ callRemoteTestUtil('fakeKeyDown', windowId1,
+ ['#file-list', 'U+0034', true], this.next);
+ },
+ function(result) {
+ chrome.test.assertTrue(result);
+ expectSelection(windowId1, DIR.D, DIR.D).then(this.next);
+ },
+
+ // Press UP to select 3rd shortcut.
+ // Current directory should be C.
+ // Shortcut to C should be selected.
+ function() {
+ callRemoteTestUtil('fakeKeyDown', windowId1,
+ ['#navigation-list', 'Up', false], this.next);
+ },
+ function(result) {
+ chrome.test.assertTrue(result);
+ expectSelection(windowId1, DIR.C, DIR.C).then(this.next);
+ },
+
+ // Press DOWN to select 4th shortcut.
+ // Current directory should be D.
+ // Shortcut to D should be selected.
+ function() {
+ callRemoteTestUtil('fakeKeyDown', windowId1,
+ ['#navigation-list', 'Down', false], this.next);
+ },
+ function(result) {
+ chrome.test.assertTrue(result);
+ expectSelection(windowId1, DIR.D, DIR.D).then(this.next);
+ },
+
+ function() {
+ checkIfNoErrorsOccured(this.next);
+ }
+ ]);
+};

Powered by Google App Engine
This is Rietveld 408576698