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 29 matching lines...) Expand all Loading... | |
| 40 void RunQuery(const AutocompleteInput& input, | 40 void RunQuery(const AutocompleteInput& input, |
| 41 bool minimal_changes) { | 41 bool minimal_changes) { |
| 42 provider_->Start(input, minimal_changes); | 42 provider_->Start(input, minimal_changes); |
| 43 | 43 |
| 44 // When we're waiting for asynchronous messages, we have to spin the message | 44 // When we're waiting for asynchronous messages, we have to spin the message |
| 45 // loop. This will be exited in the OnProviderUpdate function when complete. | 45 // loop. This will be exited in the OnProviderUpdate function when complete. |
| 46 if (!input.synchronous_only()) | 46 if (!input.synchronous_only()) |
| 47 MessageLoop::current()->Run(); | 47 MessageLoop::current()->Run(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void DeleteMatch(const AutocompleteMatch& match) { | |
| 51 MessageLoop::current()->PostTask(FROM_HERE, | |
|
Paweł Hajdan Jr.
2011/01/03 08:51:12
nit: This is on the same message loop, so why not
msw
2011/01/04 07:57:27
That was my initial strategy, but then |state_| is
Paweł Hajdan Jr.
2011/01/04 16:00:13
Right, calling Quit on a stopped message loop is a
Peter Kasting
2011/01/04 22:16:01
There are three ways to fix. One way is what you
| |
| 52 NewRunnableMethod(provider(), &HistoryProvider::DeleteMatch, match)); | |
| 53 // Run the message loop to execute the task. | |
| 54 MessageLoop::current()->Run(); | |
| 55 } | |
| 56 | |
| 50 const ACMatches& matches() const { return provider_->matches(); } | 57 const ACMatches& matches() const { return provider_->matches(); } |
| 51 | 58 |
| 52 TestingProfile* profile() const { return profile_.get(); } | 59 TestingProfile* profile() const { return profile_.get(); } |
| 53 | 60 |
| 54 HistoryContentsProvider* provider() const { return provider_.get(); } | 61 HistoryContentsProvider* provider() const { return provider_.get(); } |
| 55 | 62 |
| 56 private: | 63 private: |
| 57 // testing::Test | 64 // testing::Test |
| 58 virtual void SetUp() { | 65 virtual void SetUp() { |
| 59 profile_.reset(new TestingProfile()); | 66 profile_.reset(new TestingProfile()); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 177 AutocompleteInput async_input(L"bar", std::wstring(), true, false, true, | 184 AutocompleteInput async_input(L"bar", std::wstring(), true, false, true, |
| 178 false); | 185 false); |
| 179 provider()->Start(async_input, false); | 186 provider()->Start(async_input, false); |
| 180 const ACMatches& m2 = matches(); | 187 const ACMatches& m2 = matches(); |
| 181 ASSERT_EQ(1U, m2.size()); | 188 ASSERT_EQ(1U, m2.size()); |
| 182 EXPECT_EQ(bookmark_url, m2[0].destination_url); | 189 EXPECT_EQ(bookmark_url, m2[0].destination_url); |
| 183 | 190 |
| 184 // Run the message loop (needed for async history results). | 191 // Run the message loop (needed for async history results). |
| 185 MessageLoop::current()->Run(); | 192 MessageLoop::current()->Run(); |
| 186 | 193 |
| 187 // We should two urls now, bookmark_url and http://www.google.com/3. | 194 // We should have two urls now, bookmark_url and http://www.google.com/3. |
| 188 const ACMatches& m3 = matches(); | 195 const ACMatches& m3 = matches(); |
| 189 ASSERT_EQ(2U, m3.size()); | 196 ASSERT_EQ(2U, m3.size()); |
| 190 if (bookmark_url == m3[0].destination_url) { | 197 if (bookmark_url == m3[0].destination_url) { |
| 191 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec()); | 198 EXPECT_EQ("http://www.google.com/3", m3[1].destination_url.spec()); |
| 192 } else { | 199 } else { |
| 193 EXPECT_EQ(bookmark_url, m3[1].destination_url); | 200 EXPECT_EQ(bookmark_url, m3[1].destination_url); |
| 194 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec()); | 201 EXPECT_EQ("http://www.google.com/3", m3[0].destination_url.spec()); |
| 195 } | 202 } |
| 196 } | 203 } |
| 197 | 204 |
| 205 // Tests that history is deleted properly. | |
| 206 TEST_F(HistoryContentsProviderTest, DeleteMatch) { | |
| 207 AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); | |
| 208 RunQuery(input, false); | |
| 209 | |
| 210 // Query; the result should be the third page. | |
| 211 const ACMatches& m = matches(); | |
| 212 ASSERT_EQ(1U, m.size()); | |
| 213 EXPECT_EQ(test_entries[2].url, m[0].destination_url.spec()); | |
| 214 | |
| 215 // Now delete the match and ensure it was removed. | |
| 216 DeleteMatch(m[0]); | |
| 217 EXPECT_EQ(0U, matches().size()); | |
| 218 } | |
| 219 | |
| 220 // Tests deleting starred results from history, not affecting bookmarks/matches. | |
| 221 TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { | |
| 222 profile()->CreateBookmarkModel(false); | |
| 223 profile()->BlockUntilBookmarkModelLoaded(); | |
| 224 | |
| 225 // Bookmark a history item. | |
| 226 GURL bookmark_url(test_entries[2].url); | |
| 227 profile()->GetBookmarkModel()->SetURLStarred(bookmark_url, | |
| 228 ASCIIToUTF16("bar"), true); | |
| 229 | |
| 230 // Get the match to delete its history | |
| 231 AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); | |
| 232 RunQuery(input, false); | |
| 233 const ACMatches& m = matches(); | |
| 234 ASSERT_EQ(1U, m.size()); | |
| 235 | |
| 236 // Now delete the match and ensure it was *not* removed. | |
| 237 DeleteMatch(m[0]); | |
| 238 EXPECT_EQ(1U, matches().size()); | |
| 239 | |
| 240 // Run a query that would only match history (but the history is deleted) | |
| 241 AutocompleteInput you_input(L"you", std::wstring(), true, false, true, false); | |
| 242 RunQuery(you_input, false); | |
| 243 EXPECT_EQ(0U, matches().size()); | |
| 244 | |
| 245 // Run a query that matches the bookmark | |
| 246 RunQuery(input, false); | |
| 247 EXPECT_EQ(1U, matches().size()); | |
| 248 } | |
| 249 | |
| 198 } // namespace | 250 } // namespace |
| OLD | NEW |