Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(68)

Side by Side Diff: components/omnibox/browser/omnibox_edit_unittest.cc

Issue 2046263002: Fix DCHECK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@cleanup
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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_;
208 213
Peter Kasting 2016/06/08 01:21:34 Will remove this blank line before landing
Mark P 2016/06/08 20:35:57 Remember me.
214 AutocompleteMatch alternate_nav_match_;
215
209 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxClient); 216 DISALLOW_COPY_AND_ASSIGN(TestingOmniboxClient);
210 }; 217 };
211 218
212 TestingOmniboxClient::TestingOmniboxClient() 219 TestingOmniboxClient::TestingOmniboxClient()
213 : autocomplete_classifier_( 220 : autocomplete_classifier_(
214 base::WrapUnique(new AutocompleteController( 221 base::WrapUnique(new AutocompleteController(
215 CreateAutocompleteProviderClient(), 222 CreateAutocompleteProviderClient(),
216 nullptr, 223 nullptr,
217 AutocompleteClassifier::kDefaultOmniboxProviders)), 224 AutocompleteClassifier::kDefaultOmniboxProviders)),
218 base::WrapUnique(new TestingSchemeClassifier())) {} 225 base::WrapUnique(new TestingSchemeClassifier())) {}
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
364 model()->SetUserText(base::ASCIIToUTF16("he")); 371 model()->SetUserText(base::ASCIIToUTF16("he"));
365 model()->OnPopupDataChanged(base::ASCIIToUTF16("llo"), nullptr, 372 model()->OnPopupDataChanged(base::ASCIIToUTF16("llo"), nullptr,
366 base::string16(), false); 373 base::string16(), false);
367 EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText()); 374 EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText());
368 EXPECT_EQ(base::ASCIIToUTF16("llo"), view().inline_autocomplete_text()); 375 EXPECT_EQ(base::ASCIIToUTF16("llo"), view().inline_autocomplete_text());
369 376
370 model()->AcceptTemporaryTextAsUserText(); 377 model()->AcceptTemporaryTextAsUserText();
371 EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText()); 378 EXPECT_EQ(base::ASCIIToUTF16("hello"), view().GetText());
372 EXPECT_EQ(base::string16(), view().inline_autocomplete_text()); 379 EXPECT_EQ(base::string16(), view().inline_autocomplete_text());
373 } 380 }
381
382 TEST_F(OmniboxEditTest, HasHTTP) {
Mark P 2016/06/08 20:35:57 nit: AlternateNavHasHttp? Otherwise this test, wit
Peter Kasting 2016/06/08 20:52:24 Honestly, I need to figure out better whether the
Peter Kasting 2016/06/09 19:26:56 Turns out I can indeed just set it to false. Did
383 const TestingOmniboxClient* client =
384 static_cast<TestingOmniboxClient*>(model()->client());
385 const AutocompleteMatch match(
386 model()->autocomplete_controller()->history_url_provider(), 0, false,
387 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
Mark P 2016/06/08 20:35:57 For realism, can you please make this a search pro
Peter Kasting 2016/06/08 20:52:24 Good idea.
388 const GURL alternate_nav_url("http://ab%20cd/");
389
390 model()->OnSetFocus(false); // Avoids DCHECK in OpenMatch().
391 model()->SetUserText(base::ASCIIToUTF16("http://ab cd"));
392 model()->OpenMatch(match, CURRENT_TAB, alternate_nav_url, base::string16(),
393 0);
394 EXPECT_TRUE(AutocompleteInput::HasHTTPScheme(
395 client->alternate_nav_match().fill_into_edit));
396
397 model()->SetUserText(base::ASCIIToUTF16("ab cd"));
398 model()->OpenMatch(match, CURRENT_TAB, alternate_nav_url, base::string16(),
399 0);
400 EXPECT_FALSE(AutocompleteInput::HasHTTPScheme(
401 client->alternate_nav_match().fill_into_edit));
402 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698