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

Side by Side Diff: chrome/browser/autocomplete/autocomplete_unittest.cc

Issue 7744039: Switch ChromeTestSuite to the same convention as ContentTestSuite: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more fixing Created 9 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/scoped_ptr.h" 5 #include "base/memory/scoped_ptr.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete.h" 10 #include "chrome/browser/autocomplete/autocomplete.h"
11 #include "chrome/browser/autocomplete/autocomplete_match.h" 11 #include "chrome/browser/autocomplete/autocomplete_match.h"
12 #include "chrome/browser/autocomplete/keyword_provider.h" 12 #include "chrome/browser/autocomplete/keyword_provider.h"
13 #include "chrome/browser/autocomplete/search_provider.h" 13 #include "chrome/browser/autocomplete/search_provider.h"
14 #include "chrome/browser/search_engines/template_url.h" 14 #include "chrome/browser/search_engines/template_url.h"
15 #include "chrome/browser/search_engines/template_url_service.h" 15 #include "chrome/browser/search_engines/template_url_service.h"
16 #include "chrome/browser/search_engines/template_url_service_factory.h" 16 #include "chrome/browser/search_engines/template_url_service_factory.h"
17 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/test/base/testing_browser_process.h" 18 #include "chrome/test/base/testing_browser_process.h"
19 #include "chrome/test/base/testing_browser_process_test.h"
20 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
21 #include "content/common/notification_observer.h" 20 #include "content/common/notification_observer.h"
22 #include "content/common/notification_registrar.h" 21 #include "content/common/notification_registrar.h"
23 #include "content/common/notification_service.h" 22 #include "content/common/notification_service.h"
24 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
25 24
26 static std::ostream& operator<<(std::ostream& os, 25 static std::ostream& operator<<(std::ostream& os,
27 const AutocompleteResult::const_iterator& it) { 26 const AutocompleteResult::const_iterator& it) {
28 return os << static_cast<const AutocompleteMatch*>(&(*it)); 27 return os << static_cast<const AutocompleteMatch*>(&(*it));
29 } 28 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 ACProviders providers_; 119 ACProviders providers_;
121 120
122 AutocompleteResult result_; 121 AutocompleteResult result_;
123 122
124 private: 123 private:
125 // NotificationObserver 124 // NotificationObserver
126 virtual void Observe(int type, 125 virtual void Observe(int type,
127 const NotificationSource& source, 126 const NotificationSource& source,
128 const NotificationDetails& details); 127 const NotificationDetails& details);
129 128
130 ScopedTestingBrowserProcess browser_process_;
131
132 MessageLoopForUI message_loop_; 129 MessageLoopForUI message_loop_;
133 scoped_ptr<AutocompleteController> controller_; 130 scoped_ptr<AutocompleteController> controller_;
134 NotificationRegistrar registrar_; 131 NotificationRegistrar registrar_;
135 TestingProfile profile_; 132 TestingProfile profile_;
136 }; 133 };
137 134
138 void AutocompleteProviderTest::ResetControllerWithTestProviders( 135 void AutocompleteProviderTest::ResetControllerWithTestProviders(
139 bool same_destinations) { 136 bool same_destinations) {
140 // Forget about any existing providers. The controller owns them and will 137 // Forget about any existing providers. The controller owns them and will
141 // Release() them below, when we delete it during the call to reset(). 138 // Release() them below, when we delete it during the call to reset().
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 i != result_.end(); ++i) 263 i != result_.end(); ++i)
267 EXPECT_EQ(providers_[1], i->provider); 264 EXPECT_EQ(providers_[1], i->provider);
268 } 265 }
269 266
270 TEST_F(AutocompleteProviderTest, AllowExactKeywordMatch) { 267 TEST_F(AutocompleteProviderTest, AllowExactKeywordMatch) {
271 ResetControllerWithTestProvidersWithKeywordAndSearchProviders(); 268 ResetControllerWithTestProvidersWithKeywordAndSearchProviders();
272 RunExactKeymatchTest(true); 269 RunExactKeymatchTest(true);
273 RunExactKeymatchTest(false); 270 RunExactKeymatchTest(false);
274 } 271 }
275 272
276 typedef TestingBrowserProcessTest AutocompleteTest; 273 typedef testing::Test AutocompleteTest;
277 274
278 TEST_F(AutocompleteTest, InputType) { 275 TEST_F(AutocompleteTest, InputType) {
279 struct test_data { 276 struct test_data {
280 const string16 input; 277 const string16 input;
281 const AutocompleteInput::Type type; 278 const AutocompleteInput::Type type;
282 } input_cases[] = { 279 } input_cases[] = {
283 { ASCIIToUTF16(""), AutocompleteInput::INVALID }, 280 { ASCIIToUTF16(""), AutocompleteInput::INVALID },
284 { ASCIIToUTF16("?"), AutocompleteInput::FORCED_QUERY }, 281 { ASCIIToUTF16("?"), AutocompleteInput::FORCED_QUERY },
285 { ASCIIToUTF16("?foo"), AutocompleteInput::FORCED_QUERY }, 282 { ASCIIToUTF16("?foo"), AutocompleteInput::FORCED_QUERY },
286 { ASCIIToUTF16("?foo bar"), AutocompleteInput::FORCED_QUERY }, 283 { ASCIIToUTF16("?foo bar"), AutocompleteInput::FORCED_QUERY },
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 Component(12, 11) }, 454 Component(12, 11) },
458 { ASCIIToUTF16("view-source:"), Component(0, 11), kInvalidComponent }, 455 { ASCIIToUTF16("view-source:"), Component(0, 11), kInvalidComponent },
459 { ASCIIToUTF16("view-source:garbage"), kInvalidComponent, 456 { ASCIIToUTF16("view-source:garbage"), kInvalidComponent,
460 Component(12, 7) }, 457 Component(12, 7) },
461 { ASCIIToUTF16("view-source:http://http://foo"), Component(12, 4), 458 { ASCIIToUTF16("view-source:http://http://foo"), Component(12, 4),
462 Component(19, 4) }, 459 Component(19, 4) },
463 { ASCIIToUTF16("view-source:view-source:http://example.com/"), 460 { ASCIIToUTF16("view-source:view-source:http://example.com/"),
464 Component(12, 11), kInvalidComponent } 461 Component(12, 11), kInvalidComponent }
465 }; 462 };
466 463
467 ScopedTestingBrowserProcess browser_process;
468
469 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) { 464 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input_cases); ++i) {
470 Component scheme, host; 465 Component scheme, host;
471 AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input, 466 AutocompleteInput::ParseForEmphasizeComponents(input_cases[i].input,
472 string16(), 467 string16(),
473 &scheme, 468 &scheme,
474 &host); 469 &host);
475 AutocompleteInput input(input_cases[i].input, string16(), true, false, 470 AutocompleteInput input(input_cases[i].input, string16(), true, false,
476 true, AutocompleteInput::ALL_MATCHES); 471 true, AutocompleteInput::ALL_MATCHES);
477 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin) << "Input: " << 472 EXPECT_EQ(input_cases[i].scheme.begin, scheme.begin) << "Input: " <<
478 input_cases[i].input; 473 input_cases[i].input;
479 EXPECT_EQ(input_cases[i].scheme.len, scheme.len) << "Input: " << 474 EXPECT_EQ(input_cases[i].scheme.len, scheme.len) << "Input: " <<
480 input_cases[i].input; 475 input_cases[i].input;
481 EXPECT_EQ(input_cases[i].host.begin, host.begin) << "Input: " << 476 EXPECT_EQ(input_cases[i].host.begin, host.begin) << "Input: " <<
482 input_cases[i].input; 477 input_cases[i].input;
483 EXPECT_EQ(input_cases[i].host.len, host.len) << "Input: " << 478 EXPECT_EQ(input_cases[i].host.len, host.len) << "Input: " <<
484 input_cases[i].input; 479 input_cases[i].input;
485 } 480 }
486 } 481 }
487 482
488 } // namespace 483 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698