This source file includes following definitions.
- TEST_F
- TEST_F
- TEST_F
- TEST_F
#include "chrome/browser/chromeos/drive/file_system/search_operation.h"
#include "base/callback_helpers.h"
#include "chrome/browser/chromeos/drive/change_list_loader.h"
#include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
#include "chrome/browser/drive/fake_drive_service.h"
#include "google_apis/drive/gdata_wapi_parser.h"
#include "google_apis/drive/test_util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace drive {
namespace file_system {
typedef OperationTestBase SearchOperationTest;
TEST_F(SearchOperationTest, ContentSearch) {
SearchOperation operation(blocking_task_runner(), scheduler(), metadata(),
loader_controller());
std::set<std::string> expected_results;
expected_results.insert(
"drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder");
expected_results.insert("drive/root/Directory 1/Sub Directory Folder");
expected_results.insert("drive/root/Directory 1/SubDirectory File 1.txt");
expected_results.insert("drive/root/Directory 1");
expected_results.insert("drive/root/Directory 2 excludeDir-test");
FileError error = FILE_ERROR_FAILED;
GURL next_link;
scoped_ptr<std::vector<SearchResultInfo> > results;
operation.Search("Directory", GURL(),
google_apis::test_util::CreateCopyResultCallback(
&error, &next_link, &results));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_TRUE(next_link.is_empty());
EXPECT_EQ(expected_results.size(), results->size());
for (size_t i = 0; i < results->size(); i++) {
EXPECT_TRUE(expected_results.count(results->at(i).path.AsUTF8Unsafe()))
<< results->at(i).path.AsUTF8Unsafe();
}
}
TEST_F(SearchOperationTest, ContentSearchWithNewEntry) {
SearchOperation operation(blocking_task_runner(), scheduler(), metadata(),
loader_controller());
google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR;
scoped_ptr<google_apis::ResourceEntry> resource_entry;
fake_service()->AddNewDirectory(
fake_service()->GetRootResourceId(),
"New Directory 1!",
DriveServiceInterface::AddNewDirectoryOptions(),
google_apis::test_util::CreateCopyResultCallback(
&gdata_error, &resource_entry));
test_util::RunBlockingPoolTask();
ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error);
std::set<std::string> expected_results;
expected_results.insert("drive/root/Directory 1");
expected_results.insert("drive/other/New Directory 1!");
FileError error = FILE_ERROR_FAILED;
GURL next_link;
scoped_ptr<std::vector<SearchResultInfo> > results;
operation.Search("\"Directory 1\"", GURL(),
google_apis::test_util::CreateCopyResultCallback(
&error, &next_link, &results));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_TRUE(next_link.is_empty());
ASSERT_EQ(expected_results.size(), results->size());
for (size_t i = 0; i < results->size(); i++) {
EXPECT_TRUE(expected_results.count(results->at(i).path.AsUTF8Unsafe()))
<< results->at(i).path.AsUTF8Unsafe();
}
ASSERT_EQ(FILE_ERROR_OK, CheckForUpdates());
expected_results.clear();
expected_results.insert("drive/root/Directory 1");
expected_results.insert("drive/root/New Directory 1!");
error = FILE_ERROR_FAILED;
operation.Search("\"Directory 1\"", GURL(),
google_apis::test_util::CreateCopyResultCallback(
&error, &next_link, &results));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_TRUE(next_link.is_empty());
ASSERT_EQ(expected_results.size(), results->size());
for (size_t i = 0; i < results->size(); i++) {
EXPECT_TRUE(expected_results.count(results->at(i).path.AsUTF8Unsafe()))
<< results->at(i).path.AsUTF8Unsafe();
}
}
TEST_F(SearchOperationTest, ContentSearchEmptyResult) {
SearchOperation operation(blocking_task_runner(), scheduler(), metadata(),
loader_controller());
FileError error = FILE_ERROR_FAILED;
GURL next_link;
scoped_ptr<std::vector<SearchResultInfo> > results;
operation.Search("\"no-match query\"", GURL(),
google_apis::test_util::CreateCopyResultCallback(
&error, &next_link, &results));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
EXPECT_TRUE(next_link.is_empty());
EXPECT_EQ(0U, results->size());
}
TEST_F(SearchOperationTest, Lock) {
SearchOperation operation(blocking_task_runner(), scheduler(), metadata(),
loader_controller());
scoped_ptr<base::ScopedClosureRunner> lock = loader_controller()->GetLock();
FileError error = FILE_ERROR_FAILED;
GURL next_link;
scoped_ptr<std::vector<SearchResultInfo> > results;
operation.Search("\"Directory 1\"", GURL(),
google_apis::test_util::CreateCopyResultCallback(
&error, &next_link, &results));
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_FAILED, error);
EXPECT_FALSE(results);
lock.reset();
test_util::RunBlockingPoolTask();
EXPECT_EQ(FILE_ERROR_OK, error);
ASSERT_TRUE(results);
EXPECT_EQ(1u, results->size());
}
}
}