| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/autocomplete/history_contents_provider.h" | 5 #include "chrome/browser/autocomplete/history_contents_provider.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_match.h" | 11 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 12 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" | 12 #include "chrome/browser/autocomplete/autocomplete_provider_listener.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_model.h" | 13 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 14 #include "chrome/browser/bookmarks/bookmark_utils.h" | 15 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 15 #include "chrome/browser/history/history.h" | 16 #include "chrome/browser/history/history.h" |
| 16 #include "chrome/browser/history/history_service_factory.h" | 17 #include "chrome/browser/history/history_service_factory.h" |
| 17 #include "chrome/test/base/testing_browser_process.h" | 18 #include "chrome/test/base/testing_browser_process.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 19 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 using base::Time; | 23 using base::Time; |
| 23 using base::TimeDelta; | 24 using base::TimeDelta; |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 EXPECT_EQ(0U, m3.size()); | 194 EXPECT_EQ(0U, m3.size()); |
| 194 } | 195 } |
| 195 | 196 |
| 196 // Tests that the BookmarkModel is queried correctly. | 197 // Tests that the BookmarkModel is queried correctly. |
| 197 TEST_F(HistoryContentsProviderTest, Bookmarks) { | 198 TEST_F(HistoryContentsProviderTest, Bookmarks) { |
| 198 profile()->CreateBookmarkModel(false); | 199 profile()->CreateBookmarkModel(false); |
| 199 profile()->BlockUntilBookmarkModelLoaded(); | 200 profile()->BlockUntilBookmarkModelLoaded(); |
| 200 | 201 |
| 201 // Add a bookmark. | 202 // Add a bookmark. |
| 202 GURL bookmark_url("http://www.google.com/4"); | 203 GURL bookmark_url("http://www.google.com/4"); |
| 203 bookmark_utils::AddIfNotBookmarked(profile()->GetBookmarkModel(), | 204 bookmark_utils::AddIfNotBookmarked( |
| 204 bookmark_url, | 205 BookmarkModelFactory::GetForProfile(profile()), |
| 205 ASCIIToUTF16("bar")); | 206 bookmark_url, |
| 207 ASCIIToUTF16("bar")); |
| 206 | 208 |
| 207 // Ask for synchronous. This should only get the bookmark. | 209 // Ask for synchronous. This should only get the bookmark. |
| 208 AutocompleteInput sync_input(ASCIIToUTF16("bar"), string16(), true, false, | 210 AutocompleteInput sync_input(ASCIIToUTF16("bar"), string16(), true, false, |
| 209 true, AutocompleteInput::SYNCHRONOUS_MATCHES); | 211 true, AutocompleteInput::SYNCHRONOUS_MATCHES); |
| 210 RunQuery(sync_input, false); | 212 RunQuery(sync_input, false); |
| 211 const ACMatches& m1 = matches(); | 213 const ACMatches& m1 = matches(); |
| 212 ASSERT_EQ(1U, m1.size()); | 214 ASSERT_EQ(1U, m1.size()); |
| 213 EXPECT_EQ(bookmark_url, m1[0].destination_url); | 215 EXPECT_EQ(bookmark_url, m1[0].destination_url); |
| 214 EXPECT_EQ(ASCIIToUTF16("bar"), m1[0].description); | 216 EXPECT_EQ(ASCIIToUTF16("bar"), m1[0].description); |
| 215 EXPECT_TRUE(m1[0].starred); | 217 EXPECT_TRUE(m1[0].starred); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 EXPECT_EQ(0U, matches().size()); | 254 EXPECT_EQ(0U, matches().size()); |
| 253 } | 255 } |
| 254 | 256 |
| 255 // Tests deleting starred results from history, not affecting bookmarks/matches. | 257 // Tests deleting starred results from history, not affecting bookmarks/matches. |
| 256 TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { | 258 TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { |
| 257 profile()->CreateBookmarkModel(false); | 259 profile()->CreateBookmarkModel(false); |
| 258 profile()->BlockUntilBookmarkModelLoaded(); | 260 profile()->BlockUntilBookmarkModelLoaded(); |
| 259 | 261 |
| 260 // Bookmark a history item. | 262 // Bookmark a history item. |
| 261 GURL bookmark_url(test_entries[2].url); | 263 GURL bookmark_url(test_entries[2].url); |
| 262 bookmark_utils::AddIfNotBookmarked(profile()->GetBookmarkModel(), | 264 bookmark_utils::AddIfNotBookmarked( |
| 263 bookmark_url, | 265 BookmarkModelFactory::GetForProfile(profile()), |
| 264 ASCIIToUTF16("bar")); | 266 bookmark_url, |
| 267 ASCIIToUTF16("bar")); |
| 265 | 268 |
| 266 // Get the match to delete its history | 269 // Get the match to delete its history |
| 267 AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true, | 270 AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true, |
| 268 AutocompleteInput::ALL_MATCHES); | 271 AutocompleteInput::ALL_MATCHES); |
| 269 RunQuery(input, false); | 272 RunQuery(input, false); |
| 270 const ACMatches& m = matches(); | 273 const ACMatches& m = matches(); |
| 271 ASSERT_EQ(1U, m.size()); | 274 ASSERT_EQ(1U, m.size()); |
| 272 | 275 |
| 273 // Now delete the match and ensure it was *not* removed. | 276 // Now delete the match and ensure it was *not* removed. |
| 274 provider()->DeleteMatch(m[0]); | 277 provider()->DeleteMatch(m[0]); |
| 275 EXPECT_EQ(1U, matches().size()); | 278 EXPECT_EQ(1U, matches().size()); |
| 276 | 279 |
| 277 // Run a query that would only match history (but the history is deleted) | 280 // Run a query that would only match history (but the history is deleted) |
| 278 AutocompleteInput you_input(ASCIIToUTF16("you"), string16(), true, false, | 281 AutocompleteInput you_input(ASCIIToUTF16("you"), string16(), true, false, |
| 279 true, AutocompleteInput::ALL_MATCHES); | 282 true, AutocompleteInput::ALL_MATCHES); |
| 280 RunQuery(you_input, false); | 283 RunQuery(you_input, false); |
| 281 EXPECT_EQ(0U, matches().size()); | 284 EXPECT_EQ(0U, matches().size()); |
| 282 | 285 |
| 283 // Run a query that matches the bookmark | 286 // Run a query that matches the bookmark |
| 284 RunQuery(input, false); | 287 RunQuery(input, false); |
| 285 EXPECT_EQ(1U, matches().size()); | 288 EXPECT_EQ(1U, matches().size()); |
| 286 } | 289 } |
| 287 | 290 |
| 288 } // namespace | 291 } // namespace |
| OLD | NEW |