Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / file_manager_browsertest / file_manager / drive_specific.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 opening the "Recent" on the sidebar navigation by clicking the icon,
9  * and verifies the directory contents. We test if there are only files, since
10  * directories are not allowed in "Recent". This test is only available for
11  * Drive.
12  */
13 testcase.openSidebarRecent = function() {
14   var appId;
15   StepsRunner.run([
16     function() {
17       setupAndWaitUntilReady(null, RootPath.DRIVE, this.next);
18     },
19     // Click the icon of the Recent volume.
20     function(inAppId) {
21       appId = inAppId;
22       remoteCall.callRemoteTestUtil(
23         'selectVolume', appId, ['drive_recent'], this.next);
24     },
25     // Wait until the file list is updated.
26     function(result) {
27       chrome.test.assertFalse(!result);
28       remoteCall.waitForFileListChange(appId, BASIC_DRIVE_ENTRY_SET.length).
29           then(this.next);
30     },
31     // Verify the file list.
32     function(actualFilesAfter) {
33       chrome.test.assertEq(
34           TestEntryInfo.getExpectedRows(RECENT_ENTRY_SET).sort(),
35           actualFilesAfter);
36       checkIfNoErrorsOccured(this.next);
37     }
38   ]);
39 };
40
41 /**
42  * Tests opening the "Offline" on the sidebar navigation by clicking the icon,
43  * and checks contenets of the file list. Only the entries "available offline"
44  * should be shown. "Available offline" entires are hosted documents and the
45  * entries cached by DriveCache.
46  */
47 testcase.openSidebarOffline = function() {
48   var appId;
49   StepsRunner.run([
50     function() {
51       setupAndWaitUntilReady(null, RootPath.DRIVE, this.next);
52     },
53     // Click the icon of the Offline volume.
54     function(inAppId) {
55       appId = inAppId;
56       remoteCall.callRemoteTestUtil(
57         'selectVolume', appId, ['drive_offline'], this.next);
58     },
59     // Wait until the file list is updated.
60     function(result) {
61       chrome.test.assertFalse(!result);
62       remoteCall.waitForFileListChange(appId, BASIC_DRIVE_ENTRY_SET.length).
63           then(this.next);
64     },
65     // Verify the file list.
66     function(actualFilesAfter) {
67       chrome.test.assertEq(
68           TestEntryInfo.getExpectedRows(OFFLINE_ENTRY_SET).sort(),
69           actualFilesAfter);
70       checkIfNoErrorsOccured(this.next);
71     }
72   ]);
73 };
74
75 /**
76  * Tests opening the "Shared with me" on the sidebar navigation by clicking the
77  * icon, and checks contents of the file list. Only the entries labeled with
78  * "shared-with-me" should be shown.
79  */
80 testcase.openSidebarSharedWithMe = function() {
81   var appId;
82   StepsRunner.run([
83     function() {
84       setupAndWaitUntilReady(null, RootPath.DRIVE, this.next);
85     },
86     // Click the icon of the Shared With Me volume.
87     function(inAppId) {
88       appId = inAppId;
89       // Use the icon for a click target.
90       remoteCall.callRemoteTestUtil('selectVolume',
91                                     appId,
92                                     ['drive_shared_with_me'], this.next);
93     },
94     // Wait until the file list is updated.
95     function(result) {
96       chrome.test.assertFalse(!result);
97       remoteCall.waitForFileListChange(appId, BASIC_DRIVE_ENTRY_SET.length).
98           then(this.next);
99     },
100     // Verify the file list.
101     function(actualFilesAfter) {
102       chrome.test.assertEq(
103           TestEntryInfo.getExpectedRows(SHARED_WITH_ME_ENTRY_SET).sort(),
104           actualFilesAfter);
105       checkIfNoErrorsOccured(this.next);
106     }
107   ]);
108 };
109
110 /**
111  * Tests autocomplete with a query 'hello'. This test is only available for
112  * Drive.
113  */
114 testcase.autocomplete = function() {
115   var EXPECTED_AUTOCOMPLETE_LIST = [
116     '\'hello\' - search Drive',
117     'hello.txt',
118   ];
119   var appId;
120
121   StepsRunner.run([
122     function() {
123       setupAndWaitUntilReady(null, RootPath.DRIVE, this.next);
124     },
125     // Focus the search box.
126     function(inAppId, list) {
127       appId = inAppId;
128       remoteCall.callRemoteTestUtil('fakeEvent',
129                                     appId,
130                                     ['#search-box input', 'focus'],
131                                     this.next);
132     },
133     // Input a text.
134     function(result) {
135       chrome.test.assertTrue(result);
136       remoteCall.callRemoteTestUtil('inputText',
137                                     appId,
138                                     ['#search-box input', 'hello'],
139                                     this.next);
140     },
141     // Notify the element of the input.
142     function() {
143       remoteCall.callRemoteTestUtil('fakeEvent',
144                                     appId,
145                                     ['#search-box input', 'input'],
146                                     this.next);
147     },
148     // Wait for the auto complete list getting the expected contents.
149     function(result) {
150       chrome.test.assertTrue(result);
151       repeatUntil(function() {
152         return remoteCall.callRemoteTestUtil('queryAllElements',
153                                              appId,
154                                              ['#autocomplete-list li']).
155             then(function(elements) {
156               var list = elements.map(
157                   function(element) { return element.text; });
158               return chrome.test.checkDeepEq(EXPECTED_AUTOCOMPLETE_LIST, list) ?
159                   undefined :
160                   pending('Current auto complete list: %j.', list);
161             });
162       }).
163       then(this.next);
164     },
165     function() {
166       checkIfNoErrorsOccured(this.next);
167     }
168   ]);
169 };
170
171 /**
172  * Tests pinning a file on mobile network.
173  */
174 testcase.pinFileOnMobileNetwork = function() {
175   testPromise(setupAndWaitUntilReady(null, RootPath.DRIVE).then(
176       function(windowId) {
177         return sendTestMessage(
178             {name: 'useCellularNetwork'}).then(function(result) {
179           return remoteCall.callRemoteTestUtil(
180               'selectFile', windowId, ['hello.txt']);
181         }).then(function() {
182           return repeatUntil(function() {
183             return navigator.connection.type != 'cellular' ?
184                 pending('Network state is not changed to cellular.') : null;
185           });
186         }).then(function() {
187           return remoteCall.waitForElement(windowId, ['.table-row[selected]']);
188         }).then(function() {
189           return remoteCall.callRemoteTestUtil(
190               'fakeMouseRightClick', windowId, ['.table-row[selected]']);
191         }).then(function(result) {
192           chrome.test.assertTrue(result);
193           return remoteCall.waitForElement(
194               windowId, '#file-context-menu:not([hidden])');
195         }).then(function() {
196           return remoteCall.callRemoteTestUtil(
197               'fakeMouseClick', windowId, ['[command="#toggle-pinned"]']);
198         }).then(function(result) {
199           return remoteCall.waitForElement(
200               windowId, '#file-context-menu[hidden]');
201         }).then(function() {
202           return remoteCall.callRemoteTestUtil(
203               'fakeEvent', windowId, ['#file-list', 'contextmenu']);
204         }).then(function(result) {
205           chrome.test.assertTrue(result);
206           return remoteCall.waitForElement(
207               windowId, '[command="#toggle-pinned"][checked]');
208         }).then(function() {
209           return repeatUntil(function() {
210             return remoteCall.callRemoteTestUtil(
211                 'getNotificationIDs', null, []).then(function(idSet) {
212               return !idSet['disabled-mobile-sync'] ?
213                   pending('Sync disable notification is not found.') : null;
214             });
215           });
216         }).then(function() {
217           return sendTestMessage({
218             name: 'clickNotificationButton',
219             extensionId: FILE_MANAGER_EXTENSIONS_ID,
220             notificationId: 'disabled-mobile-sync',
221             index: 0
222           });
223         }).then(function() {
224           return repeatUntil(function() {
225             return remoteCall.callRemoteTestUtil(
226                 'getPreferences', null, []).then(function(preferences) {
227               return preferences.cellularDisabled ?
228                   pending('Drive sync is still disabled.') : null;
229             });
230           });
231         });
232       }));
233 };