Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / file_manager_browsertest / file_manager / grid_view.js
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 'use strict';
6
7 /**
8  * Shows the grid view and checks the label texts of entries.
9  *
10  * @param {string} rootPath Root path to be used as a default current directory
11  *     during initialization. Can be null, for no default path.
12  * @param {Array.<TestEntryInfo>} expectedSet Set of entries that are expected
13  *     to appear in the grid view.
14  * @return {Promise} Promise to be fulfilled or rejected depending on the test
15  *     result.
16  */
17 function showGridView(rootPath, expectedSet) {
18   var expectedLabels = expectedSet.map(function(entryInfo) {
19     return entryInfo.nameText;
20   }).sort();
21   var setupPromise = setupAndWaitUntilReady(null, rootPath);
22   return setupPromise.then(function(windowId) {
23     // Click the grid view button.
24     var clickedPromise = remoteCall.waitForElement(windowId, '#view-button').
25         then(function() {
26           return remoteCall.callRemoteTestUtil(
27               'fakeEvent', windowId, ['#view-button', 'click']);
28         });
29
30     // Compare the grid labels of the entries.
31     return clickedPromise.then(function() {
32       return repeatUntil(function() {
33         var labelsPromise = remoteCall.callRemoteTestUtil(
34             'queryAllElements',
35             windowId,
36             ['grid:not([hidden]) .thumbnail-item .entry-name']);
37         return labelsPromise.then(function(labels) {
38           var actualLabels = labels.map(function(label) {
39             return label.text;
40           }).sort();
41           if (chrome.test.checkDeepEq(expectedLabels, actualLabels))
42             return true;
43           return pending(
44               'Failed to compare the grid lables, expected: %j, actual %j.',
45               expectedLabels,
46               actualLabels);
47         });
48       });
49     });
50   });
51 }
52
53 /**
54  * Tests to show grid view on a local directory.
55  */
56 testcase.showGridViewDownloads = function() {
57   testPromise(showGridView(
58       RootPath.DOWNLOADS, BASIC_LOCAL_ENTRY_SET));
59 };
60
61 /**
62  * Tests to show grid view on a drive directory.
63  */
64 testcase.showGridViewDrive = function() {
65   testPromise(showGridView(
66       RootPath.DRIVE, BASIC_DRIVE_ENTRY_SET));
67 };