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

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

Issue 755363004: Make the sort order in thumbnail view always alphabetical. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add browser_test for sorting order in grid view. Created 6 years 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/file_manager/grid_view.js
diff --git a/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/grid_view.js b/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/grid_view.js
index 1b60e14118b8fc2ffcb6be7dd34ba3387b06085c..228e64fb0bc9cde18604ccdc09d1c0207fbc8f1f 100644
--- a/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/grid_view.js
+++ b/chrome/test/data/extensions/api_test/file_manager_browsertest/file_manager/grid_view.js
@@ -5,6 +5,52 @@
'use strict';
/**
+ * Clicks the toggle-view button.
+ * @param {string} windowId
+ * @return {!Promise}
+ */
+function clickToggleViewButton(windowId) {
+ return remoteCall.waitForElement(windowId, '#view-button').then(function() {
+ return remoteCall.callRemoteTestUtil(
+ 'fakeEvent', windowId, ['#view-button', 'click']);
+ });
+}
+
+/**
+ * Waits until the given entry set is loaded in the current file list.
+ * @param {string} windowId
+ * @param {Array.<TestEntryInfo>} expectedSet
+ * @param {boolean} orderCheck Whether this function waits fils appearing in the
+ * same order with expectedSet.
+ */
+function waitForGridViewFiles(windowId, expectedSet, orderCheck) {
+ var expectedLabels = expectedSet.map(function(entryInfo) {
+ return entryInfo.nameText;
+ });
+ return repeatUntil(function() {
+ var labelsPromise = remoteCall.callRemoteTestUtil(
+ 'queryAllElements',
+ windowId,
+ ['grid:not([hidden]) .thumbnail-item .entry-name']);
+ return labelsPromise.then(function(labels) {
+ var actualLabels = labels.map(function(label) {
+ return label.text;
+ });
+ if (!orderCheck) {
+ expectedLabels.sort();
+ actualLabels.sort();
+ }
+ if (chrome.test.checkDeepEq(expectedLabels, actualLabels))
+ return true;
+ return pending(
+ 'Failed to compare the grid lables, expected: %j, actual %j.',
+ expectedLabels,
+ actualLabels);
+ });
+ });
+}
+
+/**
* Shows the grid view and checks the label texts of entries.
*
* @param {string} rootPath Root path to be used as a default current directory
@@ -15,39 +61,81 @@
* result.
*/
function showGridView(rootPath, expectedSet) {
- var expectedLabels = expectedSet.map(function(entryInfo) {
- return entryInfo.nameText;
- }).sort();
+ var windowId;
var setupPromise = setupAndWaitUntilReady(null, rootPath);
- return setupPromise.then(function(windowId) {
- // Click the grid view button.
- var clickedPromise = remoteCall.waitForElement(windowId, '#view-button').
- then(function() {
- return remoteCall.callRemoteTestUtil(
- 'fakeEvent', windowId, ['#view-button', 'click']);
- });
-
+ return setupPromise.then(function(inWindowId) {
+ windowId = inWindowId;
+ return clickToggleViewButton(windowId);
+ }).then(function() {
// Compare the grid labels of the entries.
- return clickedPromise.then(function() {
- return repeatUntil(function() {
- var labelsPromise = remoteCall.callRemoteTestUtil(
- 'queryAllElements',
+ return waitForGridViewFiles(windowId, expectedSet, false);
+ });
+}
+
+/**
+ * Checks that files are sorted by name alphabetically in grid view, and the
+ * order in list view is kept on toggling the view.
+ *
+ * @return {Promise} Promise to be fulfilled or rejected depending on the test
+ * result.
+ */
+function checkFilesSortedInGridView() {
+ // Entries in RootPath.DOWNLOADS, sorted by their names.
+ var ENTRIES_SORTED_BY_NAME = [
+ ENTRIES.photos, // Folder: photos
+ ENTRIES.beautiful, // File: Beautiful Song.ogg (14 KB)
+ ENTRIES.hello, // File: hello.txt (51 B)
+ ENTRIES.desktop, // File: My Desktop Background.png (272 B)
+ ENTRIES.world // File: world.ogv (59 KB)
+ ];
+ // Entries in RootPath.DOWNLOADS, sorted by their sizes.
+ var ENTRIES_SORTED_BY_SIZE = [
+ ENTRIES.photos, // Folder: photos
+ ENTRIES.world, // File: world.ogv (59 KB)
+ ENTRIES.beautiful, // File: Beautiful Song.ogg (14 KB)
+ ENTRIES.desktop, // File: My Desktop Background.png (272 B)
+ ENTRIES.hello // File: hello.txt (51 B)
+ ];
+
+ var windowId;
+ return setupAndWaitUntilReady(null, RootPath.DOWNLOADS)
+ .then(function(inWindowId) {
+ windowId = inWindowId;
+ // Sort by size by clicking column header.
+ return remoteCall.callRemoteTestUtil(
+ 'fakeMouseClick', windowId, ['.table-header-cell:nth-of-type(2)']);
+ })
+ .then(function() {
+ // Wait until the descending icon appears.
+ return remoteCall.waitForElement(windowId,
+ '.table-header-sort-image-desc');
+ })
+ .then(function() {
+ // Check if the files are sorted by size.
+ return remoteCall.waitForFiles(
+ windowId,
+ TestEntryInfo.getExpectedRows(ENTRIES_SORTED_BY_SIZE),
+ {orderCheck: true});
+ })
+ .then(function() {
+ // Change the view to the grid view
+ return clickToggleViewButton(windowId);
+ })
+ .then(function() {
+ // Check if the files are sorted by name in grid view.
+ return waitForGridViewFiles(windowId, ENTRIES_SORTED_BY_NAME, true);
+ })
+ .then(function() {
+ // Change the view to the list view.
+ return clickToggleViewButton(windowId);
+ })
+ .then(function() {
+ // Check if the sort order is restored to 'by size' in list view.
+ return remoteCall.waitForFiles(
windowId,
- ['grid:not([hidden]) .thumbnail-item .entry-name']);
- return labelsPromise.then(function(labels) {
- var actualLabels = labels.map(function(label) {
- return label.text;
- }).sort();
- if (chrome.test.checkDeepEq(expectedLabels, actualLabels))
- return true;
- return pending(
- 'Failed to compare the grid lables, expected: %j, actual %j.',
- expectedLabels,
- actualLabels);
- });
+ TestEntryInfo.getExpectedRows(ENTRIES_SORTED_BY_SIZE),
+ {orderCheck: true});
});
- });
- });
}
/**
@@ -65,3 +153,10 @@ testcase.showGridViewDrive = function() {
testPromise(showGridView(
RootPath.DRIVE, BASIC_DRIVE_ENTRY_SET));
};
+
+/**
+ * Tests that files are always sorted by name alphabetically in grid view.
+ */
+testcase.checkFilesSorted = function() {
+ testPromise(checkFilesSortedInGridView());
+};

Powered by Google App Engine
This is Rietveld 408576698