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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/search_operation_unittest.cc

Issue 137533009: drive: Stop depending on order of search results from tests (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/file_browser/drive_search_test/test.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/chromeos/drive/file_system/search_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/search_operation.h"
6 6
7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" 7 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
8 #include "chrome/browser/drive/fake_drive_service.h" 8 #include "chrome/browser/drive/fake_drive_service.h"
9 #include "google_apis/drive/gdata_wapi_parser.h" 9 #include "google_apis/drive/gdata_wapi_parser.h"
10 #include "google_apis/drive/test_util.h" 10 #include "google_apis/drive/test_util.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 namespace drive { 13 namespace drive {
14 namespace file_system { 14 namespace file_system {
15 15
16 namespace {
17
18 struct SearchResultPair {
19 const char* path;
20 const bool is_directory;
21 };
22
23 } // namespace
24
25 typedef OperationTestBase SearchOperationTest; 16 typedef OperationTestBase SearchOperationTest;
26 17
27 TEST_F(SearchOperationTest, ContentSearch) { 18 TEST_F(SearchOperationTest, ContentSearch) {
28 SearchOperation operation(blocking_task_runner(), scheduler(), metadata()); 19 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
29 20
30 const SearchResultPair kExpectedResults[] = { 21 std::set<std::string> expected_results;
31 { "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder", 22 expected_results.insert(
32 true }, 23 "drive/root/Directory 1/Sub Directory Folder/Sub Sub Directory Folder");
33 { "drive/root/Directory 1/Sub Directory Folder", true }, 24 expected_results.insert("drive/root/Directory 1/Sub Directory Folder");
34 { "drive/root/Directory 1/SubDirectory File 1.txt", false }, 25 expected_results.insert("drive/root/Directory 1/SubDirectory File 1.txt");
35 { "drive/root/Directory 1", true }, 26 expected_results.insert("drive/root/Directory 1");
36 { "drive/root/Directory 2 excludeDir-test", true }, 27 expected_results.insert("drive/root/Directory 2 excludeDir-test");
37 };
38 28
39 FileError error = FILE_ERROR_FAILED; 29 FileError error = FILE_ERROR_FAILED;
40 GURL next_link; 30 GURL next_link;
41 scoped_ptr<std::vector<SearchResultInfo> > results; 31 scoped_ptr<std::vector<SearchResultInfo> > results;
42 32
43 operation.Search("Directory", GURL(), 33 operation.Search("Directory", GURL(),
44 google_apis::test_util::CreateCopyResultCallback( 34 google_apis::test_util::CreateCopyResultCallback(
45 &error, &next_link, &results)); 35 &error, &next_link, &results));
46 test_util::RunBlockingPoolTask(); 36 test_util::RunBlockingPoolTask();
47 37
48 EXPECT_EQ(FILE_ERROR_OK, error); 38 EXPECT_EQ(FILE_ERROR_OK, error);
49 EXPECT_TRUE(next_link.is_empty()); 39 EXPECT_TRUE(next_link.is_empty());
50 EXPECT_EQ(ARRAYSIZE_UNSAFE(kExpectedResults), results->size()); 40 EXPECT_EQ(expected_results.size(), results->size());
51 for (size_t i = 0; i < results->size(); i++) { 41 for (size_t i = 0; i < results->size(); i++) {
52 EXPECT_EQ(kExpectedResults[i].path, results->at(i).path.AsUTF8Unsafe()); 42 EXPECT_TRUE(expected_results.count(results->at(i).path.AsUTF8Unsafe()))
53 EXPECT_EQ(kExpectedResults[i].is_directory, results->at(i).is_directory); 43 << results->at(i).path.AsUTF8Unsafe();
54 } 44 }
55 } 45 }
56 46
57 TEST_F(SearchOperationTest, ContentSearchWithNewEntry) { 47 TEST_F(SearchOperationTest, ContentSearchWithNewEntry) {
58 SearchOperation operation(blocking_task_runner(), scheduler(), metadata()); 48 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
59 49
60 // Create a new directory in the drive service. 50 // Create a new directory in the drive service.
61 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR; 51 google_apis::GDataErrorCode gdata_error = google_apis::GDATA_OTHER_ERROR;
62 scoped_ptr<google_apis::ResourceEntry> resource_entry; 52 scoped_ptr<google_apis::ResourceEntry> resource_entry;
63 fake_service()->AddNewDirectory( 53 fake_service()->AddNewDirectory(
64 fake_service()->GetRootResourceId(), 54 fake_service()->GetRootResourceId(),
65 "New Directory 1!", 55 "New Directory 1!",
66 google_apis::test_util::CreateCopyResultCallback( 56 google_apis::test_util::CreateCopyResultCallback(
67 &gdata_error, &resource_entry)); 57 &gdata_error, &resource_entry));
68 test_util::RunBlockingPoolTask(); 58 test_util::RunBlockingPoolTask();
69 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error); 59 ASSERT_EQ(google_apis::HTTP_CREATED, gdata_error);
70 60
71 // As the result of the first Search(), only entries in the current file 61 // As the result of the first Search(), only entries in the current file
72 // system snapshot are expected to be returned in the "right" path. New 62 // system snapshot are expected to be returned in the "right" path. New
73 // entries like "New Directory 1!" is temporarily added to "drive/other". 63 // entries like "New Directory 1!" is temporarily added to "drive/other".
74 const SearchResultPair kExpectedResultsBeforeLoad[] = { 64 std::set<std::string> expected_results;
75 { "drive/root/Directory 1", true }, 65 expected_results.insert("drive/root/Directory 1");
76 { "drive/other/New Directory 1!", true }, 66 expected_results.insert("drive/other/New Directory 1!");
77 };
78 67
79 FileError error = FILE_ERROR_FAILED; 68 FileError error = FILE_ERROR_FAILED;
80 GURL next_link; 69 GURL next_link;
81 scoped_ptr<std::vector<SearchResultInfo> > results; 70 scoped_ptr<std::vector<SearchResultInfo> > results;
82 71
83 operation.Search("\"Directory 1\"", GURL(), 72 operation.Search("\"Directory 1\"", GURL(),
84 google_apis::test_util::CreateCopyResultCallback( 73 google_apis::test_util::CreateCopyResultCallback(
85 &error, &next_link, &results)); 74 &error, &next_link, &results));
86 test_util::RunBlockingPoolTask(); 75 test_util::RunBlockingPoolTask();
87 76
88 EXPECT_EQ(FILE_ERROR_OK, error); 77 EXPECT_EQ(FILE_ERROR_OK, error);
89 EXPECT_TRUE(next_link.is_empty()); 78 EXPECT_TRUE(next_link.is_empty());
90 ASSERT_EQ(ARRAYSIZE_UNSAFE(kExpectedResultsBeforeLoad), results->size()); 79 ASSERT_EQ(expected_results.size(), results->size());
91 for (size_t i = 0; i < results->size(); i++) { 80 for (size_t i = 0; i < results->size(); i++) {
92 EXPECT_EQ(kExpectedResultsBeforeLoad[i].path, 81 EXPECT_TRUE(expected_results.count(results->at(i).path.AsUTF8Unsafe()))
93 results->at(i).path.AsUTF8Unsafe()); 82 << results->at(i).path.AsUTF8Unsafe();
94 EXPECT_EQ(kExpectedResultsBeforeLoad[i].is_directory,
95 results->at(i).is_directory);
96 } 83 }
97 84
98 // Load the change from FakeDriveService. 85 // Load the change from FakeDriveService.
99 ASSERT_EQ(FILE_ERROR_OK, CheckForUpdates()); 86 ASSERT_EQ(FILE_ERROR_OK, CheckForUpdates());
100 87
101 // Now the new entry must be reported to be in the right directory. 88 // Now the new entry must be reported to be in the right directory.
102 const SearchResultPair kExpectedResultsAfterLoad[] = { 89 expected_results.clear();
103 { "drive/root/Directory 1", true }, 90 expected_results.insert("drive/root/Directory 1");
104 { "drive/root/New Directory 1!", true }, 91 expected_results.insert("drive/root/New Directory 1!");
105 };
106 error = FILE_ERROR_FAILED; 92 error = FILE_ERROR_FAILED;
107 operation.Search("\"Directory 1\"", GURL(), 93 operation.Search("\"Directory 1\"", GURL(),
108 google_apis::test_util::CreateCopyResultCallback( 94 google_apis::test_util::CreateCopyResultCallback(
109 &error, &next_link, &results)); 95 &error, &next_link, &results));
110 test_util::RunBlockingPoolTask(); 96 test_util::RunBlockingPoolTask();
111 97
112 EXPECT_EQ(FILE_ERROR_OK, error); 98 EXPECT_EQ(FILE_ERROR_OK, error);
113 EXPECT_TRUE(next_link.is_empty()); 99 EXPECT_TRUE(next_link.is_empty());
114 ASSERT_EQ(ARRAYSIZE_UNSAFE(kExpectedResultsAfterLoad), results->size()); 100 ASSERT_EQ(expected_results.size(), results->size());
115 for (size_t i = 0; i < results->size(); i++) { 101 for (size_t i = 0; i < results->size(); i++) {
116 EXPECT_EQ(kExpectedResultsAfterLoad[i].path, 102 EXPECT_TRUE(expected_results.count(results->at(i).path.AsUTF8Unsafe()))
117 results->at(i).path.AsUTF8Unsafe()); 103 << results->at(i).path.AsUTF8Unsafe();
118 EXPECT_EQ(kExpectedResultsAfterLoad[i].is_directory,
119 results->at(i).is_directory);
120 } 104 }
121 } 105 }
122 106
123 TEST_F(SearchOperationTest, ContentSearchEmptyResult) { 107 TEST_F(SearchOperationTest, ContentSearchEmptyResult) {
124 SearchOperation operation(blocking_task_runner(), scheduler(), metadata()); 108 SearchOperation operation(blocking_task_runner(), scheduler(), metadata());
125 109
126 FileError error = FILE_ERROR_FAILED; 110 FileError error = FILE_ERROR_FAILED;
127 GURL next_link; 111 GURL next_link;
128 scoped_ptr<std::vector<SearchResultInfo> > results; 112 scoped_ptr<std::vector<SearchResultInfo> > results;
129 113
130 operation.Search("\"no-match query\"", GURL(), 114 operation.Search("\"no-match query\"", GURL(),
131 google_apis::test_util::CreateCopyResultCallback( 115 google_apis::test_util::CreateCopyResultCallback(
132 &error, &next_link, &results)); 116 &error, &next_link, &results));
133 test_util::RunBlockingPoolTask(); 117 test_util::RunBlockingPoolTask();
134 118
135 EXPECT_EQ(FILE_ERROR_OK, error); 119 EXPECT_EQ(FILE_ERROR_OK, error);
136 EXPECT_TRUE(next_link.is_empty()); 120 EXPECT_TRUE(next_link.is_empty());
137 EXPECT_EQ(0U, results->size()); 121 EXPECT_EQ(0U, results->size());
138 } 122 }
139 123
140 } // namespace file_system 124 } // namespace file_system
141 } // namespace drive 125 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/extensions/api_test/file_browser/drive_search_test/test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698