| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/chrome_thread.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 public: | 98 public: |
| 99 HistoryURLProviderTest() | 99 HistoryURLProviderTest() |
| 100 : ui_thread_(ChromeThread::UI, &message_loop_), | 100 : ui_thread_(ChromeThread::UI, &message_loop_), |
| 101 file_thread_(ChromeThread::FILE, &message_loop_) {} | 101 file_thread_(ChromeThread::FILE, &message_loop_) {} |
| 102 | 102 |
| 103 // ACProviderListener | 103 // ACProviderListener |
| 104 virtual void OnProviderUpdate(bool updated_matches); | 104 virtual void OnProviderUpdate(bool updated_matches); |
| 105 | 105 |
| 106 protected: | 106 protected: |
| 107 // testing::Test | 107 // testing::Test |
| 108 virtual void SetUp(); | 108 virtual void SetUp() { |
| 109 SetUpImpl(false); |
| 110 } |
| 109 virtual void TearDown(); | 111 virtual void TearDown(); |
| 110 | 112 |
| 111 // Fills test data into the history system | 113 // Does the real setup. |
| 114 void SetUpImpl(bool no_db); |
| 115 |
| 116 // Fills test data into the history system. |
| 112 void FillData(); | 117 void FillData(); |
| 113 | 118 |
| 114 // Runs an autocomplete query on |text| and checks to see that the returned | 119 // Runs an autocomplete query on |text| and checks to see that the returned |
| 115 // results' destination URLs match those provided. | 120 // results' destination URLs match those provided. |
| 116 void RunTest(const std::wstring text, | 121 void RunTest(const std::wstring text, |
| 117 const std::wstring& desired_tld, | 122 const std::wstring& desired_tld, |
| 118 bool prevent_inline_autocomplete, | 123 bool prevent_inline_autocomplete, |
| 119 const std::string* expected_urls, | 124 const std::string* expected_urls, |
| 120 size_t num_results); | 125 size_t num_results); |
| 121 | 126 |
| 122 MessageLoopForUI message_loop_; | 127 MessageLoopForUI message_loop_; |
| 123 ChromeThread ui_thread_; | 128 ChromeThread ui_thread_; |
| 124 ChromeThread file_thread_; | 129 ChromeThread file_thread_; |
| 125 ACMatches matches_; | 130 ACMatches matches_; |
| 126 scoped_ptr<TestingProfile> profile_; | 131 scoped_ptr<TestingProfile> profile_; |
| 127 HistoryService* history_service_; | 132 HistoryService* history_service_; |
| 128 | 133 |
| 129 private: | 134 private: |
| 130 scoped_refptr<HistoryURLProvider> autocomplete_; | 135 scoped_refptr<HistoryURLProvider> autocomplete_; |
| 131 }; | 136 }; |
| 132 | 137 |
| 138 class HistoryURLProviderTestNoDB : public HistoryURLProviderTest { |
| 139 protected: |
| 140 virtual void SetUp() { |
| 141 SetUpImpl(true); |
| 142 } |
| 143 }; |
| 144 |
| 133 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { | 145 void HistoryURLProviderTest::OnProviderUpdate(bool updated_matches) { |
| 134 if (autocomplete_->done()) | 146 if (autocomplete_->done()) |
| 135 MessageLoop::current()->Quit(); | 147 MessageLoop::current()->Quit(); |
| 136 } | 148 } |
| 137 | 149 |
| 138 void HistoryURLProviderTest::SetUp() { | 150 void HistoryURLProviderTest::SetUpImpl(bool no_db) { |
| 139 profile_.reset(new TestingProfile()); | 151 profile_.reset(new TestingProfile()); |
| 140 profile_->CreateBookmarkModel(true); | 152 profile_->CreateBookmarkModel(true); |
| 141 profile_->BlockUntilBookmarkModelLoaded(); | 153 profile_->BlockUntilBookmarkModelLoaded(); |
| 142 profile_->CreateHistoryService(true); | 154 profile_->CreateHistoryService(true, no_db); |
| 143 history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); | 155 history_service_ = profile_->GetHistoryService(Profile::EXPLICIT_ACCESS); |
| 144 | 156 |
| 145 autocomplete_ = new HistoryURLProvider(this, profile_.get()); | 157 autocomplete_ = new HistoryURLProvider(this, profile_.get()); |
| 146 | 158 |
| 147 FillData(); | 159 FillData(); |
| 148 } | 160 } |
| 149 | 161 |
| 150 void HistoryURLProviderTest::TearDown() { | 162 void HistoryURLProviderTest::TearDown() { |
| 151 autocomplete_ = NULL; | 163 autocomplete_ = NULL; |
| 152 } | 164 } |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 389 |
| 378 // An input looks like a IP address like "127.0.0.1" should result in | 390 // An input looks like a IP address like "127.0.0.1" should result in |
| 379 // "http://127.0.0.1/". | 391 // "http://127.0.0.1/". |
| 380 std::string fixup_4[] = {"http://127.0.0.1/"}; | 392 std::string fixup_4[] = {"http://127.0.0.1/"}; |
| 381 RunTest(L"127.0.0.1", std::wstring(), false, fixup_4, arraysize(fixup_4)); | 393 RunTest(L"127.0.0.1", std::wstring(), false, fixup_4, arraysize(fixup_4)); |
| 382 | 394 |
| 383 // An number "17173" should result in "http://www.17173.com/" in db. | 395 // An number "17173" should result in "http://www.17173.com/" in db. |
| 384 std::string fixup_5[] = {"http://www.17173.com/"}; | 396 std::string fixup_5[] = {"http://www.17173.com/"}; |
| 385 RunTest(L"17173", std::wstring(), false, fixup_5, arraysize(fixup_5)); | 397 RunTest(L"17173", std::wstring(), false, fixup_5, arraysize(fixup_5)); |
| 386 } | 398 } |
| 399 |
| 400 TEST_F(HistoryURLProviderTestNoDB, NavigateWithoutDB) { |
| 401 // Ensure that we will still produce matches for navigation when there is no |
| 402 // database. |
| 403 std::string navigation_1[] = {"http://test.com/"}; |
| 404 RunTest(L"test.com", std::wstring(), false, navigation_1, |
| 405 arraysize(navigation_1)); |
| 406 |
| 407 std::string navigation_2[] = {"http://slash/"}; |
| 408 RunTest(L"slash", std::wstring(), false, navigation_2, |
| 409 arraysize(navigation_2)); |
| 410 |
| 411 RunTest(L"this is a query", std::wstring(), false, NULL, 0); |
| 412 } |
| OLD | NEW |