| 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" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 scoped_ptr<TestingProfile> profile_; | 113 scoped_ptr<TestingProfile> profile_; |
| 114 scoped_refptr<HistoryContentsProvider> provider_; | 114 scoped_refptr<HistoryContentsProvider> provider_; |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 class HistoryContentsProviderBodyOnlyTest : public HistoryContentsProviderTest { | 117 class HistoryContentsProviderBodyOnlyTest : public HistoryContentsProviderTest { |
| 118 protected: | 118 protected: |
| 119 virtual bool BodyOnly() { return true; } | 119 virtual bool BodyOnly() { return true; } |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 TEST_F(HistoryContentsProviderTest, Body) { | 122 TEST_F(HistoryContentsProviderTest, Body) { |
| 123 AutocompleteInput input(ASCIIToUTF16("FOO"), string16(), true, false, true, | 123 AutocompleteInput input(ASCIIToUTF16("FOO"), string16::npos, string16(), true, |
| 124 AutocompleteInput::ALL_MATCHES); | 124 false, true, AutocompleteInput::ALL_MATCHES); |
| 125 RunQuery(input, false); | 125 RunQuery(input, false); |
| 126 | 126 |
| 127 // The results should be the first two pages, in decreasing order. | 127 // The results should be the first two pages, in decreasing order. |
| 128 const ACMatches& m = matches(); | 128 const ACMatches& m = matches(); |
| 129 ASSERT_EQ(2U, m.size()); | 129 ASSERT_EQ(2U, m.size()); |
| 130 EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec()); | 130 EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec()); |
| 131 EXPECT_STREQ(test_entries[0].title, UTF16ToUTF8(m[0].description).c_str()); | 131 EXPECT_STREQ(test_entries[0].title, UTF16ToUTF8(m[0].description).c_str()); |
| 132 EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec()); | 132 EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec()); |
| 133 EXPECT_STREQ(test_entries[1].title, UTF16ToUTF8(m[1].description).c_str()); | 133 EXPECT_STREQ(test_entries[1].title, UTF16ToUTF8(m[1].description).c_str()); |
| 134 } | 134 } |
| 135 | 135 |
| 136 TEST_F(HistoryContentsProviderTest, Title) { | 136 TEST_F(HistoryContentsProviderTest, Title) { |
| 137 AutocompleteInput input(ASCIIToUTF16("PAGEONE"), string16(), true, false, | 137 AutocompleteInput input(ASCIIToUTF16("PAGEONE"), string16::npos, string16(), |
| 138 true, AutocompleteInput::ALL_MATCHES); | 138 true, false, true, AutocompleteInput::ALL_MATCHES); |
| 139 RunQuery(input, false); | 139 RunQuery(input, false); |
| 140 | 140 |
| 141 // The results should be the first two pages. | 141 // The results should be the first two pages. |
| 142 const ACMatches& m = matches(); | 142 const ACMatches& m = matches(); |
| 143 ASSERT_EQ(2U, m.size()); | 143 ASSERT_EQ(2U, m.size()); |
| 144 EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec()); | 144 EXPECT_EQ(test_entries[0].url, m[0].destination_url.spec()); |
| 145 EXPECT_STREQ(test_entries[0].title, UTF16ToUTF8(m[0].description).c_str()); | 145 EXPECT_STREQ(test_entries[0].title, UTF16ToUTF8(m[0].description).c_str()); |
| 146 EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec()); | 146 EXPECT_EQ(test_entries[1].url, m[1].destination_url.spec()); |
| 147 EXPECT_STREQ(test_entries[1].title, UTF16ToUTF8(m[1].description).c_str()); | 147 EXPECT_STREQ(test_entries[1].title, UTF16ToUTF8(m[1].description).c_str()); |
| 148 } | 148 } |
| 149 | 149 |
| 150 // The "minimal changes" flag should mean that we don't re-query the DB. | 150 // The "minimal changes" flag should mean that we don't re-query the DB. |
| 151 TEST_F(HistoryContentsProviderTest, MinimalChanges) { | 151 TEST_F(HistoryContentsProviderTest, MinimalChanges) { |
| 152 // A minimal changes request when there have been no real queries should | 152 // A minimal changes request when there have been no real queries should |
| 153 // give us no results. | 153 // give us no results. |
| 154 AutocompleteInput sync_input(ASCIIToUTF16("PAGEONE"), string16(), true, false, | 154 AutocompleteInput sync_input(ASCIIToUTF16("PAGEONE"), string16::npos, |
| 155 true, AutocompleteInput::SYNCHRONOUS_MATCHES); | 155 string16(), true, false, true, |
| 156 AutocompleteInput::SYNCHRONOUS_MATCHES); |
| 156 RunQuery(sync_input, true); | 157 RunQuery(sync_input, true); |
| 157 const ACMatches& m1 = matches(); | 158 const ACMatches& m1 = matches(); |
| 158 EXPECT_EQ(0U, m1.size()); | 159 EXPECT_EQ(0U, m1.size()); |
| 159 | 160 |
| 160 // Now do a "regular" query to get the results. | 161 // Now do a "regular" query to get the results. |
| 161 AutocompleteInput async_input(ASCIIToUTF16("PAGEONE"), string16(), true, | 162 AutocompleteInput async_input(ASCIIToUTF16("PAGEONE"), string16::npos, |
| 162 false, true, AutocompleteInput::ALL_MATCHES); | 163 string16(), true, false, true, |
| 164 AutocompleteInput::ALL_MATCHES); |
| 163 RunQuery(async_input, false); | 165 RunQuery(async_input, false); |
| 164 const ACMatches& m2 = matches(); | 166 const ACMatches& m2 = matches(); |
| 165 EXPECT_EQ(2U, m2.size()); | 167 EXPECT_EQ(2U, m2.size()); |
| 166 | 168 |
| 167 // Now do a minimal one where we want synchronous results, and the results | 169 // Now do a minimal one where we want synchronous results, and the results |
| 168 // should still be there. | 170 // should still be there. |
| 169 RunQuery(sync_input, true); | 171 RunQuery(sync_input, true); |
| 170 const ACMatches& m3 = matches(); | 172 const ACMatches& m3 = matches(); |
| 171 EXPECT_EQ(2U, m3.size()); | 173 EXPECT_EQ(2U, m3.size()); |
| 172 } | 174 } |
| 173 | 175 |
| 174 TEST_F(HistoryContentsProviderBodyOnlyTest, MinimalChanges) { | 176 TEST_F(HistoryContentsProviderBodyOnlyTest, MinimalChanges) { |
| 175 // A minimal changes request when there have been no real queries should | 177 // A minimal changes request when there have been no real queries should |
| 176 // give us no results. | 178 // give us no results. |
| 177 AutocompleteInput sync_input(ASCIIToUTF16("PAGEONE"), string16(), true, false, | 179 AutocompleteInput sync_input(ASCIIToUTF16("PAGEONE"), string16::npos, |
| 178 true, AutocompleteInput::SYNCHRONOUS_MATCHES); | 180 string16(), true, false, true, |
| 181 AutocompleteInput::SYNCHRONOUS_MATCHES); |
| 179 RunQuery(sync_input, true); | 182 RunQuery(sync_input, true); |
| 180 const ACMatches& m1 = matches(); | 183 const ACMatches& m1 = matches(); |
| 181 EXPECT_EQ(0U, m1.size()); | 184 EXPECT_EQ(0U, m1.size()); |
| 182 | 185 |
| 183 // Now do a "regular" query to get no results because we are body-only. | 186 // Now do a "regular" query to get no results because we are body-only. |
| 184 AutocompleteInput async_input(ASCIIToUTF16("PAGEONE"), string16(), true, | 187 AutocompleteInput async_input(ASCIIToUTF16("PAGEONE"), string16::npos, |
| 185 false, true, AutocompleteInput::ALL_MATCHES); | 188 string16(), true, false, true, |
| 189 AutocompleteInput::ALL_MATCHES); |
| 186 RunQuery(async_input, false); | 190 RunQuery(async_input, false); |
| 187 const ACMatches& m2 = matches(); | 191 const ACMatches& m2 = matches(); |
| 188 EXPECT_EQ(0U, m2.size()); | 192 EXPECT_EQ(0U, m2.size()); |
| 189 | 193 |
| 190 // Now do a minimal one where we want synchronous results, and the results | 194 // Now do a minimal one where we want synchronous results, and the results |
| 191 // should still not be there. | 195 // should still not be there. |
| 192 RunQuery(sync_input, true); | 196 RunQuery(sync_input, true); |
| 193 const ACMatches& m3 = matches(); | 197 const ACMatches& m3 = matches(); |
| 194 EXPECT_EQ(0U, m3.size()); | 198 EXPECT_EQ(0U, m3.size()); |
| 195 } | 199 } |
| 196 | 200 |
| 197 // Tests that history is deleted properly. | 201 // Tests that history is deleted properly. |
| 198 TEST_F(HistoryContentsProviderTest, DeleteMatch) { | 202 TEST_F(HistoryContentsProviderTest, DeleteMatch) { |
| 199 AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true, | 203 AutocompleteInput input(ASCIIToUTF16("bar"), string16::npos, string16(), true, |
| 200 AutocompleteInput::ALL_MATCHES); | 204 false, true, AutocompleteInput::ALL_MATCHES); |
| 201 RunQuery(input, false); | 205 RunQuery(input, false); |
| 202 | 206 |
| 203 // Query; the result should be the third page. | 207 // Query; the result should be the third page. |
| 204 const ACMatches& m = matches(); | 208 const ACMatches& m = matches(); |
| 205 ASSERT_EQ(1U, m.size()); | 209 ASSERT_EQ(1U, m.size()); |
| 206 EXPECT_EQ(test_entries[2].url, m[0].destination_url.spec()); | 210 EXPECT_EQ(test_entries[2].url, m[0].destination_url.spec()); |
| 207 | 211 |
| 208 // Now delete the match and ensure it was removed. | 212 // Now delete the match and ensure it was removed. |
| 209 provider()->DeleteMatch(m[0]); | 213 provider()->DeleteMatch(m[0]); |
| 210 EXPECT_EQ(0U, matches().size()); | 214 EXPECT_EQ(0U, matches().size()); |
| 211 } | 215 } |
| 212 | 216 |
| 213 // Tests deleting starred results from history, not affecting bookmarks/matches. | 217 // Tests deleting starred results from history, not affecting bookmarks/matches. |
| 214 TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { | 218 TEST_F(HistoryContentsProviderTest, DeleteStarredMatch) { |
| 215 profile()->CreateBookmarkModel(false); | 219 profile()->CreateBookmarkModel(false); |
| 216 profile()->BlockUntilBookmarkModelLoaded(); | 220 profile()->BlockUntilBookmarkModelLoaded(); |
| 217 | 221 |
| 218 // Bookmark a history item. | 222 // Bookmark a history item. |
| 219 GURL bookmark_url(test_entries[2].url); | 223 GURL bookmark_url(test_entries[2].url); |
| 220 bookmark_utils::AddIfNotBookmarked( | 224 bookmark_utils::AddIfNotBookmarked( |
| 221 BookmarkModelFactory::GetForProfile(profile()), | 225 BookmarkModelFactory::GetForProfile(profile()), |
| 222 bookmark_url, | 226 bookmark_url, |
| 223 ASCIIToUTF16("bar")); | 227 ASCIIToUTF16("bar")); |
| 224 | 228 |
| 225 // Get the match to delete its history | 229 // Get the match to delete its history |
| 226 AutocompleteInput input(ASCIIToUTF16("bar"), string16(), true, false, true, | 230 AutocompleteInput input(ASCIIToUTF16("bar"), string16::npos, string16(), true, |
| 227 AutocompleteInput::ALL_MATCHES); | 231 false, true, AutocompleteInput::ALL_MATCHES); |
| 228 RunQuery(input, false); | 232 RunQuery(input, false); |
| 229 const ACMatches& m = matches(); | 233 const ACMatches& m = matches(); |
| 230 ASSERT_EQ(1U, m.size()); | 234 ASSERT_EQ(1U, m.size()); |
| 231 | 235 |
| 232 // Now delete the match and ensure it was *not* removed. | 236 // Now delete the match and ensure it was *not* removed. |
| 233 provider()->DeleteMatch(m[0]); | 237 provider()->DeleteMatch(m[0]); |
| 234 EXPECT_EQ(1U, matches().size()); | 238 EXPECT_EQ(1U, matches().size()); |
| 235 | 239 |
| 236 // Run a query that would only match history (but the history is deleted) | 240 // Run a query that would only match history (but the history is deleted) |
| 237 AutocompleteInput you_input(ASCIIToUTF16("you"), string16(), true, false, | 241 AutocompleteInput you_input(ASCIIToUTF16("you"), string16::npos, string16(), |
| 238 true, AutocompleteInput::ALL_MATCHES); | 242 true, false, true, |
| 243 AutocompleteInput::ALL_MATCHES); |
| 239 RunQuery(you_input, false); | 244 RunQuery(you_input, false); |
| 240 EXPECT_EQ(0U, matches().size()); | 245 EXPECT_EQ(0U, matches().size()); |
| 241 } | 246 } |
| 242 | 247 |
| 243 } // namespace | 248 } // namespace |
| OLD | NEW |