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

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

Issue 342068: Third patch in getting rid of caching MessageLoop pointers and always using C... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/file_util.h" 5 #include "base/file_util.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/autocomplete/history_url_provider.h" 9 #include "chrome/browser/autocomplete/history_url_provider.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h" 10 #include "chrome/browser/bookmarks/bookmark_model.h"
11 #include "chrome/browser/chrome_thread.h"
11 #include "chrome/browser/history/history.h" 12 #include "chrome/browser/history/history.h"
12 #include "chrome/test/testing_profile.h" 13 #include "chrome/test/testing_profile.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #if defined(OS_MACOSX) 15 #if defined(OS_MACOSX)
15 #include "base/mac_util.h" 16 #include "base/mac_util.h"
16 #endif 17 #endif
17 18
18 using base::Time; 19 using base::Time;
19 using base::TimeDelta; 20 using base::TimeDelta;
20 21
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 {"http://www.17173.com/", L"Domain with number", 3, 3, false}, 88 {"http://www.17173.com/", L"Domain with number", 3, 3, false},
88 89
89 // URLs to test exact-matching behavior. 90 // URLs to test exact-matching behavior.
90 {"http://go/", L"Intranet URL", 1, 1, false}, 91 {"http://go/", L"Intranet URL", 1, 1, false},
91 {"http://gooey/", L"Intranet URL 2", 5, 5, false}, 92 {"http://gooey/", L"Intranet URL 2", 5, 5, false},
92 93
93 }; 94 };
94 95
95 class HistoryURLProviderTest : public testing::Test, 96 class HistoryURLProviderTest : public testing::Test,
96 public ACProviderListener { 97 public ACProviderListener {
98 public:
99 HistoryURLProviderTest()
100 : ui_thread_(ChromeThread::UI, &message_loop_),
101 file_thread_(ChromeThread::FILE, &message_loop_) {}
102
97 // ACProviderListener 103 // ACProviderListener
98 virtual void OnProviderUpdate(bool updated_matches); 104 virtual void OnProviderUpdate(bool updated_matches);
99 105
100 protected: 106 protected:
101 // testing::Test 107 // testing::Test
102 virtual void SetUp(); 108 virtual void SetUp();
103 virtual void TearDown(); 109 virtual void TearDown();
104 110
105 // Fills test data into the history system 111 // Fills test data into the history system
106 void FillData(); 112 void FillData();
107 113
108 // Runs an autocomplete query on |text| and checks to see that the returned 114 // Runs an autocomplete query on |text| and checks to see that the returned
109 // results' destination URLs match those provided. 115 // results' destination URLs match those provided.
110 void RunTest(const std::wstring text, 116 void RunTest(const std::wstring text,
111 const std::wstring& desired_tld, 117 const std::wstring& desired_tld,
112 bool prevent_inline_autocomplete, 118 bool prevent_inline_autocomplete,
113 const std::string* expected_urls, 119 const std::string* expected_urls,
114 size_t num_results); 120 size_t num_results);
115 121
116 MessageLoopForUI message_loop_; 122 MessageLoopForUI message_loop_;
123 ChromeThread ui_thread_;
124 ChromeThread file_thread_;
117 ACMatches matches_; 125 ACMatches matches_;
118 scoped_ptr<TestingProfile> profile_; 126 scoped_ptr<TestingProfile> profile_;
119 HistoryService* history_service_; 127 HistoryService* history_service_;
120 128
121 private: 129 private:
122 scoped_refptr<HistoryURLProvider> autocomplete_; 130 scoped_refptr<HistoryURLProvider> autocomplete_;
123 }; 131 };
124 132
125 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { 133 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) {
126 if (autocomplete_->done()) 134 if (autocomplete_->done())
127 MessageLoop::current()->Quit(); 135 MessageLoop::current()->Quit();
128 } 136 }
129 137
130 void HistoryURLProviderTest::SetUp() { 138 void HistoryURLProviderTest::SetUp() {
131 profile_.reset(new TestingProfile()); 139 profile_.reset(new TestingProfile());
132 profile_->CreateBookmarkModel(true); 140 profile_->CreateBookmarkModel(true);
141 profile_->BlockUntilBookmarkModelLoaded();
133 profile_->CreateHistoryService(true); 142 profile_->CreateHistoryService(true);
134 history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); 143 history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS);
135 144
136 autocomplete_ = new HistoryURLProvider(this, profile_.get()); 145 autocomplete_ = new HistoryURLProvider(this, profile_.get());
137 146
138 FillData(); 147 FillData();
139 } 148 }
140 149
141 void HistoryURLProviderTest::TearDown() { 150 void HistoryURLProviderTest::TearDown() {
142 autocomplete_ = NULL; 151 autocomplete_ = NULL;
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 377
369 // An input looks like a IP address like "127.0.0.1" should result in 378 // An input looks like a IP address like "127.0.0.1" should result in
370 // "http://127.0.0.1/". 379 // "http://127.0.0.1/".
371 std::string fixup_4[] = {"http://127.0.0.1/"}; 380 std::string fixup_4[] = {"http://127.0.0.1/"};
372 RunTest(L"127.0.0.1", std::wstring(), false, fixup_4, arraysize(fixup_4)); 381 RunTest(L"127.0.0.1", std::wstring(), false, fixup_4, arraysize(fixup_4));
373 382
374 // An number "17173" should result in "http://www.17173.com/" in db. 383 // An number "17173" should result in "http://www.17173.com/" in db.
375 std::string fixup_5[] = {"http://www.17173.com/"}; 384 std::string fixup_5[] = {"http://www.17173.com/"};
376 RunTest(L"17173", std::wstring(), false, fixup_5, arraysize(fixup_5)); 385 RunTest(L"17173", std::wstring(), false, fixup_5, arraysize(fixup_5));
377 } 386 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698