| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "components/omnibox/browser/autocomplete_classifier.h" | 11 #include "components/omnibox/browser/autocomplete_classifier.h" |
| 12 #include "components/omnibox/browser/autocomplete_controller.h" | 12 #include "components/omnibox/browser/autocomplete_controller.h" |
| 13 #include "components/omnibox/browser/autocomplete_scheme_classifier.h" | 13 #include "components/omnibox/browser/autocomplete_scheme_classifier.h" |
| 14 #include "components/omnibox/browser/history_url_provider.h" | |
| 15 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" | 14 #include "components/omnibox/browser/mock_autocomplete_provider_client.h" |
| 16 #include "components/omnibox/browser/omnibox_client.h" | 15 #include "components/omnibox/browser/omnibox_client.h" |
| 17 #include "components/omnibox/browser/omnibox_edit_controller.h" | 16 #include "components/omnibox/browser/omnibox_edit_controller.h" |
| 18 #include "components/omnibox/browser/omnibox_edit_model.h" | 17 #include "components/omnibox/browser/omnibox_edit_model.h" |
| 19 #include "components/omnibox/browser/omnibox_view.h" | 18 #include "components/omnibox/browser/omnibox_view.h" |
| 19 #include "components/omnibox/browser/search_provider.h" |
| 20 #include "components/search_engines/search_terms_data.h" | 20 #include "components/search_engines/search_terms_data.h" |
| 21 #include "components/search_engines/template_url_service.h" | 21 #include "components/search_engines/template_url_service.h" |
| 22 #include "components/search_engines/template_url_service_client.h" | 22 #include "components/search_engines/template_url_service_client.h" |
| 23 #include "components/sessions/core/session_id.h" | 23 #include "components/sessions/core/session_id.h" |
| 24 #include "components/toolbar/test_toolbar_model.h" | 24 #include "components/toolbar/test_toolbar_model.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 class TestingOmniboxView : public OmniboxView { | 29 class TestingOmniboxView : public OmniboxView { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 private: | 134 private: |
| 135 DISALLOW_COPY_AND_ASSIGN(TestingSchemeClassifier); | 135 DISALLOW_COPY_AND_ASSIGN(TestingSchemeClassifier); |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 class TestingOmniboxClient : public OmniboxClient { | 138 class TestingOmniboxClient : public OmniboxClient { |
| 139 public: | 139 public: |
| 140 TestingOmniboxClient(); | 140 TestingOmniboxClient(); |
| 141 ~TestingOmniboxClient() override; | 141 ~TestingOmniboxClient() override; |
| 142 | 142 |
| 143 const AutocompleteMatch& alternate_nav_match() const { |
| 144 return alternate_nav_match_; |
| 145 } |
| 146 |
| 143 // OmniboxClient: | 147 // OmniboxClient: |
| 144 std::unique_ptr<AutocompleteProviderClient> CreateAutocompleteProviderClient() | 148 std::unique_ptr<AutocompleteProviderClient> CreateAutocompleteProviderClient() |
| 145 override; | 149 override; |
| 146 | 150 |
| 147 std::unique_ptr<OmniboxNavigationObserver> CreateOmniboxNavigationObserver( | 151 std::unique_ptr<OmniboxNavigationObserver> CreateOmniboxNavigationObserver( |
| 148 const base::string16& text, | 152 const base::string16& text, |
| 149 const AutocompleteMatch& match, | 153 const AutocompleteMatch& match, |
| 150 const AutocompleteMatch& alternate_nav_match) override { | 154 const AutocompleteMatch& alternate_nav_match) override { |
| 155 alternate_nav_match_ = alternate_nav_match; |
| 151 return nullptr; | 156 return nullptr; |
| 152 } | 157 } |
| 153 bool CurrentPageExists() const override { return true; } | 158 bool CurrentPageExists() const override { return true; } |
| 154 const GURL& GetURL() const override { return GURL::EmptyGURL(); } | 159 const GURL& GetURL() const override { return GURL::EmptyGURL(); } |
| 155 const base::string16& GetTitle() const override { | 160 const base::string16& GetTitle() const override { |
| 156 return base::EmptyString16(); | 161 return base::EmptyString16(); |
| 157 } | 162 } |
| 158 gfx::Image GetFavicon() const override { return gfx::Image(); } | 163 gfx::Image GetFavicon() const override { return gfx::Image(); } |
| 159 bool IsInstantNTP() const override { return false; } | 164 bool IsInstantNTP() const override { return false; } |
| 160 bool IsSearchResultsPage() const override { return false; } | 165 bool IsSearchResultsPage() const override { return false; } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 void OnInputAccepted(const AutocompleteMatch& match) override {} | 203 void OnInputAccepted(const AutocompleteMatch& match) override {} |
| 199 void OnRevert() override {} | 204 void OnRevert() override {} |
| 200 void OnURLOpenedFromOmnibox(OmniboxLog* log) override {} | 205 void OnURLOpenedFromOmnibox(OmniboxLog* log) override {} |
| 201 void OnBookmarkLaunched() override {} | 206 void OnBookmarkLaunched() override {} |
| 202 void DiscardNonCommittedNavigations() override {} | 207 void DiscardNonCommittedNavigations() override {} |
| 203 | 208 |
| 204 private: | 209 private: |
| 205 SessionID session_id_; | 210 SessionID session_id_; |
| 206 TestingSchemeClassifier scheme_classifier_; | 211 TestingSchemeClassifier scheme_classifier_; |
| 207 AutocompleteClassifier autocomplete_classifier_; | 212 AutocompleteClassifier autocomplete_classifier_; |
| 213 AutocompleteMatch alternate_nav_match_; |
| 208 | 214 |
| 209 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxClient); | 215 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxClient); |
| 210 }; | 216 }; |
| 211 | 217 |
| 212 TestingOmniboxClient::TestingOmniboxClient() | 218 TestingOmniboxClient::TestingOmniboxClient() |
| 213 : autocomplete_classifier_( | 219 : autocomplete_classifier_( |
| 214 base::WrapUnique(new AutocompleteController( | 220 base::WrapUnique(new AutocompleteController( |
| 215 CreateAutocompleteProviderClient(), | 221 CreateAutocompleteProviderClient(), |
| 216 nullptr, | 222 nullptr, |
| 217 AutocompleteClassifier::kDefaultOmniboxProviders)), | 223 AutocompleteClassifier::kDefaultOmniboxProviders)), |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 model()->SetUserText(base::ASCIIToUTF16("he")); | 372 model()->SetUserText(base::ASCIIToUTF16("he")); |
| 367 model()->OnPopupDataChanged(base::ASCIIToUTF16("llo"), nullptr, | 373 model()->OnPopupDataChanged(base::ASCIIToUTF16("llo"), nullptr, |
| 368 base::string16(), false); | 374 base::string16(), false); |
| 369 EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText()); | 375 EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText()); |
| 370 EXPECT_EQ(base::ASCIIToUTF16("llo"), view().inline_autocomplete_text()); | 376 EXPECT_EQ(base::ASCIIToUTF16("llo"), view().inline_autocomplete_text()); |
| 371 | 377 |
| 372 model()->AcceptTemporaryTextAsUserText(); | 378 model()->AcceptTemporaryTextAsUserText(); |
| 373 EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText()); | 379 EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText()); |
| 374 EXPECT_EQ(base::string16(), view().inline_autocomplete_text()); | 380 EXPECT_EQ(base::string16(), view().inline_autocomplete_text()); |
| 375 } | 381 } |
| 382 |
| 383 // This verifies the fix for a bug where calling OpenMatch() with a valid |
| 384 // alternate nav URL would fail a DCHECK if the input began with "http://". |
| 385 // The failure was due to erroneously trying to strip the scheme from the |
| 386 // resulting fill_into_edit. Alternate nav matches are never shown, so there's |
| 387 // no need to ever try and strip this scheme. |
| 388 TEST_F(OmniboxEditTest, AlternateNavHasHTTP) { |
| 389 const TestingOmniboxClient* client = |
| 390 static_cast<TestingOmniboxClient*>(model()->client()); |
| 391 const AutocompleteMatch match( |
| 392 model()->autocomplete_controller()->search_provider(), 0, false, |
| 393 AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED); |
| 394 const GURL alternate_nav_url("http://ab%20cd/"); |
| 395 |
| 396 model()->OnSetFocus(false); // Avoids DCHECK in OpenMatch(). |
| 397 model()->SetUserText(base::ASCIIToUTF16("http://ab cd")); |
| 398 model()->OpenMatch(match, CURRENT_TAB, alternate_nav_url, base::string16(), |
| 399 0); |
| 400 EXPECT_TRUE(AutocompleteInput::HasHTTPScheme( |
| 401 client->alternate_nav_match().fill_into_edit)); |
| 402 |
| 403 model()->SetUserText(base::ASCIIToUTF16("ab cd")); |
| 404 model()->OpenMatch(match, CURRENT_TAB, alternate_nav_url, base::string16(), |
| 405 0); |
| 406 EXPECT_TRUE(AutocompleteInput::HasHTTPScheme( |
| 407 client->alternate_nav_match().fill_into_edit)); |
| 408 } |
| OLD | NEW |