Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(516)

Unified Diff: chrome/browser/chromeos/drive/file_system/search_operation_unittest.cc

Issue 16081002: Add SearchOperationTest for drive::file_system::SearchOperation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/file_system_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/chromeos/drive/file_system/search_operation_unittest.cc
diff --git a/chrome/browser/chromeos/drive/file_system/search_operation_unittest.cc b/chrome/browser/chromeos/drive/file_system/search_operation_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bccc9b1a9b663a10d232e8cddcd10f7135ad0356
--- /dev/null
+++ b/chrome/browser/chromeos/drive/file_system/search_operation_unittest.cc
@@ -0,0 +1,113 @@
+// Copyright 2013 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.
+
+#include "chrome/browser/chromeos/drive/file_system/search_operation.h"
+
+#include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
+#include "chrome/browser/google_apis/fake_drive_service.h"
+#include "chrome/browser/google_apis/gdata_wapi_parser.h"
+#include "chrome/browser/google_apis/test_util.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace drive {
+namespace file_system {
+
+namespace {
+
+struct SearchResultPair {
+ const char* path;
+ const bool is_directory;
+};
+
+} // namespace
+
+typedef OperationTestBase SearchOperationTest;
+
+TEST_F(SearchOperationTest, ContentSearch) {
+ SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
+
+ const SearchResultPair kExpectedResults[] = {
+ { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder",
+ true },
+ { "drive/root/Directory 1/Sub Directory Folder", true },
+ { "drive/root/Directory 1/SubDirectory File 1.txt", false },
+ { "drive/root/Directory 1", true },
+ { "drive/root/Directory 2 excludeDir-test", true },
+ };
+
+ FileError error = FILE_ERROR_FAILED;
+ GURL next_feed;
+ scoped_ptr<std::vector<SearchResultInfo> > results;
+
+ operation.Search("Directory", GURL(),
+ google_apis::test_util::CreateCopyResultCallback(
+ &error, &next_feed, &results));
+ google_apis::test_util::RunBlockingPoolTask();
+
+ EXPECT_EQ(FILE_ERROR_OK, error);
+ EXPECT_EQ(GURL(), next_feed);
+ EXPECT_EQ(ARRAYSIZE_UNSAFE(kExpectedResults), results->size());
+ for (size_t i = 0; i < results->size(); i++) {
+ EXPECT_EQ(kExpectedResults[i].path, results->at(i).path.AsUTF8Unsafe());
+ EXPECT_EQ(kExpectedResults[i].is_directory,
+ results->at(i).entry.file_info().is_directory());
+ }
+}
+
+TEST_F(SearchOperationTest, ContentSearchWithNewEntry) {
+ SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
+
+ // Create a new directory in the drive service.
+ 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!",
+ google_apis::test_util::CreateCopyResultCallback(
+ &gdata_error, &resource_entry));
+ google_apis::test_util::RunBlockingPoolTask();
+ ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error);
+
+ // As the result of the first Search(), only entries in the current file
+ // system snapshot are expected to be returned (i.e. "New Directory 1!"
+ // shouldn't be included in the search result even though it matches
+ // "Directory 1".
+ const SearchResultPair kExpectedResults[] = {
+ { "drive/root/Directory 1", true }
+ };
+
+ FileError error = FILE_ERROR_FAILED;
+ GURL next_feed;
+ scoped_ptr<std::vector<SearchResultInfo> > results;
+
+ operation.Search("\"Directory 1\"", GURL(),
+ google_apis::test_util::CreateCopyResultCallback(
+ &error, &next_feed, &results));
+ google_apis::test_util::RunBlockingPoolTask();
+
+ EXPECT_EQ(FILE_ERROR_OK, error);
+ EXPECT_EQ(GURL(), next_feed);
+ ASSERT_EQ(1U, results->size());
+ EXPECT_EQ(kExpectedResults[0].path, results->at(0).path.AsUTF8Unsafe());
+}
+
+TEST_F(SearchOperationTest, ContentSearchEmptyResult) {
+ SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
+
+ FileError error = FILE_ERROR_FAILED;
+ GURL next_feed;
+ scoped_ptr<std::vector<SearchResultInfo> > results;
+
+ operation.Search("\"no-match query\"", GURL(),
+ google_apis::test_util::CreateCopyResultCallback(
+ &error, &next_feed, &results));
+ google_apis::test_util::RunBlockingPoolTask();
+
+ EXPECT_EQ(FILE_ERROR_OK, error);
+ EXPECT_EQ(GURL(), next_feed);
+ EXPECT_EQ(0U, results->size());
+}
+
+} // namespace file_system
+} // namespace drive
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/file_system_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698