diff --git a/chrome/browser/ash/file_manager/file_manager_browsertest.cc b/chrome/browser/ash/file_manager/file_manager_browsertest.cc index 1481e89ce89fd7..871e945c168353 100644 --- a/chrome/browser/ash/file_manager/file_manager_browsertest.cc +++ b/chrome/browser/ash/file_manager/file_manager_browsertest.cc @@ -1132,6 +1132,8 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P( TestCase("driveClickFirstSearchResult").FilesSwa(), TestCase("drivePressEnterToSearch"), TestCase("drivePressEnterToSearch").FilesSwa(), + TestCase("driveSearchAlwaysDisplaysMyDrive"), + TestCase("driveSearchAlwaysDisplaysMyDrive").FilesSwa(), TestCase("drivePressClearSearch"), TestCase("drivePressClearSearch").FilesSwa(), TestCase("drivePressCtrlAFromSearch"), @@ -1753,6 +1755,11 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P( TestCase("myFilesToolbarDelete"), TestCase("myFilesToolbarDelete").FilesSwa())); +WRAPPED_INSTANTIATE_TEST_SUITE_P( + Navigation, /* navigation.js */ + FilesAppBrowserTest, + ::testing::Values(TestCase("navigateToParent"))); + WRAPPED_INSTANTIATE_TEST_SUITE_P( InstallLinuxPackageDialog, /* install_linux_package_dialog.js */ FilesAppBrowserTest, diff --git a/ui/file_manager/integration_tests/file_manager/background.js b/ui/file_manager/integration_tests/file_manager/background.js index 95c3d45aca52f8..ac3f7d4b6a3ce4 100644 --- a/ui/file_manager/integration_tests/file_manager/background.js +++ b/ui/file_manager/integration_tests/file_manager/background.js @@ -27,6 +27,7 @@ import './keyboard_operations.js'; import './metadata.js'; import './metrics.js'; import './my_files.js'; +import './navigation.js'; import './office.js'; import './open_audio_media_app.js'; import './open_image_media_app.js'; diff --git a/ui/file_manager/integration_tests/file_manager/drive_specific.js b/ui/file_manager/integration_tests/file_manager/drive_specific.js index f864ac3ebe5a09..b6d28b82252bf7 100644 --- a/ui/file_manager/integration_tests/file_manager/drive_specific.js +++ b/ui/file_manager/integration_tests/file_manager/drive_specific.js @@ -38,6 +38,9 @@ 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. @@ -236,19 +239,51 @@ testcase.drivePressEnterToSearch = async () => { 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.drivePressEnterToSearch(); + 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, TestEntryInfo.getExpectedRows(BASIC_DRIVE_ENTRY_SET)); + await remoteCall.waitForFiles(appId, []); // Check that a11y message for clearing the search term has been issued. const a11yMessages = @@ -256,10 +291,15 @@ testcase.drivePressClearSearch = async () => { 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. + * Tests that pinning multiple files affects the pin action of individual + * files. */ testcase.drivePinMultiple = async () => { const appId = await setupAndWaitUntilReady(RootPath.DRIVE); @@ -492,8 +532,8 @@ testcase.drivePinToggleUpdatesInFakeEntries = async () => { }; /** - * 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). + * 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. diff --git a/ui/file_manager/integration_tests/file_manager/navigation.js b/ui/file_manager/integration_tests/file_manager/navigation.js new file mode 100644 index 00000000000000..50cffb29f61b68 --- /dev/null +++ b/ui/file_manager/integration_tests/file_manager/navigation.js @@ -0,0 +1,26 @@ +// Copyright 2022 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import {ENTRIES, RootPath} from '../test_util.js'; +import {testcase} from '../testcase.js'; + +import {remoteCall, setupAndWaitUntilReady} from './background.js'; + +/** Tests that the Backspace key navigates to parent directory. */ +testcase.navigateToParent = async () => { + // Open Files app on local Downloads. + const appId = + await setupAndWaitUntilReady(RootPath.DOWNLOADS, [ENTRIES.beautiful], []); + + // It should start in Downloads. + await remoteCall.waitUntilCurrentDirectoryIsChanged( + appId, '/My files/Downloads'); + + // Send the Backspace key to the file list. + const backspaceKey = ['#file-list', 'Backspace', false, false, false]; + await remoteCall.fakeKeyDown(appId, ...backspaceKey); + + // It should navigate to the parent. + await remoteCall.waitUntilCurrentDirectoryIsChanged(appId, '/My files'); +}; diff --git a/ui/file_manager/integration_tests/remote_call.js b/ui/file_manager/integration_tests/remote_call.js index 651fad61a85cbc..9b61df60af94da 100644 --- a/ui/file_manager/integration_tests/remote_call.js +++ b/ui/file_manager/integration_tests/remote_call.js @@ -939,4 +939,39 @@ export class RemoteCallFilesApp extends RemoteCall { chrome.test.assertTrue( await this.callRemoteTestUtil('disableBannersForTesting', appId, [])); } + + /** + * Sends text to the search box in the Files app. + * @param {string} appId App window Id + * @param {string} text The text to type in the search box. + */ + async typeSearchText(appId, text) { + const searchBoxInput = ['#search-box cr-input']; + + // Focus the search box. + await this.waitAndClickElement(appId, '#search-button'); + + // Input the text. + await this.inputText(appId, searchBoxInput, text); + + // Notify the element of the input. + chrome.test.assertTrue(await this.callRemoteTestUtil( + 'fakeEvent', appId, ['#search-box cr-input', 'input'])); + } + + /** + * Waits for the search box auto complete list to appear. + * @param {string} appId + * @return {!Promise>} Array of the names in the auto complete + * list. + */ + async waitForSearchAutoComplete(appId) { + // Wait for the list to appear. + await this.waitForElement(appId, '#autocomplete-list li'); + + // Return the result. + const elements = await this.callRemoteTestUtil( + 'deepQueryAllElements', appId, ['#autocomplete-list li']); + return elements.map((element) => element.text); + } }