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/download/download_query_unittest.cc

Issue 16924017: A few minor changes to the chrome.downloads extension API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: @r214130 Created 7 years, 4 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 | « chrome/browser/download/download_query.cc ('k') | chrome/browser/download/download_util.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <string> 5 #include <string>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 scoped_ptr<base::Value> value(Value::CreateStringValue(cpp_value)); 121 scoped_ptr<base::Value> value(Value::CreateStringValue(cpp_value));
122 CHECK(query_.AddFilter(name, *value.get())); 122 CHECK(query_.AddFilter(name, *value.get()));
123 } 123 }
124 124
125 template<> void DownloadQueryTest::AddFilter( 125 template<> void DownloadQueryTest::AddFilter(
126 DownloadQuery::FilterType name, const char16* cpp_value) { 126 DownloadQuery::FilterType name, const char16* cpp_value) {
127 scoped_ptr<base::Value> value(Value::CreateStringValue(string16(cpp_value))); 127 scoped_ptr<base::Value> value(Value::CreateStringValue(string16(cpp_value)));
128 CHECK(query_.AddFilter(name, *value.get())); 128 CHECK(query_.AddFilter(name, *value.get()));
129 } 129 }
130 130
131 template<> void DownloadQueryTest::AddFilter(
132 DownloadQuery::FilterType name, std::vector<string16> cpp_value) {
133 scoped_ptr<base::ListValue> list(new base::ListValue());
134 for (std::vector<string16>::const_iterator it = cpp_value.begin();
135 it != cpp_value.end(); ++it) {
136 list->Append(Value::CreateStringValue(*it));
137 }
138 CHECK(query_.AddFilter(name, *list.get()));
139 }
140
141 template<> void DownloadQueryTest::AddFilter(
142 DownloadQuery::FilterType name, std::vector<std::string> cpp_value) {
143 scoped_ptr<base::ListValue> list(new base::ListValue());
144 for (std::vector<std::string>::const_iterator it = cpp_value.begin();
145 it != cpp_value.end(); ++it) {
146 list->Append(Value::CreateStringValue(*it));
147 }
148 CHECK(query_.AddFilter(name, *list.get()));
149 }
150
131 #if defined(OS_WIN) 151 #if defined(OS_WIN)
132 template<> void DownloadQueryTest::AddFilter( 152 template<> void DownloadQueryTest::AddFilter(
133 DownloadQuery::FilterType name, std::wstring cpp_value) { 153 DownloadQuery::FilterType name, std::wstring cpp_value) {
134 scoped_ptr<base::Value> value(Value::CreateStringValue(cpp_value)); 154 scoped_ptr<base::Value> value(Value::CreateStringValue(cpp_value));
135 CHECK(query_.AddFilter(name, *value.get())); 155 CHECK(query_.AddFilter(name, *value.get()));
136 } 156 }
137 #endif 157 #endif
138 158
139 TEST_F(DownloadQueryTest, DownloadQueryTest_ZeroItems) { 159 TEST_F(DownloadQueryTest, DownloadQueryTest_ZeroItems) {
140 Search(); 160 Search();
(...skipping 29 matching lines...) Expand all
170 static_cast<content::BrowserContext*>(NULL))); 190 static_cast<content::BrowserContext*>(NULL)));
171 base::FilePath match_filename(FILE_PATH_LITERAL("query")); 191 base::FilePath match_filename(FILE_PATH_LITERAL("query"));
172 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( 192 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef(
173 match_filename)); 193 match_filename));
174 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); 194 base::FilePath fail_filename(FILE_PATH_LITERAL("fail"));
175 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( 195 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef(
176 fail_filename)); 196 fail_filename));
177 GURL fail_url("http://example.com/fail"); 197 GURL fail_url("http://example.com/fail");
178 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); 198 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
179 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); 199 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
180 AddFilter(DownloadQuery::FILTER_QUERY, "query"); 200 std::vector<std::string> query_terms;
201 query_terms.push_back("query");
202 AddFilter(DownloadQuery::FILTER_QUERY, query_terms);
181 ExpectStandardFilterResults(); 203 ExpectStandardFilterResults();
182 } 204 }
183 205
184 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) { 206 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryUrl) {
185 CreateMocks(2); 207 CreateMocks(2);
186 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( 208 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return(
187 static_cast<content::BrowserContext*>(NULL))); 209 static_cast<content::BrowserContext*>(NULL)));
188 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( 210 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return(
189 static_cast<content::BrowserContext*>(NULL))); 211 static_cast<content::BrowserContext*>(NULL)));
190 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); 212 base::FilePath fail_filename(FILE_PATH_LITERAL("fail"));
191 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( 213 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef(
192 fail_filename)); 214 fail_filename));
193 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( 215 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef(
194 fail_filename)); 216 fail_filename));
195 GURL match_url("http://query.com/query"); 217 GURL match_url("http://query.com/query");
196 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url)); 218 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(match_url));
197 GURL fail_url("http://example.com/fail"); 219 GURL fail_url("http://example.com/fail");
198 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); 220 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
199 AddFilter(DownloadQuery::FILTER_QUERY, "query"); 221 std::vector<std::string> query_terms;
222 query_terms.push_back("query");
223 AddFilter(DownloadQuery::FILTER_QUERY, query_terms);
200 ExpectStandardFilterResults(); 224 ExpectStandardFilterResults();
201 } 225 }
202 226
203 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilenameI18N) { 227 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterGenericQueryFilenameI18N) {
204 CreateMocks(2); 228 CreateMocks(2);
205 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return( 229 EXPECT_CALL(mock(0), GetBrowserContext()).WillRepeatedly(Return(
206 static_cast<content::BrowserContext*>(NULL))); 230 static_cast<content::BrowserContext*>(NULL)));
207 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return( 231 EXPECT_CALL(mock(1), GetBrowserContext()).WillRepeatedly(Return(
208 static_cast<content::BrowserContext*>(NULL))); 232 static_cast<content::BrowserContext*>(NULL)));
209 const base::FilePath::StringType kTestString( 233 const base::FilePath::StringType kTestString(
210 #if defined(OS_POSIX) 234 #if defined(OS_POSIX)
211 "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd" 235 "/\xe4\xbd\xa0\xe5\xa5\xbd\xe4\xbd\xa0\xe5\xa5\xbd"
212 #elif defined(OS_WIN) 236 #elif defined(OS_WIN)
213 L"/\x4f60\x597d\x4f60\x597d" 237 L"/\x4f60\x597d\x4f60\x597d"
214 #endif 238 #endif
215 ); 239 );
216 base::FilePath match_filename(kTestString); 240 base::FilePath match_filename(kTestString);
217 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( 241 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef(
218 match_filename)); 242 match_filename));
219 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); 243 base::FilePath fail_filename(FILE_PATH_LITERAL("fail"));
220 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( 244 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef(
221 fail_filename)); 245 fail_filename));
222 GURL fail_url("http://example.com/fail"); 246 GURL fail_url("http://example.com/fail");
223 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); 247 EXPECT_CALL(mock(0), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
224 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url)); 248 EXPECT_CALL(mock(1), GetOriginalUrl()).WillRepeatedly(ReturnRef(fail_url));
225 AddFilter(DownloadQuery::FILTER_QUERY, kTestString); 249 std::vector<base::FilePath::StringType> query_terms;
250 query_terms.push_back(kTestString);
251 AddFilter(DownloadQuery::FILTER_QUERY, query_terms);
226 ExpectStandardFilterResults(); 252 ExpectStandardFilterResults();
227 } 253 }
228 254
229 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterFilenameRegex) { 255 TEST_F(DownloadQueryTest, DownloadQueryTest_FilterFilenameRegex) {
230 CreateMocks(2); 256 CreateMocks(2);
231 base::FilePath match_filename(FILE_PATH_LITERAL("query")); 257 base::FilePath match_filename(FILE_PATH_LITERAL("query"));
232 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef( 258 EXPECT_CALL(mock(0), GetTargetFilePath()).WillRepeatedly(ReturnRef(
233 match_filename)); 259 match_filename));
234 base::FilePath fail_filename(FILE_PATH_LITERAL("fail")); 260 base::FilePath fail_filename(FILE_PATH_LITERAL("fail"));
235 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef( 261 EXPECT_CALL(mock(1), GetTargetFilePath()).WillRepeatedly(ReturnRef(
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 base::Time start = base::Time::Now(); 609 base::Time start = base::Time::Now();
584 Search(); 610 Search();
585 base::Time end = base::Time::Now(); 611 base::Time end = base::Time::Now();
586 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0; 612 double nanos = (end - start).InMillisecondsF() * 1000.0 * 1000.0;
587 double nanos_per_item = nanos / static_cast<double>(kNumItems); 613 double nanos_per_item = nanos / static_cast<double>(kNumItems);
588 double nanos_per_item_per_filter = nanos_per_item 614 double nanos_per_item_per_filter = nanos_per_item
589 / static_cast<double>(kNumFilters); 615 / static_cast<double>(kNumFilters);
590 std::cout << "Search took " << nanos_per_item_per_filter 616 std::cout << "Search took " << nanos_per_item_per_filter
591 << " nanoseconds per item per filter.\n"; 617 << " nanoseconds per item per filter.\n";
592 } 618 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_query.cc ('k') | chrome/browser/download/download_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698