Index: chrome/browser/autocomplete/history_quick_provider_unittest.cc |
diff --git a/chrome/browser/autocomplete/history_quick_provider_unittest.cc b/chrome/browser/autocomplete/history_quick_provider_unittest.cc |
index 14bb024ec49678ffbda1dfa670e56d7df3acb379..9f9e36b47b3fe32d2be9e531fd41ccc143cbb4e7 100644 |
--- a/chrome/browser/autocomplete/history_quick_provider_unittest.cc |
+++ b/chrome/browser/autocomplete/history_quick_provider_unittest.cc |
@@ -152,6 +152,15 @@ class HistoryQuickProviderTest : public testing::Test, |
base::string16 expected_fill_into_edit, |
base::string16 autocompletion); |
+ // As above, simply with a cursor position specified. |
+ void RunTestWithCursor(const base::string16 text, |
+ const size_t cursor_position, |
+ bool prevent_inline_autocomplete, |
+ std::vector<std::string> expected_urls, |
+ bool can_inline_top_result, |
+ base::string16 expected_fill_into_edit, |
+ base::string16 autocompletion); |
+ |
history::HistoryBackend* history_backend() { |
return history_service_->history_backend_; |
} |
@@ -255,16 +264,29 @@ void HistoryQuickProviderTest::SetShouldContain::operator()( |
<< "Results did not contain '" << expected << "' but should have."; |
} |
+void HistoryQuickProviderTest::RunTest( |
+ const base::string16 text, |
+ bool prevent_inline_autocomplete, |
+ std::vector<std::string> expected_urls, |
+ bool can_inline_top_result, |
+ base::string16 expected_fill_into_edit, |
+ base::string16 expected_autocompletion) { |
+ RunTestWithCursor(text, base::string16::npos, prevent_inline_autocomplete, |
+ expected_urls, can_inline_top_result, |
+ expected_fill_into_edit, expected_autocompletion); |
+} |
-void HistoryQuickProviderTest::RunTest(const base::string16 text, |
- bool prevent_inline_autocomplete, |
- std::vector<std::string> expected_urls, |
- bool can_inline_top_result, |
- base::string16 expected_fill_into_edit, |
- base::string16 expected_autocompletion) { |
+void HistoryQuickProviderTest::RunTestWithCursor( |
+ const base::string16 text, |
+ const size_t cursor_position, |
+ bool prevent_inline_autocomplete, |
+ std::vector<std::string> expected_urls, |
+ bool can_inline_top_result, |
+ base::string16 expected_fill_into_edit, |
+ base::string16 expected_autocompletion) { |
SCOPED_TRACE(text); // Minimal hint to query being run. |
base::MessageLoop::current()->RunUntilIdle(); |
- AutocompleteInput input(text, base::string16::npos, base::string16(), |
+ AutocompleteInput input(text, cursor_position, base::string16(), |
GURL(), metrics::OmniboxEventProto::INVALID_SPEC, |
prevent_inline_autocomplete, false, true, true, |
ChromeAutocompleteSchemeClassifier(profile_.get())); |
@@ -322,6 +344,24 @@ TEST_F(HistoryQuickProviderTest, SimpleSingleMatch) { |
ASCIIToUTF16(".org/favorite_page.html")); |
} |
+TEST_F(HistoryQuickProviderTest, SingleMatchWithCursor) { |
+ std::vector<std::string> expected_urls; |
+ expected_urls.push_back("http://slashdot.org/favorite_page.html"); |
+ // With cursor after "slash", we should retrieve the desired result but it |
+ // should not be allowed to be the default match. |
+ RunTestWithCursor(ASCIIToUTF16("slashfavorite_page.html"), 5, false, |
+ expected_urls, false, |
+ ASCIIToUTF16("slashdot.org/favorite_page.html"), |
+ base::string16()); |
+ // If the cursor is in the middle of a valid URL suggestion, it should be |
+ // allowed to be the default match. The inline completion will be empty |
+ // though as no completion is necessary. |
+ RunTestWithCursor(ASCIIToUTF16("slashdot.org/favorite_page.html"), 5, false, |
+ expected_urls, true, |
+ ASCIIToUTF16("slashdot.org/favorite_page.html"), |
+ base::string16()); |
+} |
+ |
TEST_F(HistoryQuickProviderTest, WordBoundariesWithPunctuationMatch) { |
std::vector<std::string> expected_urls; |
expected_urls.push_back("http://popularsitewithpathonly.com/moo"); |