| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete.h" | 9 #include "chrome/browser/autocomplete/autocomplete.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 provider_ = new HistoryContentsProvider(this, profile_.get()); | 83 provider_ = new HistoryContentsProvider(this, profile_.get()); |
| 84 } | 84 } |
| 85 | 85 |
| 86 virtual void TearDown() { | 86 virtual void TearDown() { |
| 87 provider_ = NULL; | 87 provider_ = NULL; |
| 88 profile_.reset(NULL); | 88 profile_.reset(NULL); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // ACProviderListener | 91 // ACProviderListener |
| 92 virtual void OnProviderUpdate(bool updated_matches) { | 92 virtual void OnProviderUpdate(bool updated_matches) { |
| 93 // When we quit, the test will get back control. | 93 // We must quit the message loop (if running) to return control to the test. |
| 94 MessageLoop::current()->Quit(); | 94 // Note, calling Quit() directly will checkfail if the loop isn't running, |
| 95 // so we post a task, which is safe for either case. |
| 96 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 95 } | 97 } |
| 96 | 98 |
| 97 MessageLoopForUI message_loop_; | 99 MessageLoopForUI message_loop_; |
| 98 BrowserThread ui_thread_; | 100 BrowserThread ui_thread_; |
| 99 BrowserThread file_thread_; | 101 BrowserThread file_thread_; |
| 100 | 102 |
| 101 std::wstring history_dir_; | 103 std::wstring history_dir_; |
| 102 | 104 |
| 103 scoped_ptr<TestingProfile> profile_; | 105 scoped_ptr<TestingProfile> profile_; |
| 104 scoped_refptr<HistoryContentsProvider> provider_; | 106 scoped_refptr<HistoryContentsProvider> provider_; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 AutocompleteInput async_input(L"bar", std::wstring(), true, false, true, | 179 AutocompleteInput async_input(L"bar", std::wstring(), true, false, true, |
| 178 false); | 180 false); |
| 179 provider()->Start(async_input, false); | 181 provider()->Start(async_input, false); |
| 180 const ACMatches& m2 = matches(); | 182 const ACMatches& m2 = matches(); |
| 181 ASSERT_EQ(1U, m2.size()); | 183 ASSERT_EQ(1U, m2.size()); |
| 182 EXPECT_EQ(bookmark_url, m2[0].destination_url); | 184 EXPECT_EQ(bookmark_url, m2[0].destination_url); |
| 183 | 185 |
| 184 // Run the message loop (needed for async history results). | 186 // Run the message loop (needed for async history results). |
| 185 MessageLoop::current()->Run(); | 187 MessageLoop::current()->Run(); |
| 186 | 188 |
| 187 // We should two urls now, bookmark_url and http://www.google.com/3. | 189 // We should have two urls now, bookmark_url and http://www.google.com/3. |
| 188 const ACMatches& m3 = matches(); | 190 const ACMatches& m3 = matches(); |
| 189 ASSERT_EQ(2U, m3.size()); | 191 ASSERT_EQ(2U, m3.size()); |
| 190 if (bookmark_url == m3[0].destination_url) { | 192 if (bookmark_url == m3[0].destination_url) { |
| 191 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec()); | 193 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec()); |
| 192 } else { | 194 } else { |
| 193 EXPECT_EQ(bookmark_url, m3[1].destination_url); | 195 EXPECT_EQ(bookmark_url, m3[1].destination_url); |
| 194 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec()); | 196 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec()); |
| 195 } | 197 } |
| 196 } | 198 } |
| 197 | 199 |
| 200 // Tests that history is deleted properly. |
| 201 TEST_F(HistoryContentsProviderTest, DeleteMatch) { |
| 202 AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); |
| 203 RunQuery(input, false); |
| 204 |
| 205 // Query; the result should be the third page. |
| 206 const ACMatches& m = matches(); |
| 207 ASSERT_EQ(1U, m.size()); |
| 208 EXPECT_EQ(test_entries[2].url, m[0].destination_url.spec()); |
| 209 |
| 210 // Now delete the match and ensure it was removed. |
| 211 provider()->DeleteMatch(m[0]); |
| 212 EXPECT_EQ(0U, matches().size()); |
| 213 } |
| 214 |
| 215 // Tests deleting starred results from history, not affecting bookmarks/matches. |
| 216 TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { |
| 217 profile()->CreateBookmarkModel(false); |
| 218 profile()->BlockUntilBookmarkModelLoaded(); |
| 219 |
| 220 // Bookmark a history item. |
| 221 GURL bookmark_url(test_entries[2].url); |
| 222 profile()->GetBookmarkModel()->SetURLStarred(bookmark_url, |
| 223 ASCIIToUTF16("bar"), true); |
| 224 |
| 225 // Get the match to delete its history |
| 226 AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); |
| 227 RunQuery(input, false); |
| 228 const ACMatches& m = matches(); |
| 229 ASSERT_EQ(1U, m.size()); |
| 230 |
| 231 // Now delete the match and ensure it was *not* removed. |
| 232 provider()->DeleteMatch(m[0]); |
| 233 EXPECT_EQ(1U, matches().size()); |
| 234 |
| 235 // Run a query that would only match history (but the history is deleted) |
| 236 AutocompleteInput you_input(L"you", std::wstring(), true, false, true, false); |
| 237 RunQuery(you_input, false); |
| 238 EXPECT_EQ(0U, matches().size()); |
| 239 |
| 240 // Run a query that matches the bookmark |
| 241 RunQuery(input, false); |
| 242 EXPECT_EQ(1U, matches().size()); |
| 243 } |
| 244 |
| 198 } // namespace | 245 } // namespace |
| OLD | NEW |