Commit b64e3483 authored by Stuart Langley's avatar Stuart Langley Committed by Commit Bot

Show team drives results in file system search results.

SearchMetadata is used to query for recents and file system searches.

There are a number of folders under <drive> that are hidden by default,
and to be searched needed to be whitelisted. This adds team_drives to
the whitelist and adds unit tests to verify that team drives results
are returned in searches.

Bug: 866575
Change-Id: I583ba06672f3d6a8112680ff22124b65048b74a7
Reviewed-on: https://chromium-review.googlesource.com/1149669Reviewed-by: default avatarNoel Gordon <noel@chromium.org>
Commit-Queue: Stuart Langley <slangley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#578527}
parent adb11358
......@@ -5,6 +5,7 @@
#include "components/drive/chromeos/search_metadata.h"
#include <algorithm>
#include <map>
#include <queue>
#include <utility>
......@@ -85,9 +86,11 @@ class HiddenEntryClassifier {
HiddenEntryClassifier(ResourceMetadata* metadata,
const std::string& mydrive_local_id)
: metadata_(metadata) {
// Only things under My Drive and drive/other are not hidden.
// Only things under My Drive, drive/other and drive/team_drives are not
// hidden.
is_hiding_child_[mydrive_local_id] = false;
is_hiding_child_[util::kDriveOtherDirLocalId] = false;
is_hiding_child_[util::kDriveTeamDrivesDirLocalId] = false;
// Everything else is hidden, including the directories mentioned above
// themselves.
......
......@@ -25,7 +25,8 @@ namespace internal {
class ResourceMetadata;
typedef base::Callback<bool(const ResourceEntry&)> SearchMetadataPredicate;
typedef base::RepeatingCallback<bool(const ResourceEntry&)>
SearchMetadataPredicate;
// Searches the local resource metadata, and returns the entries
// |at_most_num_matches| that contain |query| in their base names. Search is
......
......@@ -146,6 +146,26 @@ class SearchMetadataTest : public testing::Test {
entry.mutable_file_specific_info()->set_content_mime_type(
drive::util::kGoogleDocumentMimeType);
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(entry, &local_id));
// drive/team_drives
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->GetIdByPath(
util::GetDriveTeamDrivesRootPath(), &local_id));
const std::string team_drive_root_local_id = local_id;
// drive/team_drives/TD-1
EXPECT_EQ(FILE_ERROR_OK, resource_metadata_->AddEntry(
GetDirectoryEntry("TD-1", "team_drive1", 1, 1,
team_drive_root_local_id),
&local_id));
const std::string team_drive_dir1_local_id = local_id;
// drive/team_drives/TD-1/TD File 1.txt
EXPECT_EQ(FILE_ERROR_OK,
resource_metadata_->AddEntry(
GetFileEntry("TD File 1.txt", "team_drive1_file1a", 2, 99,
team_drive_dir1_local_id),
&local_id));
}
ResourceEntry GetFileEntry(const std::string& name,
......@@ -219,6 +239,23 @@ TEST_F(SearchMetadataTest, SearchMetadata_RegularFile) {
result->at(0).path.AsUTF8Unsafe());
}
TEST_F(SearchMetadataTest, SearchMetadata_TeamDrive_RegularFile) {
FileError error = FILE_ERROR_FAILED;
std::unique_ptr<MetadataSearchResultVector> result;
SearchMetadata(
base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(),
"TD File 1.txt", base::BindRepeating(&MatchesType, SEARCH_METADATA_ALL),
kDefaultAtMostNumMatches, MetadataSearchOrder::LAST_ACCESSED,
google_apis::test_util::CreateCopyResultCallback(&error, &result));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
ASSERT_TRUE(result);
ASSERT_EQ(1U, result->size());
EXPECT_EQ("drive/team_drives/TD-1/TD File 1.txt",
result->at(0).path.AsUTF8Unsafe());
}
// This test checks if |FindAndHighlightWrapper| does case-insensitive search.
// Tricker test cases for |FindAndHighlightWrapper| can be found below.
TEST_F(SearchMetadataTest, SearchMetadata_CaseInsensitiveSearch) {
......@@ -317,6 +354,22 @@ TEST_F(SearchMetadataTest, SearchMetadata_Directory) {
EXPECT_EQ("drive/root/Directory-1", result->at(0).path.AsUTF8Unsafe());
}
TEST_F(SearchMetadataTest, SearchMetadata_TeamDrive_Directory) {
FileError error = FILE_ERROR_FAILED;
std::unique_ptr<MetadataSearchResultVector> result;
SearchMetadata(
base::ThreadTaskRunnerHandle::Get(), resource_metadata_.get(), "TD-1",
base::BindRepeating(&MatchesType, SEARCH_METADATA_ALL),
kDefaultAtMostNumMatches, MetadataSearchOrder::LAST_ACCESSED,
google_apis::test_util::CreateCopyResultCallback(&error, &result));
base::RunLoop().RunUntilIdle();
EXPECT_EQ(FILE_ERROR_OK, error);
ASSERT_TRUE(result);
ASSERT_EQ(1U, result->size());
EXPECT_EQ("drive/team_drives/TD-1", result->at(0).path.AsUTF8Unsafe());
}
TEST_F(SearchMetadataTest, SearchMetadata_HostedDocument) {
FileError error = FILE_ERROR_FAILED;
std::unique_ptr<MetadataSearchResultVector> 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