Index: chrome/browser/autocomplete/history_contents_provider_unittest.cc |
diff --git a/chrome/browser/autocomplete/history_contents_provider_unittest.cc b/chrome/browser/autocomplete/history_contents_provider_unittest.cc |
index b6c32082abf1fba8f58f46f43c120a1dc33b2990..d71717dbb2d64176552af420f720cf4cc405d513 100644 |
--- a/chrome/browser/autocomplete/history_contents_provider_unittest.cc |
+++ b/chrome/browser/autocomplete/history_contents_provider_unittest.cc |
@@ -47,6 +47,13 @@ class HistoryContentsProviderTest : public testing::Test, |
MessageLoop::current()->Run(); |
} |
+ void DeleteMatch(const AutocompleteMatch& match) { |
+ 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
|
+ NewRunnableMethod(provider(), &HistoryProvider::DeleteMatch, match)); |
+ // Run the message loop to execute the task. |
+ MessageLoop::current()->Run(); |
+ } |
+ |
const ACMatches& matches() const { return provider_->matches(); } |
TestingProfile* profile() const { return profile_.get(); } |
@@ -184,7 +191,7 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) { |
// Run the message loop (needed for async history results). |
MessageLoop::current()->Run(); |
- // We should two urls now, bookmark_url and http://www.google.com/3. |
+ // We should have two urls now, bookmark_url and http://www.google.com/3. |
const ACMatches& m3 = matches(); |
ASSERT_EQ(2U, m3.size()); |
if (bookmark_url == m3[0].destination_url) { |
@@ -195,4 +202,49 @@ TEST_F(HistoryContentsProviderTest, Bookmarks) { |
} |
} |
+// Tests that history is deleted properly. |
+TEST_F(HistoryContentsProviderTest, DeleteMatch) { |
+ AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); |
+ RunQuery(input, false); |
+ |
+ // Query; the result should be the third page. |
+ const ACMatches& m = matches(); |
+ ASSERT_EQ(1U, m.size()); |
+ EXPECT_EQ(test_entries[2].url, m[0].destination_url.spec()); |
+ |
+ // Now delete the match and ensure it was removed. |
+ DeleteMatch(m[0]); |
+ EXPECT_EQ(0U, matches().size()); |
+} |
+ |
+// Tests deleting starred results from history, not affecting bookmarks/matches. |
+TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { |
+ profile()->CreateBookmarkModel(false); |
+ profile()->BlockUntilBookmarkModelLoaded(); |
+ |
+ // Bookmark a history item. |
+ GURL bookmark_url(test_entries[2].url); |
+ profile()->GetBookmarkModel()->SetURLStarred(bookmark_url, |
+ ASCIIToUTF16("bar"), true); |
+ |
+ // Get the match to delete its history |
+ AutocompleteInput input(L"bar", std::wstring(), true, false, true, false); |
+ RunQuery(input, false); |
+ const ACMatches& m = matches(); |
+ ASSERT_EQ(1U, m.size()); |
+ |
+ // Now delete the match and ensure it was *not* removed. |
+ DeleteMatch(m[0]); |
+ EXPECT_EQ(1U, matches().size()); |
+ |
+ // Run a query that would only match history (but the history is deleted) |
+ AutocompleteInput you_input(L"you", std::wstring(), true, false, true, false); |
+ RunQuery(you_input, false); |
+ EXPECT_EQ(0U, matches().size()); |
+ |
+ // Run a query that matches the bookmark |
+ RunQuery(input, false); |
+ EXPECT_EQ(1U, matches().size()); |
+} |
+ |
} // namespace |