1 // Copyright (c) 2013 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.
11 var EntryType = Object.freeze({
13 DIRECTORY: 'directory'
20 var SharedOption = Object.freeze({
26 * File system entry information for tests.
28 * @param {EntryType} type Entry type.
29 * @param {string} sourceFileName Source file name that provides file contents.
30 * @param {string} targetName Name of entry on the test file system.
31 * @param {string} mimeType Mime type.
32 * @param {SharedOption} sharedOption Shared option.
33 * @param {string} lastModifiedTime Last modified time as a text to be shown in
34 * the last modified column.
35 * @param {string} nameText File name to be shown in the name column.
36 * @param {string} sizeText Size text to be shown in the size column.
37 * @param {string} typeText Type name to be shown in the type column.
40 var TestEntryInfo = function(type,
50 this.sourceFileName = sourceFileName || '';
51 this.targetPath = targetPath;
52 this.mimeType = mimeType || '';
53 this.sharedOption = sharedOption;
54 this.lastModifiedTime = lastModifiedTime;
55 this.nameText = nameText;
56 this.sizeText = sizeText;
57 this.typeText = typeText;
61 TestEntryInfo.getExpectedRows = function(entries) {
62 return entries.map(function(entry) { return entry.getExpectedRow(); });
66 * Obtains a expected row contents of the file in the file list.
68 TestEntryInfo.prototype.getExpectedRow = function() {
69 return [this.nameText, this.sizeText, this.typeText, this.lastModifiedTime];
73 * Filesystem entries used by the test cases.
74 * @type {Object.<string, TestEntryInfo>}
78 hello: new TestEntryInfo(
79 EntryType.FILE, 'text.txt', 'hello.txt',
80 'text/plain', SharedOption.NONE, 'Sep 4, 1998 12:34 PM',
81 'hello.txt', '51 bytes', 'Plain text'),
83 world: new TestEntryInfo(
84 EntryType.FILE, 'video.ogv', 'world.ogv',
85 'text/plain', SharedOption.NONE, 'Jul 4, 2012 10:35 AM',
86 'world.ogv', '59 KB', 'OGG video'),
88 unsupported: new TestEntryInfo(
89 EntryType.FILE, 'random.bin', 'unsupported.foo',
90 'application/x-foo', SharedOption.NONE, 'Jul 4, 2012 10:36 AM',
91 'unsupported.foo', '8 KB', 'FOO file'),
93 desktop: new TestEntryInfo(
94 EntryType.FILE, 'image.png', 'My Desktop Background.png',
95 'text/plain', SharedOption.NONE, 'Jan 18, 2038 1:02 AM',
96 'My Desktop Background.png', '272 bytes', 'PNG image'),
98 beautiful: new TestEntryInfo(
99 EntryType.FILE, 'music.ogg', 'Beautiful Song.ogg',
100 'text/plain', SharedOption.NONE, 'Nov 12, 2086 12:00 PM',
101 'Beautiful Song.ogg', '14 KB', 'OGG audio'),
103 photos: new TestEntryInfo(
104 EntryType.DIRECTORY, null, 'photos',
105 null, SharedOption.NONE, 'Jan 1, 1980 11:59 PM',
106 'photos', '--', 'Folder'),
108 testDocument: new TestEntryInfo(
109 EntryType.FILE, null, 'Test Document',
110 'application/vnd.google-apps.document',
111 SharedOption.NONE, 'Apr 10, 2013 4:20 PM',
112 'Test Document.gdoc', '--', 'Google document'),
114 testSharedDocument: new TestEntryInfo(
115 EntryType.FILE, null, 'Test Shared Document',
116 'application/vnd.google-apps.document',
117 SharedOption.SHARED, 'Mar 20, 2013 10:40 PM',
118 'Test Shared Document.gdoc', '--', 'Google document'),
120 newlyAdded: new TestEntryInfo(
121 EntryType.FILE, 'music.ogg', 'newly added file.ogg',
122 'audio/ogg', SharedOption.NONE, 'Sep 4, 1998 12:00 AM',
123 'newly added file.ogg', '14 KB', 'OGG audio'),
125 directoryA: new TestEntryInfo(
126 EntryType.DIRECTORY, null, 'A',
127 null, SharedOption.NONE, 'Jan 1, 2000 1:00 AM',
128 'A', '--', 'Folder'),
130 directoryB: new TestEntryInfo(
131 EntryType.DIRECTORY, null, 'A/B',
132 null, SharedOption.NONE, 'Jan 1, 2000 1:00 AM',
133 'B', '--', 'Folder'),
135 directoryC: new TestEntryInfo(
136 EntryType.DIRECTORY, null, 'A/B/C',
137 null, SharedOption.NONE, 'Jan 1, 2000 1:00 AM',
142 * Basic entry set for the local volume.
143 * @type {Array.<TestEntryInfo>}
146 var BASIC_LOCAL_ENTRY_SET = [
155 * Basic entry set for the drive volume.
157 * TODO(hirono): Add a case for an entry cached by FileCache. For testing
158 * Drive, create more entries with Drive specific attributes.
160 * @type {Array.<TestEntryInfo>}
163 var BASIC_DRIVE_ENTRY_SET = [
170 ENTRIES.testDocument,
171 ENTRIES.testSharedDocument
174 var NESTED_ENTRY_SET = [
181 * Expected files shown in "Recent". Directories (e.g. 'photos') are not in this
182 * list as they are not expected in "Recent".
184 * @type {Array.<TestEntryInfo>}
187 var RECENT_ENTRY_SET = [
193 ENTRIES.testDocument,
194 ENTRIES.testSharedDocument
198 * Expected files shown in "Offline", which should have the files
199 * "available offline". Google Documents, Google Spreadsheets, and the files
200 * cached locally are "available offline".
202 * @type {Array.<TestEntryInfo>}
205 var OFFLINE_ENTRY_SET = [
206 ENTRIES.testDocument,
207 ENTRIES.testSharedDocument
211 * Expected files shown in "Shared with me", which should be the entries labeled
212 * with "shared-with-me".
214 * @type {Array.<TestEntryInfo>}
217 var SHARED_WITH_ME_ENTRY_SET = [
218 ENTRIES.testSharedDocument
222 * Opens a Files.app's main window and waits until it is initialized.
224 * TODO(hirono): Add parameters to specify the entry set to be prepared.
226 * @param {Object} appState App state to be passed with on opening Files.app.
227 * @param {function(string, Array.<Array.<string>>)} Callback with the app id
228 * and with the file list.
230 function setupAndWaitUntilReady(appState, callback) {
234 callRemoteTestUtil('openMainWindow', null, [appState], steps.shift());
238 addEntries(['local'], BASIC_LOCAL_ENTRY_SET, steps.shift());
241 chrome.test.assertTrue(success);
242 addEntries(['drive'], BASIC_DRIVE_ENTRY_SET, steps.shift());
245 chrome.test.assertTrue(success);
246 callRemoteTestUtil('waitForFileListChange', appId, [0], steps.shift());
249 callback(appId, fileList);
256 * Verifies if there are no Javascript errors in any of the app windows.
257 * @param {function()} Completion callback.
259 function checkIfNoErrorsOccured(callback) {
260 callRemoteTestUtil('getErrorCount', null, [], function(count) {
261 chrome.test.assertEq(0, count);
269 * Returns the name of the given file list entry.
270 * @param {Array.<string>} file An entry in a file list.
271 * @return {string} Name of the file.
273 function getFileName(fileListEntry) {
274 return fileListEntry[0];
278 * Returns the size of the given file list entry.
279 * @param {Array.<string>} An entry in a file list.
280 * @return {string} Size of the file.
282 function getFileSize(fileListEntry) {
283 return fileListEntry[1];
287 * Returns the type of the given file list entry.
288 * @param {Array.<string>} An entry in a file list.
289 * @return {string} Type of the file.
291 function getFileType(fileListEntry) {
292 return fileListEntry[2];
296 * Namespace for test cases.
301 * Namespace for intermediate test cases.
303 testcase.intermediate = {};
306 * Tests if the files initially added by the C++ side are displayed, and
307 * that a subsequently added file shows up.
309 * @param {string} path Directory path to be tested.
311 testcase.intermediate.fileDisplay = function(path) {
314 var expectedFilesBefore =
315 TestEntryInfo.getExpectedRows(path == '/drive/root' ?
316 BASIC_DRIVE_ENTRY_SET : BASIC_LOCAL_ENTRY_SET).sort();
318 var expectedFilesAfter =
319 expectedFilesBefore.concat([ENTRIES.newlyAdded.getExpectedRow()]).sort();
323 var appState = {defaultPath: path};
324 setupAndWaitUntilReady(appState, this.next);
326 // Notify that the list has been verified and a new file can be added
327 // in file_manager_browsertest.cc.
328 function(inAppId, actualFilesBefore) {
330 chrome.test.assertEq(expectedFilesBefore, actualFilesBefore);
331 addEntries(['local', 'drive'], [ENTRIES.newlyAdded], this.next);
334 chrome.test.assertTrue(result);
336 'waitForFileListChange',
338 [expectedFilesBefore.length],
341 // Confirm the file list.
342 function(actualFilesAfter) {
343 chrome.test.assertEq(expectedFilesAfter, actualFilesAfter);
344 checkIfNoErrorsOccured(this.next);
350 * Tests if the gallery shows up for the selected image and that the image
353 * @param {string} path Directory path to be tested.
355 testcase.intermediate.galleryOpen = function(path) {
359 var appState = {defaultPath: path};
360 setupAndWaitUntilReady(appState, this.next);
362 // Resize the window to desired dimensions to avoid flakyness.
365 callRemoteTestUtil('resizeWindow',
372 chrome.test.assertTrue(result);
373 callRemoteTestUtil('openFile',
375 ['My Desktop Background.png'],
378 // Wait for the image in the gallery's screen image.
380 chrome.test.assertTrue(result);
381 callRemoteTestUtil('waitForElement',
383 ['.gallery .content canvas.image',
384 'iframe.overlay-pane'],
387 // Verify the gallery's screen image.
389 chrome.test.assertEq('320', element.attributes.width);
390 chrome.test.assertEq('240', element.attributes.height);
391 // Get the full-resolution image.
392 callRemoteTestUtil('waitForElement',
394 ['.gallery .content canvas.fullres',
395 'iframe.overlay-pane'],
398 // Verify the gallery's full resolution image.
400 chrome.test.assertEq('800', element.attributes.width);
401 chrome.test.assertEq('600', element.attributes.height);
402 checkIfNoErrorsOccured(this.next);
408 * Tests if the audio player shows up for the selected image and that the audio
409 * is loaded successfully.
411 * @param {string} path Directory path to be tested.
413 testcase.intermediate.audioOpen = function(path) {
418 var appState = {defaultPath: path};
419 setupAndWaitUntilReady(appState, this.next);
425 'openFile', appId, ['Beautiful Song.ogg'], this.next);
427 // Wait for the audio player.
429 chrome.test.assertTrue(result);
430 callRemoteTestUtil('waitForWindow',
432 ['mediaplayer.html'],
435 // Wait for the audio tag and verify the source.
437 audioAppId = inAppId;
438 callRemoteTestUtil('waitForElement',
443 // Get the title tag.
445 chrome.test.assertEq(
446 'filesystem:chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/' +
447 'external' + path + '/Beautiful%20Song.ogg',
448 element.attributes.src);
449 callRemoteTestUtil('waitForElement',
454 // Get the artist tag.
456 chrome.test.assertEq('Beautiful Song', element.text);
457 callRemoteTestUtil('waitForElement',
462 // Verify the artist and if there are no javascript errors.
464 chrome.test.assertEq('Unknown Artist', element.text);
465 checkIfNoErrorsOccured(this.next);
471 * Tests if the video player shows up for the selected movie and that it is
472 * loaded successfully.
474 * @param {string} path Directory path to be tested.
476 testcase.intermediate.videoOpen = function(path) {
481 var appState = {defaultPath: path};
482 setupAndWaitUntilReady(appState, this.next);
488 'openFile', appId, ['world.ogv'], this.next);
491 chrome.test.assertTrue(result);
492 // Wait for the video player.
493 callRemoteTestUtil('waitForWindow',
495 ['video_player.html'],
499 videoAppId = inAppId;
500 // Wait for the video tag and verify the source.
501 callRemoteTestUtil('waitForElement',
507 chrome.test.assertEq(
508 'filesystem:chrome-extension://hhaomjibdihmijegdhdafkllkbggdgoj/' +
509 'external' + path + '/world.ogv',
510 element.attributes.src);
511 // Wait for the window's inner dimensions. Should be changed to the video
512 // size once the metadata is loaded.
513 callRemoteTestUtil('waitForWindowGeometry',
519 checkIfNoErrorsOccured(this.next);
525 * Tests copying a file to the same directory and waits until the file lists
528 * @param {string} path Directory path to be tested.
530 testcase.intermediate.keyboardCopy = function(path, callback) {
531 var filename = 'world.ogv';
532 var expectedFilesBefore =
533 TestEntryInfo.getExpectedRows(path == '/drive/root' ?
534 BASIC_DRIVE_ENTRY_SET : BASIC_LOCAL_ENTRY_SET).sort();
535 var expectedFilesAfter =
536 expectedFilesBefore.concat([['world (1).ogv', '59 KB', 'OGG video']]);
538 var appId, fileListBefore;
540 // Set up File Manager.
542 var appState = {defaultPath: path};
543 setupAndWaitUntilReady(appState, this.next);
546 function(inAppId, inFileListBefore) {
548 fileListBefore = inFileListBefore;
549 chrome.test.assertEq(expectedFilesBefore, inFileListBefore);
550 callRemoteTestUtil('copyFile', appId, [filename], this.next);
552 // Wait for a file list change.
554 chrome.test.assertTrue(result);
555 callRemoteTestUtil('waitForFiles',
558 {ignoreLastModifiedTime: true}],
561 // Verify the result.
563 checkIfNoErrorsOccured(this.next);
569 * Tests deleting a file and and waits until the file lists changes.
570 * @param {string} path Directory path to be tested.
572 testcase.intermediate.keyboardDelete = function(path) {
573 // Returns true if |fileList| contains |filename|.
574 var isFilePresent = function(filename, fileList) {
575 for (var i = 0; i < fileList.length; i++) {
576 if (getFileName(fileList[i]) == filename)
582 var filename = 'world.ogv';
583 var directoryName = 'photos';
584 var appId, fileListBefore;
586 // Set up File Manager.
588 var appState = {defaultPath: path};
589 setupAndWaitUntilReady(appState, this.next);
592 function(inAppId, inFileListBefore) {
594 fileListBefore = inFileListBefore;
595 chrome.test.assertTrue(isFilePresent(filename, fileListBefore));
597 'deleteFile', appId, [filename], this.next);
599 // Reply to a dialog.
601 chrome.test.assertTrue(result);
603 'waitAndAcceptDialog', appId, [], this.next);
605 // Wait for a file list change.
607 callRemoteTestUtil('waitForFileListChange',
609 [fileListBefore.length],
612 // Delete the directory.
614 fileListBefore = fileList;
615 chrome.test.assertFalse(isFilePresent(filename, fileList));
616 chrome.test.assertTrue(isFilePresent(directoryName, fileList));
617 callRemoteTestUtil('deleteFile', appId, [directoryName], this.next);
619 // Reply to a dialog.
621 chrome.test.assertTrue(result);
622 callRemoteTestUtil('waitAndAcceptDialog', appId, [], this.next);
624 // Wait for a file list change.
626 callRemoteTestUtil('waitForFileListChange', appId,
627 [fileListBefore.length], this.next);
629 // Verify the result.
631 chrome.test.assertFalse(isFilePresent(directoryName, fileList));
632 checkIfNoErrorsOccured(this.next);
637 testcase.fileDisplayDownloads = function() {
638 testcase.intermediate.fileDisplay('/Downloads');
641 testcase.galleryOpenDownloads = function() {
642 testcase.intermediate.galleryOpen('/Downloads');
645 testcase.audioOpenDownloads = function() {
646 testcase.intermediate.audioOpen('/Downloads');
649 testcase.videoOpenDownloads = function() {
650 testcase.intermediate.videoOpen('/Downloads');
653 testcase.keyboardCopyDownloads = function() {
654 testcase.intermediate.keyboardCopy('/Downloads');
657 testcase.keyboardDeleteDownloads = function() {
658 testcase.intermediate.keyboardDelete('/Downloads');
661 testcase.fileDisplayDrive = function() {
662 testcase.intermediate.fileDisplay('/drive/root');
665 testcase.galleryOpenDrive = function() {
666 testcase.intermediate.galleryOpen('/drive/root');
669 testcase.audioOpenDrive = function() {
670 testcase.intermediate.audioOpen('/drive/root');
673 testcase.videoOpenDrive = function() {
674 testcase.intermediate.videoOpen('/drive/root');
677 testcase.keyboardCopyDrive = function() {
678 testcase.intermediate.keyboardCopy('/drive/root');
681 testcase.keyboardDeleteDrive = function() {
682 testcase.intermediate.keyboardDelete('/drive/root');
686 * Tests opening the "Recent" on the sidebar navigation by clicking the icon,
687 * and verifies the directory contents. We test if there are only files, since
688 * directories are not allowed in "Recent". This test is only available for
691 testcase.openSidebarRecent = function() {
695 var appState = {defaultPath: '/drive/root'};
696 setupAndWaitUntilReady(appState, this.next);
698 // Click the icon of the Recent volume.
702 'selectVolume', appId, ['drive_recent'], this.next);
704 // Wait until the file list is updated.
706 chrome.test.assertFalse(!result);
708 'waitForFileListChange',
710 [BASIC_DRIVE_ENTRY_SET.length],
713 // Verify the file list.
714 function(actualFilesAfter) {
715 chrome.test.assertEq(
716 TestEntryInfo.getExpectedRows(RECENT_ENTRY_SET).sort(),
718 checkIfNoErrorsOccured(this.next);
724 * Tests opening the "Offline" on the sidebar navigation by clicking the icon,
725 * and checks contenets of the file list. Only the entries "available offline"
726 * should be shown. "Available offline" entires are hosted documents and the
727 * entries cached by DriveCache.
729 testcase.openSidebarOffline = function() {
733 var appState = {defaultPath: '/drive/root/'};
734 setupAndWaitUntilReady(appState, this.next);
736 // Click the icon of the Offline volume.
740 'selectVolume', appId, ['drive_offline'], this.next);
742 // Wait until the file list is updated.
744 chrome.test.assertFalse(!result);
746 'waitForFileListChange',
748 [BASIC_DRIVE_ENTRY_SET.length],
751 // Verify the file list.
752 function(actualFilesAfter) {
753 chrome.test.assertEq(
754 TestEntryInfo.getExpectedRows(OFFLINE_ENTRY_SET).sort(),
756 checkIfNoErrorsOccured(this.next);
762 * Tests opening the "Shared with me" on the sidebar navigation by clicking the
763 * icon, and checks contents of the file list. Only the entries labeled with
764 * "shared-with-me" should be shown.
766 testcase.openSidebarSharedWithMe = function() {
770 var appState = {defaultPath: '/drive/root/'};
771 setupAndWaitUntilReady(appState, this.next);
773 // Click the icon of the Shared With Me volume.
776 // Use the icon for a click target.
777 callRemoteTestUtil('selectVolume',
779 ['drive_shared_with_me'], this.next);
781 // Wait until the file list is updated.
783 chrome.test.assertFalse(!result);
785 'waitForFileListChange',
787 [BASIC_DRIVE_ENTRY_SET.length],
790 // Verify the file list.
791 function(actualFilesAfter) {
792 chrome.test.assertEq(
793 TestEntryInfo.getExpectedRows(SHARED_WITH_ME_ENTRY_SET).sort(),
795 checkIfNoErrorsOccured(this.next);
801 * Tests autocomplete with a query 'hello'. This test is only available for
804 testcase.autocomplete = function() {
805 var EXPECTED_AUTOCOMPLETE_LIST = [
806 '\'hello\' - search Drive\n',
812 var appState = {defaultPath: '/drive/root'};
813 setupAndWaitUntilReady(appState, this.next);
815 // Perform an auto complete test and wait until the list changes.
816 // TODO(mtomasz): Move the operation from test_util.js to tests_cases.js.
817 function(appId, list) {
818 callRemoteTestUtil('performAutocompleteAndWait',
820 ['hello', EXPECTED_AUTOCOMPLETE_LIST.length],
823 // Verify the list contents.
824 function(autocompleteList) {
825 chrome.test.assertEq(EXPECTED_AUTOCOMPLETE_LIST, autocompleteList);
826 checkIfNoErrorsOccured(this.next);
832 * Test function to copy from the specified source to the specified destination.
833 * @param {string} targetFile Name of target file to be copied.
834 * @param {string} srcName Type of source volume. e.g. downloads, drive,
835 * drive_recent, drive_shared_with_me, drive_offline.
836 * @param {Array.<TestEntryInfo>} srcEntries Expected initial contents in the
838 * @param {string} dstName Type of destination volume.
839 * @param {Array.<TestEntryInfo>} dstEntries Expected initial contents in the
840 * destination volume.
842 testcase.intermediate.copyBetweenVolumes = function(targetFile,
847 var srcContents = TestEntryInfo.getExpectedRows(srcEntries).sort();
848 var dstContents = TestEntryInfo.getExpectedRows(dstEntries).sort();
852 // Set up File Manager.
854 var appState = {defaultPath: '/Downloads'};
855 setupAndWaitUntilReady(appState, this.next);
857 // Select the source volume.
861 'selectVolume', appId, [srcName], this.next);
863 // Wait for the expected files to appear in the file list.
865 chrome.test.assertTrue(result);
867 'waitForFiles', appId, [srcContents], this.next);
869 // Select the source file.
872 'selectFile', appId, [targetFile], this.next);
876 chrome.test.assertTrue(result);
877 callRemoteTestUtil('execCommand', appId, ['copy'], this.next);
879 // Select the destination volume.
881 chrome.test.assertTrue(result);
883 'selectVolume', appId, [dstName], this.next);
885 // Wait for the expected files to appear in the file list.
887 chrome.test.assertTrue(result);
889 'waitForFiles', appId, [dstContents], this.next);
894 'execCommand', appId, ['paste'], this.next);
896 // Wait for the file list to change.
898 chrome.test.assertTrue(result);
899 callRemoteTestUtil('waitForFileListChange',
901 [dstContents.length],
904 // Check the last contents of file list.
905 function(actualFilesAfter) {
906 chrome.test.assertEq(dstContents.length + 1,
907 actualFilesAfter.length);
908 var copiedItem = null;
909 for (var i = 0; i < srcContents.length; i++) {
910 if (srcContents[i][0] == targetFile) {
911 copiedItem = srcContents[i];
915 chrome.test.assertTrue(copiedItem != null);
916 for (var i = 0; i < dstContents.length; i++) {
917 if (dstContents[i][0] == targetFile) {
918 // Replace the last '.' in filename with ' (1).'.
919 // e.g. 'my.note.txt' -> 'my.note (1).txt'
920 copiedItem[0] = copiedItem[0].replace(/\.(?=[^\.]+$)/, ' (1).');
924 // File size can not be obtained on drive_shared_with_me volume and
926 var ignoreSize = srcName == 'drive_shared_with_me' ||
927 dstName == 'drive_shared_with_me' ||
928 srcName == 'drive_offline' ||
929 dstName == 'drive_offline';
930 for (var i = 0; i < actualFilesAfter.length; i++) {
931 if (actualFilesAfter[i][0] == copiedItem[0] &&
932 (ignoreSize || actualFilesAfter[i][1] == copiedItem[1]) &&
933 actualFilesAfter[i][2] == copiedItem[2]) {
934 checkIfNoErrorsOccured(this.next);
944 * Test sharing dialog for a file or directory on Drive
945 * @param {string} path Path for a file or a directory to be shared.
947 testcase.intermediate.share = function(path) {
950 // Set up File Manager.
952 var appState = {defaultPath: '/drive/root/'};
953 setupAndWaitUntilReady(appState, this.next);
955 // Select the source file.
959 'selectFile', appId, [path], this.next);
961 // Wait for the share button.
963 chrome.test.assertTrue(result);
964 callRemoteTestUtil('waitForElement',
966 ['#share-button:not([disabled])'],
969 // Invoke the share dialog.
971 callRemoteTestUtil('fakeMouseClick',
976 // Wait until the share dialog's contents are shown.
978 chrome.test.assertTrue(result);
979 callRemoteTestUtil('waitForElement',
981 ['.share-dialog-webview-wrapper.loaded'],
985 callRemoteTestUtil('waitForStyles',
988 query: '.share-dialog-webview-wrapper.loaded',
996 // Wait until the share dialog's contents are shown.
998 callRemoteTestUtil('executeScriptInWebView',
1000 ['.share-dialog-webview-wrapper.loaded webview',
1001 'document.querySelector("button").click()'],
1004 // Wait until the share dialog's contents are hidden.
1006 callRemoteTestUtil('waitForElement',
1008 ['.share-dialog-webview-wrapper.loaded',
1009 null, // iframeQuery
1013 // Check for Javascript errros.
1015 checkIfNoErrorsOccured(this.next);
1021 * Test utility for traverse tests.
1023 testcase.intermediate.traverseDirectories = function(root) {
1026 // Set up File Manager.
1028 var appState = {defaultPath: root};
1029 callRemoteTestUtil('openMainWindow', null, [appState], this.next);
1031 // Check the initial view.
1034 addEntries(['local', 'drive'], NESTED_ENTRY_SET, this.next);
1037 chrome.test.assertTrue(result);
1038 callRemoteTestUtil('waitForFiles',
1040 [[ENTRIES.directoryA.getExpectedRow()]],
1043 // Open the directory
1045 callRemoteTestUtil('openFile', appId, ['A'], this.next);
1047 // Check the contents of current directory.
1049 chrome.test.assertTrue(result);
1050 callRemoteTestUtil('waitForFiles',
1052 [[ENTRIES.directoryB.getExpectedRow()]],
1055 // Open the directory
1057 callRemoteTestUtil('openFile', appId, ['B'], this.next);
1059 // Check the contents of current directory.
1061 chrome.test.assertTrue(result);
1062 callRemoteTestUtil('waitForFiles',
1064 [[ENTRIES.directoryC.getExpectedRow()]],
1069 checkIfNoErrorsOccured(this.next);
1075 * Tests copy from drive's root to local's downloads.
1077 testcase.transferFromDriveToDownloads = function() {
1078 testcase.intermediate.copyBetweenVolumes('hello.txt',
1080 BASIC_DRIVE_ENTRY_SET,
1082 BASIC_LOCAL_ENTRY_SET);
1086 * Tests copy from local's downloads to drive's root.
1088 testcase.transferFromDownloadsToDrive = function() {
1089 testcase.intermediate.copyBetweenVolumes('hello.txt',
1091 BASIC_LOCAL_ENTRY_SET,
1093 BASIC_DRIVE_ENTRY_SET);
1097 * Tests copy from drive's shared_with_me to local's downloads.
1099 testcase.transferFromSharedToDownloads = function() {
1100 testcase.intermediate.copyBetweenVolumes('Test Shared Document.gdoc',
1101 'drive_shared_with_me',
1102 SHARED_WITH_ME_ENTRY_SET,
1104 BASIC_LOCAL_ENTRY_SET);
1108 * Tests copy from drive's shared_with_me to drive's root.
1110 testcase.transferFromSharedToDrive = function() {
1111 testcase.intermediate.copyBetweenVolumes('Test Shared Document.gdoc',
1112 'drive_shared_with_me',
1113 SHARED_WITH_ME_ENTRY_SET,
1115 BASIC_DRIVE_ENTRY_SET);
1119 * Tests copy from drive's recent to local's downloads.
1121 testcase.transferFromRecentToDownloads = function() {
1122 testcase.intermediate.copyBetweenVolumes('hello.txt',
1126 BASIC_LOCAL_ENTRY_SET);
1130 * Tests copy from drive's recent to drive's root.
1132 testcase.transferFromRecentToDrive = function() {
1133 testcase.intermediate.copyBetweenVolumes('hello.txt',
1137 BASIC_DRIVE_ENTRY_SET);
1141 * Tests copy from drive's offline to local's downloads.
1143 testcase.transferFromOfflineToDownloads = function() {
1144 testcase.intermediate.copyBetweenVolumes('Test Document.gdoc',
1148 BASIC_LOCAL_ENTRY_SET);
1152 * Tests copy from drive's offline to drive's root.
1154 testcase.transferFromOfflineToDrive = function() {
1155 testcase.intermediate.copyBetweenVolumes('Test Document.gdoc',
1159 BASIC_DRIVE_ENTRY_SET);
1163 * Tests sharing a file on Drive
1165 testcase.shareFile = function() {
1166 testcase.intermediate.share('world.ogv');
1170 * Tests sharing a directory on Drive
1172 testcase.shareDirectory = function() {
1173 testcase.intermediate.share('photos');
1177 * Tests sharing a file on Drive
1179 testcase.suggestAppDialog = function() {
1182 // Set up File Manager.
1184 chrome.test.sendMessage(
1185 JSON.stringify({name: 'getCwsWidgetContainerMockUrl'}),
1188 // Override the container URL with the mock.
1190 var data = JSON.parse(json);
1193 defaultPath: '/drive/root',
1194 suggestAppsDialogState: {
1195 overrideCwsContainerUrlForTest: data.url,
1196 overrideCwsContainerOriginForTest: data.origin
1199 setupAndWaitUntilReady(appState, this.next);
1201 function(inAppId, inFileListBefore) {
1205 'selectFile', appId, ['unsupported.foo'], this.next);
1207 // Double-click the file.
1209 chrome.test.assertTrue(result);
1211 'fakeMouseDoubleClick',
1213 ['#file-list li.table-row[selected] .filename-label span'],
1216 // Wait for the widget is loaded.
1218 chrome.test.assertTrue(result);
1222 ['#suggest-app-dialog webview[src]'],
1225 // Wait for the widget is initialized.
1227 chrome.test.assertTrue(!!result);
1231 ['#suggest-app-dialog:not(.show-spinner)'],
1234 // Initiate an installation from the widget.
1236 chrome.test.assertTrue(!!result);
1238 'executeScriptInWebView',
1240 ['#suggest-app-dialog webview',
1241 'document.querySelector("button").click()'],
1244 // Wait until the installation is finished and the dialog is closed.
1246 chrome.test.assertTrue(!!result);
1247 callRemoteTestUtil('waitForElement',
1249 ['#suggest-app-dialog',
1250 null, // iframeQuery
1256 chrome.test.assertTrue(!!result);
1257 checkIfNoErrorsOccured(this.next);
1263 * Tests hiding the search box.
1265 testcase.hideSearchBox = function() {
1268 // Set up File Manager.
1270 var appState = {defaultPath: '/Downloads'};
1271 setupAndWaitUntilReady(appState, this.next);
1273 // Resize the window.
1274 function(inAppId, inFileListBefore) {
1276 callRemoteTestUtil('resizeWindow', appId, [100, 100], this.next);
1278 // Wait for the style change.
1280 chrome.test.assertTrue(result);
1281 callRemoteTestUtil('waitForStyles',
1284 query: '#search-box',
1285 styles: {visibility: 'hidden'}
1291 checkIfNoErrorsOccured(this.next);
1297 * Tests restoring the sorting order.
1299 testcase.restoreSortColumn = function() {
1301 var EXPECTED_FILES = TestEntryInfo.getExpectedRows([
1309 // Set up File Manager.
1311 var appState = {defaultPath: '/Downloads'};
1312 setupAndWaitUntilReady(appState, this.next);
1317 callRemoteTestUtil('fakeMouseClick',
1319 ['.table-header-cell:nth-of-type(1)'],
1322 // Check the sorted style of the header.
1324 callRemoteTestUtil('waitForElement',
1326 ['.table-header-sort-image-asc'],
1331 callRemoteTestUtil('fakeMouseClick',
1333 ['.table-header-cell:nth-of-type(1)'],
1336 // Check the sorted style of the header.
1338 callRemoteTestUtil('waitForElement',
1340 ['.table-header-sort-image-desc'],
1343 // Check the sorted files.
1345 callRemoteTestUtil('waitForFiles',
1347 [EXPECTED_FILES, {orderCheck: true}],
1350 // Open another window, where the sorted column should be restored.
1352 var appState = {defaultPath: '/Downloads'};
1353 setupAndWaitUntilReady(appState, this.next);
1355 // Check the sorted style of the header.
1358 callRemoteTestUtil('waitForElement',
1360 ['.table-header-sort-image-desc'],
1363 // Check the sorted files.
1365 callRemoteTestUtil('waitForFiles',
1367 [EXPECTED_FILES, {orderCheck: true}],
1372 checkIfNoErrorsOccured(this.next);
1378 * Tests restoring the current view (the file list or the thumbnail grid).
1380 testcase.restoreCurrentView = function() {
1383 // Set up File Manager.
1385 var appState = {defaultPath: '/Downloads'};
1386 setupAndWaitUntilReady(appState, this.next);
1388 // Check the initial view.
1391 callRemoteTestUtil('waitForElement',
1393 ['.thumbnail-grid[hidden]'],
1396 // Change the current view.
1398 callRemoteTestUtil('fakeMouseClick',
1400 ['#thumbnail-view'],
1403 // Check the new current view.
1405 chrome.test.assertTrue(result);
1406 callRemoteTestUtil('waitForElement',
1408 ['.detail-table[hidden]'],
1411 // Open another window, where the current view is restored.
1413 var appState = {defaultPath: '/Downloads'};
1414 callRemoteTestUtil('openMainWindow', null, [appState], this.next);
1416 // Check the current view.
1419 callRemoteTestUtil('waitForElement',
1421 ['.detail-table[hidden]'],
1426 checkIfNoErrorsOccured(this.next);
1432 * Tests keyboard operations of the navigation list.
1434 testcase.traverseNavigationList = function() {
1437 // Set up File Manager.
1439 var appState = {defaultPath: '/drive/root'};
1440 setupAndWaitUntilReady(appState, this.next);
1442 // Wait for the navigation list.
1448 ['#navigation-list > .root-item > ' +
1449 '.volume-icon[volume-type-icon="drive"]'],
1452 // Ensure that the 'Gogole Drive' is selected.
1454 callRemoteTestUtil('checkSelectedVolume',
1456 ['Google Drive', '/drive/root'],
1459 // Ensure that the current directory is changed to 'Gogole Drive'.
1461 chrome.test.assertTrue(result);
1462 callRemoteTestUtil('waitForFiles',
1464 [TestEntryInfo.getExpectedRows(BASIC_DRIVE_ENTRY_SET),
1465 {ignoreLastModifiedTime: true}],
1468 // Press the UP key.
1470 chrome.test.assertTrue(result);
1471 callRemoteTestUtil('fakeKeyDown',
1473 ['#navigation-list', 'Up', true],
1476 // Ensure that the 'Gogole Drive' is still selected since it is the first
1479 chrome.test.assertTrue(result);
1480 callRemoteTestUtil('checkSelectedVolume',
1482 ['Google Drive', '/drive/root'],
1485 // Press the DOWN key.
1487 chrome.test.assertTrue(result);
1488 callRemoteTestUtil('fakeKeyDown',
1490 ['#navigation-list', 'Down', true],
1493 // Ensure that the 'Download' is selected.
1495 chrome.test.assertTrue(result);
1496 callRemoteTestUtil('checkSelectedVolume',
1498 ['Downloads', '/Downloads'],
1501 // Ensure that the current directory is changed to 'Downloads'.
1503 chrome.test.assertTrue(result);
1504 callRemoteTestUtil('waitForFiles',
1506 [TestEntryInfo.getExpectedRows(BASIC_LOCAL_ENTRY_SET),
1507 {ignoreLastModifiedTime: true}],
1510 // Press the DOWN key again.
1512 chrome.test.assertTrue(result);
1513 callRemoteTestUtil('fakeKeyDown',
1515 ['#navigation-list', 'Down', true],
1518 // Ensure that the 'Downloads' is still selected since it is the last item.
1520 chrome.test.assertTrue(result);
1521 callRemoteTestUtil('checkSelectedVolume',
1523 ['Downloads', '/Downloads'],
1526 // Check for errors.
1528 chrome.test.assertTrue(result);
1529 checkIfNoErrorsOccured(this.next);
1535 * Tests restoring geometry of the Files app.
1537 testcase.restoreGeometry = function() {
1541 // Set up File Manager.
1543 var appState = {defaultPath: '/Downloads'};
1544 setupAndWaitUntilReady(appState, this.next);
1546 // Resize the window to minimal dimensions.
1550 'resizeWindow', appId, [640, 480], this.next);
1552 // Check the current window's size.
1554 callRemoteTestUtil('waitForWindowGeometry',
1559 // Enlarge the window by 10 pixels.
1562 'resizeWindow', appId, [650, 490], this.next);
1564 // Check the current window's size.
1566 callRemoteTestUtil('waitForWindowGeometry',
1571 // Open another window, where the current view is restored.
1573 var appState = {defaultPath: '/Downloads'};
1574 setupAndWaitUntilReady(appState, this.next);
1576 // Check the next window's size.
1579 callRemoteTestUtil('waitForWindowGeometry',
1584 // Check for errors.
1586 checkIfNoErrorsOccured(this.next);
1592 * Tests to traverse local directories.
1594 testcase.traverseDownloads =
1595 testcase.intermediate.traverseDirectories.bind(null, '/Downloads');
1598 * Tests to traverse drive directories.
1600 testcase.traverseDrive =
1601 testcase.intermediate.traverseDirectories.bind(null, '/drive/root');
1604 * Tests the focus behavior of the search box.
1606 testcase.searchBoxFocus = function() {
1609 // Set up File Manager.
1611 var appState = {defaultPath: '/drive/root'};
1612 setupAndWaitUntilReady(appState, this.next);
1614 // Check that the file list has the focus on launch.
1618 'waitForElement', appId, ['#file-list:focus'], this.next);
1620 // Press the Ctrl-F key.
1622 callRemoteTestUtil('fakeKeyDown',
1624 ['body', 'U+0046', true],
1627 // Check that the search box has the focus.
1629 chrome.test.assertTrue(result);
1631 'waitForElement', appId, ['#search-box input:focus'], this.next);
1633 // Press the Tab key.
1635 callRemoteTestUtil('fakeKeyDown',
1637 ['body', 'U+0009', false],
1640 // Check that the file list has the focus.
1642 chrome.test.assertTrue(result);
1644 'waitForElement', appId, ['#file-list:focus'], this.next);
1646 // Check for errors.
1648 checkIfNoErrorsOccured(this.next);