Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / file_manager_browsertest / file_manager / file_display.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  * Tests if the files initially added by the C++ side are displayed, and
9  * that a subsequently added file shows up.
10  *
11  * @param {string} path Directory path to be tested.
12  */
13 function fileDisplay(path) {
14   var appId;
15
16   var expectedFilesBefore =
17       TestEntryInfo.getExpectedRows(path == RootPath.DRIVE ?
18           BASIC_DRIVE_ENTRY_SET : BASIC_LOCAL_ENTRY_SET).sort();
19
20   var expectedFilesAfter =
21       expectedFilesBefore.concat([ENTRIES.newlyAdded.getExpectedRow()]).sort();
22
23   StepsRunner.run([
24     function() {
25       setupAndWaitUntilReady(null, path, this.next);
26     },
27     // Notify that the list has been verified and a new file can be added
28     // in file_manager_browsertest.cc.
29     function(inAppId, actualFilesBefore) {
30       appId = inAppId;
31       chrome.test.assertEq(expectedFilesBefore, actualFilesBefore);
32       addEntries(['local', 'drive'], [ENTRIES.newlyAdded], this.next);
33     },
34     function(result) {
35       chrome.test.assertTrue(result);
36       remoteCall.waitForFileListChange(appId, expectedFilesBefore.length).
37           then(this.next);
38     },
39     // Confirm the file list.
40     function(actualFilesAfter) {
41       chrome.test.assertEq(expectedFilesAfter, actualFilesAfter);
42       checkIfNoErrorsOccured(this.next);
43     },
44   ]);
45 }
46
47 testcase.fileDisplayDownloads = function() {
48   fileDisplay(RootPath.DOWNLOADS);
49 };
50
51 testcase.fileDisplayDrive = function() {
52   fileDisplay(RootPath.DRIVE);
53 };
54
55 testcase.fileDisplayMtp = function() {
56   var appId;
57   var MTP_VOLUME_QUERY = '#directory-tree > .tree-item > .tree-row > ' +
58     '.volume-icon[volume-type-icon="mtp"]';
59
60   StepsRunner.run([
61     function() {
62       setupAndWaitUntilReady(null, RootPath.DOWNLOADS, this.next);
63     },
64     // Mount a fake MTP volume.
65     function(inAppId, files) {
66       appId = inAppId;
67       chrome.test.sendMessage(JSON.stringify({name: 'mountFakeMtp'}),
68                               this.next);
69     },
70     // Wait for the mount.
71     function(result) {
72       remoteCall.waitForElement(appId, MTP_VOLUME_QUERY).then(this.next);
73     },
74     // Click the MTP volume.
75     function() {
76       remoteCall.callRemoteTestUtil(
77           'fakeMouseClick', appId, [MTP_VOLUME_QUERY], this.next);
78     },
79     // Wait for the file list to change.
80     function(appIds) {
81       remoteCall.waitForFiles(
82           appId,
83           TestEntryInfo.getExpectedRows(BASIC_FAKE_ENTRY_SET),
84           {ignoreLastModifiedTime: true}).then(this.next);
85     },
86     function() {
87       checkIfNoErrorsOccured(this.next);
88     }
89   ]);
90 };