Commit 0203197f authored by Sam McNally's avatar Sam McNally Committed by Commit Bot

Filter unavailable Drive files from launcher searches when offline.

Bug: 934549
Change-Id: Idd9d1f6c5733e4d993a0bd5d1bc4d33311622e4a
Reviewed-on: https://chromium-review.googlesource.com/c/1488394Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Sam McNally <sammc@chromium.org>
Auto-Submit: Sam McNally <sammc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635851}
parent b320833a
...@@ -86,6 +86,8 @@ const char kDriveConnectionReasonNotReady[] = "not_ready"; ...@@ -86,6 +86,8 @@ const char kDriveConnectionReasonNotReady[] = "not_ready";
const char kDriveConnectionReasonNoNetwork[] = "no_network"; const char kDriveConnectionReasonNoNetwork[] = "no_network";
const char kDriveConnectionReasonNoService[] = "no_service"; const char kDriveConnectionReasonNoService[] = "no_service";
constexpr char kAvailableOfflinePropertyName[] = "availableOffline";
// Maximum dimension of thumbnail in file manager. File manager shows 180x180 // Maximum dimension of thumbnail in file manager. File manager shows 180x180
// thumbnail. Given that we support hdpi devices, maximum dimension is 360. // thumbnail. Given that we support hdpi devices, maximum dimension is 360.
const int kFileManagerMaximumThumbnailDimension = 360; const int kFileManagerMaximumThumbnailDimension = 360;
...@@ -808,6 +810,8 @@ void OnSearchDriveFs( ...@@ -808,6 +810,8 @@ void OnSearchDriveFs(
bool is_dir = bool is_dir =
item->metadata->type == drivefs::mojom::FileMetadata::Type::kDirectory; item->metadata->type == drivefs::mojom::FileMetadata::Type::kDirectory;
entry.SetKey("fileIsDirectory", base::Value(is_dir)); entry.SetKey("fileIsDirectory", base::Value(is_dir));
entry.SetKey(kAvailableOfflinePropertyName,
base::Value(item->metadata->available_offline));
if (!filter_dirs || !is_dir) { if (!filter_dirs || !is_dir) {
result->GetList().emplace_back(std::move(entry)); result->GetList().emplace_back(std::move(entry));
} }
...@@ -1419,6 +1423,11 @@ void FileManagerPrivateSearchDriveMetadataFunction::OnSearchDriveFs( ...@@ -1419,6 +1423,11 @@ void FileManagerPrivateSearchDriveMetadataFunction::OnSearchDriveFs(
highlight = path.BaseName().value(); highlight = path.BaseName().value();
} }
} }
if (base::Value* availableOffline = entry.FindKeyOfType(
kAvailableOfflinePropertyName, base::Value::Type::BOOLEAN)) {
dict.SetKey(kAvailableOfflinePropertyName, std::move(*availableOffline));
entry.RemoveKey(kAvailableOfflinePropertyName);
}
dict.SetKey("entry", std::move(entry)); dict.SetKey("entry", std::move(entry));
dict.SetKey("highlightedBaseName", base::Value(highlight)); dict.SetKey("highlightedBaseName", base::Value(highlight));
results_list->GetList().emplace_back(std::move(dict)); results_list->GetList().emplace_back(std::move(dict));
......
...@@ -925,7 +925,9 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P( ...@@ -925,7 +925,9 @@ WRAPPED_INSTANTIATE_TEST_SUITE_P(
WRAPPED_INSTANTIATE_TEST_SUITE_P( WRAPPED_INSTANTIATE_TEST_SUITE_P(
LauncherSearch, /* launcher_search.js */ LauncherSearch, /* launcher_search.js */
FilesAppBrowserTest, FilesAppBrowserTest,
::testing::Values(TestCase("launcherOpenSearchResult"))); ::testing::Values(TestCase("launcherOpenSearchResult"),
TestCase("launcherSearch"),
TestCase("launcherSearchOffline").Offline()));
WRAPPED_INSTANTIATE_TEST_SUITE_P( WRAPPED_INSTANTIATE_TEST_SUITE_P(
Recents, /* recents.js */ Recents, /* recents.js */
......
...@@ -43,6 +43,8 @@ ...@@ -43,6 +43,8 @@
#include "chrome/browser/notifications/notification_display_service_tester.h" #include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h" #include "chrome/browser/sync_file_system/mock_remote_file_sync_service.h"
#include "chrome/browser/sync_file_system/sync_file_system_service_factory.h" #include "chrome/browser/sync_file_system/sync_file_system_service_factory.h"
#include "chrome/browser/ui/app_list/search/chrome_search_result.h"
#include "chrome/browser/ui/app_list/search/launcher_search/launcher_search_provider.h"
#include "chrome/browser/ui/ash/tablet_mode_client_test_util.h" #include "chrome/browser/ui/ash/tablet_mode_client_test_util.h"
#include "chrome/browser/ui/views/extensions/extension_dialog.h" #include "chrome/browser/ui/views/extensions/extension_dialog.h"
#include "chrome/browser/ui/views/select_file_dialog_extension.h" #include "chrome/browser/ui/views/select_file_dialog_extension.h"
...@@ -2032,6 +2034,25 @@ void FileManagerBrowserTestBase::OnCommand(const std::string& name, ...@@ -2032,6 +2034,25 @@ void FileManagerBrowserTestBase::OnCommand(const std::string& name,
return; return;
} }
if (name == "runLauncherSearch") {
app_list::LauncherSearchProvider search_provider(profile());
base::string16 query;
ASSERT_TRUE(value.GetString("query", &query));
search_provider.Start(query);
base::RunLoop run_loop;
search_provider.set_result_changed_callback(run_loop.QuitClosure());
run_loop.Run();
std::vector<base::Value> names;
for (auto& result : search_provider.results()) {
names.emplace_back(result->title());
}
std::sort(names.begin(), names.end());
base::JSONWriter::Write(base::Value(std::move(names)), output);
return;
}
FAIL() << "Unknown test message: " << name; FAIL() << "Unknown test message: " << name;
} }
......
...@@ -600,6 +600,10 @@ dictionary SearchResult { ...@@ -600,6 +600,10 @@ dictionary SearchResult {
// sub strings are highlighted with <b> element. Meta characters are escaped // sub strings are highlighted with <b> element. Meta characters are escaped
// like &lt;. // like &lt;.
DOMString highlightedBaseName; DOMString highlightedBaseName;
// Whether the file is available while offline. May be unset if not
// applicable.
boolean? availableOffline;
}; };
dictionary DriveConnectionState { dictionary DriveConnectionState {
......
...@@ -425,7 +425,8 @@ chrome.fileManagerPrivate.SearchMetadataParams; ...@@ -425,7 +425,8 @@ chrome.fileManagerPrivate.SearchMetadataParams;
/** /**
* @typedef {{ * @typedef {{
* entry: Entry, * entry: Entry,
* highlightedBaseName: string * highlightedBaseName: string,
* availableOffline: (boolean|undefined)
* }} * }}
*/ */
chrome.fileManagerPrivate.SearchResult; chrome.fileManagerPrivate.SearchResult;
......
...@@ -237,7 +237,12 @@ LauncherSearch.prototype.queryDriveEntries_ = (queryId, query, limit) => { ...@@ -237,7 +237,12 @@ LauncherSearch.prototype.queryDriveEntries_ = (queryId, query, limit) => {
const param = {query: query, types: 'ALL', maxResults: limit}; const param = {query: query, types: 'ALL', maxResults: limit};
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
chrome.fileManagerPrivate.searchDriveMetadata(param, results => { chrome.fileManagerPrivate.searchDriveMetadata(param, results => {
resolve(results.map(result => result.entry)); chrome.fileManagerPrivate.getDriveConnectionState(connectionState => {
if (connectionState.type !== 'online') {
results = results.filter(result => result.availableOffline !== false);
}
resolve(results.map(result => result.entry));
});
}); });
}); });
}; };
......
...@@ -41,4 +41,53 @@ testcase.launcherOpenSearchResult = async function() { ...@@ -41,4 +41,53 @@ testcase.launcherOpenSearchResult = async function() {
galleryAppId, 0, 0, imageNameNoExtension), galleryAppId, 0, 0, imageNameNoExtension),
'Failed to find the slide image element'); 'Failed to find the slide image element');
}; };
const hostedDocument = Object.assign(
{}, ENTRIES.testDocument,
{nameText: 'testDocument.txt.gdoc', targetPath: 'testDocument.txt'});
/**
* Tests Local and Drive files show up in search results.
*/
testcase.launcherSearch = async function() {
// Create a file in Downloads, and a pinned and unpinned file in Drive.
await setupAndWaitUntilReady(
'downloads', [ENTRIES.tallText],
[ENTRIES.hello, ENTRIES.pinned, hostedDocument]);
const result = JSON.parse(await sendTestMessage({
name: 'runLauncherSearch',
query: '.txt',
}));
chrome.test.assertEq(
[
ENTRIES.hello.targetPath,
ENTRIES.pinned.targetPath,
ENTRIES.tallText.targetPath,
hostedDocument.targetPath,
],
result);
};
/**
* Tests Local and Drive files show up in search results.
*/
testcase.launcherSearchOffline = async function() {
// Create a file in Downloads, and a pinned and unpinned file in Drive.
await setupAndWaitUntilReady(
'downloads', [ENTRIES.tallText],
[ENTRIES.hello, ENTRIES.pinned, hostedDocument]);
const result = JSON.parse(await sendTestMessage({
name: 'runLauncherSearch',
query: '.txt',
}));
chrome.test.assertEq(
[
ENTRIES.pinned.targetPath,
ENTRIES.tallText.targetPath,
],
result);
};
})(); })();
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment