-
Notifications
You must be signed in to change notification settings - Fork 6.6k
/
drive_specific.js
1209 lines (995 loc) · 42 KB
/
drive_specific.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import {ENTRIES, EntryType, getCaller, pending, repeatUntil, RootPath, sendTestMessage, TestEntryInfo} from '../test_util.js';
import {testcase} from '../testcase.js';
import {navigateWithDirectoryTree, remoteCall, setupAndWaitUntilReady, waitForMediaApp} from './background.js';
import {BASIC_DRIVE_ENTRY_SET, FILE_MANAGER_EXTENSIONS_ID, OFFLINE_ENTRY_SET, SHARED_WITH_ME_ENTRY_SET} from './test_data.js';
/**
* Expected autocomplete results for 'hello'.
* @type {Array<string>}
* @const
*/
const EXPECTED_AUTOCOMPLETE_LIST = [
'\'hello\' - search Drive',
'hello.txt',
];
/**
* Expected files shown in the search results for 'hello'
*
* @type {!Array<!TestEntryInfo>}
* @const
*/
const SEARCH_RESULTS_ENTRY_SET = [
ENTRIES.hello,
];
/**
* Expected text shown in the Enable Docs Offline dialog.
*
* @type {string}
* @const
*/
const ENABLE_DOCS_OFFLINE_MESSAGE =
'Enable Google Docs Offline to make Docs, Sheets and Slides ' +
'available offline.';
/** The query selector for the search box input field. */
const searchBox = '#search-box cr-input';
/**
* Returns the steps to start a search for 'hello' and wait for the
* autocomplete results to appear.
*/
async function startDriveSearchWithAutoComplete() {
// Open Files app on Drive.
const appId = await setupAndWaitUntilReady(RootPath.DRIVE);
// Focus the search box.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'focus']));
// Input a text.
await remoteCall.inputText(appId, '#search-box cr-input', 'hello');
// Notify the element of the input.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'input']));
// Wait for the auto complete list getting the expected contents.
const caller = getCaller();
await repeatUntil(async () => {
const elements = await remoteCall.callRemoteTestUtil(
'queryAllElements', appId, ['#autocomplete-list li']);
const list = elements.map((element) => element.text);
return chrome.test.checkDeepEq(EXPECTED_AUTOCOMPLETE_LIST, list) ?
undefined :
pending(caller, 'Current auto complete list: %j.', list);
});
return appId;
}
/**
* Opens the Enable Docs Offline dialog and waits for it to appear in the given
* |appId| window.
*
* @param {string} appId
*/
async function openAndWaitForEnableDocsOfflineDialog(appId) {
// Simulate Drive signalling Files App to open a dialog.
await sendTestMessage({name: 'displayEnableDocsOfflineDialog'});
// Check: the Enable Docs Offline dialog should appear.
const dialogText = await remoteCall.waitForElement(
appId, '.cr-dialog-container.shown .cr-dialog-text');
chrome.test.assertEq(ENABLE_DOCS_OFFLINE_MESSAGE, dialogText.text);
}
/**
* Waits for getLastDriveDialogResult to return the given |expectedResult|.
*
* @param {string} expectedResult
*/
async function waitForLastDriveDialogResult(expectedResult) {
const caller = getCaller();
await repeatUntil(async () => {
const result = await sendTestMessage({name: 'getLastDriveDialogResult'});
if (result !== expectedResult) {
return pending(
caller,
'Waiting for getLastDriveDialogResult: expected %s, actual %s',
expectedResult, result);
}
});
}
/**
* Waits for a given notification to appear.
*
* @param {string} notification_id ID of notification to wait for.
*/
async function waitForNotification(notification_id) {
const caller = getCaller();
await repeatUntil(async () => {
const idSet =
await remoteCall.callRemoteTestUtil('getNotificationIDs', null, []);
return !idSet[notification_id] ?
pending(
caller, 'Waiting for notification "%s" to appear.',
notification_id) :
null;
});
}
/**
* Tests opening the "Offline" on the sidebar navigation by clicking the icon,
* and checks contents of the file list. Only the entries "available offline"
* should be shown. "Available offline" entries are hosted documents and the
* entries cached by DriveCache.
*/
testcase.driveOpenSidebarOffline = async () => {
// Open Files app on Drive.
const appId = await setupAndWaitUntilReady(RootPath.DRIVE);
// Click the icon of the Offline volume.
chrome.test.assertFalse(!await remoteCall.callRemoteTestUtil(
'selectVolume', appId, ['drive_offline']));
// Check: the file list should display the offline file set.
await remoteCall.waitForFiles(
appId, TestEntryInfo.getExpectedRows(OFFLINE_ENTRY_SET));
};
/**
* Tests opening the "Shared with me" on the sidebar navigation by clicking the
* icon, and checks contents of the file list. Only the entries labeled with
* "shared-with-me" should be shown.
*/
testcase.driveOpenSidebarSharedWithMe = async () => {
// Open Files app on Drive containing "Shared with me" file entries.
const appId = await setupAndWaitUntilReady(
RootPath.DRIVE, [], BASIC_DRIVE_ENTRY_SET.concat([
ENTRIES.sharedWithMeDirectory,
ENTRIES.sharedWithMeDirectoryFile,
]));
// Click the icon of the Shared With Me volume.
// Use the icon for a click target.
chrome.test.assertFalse(!await remoteCall.callRemoteTestUtil(
'selectVolume', appId, ['drive_shared_with_me']));
// Wait until the breadcrumb path is updated.
await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/Shared with me');
// Verify the file list.
await remoteCall.waitForFiles(
appId,
TestEntryInfo.getExpectedRows(
SHARED_WITH_ME_ENTRY_SET.concat([ENTRIES.sharedWithMeDirectory])));
// Navigate to the directory within Shared with me.
chrome.test.assertFalse(!await remoteCall.callRemoteTestUtil(
'openFile', appId, ['Shared Directory']));
// Wait until the breadcrumb path is updated.
await remoteCall.waitUntilCurrentDirectoryIsChanged(
appId, '/Shared with me/Shared Directory');
// Verify the file list.
await remoteCall.waitForFiles(
appId,
TestEntryInfo.getExpectedRows([ENTRIES.sharedWithMeDirectoryFile]));
};
/**
* Tests autocomplete with a query 'hello'.
*/
testcase.driveAutoCompleteQuery = async () => {
return startDriveSearchWithAutoComplete();
};
/**
* Tests that clicking the first option in the autocomplete box shows all of
* the results for that query.
*/
testcase.driveClickFirstSearchResult = async () => {
const appId = await startDriveSearchWithAutoComplete();
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'fakeKeyDown', appId,
['#autocomplete-list', 'ArrowDown', false, false, false]));
await remoteCall.waitForElement(appId, ['#autocomplete-list li[selected]']);
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'fakeMouseDown', appId, ['#autocomplete-list li[selected]']));
await remoteCall.waitForFiles(
appId, TestEntryInfo.getExpectedRows(SEARCH_RESULTS_ENTRY_SET));
// Fetch A11y messages.
const a11yMessages =
await remoteCall.callRemoteTestUtil('getA11yAnnounces', appId, []);
chrome.test.assertEq(1, a11yMessages.length, 'Missing a11y message');
chrome.test.assertEq('Showing results for hello.', a11yMessages[0]);
};
/**
* Tests that pressing enter after typing a search shows all of
* the results for that query.
*/
testcase.drivePressEnterToSearch = async () => {
const appId = await startDriveSearchWithAutoComplete();
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#search-box cr-input', 'focus']));
chrome.test.assertTrue(!!await remoteCall.callRemoteTestUtil(
'fakeKeyDown', appId,
['#search-box cr-input', 'Enter', false, false, false]));
await remoteCall.waitForFiles(
appId, TestEntryInfo.getExpectedRows(SEARCH_RESULTS_ENTRY_SET));
// Fetch A11y messages.
const a11yMessages =
await remoteCall.callRemoteTestUtil('getA11yAnnounces', appId, []);
chrome.test.assertEq(1, a11yMessages.length, 'Missing a11y message');
chrome.test.assertEq('Showing results for hello.', a11yMessages[0]);
return appId;
};
/**
* Tests that the breadcrumbs always shows "My Drive" when searching inside any
* folder in Drive.
*/
testcase.driveSearchAlwaysDisplaysMyDrive = async () => {
// Open Files app on Drive.
const appId =
await setupAndWaitUntilReady(RootPath.DRIVE, [], BASIC_DRIVE_ENTRY_SET);
// Start the search from a sub-folder.
await navigateWithDirectoryTree(appId, '/My Drive/photos');
// Search the text.
remoteCall.typeSearchText(appId, 'hello');
// Wait for the auto complete list to appear;
await remoteCall.waitForSearchAutoComplete(appId);
// Send Enter to perform the search.
const enterKey = ['Enter', false, false, false];
await remoteCall.fakeKeyDown(appId, searchBox, ...enterKey);
// Wait for the result in the file list.
await remoteCall.waitForFiles(
appId, TestEntryInfo.getExpectedRows(SEARCH_RESULTS_ENTRY_SET));
// When displaying the search result the breadcrumbs should always display "My
// drive".
await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/My Drive');
return appId;
};
/**
* Tests that pressing the clear search button announces an a11y message and
* shows all files/folders.
*/
testcase.drivePressClearSearch = async () => {
const appId = await testcase.driveSearchAlwaysDisplaysMyDrive();
// Click on the clear search button.
await remoteCall.waitAndClickElement(appId, '#search-box cr-input .clear');
// Wait for fil list to display all files.
await remoteCall.waitForFiles(appId, []);
// Check that a11y message for clearing the search term has been issued.
const a11yMessages =
await remoteCall.callRemoteTestUtil('getA11yAnnounces', appId, []);
chrome.test.assertEq(2, a11yMessages.length, 'Missing a11y message');
chrome.test.assertEq(
'Search text cleared, showing all files and folders.', a11yMessages[1]);
// The breadcrumbs should return back to the previous original folder.
await remoteCall.waitUntilCurrentDirectoryIsChanged(
appId, '/My Drive/photos');
};
/**
* Tests that pinning multiple files affects the pin action of individual
* files.
*/
testcase.drivePinMultiple = async () => {
const appId = await setupAndWaitUntilReady(RootPath.DRIVE);
// Select world.ogv.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="world.ogv"]');
await remoteCall.waitForElement(appId, '[file-name="world.ogv"][selected]');
// Open the context menu once the file is selected.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
// Check that the pin action is unticked, i.e. the action will pin the file.
await remoteCall.waitForElement(
appId,
'#file-context-menu:not([hidden]) ' +
'[command="#toggle-pinned"]:not([checked])');
// Additionally select hello.txt.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="hello.txt"]', {shift: true});
await remoteCall.waitForElement(appId, '[file-name="hello.txt"][selected]');
// Open the context menu with both files selected.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
// Pin both files.
await remoteCall.waitAndClickElement(
appId,
'#file-context-menu:not([hidden]) ' +
'[command="#toggle-pinned"]:not([checked])');
// Wait for the toggle pinned async action to finish, so the next call to
// display context menu is after the action has finished.
await remoteCall.waitForElement(appId, '#file-context-menu[hidden]');
// Wait for the pinned action to finish, it's flagged in the file list by
// removing CSS class "dim-offline" and adding class "pinned".
await remoteCall.waitForElementLost(
appId, '#file-list .dim-offline[file-name="world.ogv"]');
await remoteCall.waitForElement(
appId, '#file-list .pinned[file-name="world.ogv"] .inline-status');
// Select world.ogv by itself.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="world.ogv"]');
// Wait for hello.txt to be unselected.
await remoteCall.waitForElement(
appId, '[file-name="hello.txt"]:not([selected])');
// Open the context menu for world.ogv.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
// Check that the pin action is ticked, i.e. the action will unpin the file.
await remoteCall.waitForElement(
appId,
'#file-context-menu:not([hidden]) ' +
'[command="#toggle-pinned"][checked]');
};
/**
* Tests that pinning hosted files without the required extensions is disabled,
* and that it does not affect multiple selections with non-hosted files.
*/
testcase.drivePinHosted = async () => {
const appId = await setupAndWaitUntilReady(RootPath.DRIVE);
// Select Test Document.gdoc.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="Test Document.gdoc"]');
await remoteCall.waitForElement(
appId, '[file-name="Test Document.gdoc"][selected]');
// Open the context menu once the file is selected.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
// Check that the pin action is disabled and unticked.
await remoteCall.waitForElement(
appId,
'#file-context-menu:not([hidden]) ' +
'[command="#toggle-pinned"][disabled]:not([checked])');
// Additionally select hello.txt.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="hello.txt"]', {shift: true});
await remoteCall.waitForElement(appId, '[file-name="hello.txt"][selected]');
// Open the context menu with both files selected.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
// The pin action should be enabled to pin only hello.txt, so select it.
await remoteCall.waitAndClickElement(
appId,
'#file-context-menu:not([hidden]) ' +
'[command="#toggle-pinned"]:not([checked]):not([disabled])');
// Wait for the toggle pinned async action to finish, so the next call to
// display context menu is after the action has finished.
await remoteCall.waitForElement(appId, '#file-context-menu[hidden]');
// Wait for the pinned action to finish, it's flagged in the file list by
// removing CSS class "dim-offline" and adding class "pinned".
await remoteCall.waitForElementLost(
appId, '#file-list .dim-offline[file-name="hello.txt"]');
await remoteCall.waitForElement(
appId, '#file-list .pinned[file-name="hello.txt"] .inline-status');
// Test Document.gdoc should not be pinned however.
await remoteCall.waitForElement(
appId, '#file-list [file-name="Test Document.gdoc"]:not(.pinned)');
// Open the context menu with both files selected.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
// Check that the pin action is ticked, i.e. the action will unpin the file.
await remoteCall.waitForElement(
appId,
'#file-context-menu:not([hidden]) ' +
'[command="#toggle-pinned"][checked]:not([disabled])');
};
/**
* Tests pinning a file to a mobile network.
*/
testcase.drivePinFileMobileNetwork = async () => {
const appId = await setupAndWaitUntilReady(RootPath.DRIVE);
const caller = getCaller();
await sendTestMessage({name: 'useCellularNetwork'});
await remoteCall.waitUntilSelected(appId, 'hello.txt');
await repeatUntil(() => {
return navigator.connection.type != 'cellular' ?
pending(caller, 'Network state is not changed to cellular.') :
null;
});
await remoteCall.waitForElement(appId, ['.table-row[selected]']);
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseRightClick', appId, ['.table-row[selected]']));
// Wait for the menu to appear and click on toggle pinned.
await remoteCall.waitForElement(appId, '#file-context-menu:not([hidden])');
await remoteCall.waitAndClickElement(
appId, '[command="#toggle-pinned"]:not([hidden]):not([disabled])');
// Wait for the toggle pinned async action to finish, so the next call to
// display context menu is after the action has finished.
await remoteCall.waitForElement(appId, '#file-context-menu[hidden]');
// Wait for the pinned action to finish, it's flagged in the file list by
// removing CSS class "dim-offline".
await remoteCall.waitForElementLost(
appId, '#file-list .dim-offline[file-name="hello.txt"]');
// Open context menu again.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeEvent', appId, ['#file-list', 'contextmenu']));
// Check: File is pinned.
await remoteCall.waitForElement(appId, '[command="#toggle-pinned"][checked]');
await remoteCall.waitForElement(
appId, '#file-list .pinned[file-name="hello.txt"] .inline-status');
await waitForNotification('disabled-mobile-sync');
await sendTestMessage({
name: 'clickNotificationButton',
extensionId: FILE_MANAGER_EXTENSIONS_ID,
notificationId: 'disabled-mobile-sync',
index: 0,
});
await repeatUntil(async () => {
const preferences =
await remoteCall.callRemoteTestUtil('getPreferences', null, []);
return preferences.cellularDisabled ?
pending(caller, 'Drive sync is still disabled.') :
null;
});
};
/**
* Tests that the pinned toggle in the toolbar updates on pinned state changes
* within fake entries.
*/
testcase.drivePinToggleUpdatesInFakeEntries = async () => {
const appId = await setupAndWaitUntilReady(RootPath.DRIVE);
// Navigate to the Offline fake entry.
await navigateWithDirectoryTree(appId, '/Offline');
// Bring up the context menu for test.txt.
await remoteCall.waitAndRightClick(
appId, '#file-list [file-name="test.txt"]');
// The pinned toggle should update to be checked.
await remoteCall.waitForElement(appId, '#pinned-toggle[checked]');
// Unpin the file.
await remoteCall.waitAndClickElement(
appId,
'#file-context-menu:not([hidden]) ' +
'[command="#toggle-pinned"][checked]');
// The pinned toggle should change to be unchecked.
await remoteCall.waitForElement(appId, '#pinned-toggle:not([checked])');
// Navigate to the Shared with me fake entry.
await navigateWithDirectoryTree(appId, '/Shared with me');
// Bring up the context menu for test.txt.
await remoteCall.waitAndRightClick(
appId, '#file-list [file-name="test.txt"]');
// The pinned toggle should remain unchecked.
await remoteCall.waitForElement(appId, '#pinned-toggle:not([checked])');
// Pin the file.
await remoteCall.waitAndClickElement(
appId,
'#file-context-menu:not([hidden]) ' +
'[command="#toggle-pinned"]:not([checked])');
// The pinned toggle should change to be checked.
await remoteCall.waitForElement(appId, '#pinned-toggle[checked]');
};
/**
* Tests that pressing Ctrl+A (select all files) from the search box doesn't
* put the Files App into check-select mode (crbug.com/849253).
*/
testcase.drivePressCtrlAFromSearch = async () => {
// Open Files app on Drive.
const appId = await setupAndWaitUntilReady(RootPath.DRIVE);
// Focus the search box.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['#search-button']));
// Wait for the search box to be visible.
await remoteCall.waitForElement(
appId, ['#search-box cr-input:not([hidden])']);
// Press Ctrl+A inside the search box.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeKeyDown', appId, ['#search-box cr-input', 'A', true, false, false]));
// Check we didn't enter check-select mode.
await remoteCall.waitForElement(appId, ['body:not(.check-select)']);
};
// Match the way the production version formats dates.
function formatDate(date) {
const padAndConvert = i => {
return (i < 10 ? '0' : '') + i.toString();
};
const year = date.getFullYear().toString();
// Months are 0-based, but days aren't.
const month = padAndConvert(date.getMonth() + 1);
const day = padAndConvert(date.getDate());
return `${year}-${month}-${day}`;
}
/**
* Verify that "Available Offline" is not available from the gear menu for a
* drive file.
*/
testcase.driveAvailableOfflineGearMenu = async () => {
const pinnedMenuQuery = '#file-context-menu:not([hidden]) ' +
'cr-menu-item[command="#toggle-pinned"]:not([disabled])';
// Open Files app on Drive.
const appId = await setupAndWaitUntilReady(RootPath.DRIVE, []);
// Select a file.
await remoteCall.waitUntilSelected(appId, 'hello.txt');
// Wait for the entry to be selected.
await remoteCall.waitForElement(appId, '.table-row[selected]');
// Click on the icon of the file to check select it
await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId,
['#file-list .table-row[selected] .detail-checkmark']);
// Ensure gear button is available
await remoteCall.waitForElement(appId, '#selection-menu-button');
// Click on gear menu and ensure "Available Offline" is not shown.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['#selection-menu-button']));
// Check that "Available Offline" is not shown in the menu. This element is
// hidden via a display:none css rule, so check that.
const e = await remoteCall.waitForElementStyles(
appId, pinnedMenuQuery, ['display']);
chrome.test.assertEq('none', e.styles.display);
};
/**
* Verify that "Available Offline" is not available from the gear menu for a
* drive directory.
*/
testcase.driveAvailableOfflineDirectoryGearMenu = async () => {
const pinnedMenuQuery = '#file-context-menu:not([hidden]) ' +
'cr-menu-item[command="#toggle-pinned"]:not([disabled])';
// Open Files app on Drive.
const appId = await setupAndWaitUntilReady(RootPath.DRIVE, []);
// Select a file.
await remoteCall.waitUntilSelected(appId, 'photos');
// Wait for the entry to be selected.
await remoteCall.waitForElement(appId, '.table-row[selected]');
// Click on the icon of the file to check select it
await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId,
['#file-list .table-row[selected] .detail-checkmark']);
// Ensure gear button is available
await remoteCall.waitForElement(appId, '#selection-menu-button');
// Click on gear menu and ensure "Available Offline" is not shown.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['#selection-menu-button']));
// Check that "Available Offline" is not shown in the menu. This element is
// hidden via a display:none css rule, so check that.
const e = await remoteCall.waitForElementStyles(
appId, pinnedMenuQuery, ['display']);
chrome.test.assertEq('none', e.styles.display);
};
/**
* Verify that the "Available Offline" toggle in the action bar appears and
* changes according to the selection.
*/
testcase.driveAvailableOfflineActionBar = async () => {
// Open Files app on Drive.
const appId = await setupAndWaitUntilReady(RootPath.DRIVE, []);
// Check the "Available Offline" toggle is currently hidden as no file is
// currently selected.
await remoteCall.waitForElement(
appId, '#action-bar #pinned-toggle-wrapper[hidden]');
// Select a hosted file.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="Test Document.gdoc"]');
// Wait for the entry to be selected.
await remoteCall.waitForElement(appId, '.table-row[selected]');
// Check the "Available Offline" toggle is shown in the action bar, but
// disabled.
await remoteCall.waitForElement(
appId,
'#action-bar #pinned-toggle-wrapper:not([hidden]) ' +
'#pinned-toggle[disabled]:not([checked])');
// Now select a non-hosted file.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="hello.txt"]');
// Check the "Available Offline" toggle is now enabled, and pin the file.
await remoteCall.waitAndClickElement(
appId,
'#action-bar #pinned-toggle-wrapper:not([hidden]) ' +
'#pinned-toggle:not([disabled]):not([checked])');
// Wait for the file to be pinned.
await remoteCall.waitForElement(
appId, '#file-list .pinned[file-name="hello.txt"]');
// Check the "Available Offline" toggle is enabled and checked.
await remoteCall.waitForElement(
appId,
'#action-bar #pinned-toggle-wrapper:not([hidden]) ' +
'#pinned-toggle[checked]:not([disabled])');
// Select another file that is not pinned.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="world.ogv"]');
// Check the "Available Offline" toggle is enabled and unchecked.
await remoteCall.waitForElement(
appId,
'#action-bar #pinned-toggle-wrapper:not([hidden]) ' +
'#pinned-toggle:not([disabled]):not([checked])');
// Reselect the previously pinned file.
await remoteCall.waitAndClickElement(
appId, '#file-list [file-name="hello.txt"]');
// Check the "Available Offline" toggle is enabled and checked.
await remoteCall.waitForElement(
appId,
'#action-bar #pinned-toggle-wrapper:not([hidden]) ' +
'#pinned-toggle[checked]:not([disabled])');
// Focus on the directory tree.
await remoteCall.focus(appId, ['#directory-tree']);
// Check the "Available Offline" toggle is still available in the action bar.
await remoteCall.waitForElement(
appId,
'#action-bar #pinned-toggle-wrapper:not([hidden]) ' +
'#pinned-toggle[checked]:not([disabled])');
};
/**
* Tests following links to folders.
*/
testcase.driveLinkToDirectory = async () => {
const appId = await setupAndWaitUntilReady(
RootPath.DRIVE, [], BASIC_DRIVE_ENTRY_SET.concat([
ENTRIES.directoryA,
ENTRIES.directoryB,
ENTRIES.directoryC,
ENTRIES.deeplyBurriedSmallJpeg,
ENTRIES.linkGtoB,
ENTRIES.linkHtoFile,
ENTRIES.linkTtoTransitiveDirectory,
]));
// Select the link
await remoteCall.waitUntilSelected(appId, 'G');
await remoteCall.waitForElement(appId, '.table-row[selected]');
// Open the link
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('openFile', appId, ['G']));
// Check the contents of current directory.
await remoteCall.waitForFiles(appId, [ENTRIES.directoryC.getExpectedRow()]);
};
/**
* Tests opening files through folder links.
*/
testcase.driveLinkOpenFileThroughLinkedDirectory = async () => {
const appId = await setupAndWaitUntilReady(
RootPath.DRIVE, [], BASIC_DRIVE_ENTRY_SET.concat([
ENTRIES.directoryA,
ENTRIES.directoryB,
ENTRIES.directoryC,
ENTRIES.deeplyBurriedSmallJpeg,
ENTRIES.linkGtoB,
ENTRIES.linkHtoFile,
ENTRIES.linkTtoTransitiveDirectory,
]));
// Navigate through link.
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('openFile', appId, ['G']));
await remoteCall.waitForFiles(appId, [ENTRIES.directoryC.getExpectedRow()]);
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('openFile', appId, ['C']));
await remoteCall.waitForFiles(
appId, [ENTRIES.deeplyBurriedSmallJpeg.getExpectedRow()]);
await sendTestMessage(
{name: 'expectFileTask', fileNames: ['deep.jpg'], openType: 'launch'});
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('openFile', appId, ['deep.jpg']));
// The MediaApp window should open for the image.
await waitForMediaApp();
};
/**
* Tests opening files through transitive links.
*/
testcase.driveLinkOpenFileThroughTransitiveLink = async () => {
const appId = await setupAndWaitUntilReady(
RootPath.DRIVE, [], BASIC_DRIVE_ENTRY_SET.concat([
ENTRIES.directoryA,
ENTRIES.directoryB,
ENTRIES.directoryC,
ENTRIES.deeplyBurriedSmallJpeg,
ENTRIES.linkGtoB,
ENTRIES.linkHtoFile,
ENTRIES.linkTtoTransitiveDirectory,
]));
// Navigate through link.
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('openFile', appId, ['T']));
await remoteCall.waitForFiles(
appId, [ENTRIES.deeplyBurriedSmallJpeg.getExpectedRow()]);
await sendTestMessage(
{name: 'expectFileTask', fileNames: ['deep.jpg'], openType: 'launch'});
chrome.test.assertTrue(
await remoteCall.callRemoteTestUtil('openFile', appId, ['deep.jpg']));
// The MediaApp window should open for the image.
await waitForMediaApp();
};
/**
* Tests that the welcome banner appears when a Drive volume is opened.
*/
testcase.driveWelcomeBanner = async () => {
// Open Files app on Drive.
const appId = await setupAndWaitUntilReady(RootPath.DRIVE, []);
await remoteCall.isolateBannerForTesting(appId, 'drive-welcome-banner');
const driveWelcomeBannerQuery = '#banners > drive-welcome-banner';
const driveWelcomeBannerDismissButtonQuery = [
'#banners > drive-welcome-banner',
'educational-banner',
'#dismiss-button',
];
// Open the Drive volume in the files-list.
chrome.test.assertTrue(await remoteCall.callRemoteTestUtil(
'fakeMouseClick', appId, ['.drive-volume']));
// Check: the Drive welcome banner should appear.
await remoteCall.waitForElement(appId, driveWelcomeBannerQuery);
// Close the Drive welcome banner.
await remoteCall.waitAndClickElement(
appId, driveWelcomeBannerDismissButtonQuery);
await remoteCall.waitForElement(
appId, '#banners > drive-welcome-banner[hidden]');
};
/**
* Tests that the Drive offline info banner appears when a Drive volume is
* opened.
*/
testcase.driveOfflineInfoBanner = async () => {
// Open Files app on Drive.
const appId = await setupAndWaitUntilReady(RootPath.DRIVE, []);
await remoteCall.isolateBannerForTesting(
appId, 'drive-offline-pinning-banner');
const driveOfflineBannerShownQuery =
'#banners > drive-offline-pinning-banner:not([hidden])';
const driveOfflineBannerHiddenQuery =
'#banners > drive-offline-pinning-banner[hidden]';
const driveOfflineLearnMoreLinkQuery =
['#banners > drive-offline-pinning-banner', '[slot="extra-button"]'];
// Check: the Drive Offline info banner should appear.
await remoteCall.waitForElement(appId, driveOfflineBannerShownQuery);
// Click on the 'Learn more' button.
await remoteCall.waitAndClickElement(appId, driveOfflineLearnMoreLinkQuery);
// Check: the Drive offline info banner should disappear.
await remoteCall.waitForElement(appId, driveOfflineBannerHiddenQuery);
// Navigate to a different directory within Drive.
await navigateWithDirectoryTree(appId, '/My Drive/photos');
// Check: the Drive offline info banner should stay hidden.
await remoteCall.waitForElement(appId, driveOfflineBannerHiddenQuery);
};
/**
* Tests that the Drive offline info banner does not show when the
* DriveFsBidirectionalNativeMessaging flag is disabled.
*/
testcase.driveOfflineInfoBannerWithoutFlag = async () => {
// Open Files app on Drive.
const appId = await setupAndWaitUntilReady(RootPath.DRIVE, []);
await remoteCall.isolateBannerForTesting(
appId, 'drive-offline-pinning-banner');
const driveOfflineInfoBannerHiddenQuery =
'#banners > drive-offline-pinning-banner';
// Check: the Drive Offline info banner should not appear.
await remoteCall.waitForElementLost(appId, driveOfflineInfoBannerHiddenQuery);
};
/**
* Tests that the inline file sync "in progress" icon is displayed in Drive as
* the file starts syncing then disappears as it finishes syncing.
*/
testcase.driveInlineSyncStatusSingleFile = async () => {
const toBeUploaded = new TestEntryInfo({
type: EntryType.FILE,
sourceFileName: 'video.ogv',
thumbnailFileName: 'image.png',
targetPath: 'toBeUploaded.ogv',
mimeType: 'video/ogg',
lastModifiedTime: 'Jul 4, 2012, 10:35 AM',
nameText: 'toBeUploaded.ogv',
sizeText: '59 KB',
typeText: 'OGG video',
availableOffline: true,
});
// Open Files app on Drive and copy over entry to be uploaded.
const appId =
await setupAndWaitUntilReady(RootPath.DRIVE, [], [toBeUploaded]);
// Fake the file starting to sync.
await sendTestMessage({
name: 'setDriveFileSyncStatus',
path: `/root/${toBeUploaded.targetPath}`,
syncStatus: 'in_progress',
});
const syncInProgressQuery = '[data-sync-status=in_progress]';
// Verify the "sync in progress" icon is displayed.
await remoteCall.waitForElement(appId, syncInProgressQuery);
// Fake the file finishing syncing.
await sendTestMessage({
name: 'setDriveFileSyncStatus',
path: `/root/${toBeUploaded.targetPath}`,
syncStatus: 'completed',
});
// Verify the "sync in progress" icon is no longer displayed.
await remoteCall.waitForElementLost(appId, syncInProgressQuery);
};
/**
* Tests that the inline file sync icons are displayed in Drive on parent
* folders containing entries and that child entries' statuses are aggregated
* respecting the order of precedence (failed > in progress > completed).
*/
testcase.driveInlineSyncStatusParentFolder = async () => {
const parentDir = new TestEntryInfo({
type: EntryType.DIRECTORY,
targetPath: 'some_folder',
lastModifiedTime: 'Jan 1, 1980, 11:59 PM',
nameText: 'some_folder',
sizeText: '--',
typeText: 'Folder',
});
const toBeUploaded = new TestEntryInfo({
type: EntryType.FILE,
sourceFileName: 'video.ogv',
thumbnailFileName: 'image.png',
targetPath: 'some_folder/toBeUploaded.ogv',
mimeType: 'video/ogg',
lastModifiedTime: 'Jul 4, 2012, 10:35 AM',
nameText: 'toBeUploaded.ogv',
sizeText: '59 KB',
typeText: 'OGG video',
availableOffline: true,
});
const toFailUploading = new TestEntryInfo({
type: EntryType.FILE,
sourceFileName: 'video.ogv',
thumbnailFileName: 'image.png',
targetPath: 'some_folder/toFailUploading.ogv',
mimeType: 'video/ogg',
lastModifiedTime: 'Jul 4, 2012, 10:35 AM',
nameText: 'toFailUploading.ogv',
sizeText: '59 KB',
typeText: 'OGG video',
availableOffline: true,
});
// Open Files app on Drive and copy over entry to be uploaded.
const appId = await setupAndWaitUntilReady(
RootPath.DRIVE, [], [parentDir, toBeUploaded, toFailUploading]);
// Fake syncing both files to Drive.
await sendTestMessage({
name: 'setDriveFileSyncStatus',
path: `/root/${toBeUploaded.targetPath}`,
syncStatus: 'in_progress',
});
await sendTestMessage({
name: 'setDriveFileSyncStatus',
path: `/root/${toFailUploading.targetPath}`,
syncStatus: 'in_progress',
});
// States:
// toBeUploaded - syncing in progress
// toFailUploading - syncing in progress
const syncInProgressQuery = '[data-sync-status=in_progress]';
const syncFailedQuery = '[data-sync-status=error]';
// Verify the "sync in progress" icon is displayed in the parent folder.
await remoteCall.waitForElement(appId, syncInProgressQuery);