Chromium Code Reviews| 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. |
|
Peter Kasting
2011/01/06 19:10:39
Nit: I'd probably add "Note that calling Quit() di
msw
2011/01/06 20:24:56
Done.
| |
| 94 MessageLoop::current()->Quit(); | 94 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 95 } | 95 } |
| 96 | 96 |
| 97 MessageLoopForUI message_loop_; | 97 MessageLoopForUI message_loop_; |
| 98 BrowserThread ui_thread_; | 98 BrowserThread ui_thread_; |
| 99 BrowserThread file_thread_; | 99 BrowserThread file_thread_; |
| 100 | 100 |
| 101 std::wstring history_dir_; | 101 std::wstring history_dir_; |
| 102 | 102 |
| 103 scoped_ptr<TestingProfile> profile_; | 103 scoped_ptr<TestingProfile> profile_; |
| 104 scoped_refptr<HistoryContentsProvider> provider_; | 104 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, | 177 AutocompleteInput async_input(L"bar", std::wstring(), true, false, true, |
| 178 false); | 178 false); |
| 179 provider()->Start(async_input, false); | 179 provider()->Start(async_input, false); |
| 180 const ACMatches& m2 = matches(); | 180 const ACMatches& m2 = matches(); |
| 181 ASSERT_EQ(1U, m2.size()); | 181 ASSERT_EQ(1U, m2.size()); |
| 182 EXPECT_EQ(bookmark_url, m2[0].destination_url); | 182 EXPECT_EQ(bookmark_url, m2[0].destination_url); |
| 183 | 183 |
| 184 // Run the message loop (needed for async history results). | 184 // Run the message loop (needed for async history results). |
| 185 MessageLoop::current()->Run(); | 185 MessageLoop::current()->Run(); |
| 186 | 186 |
| 187 // We should two urls now, bookmark_url and http://www.google.com/3. | 187 // We should have two urls now, bookmark_url and http://www.google.com/3. |
| 188 const ACMatches& m3 = matches(); | 188 const ACMatches& m3 = matches(); |
| 189 ASSERT_EQ(2U, m3.size()); | 189 ASSERT_EQ(2U, m3.size()); |
| 190 if (bookmark_url == m3[0].destination_url) { | 190 if (bookmark_url == m3[0].destination_url) { |
| 191 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec()); | 191 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec()); |
| 192 } else { | 192 } else { |
| 193 EXPECT_EQ(bookmark_url, m3[1].destination_url); | 193 EXPECT_EQ(bookmark_url, m3[1].destination_url); |
| 194 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec()); | 194 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec()); |
| 195 } | 195 } |
| 196 } | 196 } |
| 197 | 197 |
| 198 // Tests that history is deleted properly. | |
| 199 TEST_F(HistoryContentsProviderTest, DeleteMatch) { | |
| 200 AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); | |
| 201 RunQuery(input, false); | |
| 202 | |
| 203 // Query; the result should be the third page. | |
| 204 const ACMatches& m = matches(); | |
| 205 ASSERT_EQ(1U, m.size()); | |
| 206 EXPECT_EQ(test_entries[2].url, m[0].destination_url.spec()); | |
| 207 | |
| 208 // Now delete the match and ensure it was removed. | |
| 209 provider()->DeleteMatch(m[0]); | |
| 210 EXPECT_EQ(0U, matches().size()); | |
| 211 } | |
| 212 | |
| 213 // Tests deleting starred results from history, not affecting bookmarks/matches. | |
| 214 TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { | |
| 215 profile()->CreateBookmarkModel(false); | |
| 216 profile()->BlockUntilBookmarkModelLoaded(); | |
| 217 | |
| 218 // Bookmark a history item. | |
| 219 GURL bookmark_url(test_entries[2].url); | |
| 220 profile()->GetBookmarkModel()->SetURLStarred(bookmark_url, | |
| 221 ASCIIToUTF16("bar"), true); | |
| 222 | |
| 223 // Get the match to delete its history | |
| 224 AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); | |
| 225 RunQuery(input, false); | |
| 226 const ACMatches& m = matches(); | |
| 227 ASSERT_EQ(1U, m.size()); | |
| 228 | |
| 229 // Now delete the match and ensure it was *not* removed. | |
| 230 provider()->DeleteMatch(m[0]); | |
| 231 EXPECT_EQ(1U, matches().size()); | |
| 232 | |
| 233 // Run a query that would only match history (but the history is deleted) | |
| 234 AutocompleteInput you_input(L"you", std::wstring(), true, false, true, false); | |
| 235 RunQuery(you_input, false); | |
| 236 EXPECT_EQ(0U, matches().size()); | |
| 237 | |
| 238 // Run a query that matches the bookmark | |
| 239 RunQuery(input, false); | |
| 240 EXPECT_EQ(1U, matches().size()); | |
| 241 } | |
| 242 | |
| 198 } // namespace | 243 } // namespace |
| OLD | NEW |