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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_model_unittest.cc

Issue 1324293003: Revert of Refactor connection_security into SecurityStateModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 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 "components/toolbar/toolbar_model.h" 5 #include "components/toolbar/toolbar_model.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/field_trial.h" 8 #include "base/metrics/field_trial.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 10 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
11 #include "chrome/browser/search/search.h" 11 #include "chrome/browser/search/search.h"
12 #include "chrome/browser/search_engines/template_url_service_factory.h" 12 #include "chrome/browser/search_engines/template_url_service_factory.h"
13 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" 13 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h"
14 #include "chrome/browser/ssl/security_state_model.h"
15 #include "chrome/browser/ui/browser.h" 14 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
18 #include "chrome/test/base/browser_with_test_window_test.h" 17 #include "chrome/test/base/browser_with_test_window_test.h"
19 #include "components/google/core/browser/google_switches.h" 18 #include "components/google/core/browser/google_switches.h"
20 #include "components/search/search.h" 19 #include "components/search/search.h"
21 #include "components/toolbar/toolbar_model.h" 20 #include "components/toolbar/toolbar_model.h"
22 #include "components/variations/entropy_provider.h" 21 #include "components/variations/entropy_provider.h"
23 #include "content/public/browser/navigation_entry.h" 22 #include "content/public/browser/navigation_entry.h"
24 #include "content/public/common/ssl_status.h" 23 #include "content/public/common/ssl_status.h"
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), 125 GURL("https://google.com/search?q=ftp://tractorsupply.ie&espv=1"),
127 base::ASCIIToUTF16( 126 base::ASCIIToUTF16(
128 "https://google.com/search?q=ftp://tractorsupply.ie&espv=1"), 127 "https://google.com/search?q=ftp://tractorsupply.ie&espv=1"),
129 base::ASCIIToUTF16("ftp://tractorsupply.ie"), 128 base::ASCIIToUTF16("ftp://tractorsupply.ie"),
130 base::ASCIIToUTF16("ftp://tractorsupply.ie"), 129 base::ASCIIToUTF16("ftp://tractorsupply.ie"),
131 true, 130 true,
132 true 131 true
133 }, 132 },
134 }; 133 };
135 134
136 void SetSecurityStyle(content::NavigationController* controller,
137 content::SecurityStyle new_style) {
138 controller->GetVisibleEntry()->GetSSL().security_style = new_style;
139 SecurityStateModel* model =
140 SecurityStateModel::FromWebContents(controller->GetWebContents());
141 ASSERT_TRUE(model);
142 model->SecurityStateChanged();
143 }
144
145 } // namespace 135 } // namespace
146 136
147 137
148 // ToolbarModelTest ----------------------------------------------------------- 138 // ToolbarModelTest -----------------------------------------------------------
149 139
150 class ToolbarModelTest : public BrowserWithTestWindowTest { 140 class ToolbarModelTest : public BrowserWithTestWindowTest {
151 public: 141 public:
152 ToolbarModelTest(); 142 ToolbarModelTest();
153 ToolbarModelTest(Browser::Type browser_type, 143 ToolbarModelTest(Browser::Type browser_type,
154 chrome::HostDesktopType host_desktop_type, 144 chrome::HostDesktopType host_desktop_type,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 EXPECT_EQ(expected_text, toolbar_model->GetText()); 198 EXPECT_EQ(expected_text, toolbar_model->GetText());
209 EXPECT_EQ(would_perform_search_term_replacement, 199 EXPECT_EQ(would_perform_search_term_replacement,
210 toolbar_model->WouldPerformSearchTermReplacement(false)); 200 toolbar_model->WouldPerformSearchTermReplacement(false));
211 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL()); 201 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL());
212 202
213 // Check after commit. 203 // Check after commit.
214 CommitPendingLoad(controller); 204 CommitPendingLoad(controller);
215 // Fake a secure connection for HTTPS URLs, or the toolbar will refuse to 205 // Fake a secure connection for HTTPS URLs, or the toolbar will refuse to
216 // extract search terms. 206 // extract search terms.
217 if (url.SchemeIsCryptographic()) { 207 if (url.SchemeIsCryptographic()) {
218 ASSERT_NO_FATAL_FAILURE( 208 controller->GetVisibleEntry()->GetSSL().security_style =
219 SetSecurityStyle(controller, content::SECURITY_STYLE_AUTHENTICATED)); 209 content::SECURITY_STYLE_AUTHENTICATED;
220 } 210 }
221 EXPECT_EQ(expected_text, toolbar_model->GetText()); 211 EXPECT_EQ(expected_text, toolbar_model->GetText());
222 EXPECT_EQ(would_perform_search_term_replacement, 212 EXPECT_EQ(would_perform_search_term_replacement,
223 toolbar_model->WouldPerformSearchTermReplacement(false)); 213 toolbar_model->WouldPerformSearchTermReplacement(false));
224 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL()); 214 EXPECT_EQ(should_display_url, toolbar_model->ShouldDisplayURL());
225 215
226 // Now pretend the user started modifying the omnibox. 216 // Now pretend the user started modifying the omnibox.
227 toolbar_model->set_input_in_progress(true); 217 toolbar_model->set_input_in_progress(true);
228 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); 218 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false));
229 EXPECT_EQ(would_perform_search_term_replacement, 219 EXPECT_EQ(would_perform_search_term_replacement,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 search::EnableQueryExtractionForTesting(); 284 search::EnableQueryExtractionForTesting();
295 AddTab(browser(), GURL(url::kAboutBlankURL)); 285 AddTab(browser(), GURL(url::kAboutBlankURL));
296 286
297 // While loading, we should be willing to extract search terms. 287 // While loading, we should be willing to extract search terms.
298 content::NavigationController* controller = 288 content::NavigationController* controller =
299 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController(); 289 &browser()->tab_strip_model()->GetWebContentsAt(0)->GetController();
300 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"), 290 controller->LoadURL(GURL("https://google.com/search?q=tractor+supply&espv=1"),
301 content::Referrer(), ui::PAGE_TRANSITION_LINK, 291 content::Referrer(), ui::PAGE_TRANSITION_LINK,
302 std::string()); 292 std::string());
303 ToolbarModel* toolbar_model = browser()->toolbar_model(); 293 ToolbarModel* toolbar_model = browser()->toolbar_model();
304 ASSERT_NO_FATAL_FAILURE( 294 controller->GetVisibleEntry()->GetSSL().security_style =
305 SetSecurityStyle(controller, content::SECURITY_STYLE_UNKNOWN)); 295 content::SECURITY_STYLE_UNKNOWN;
306 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false)); 296 EXPECT_TRUE(toolbar_model->WouldPerformSearchTermReplacement(false));
307 297
308 // When done loading, we shouldn't extract search terms if we didn't get an 298 // When done loading, we shouldn't extract search terms if we didn't get an
309 // authenticated connection. 299 // authenticated connection.
310 CommitPendingLoad(controller); 300 CommitPendingLoad(controller);
311 ASSERT_NO_FATAL_FAILURE( 301 controller->GetVisibleEntry()->GetSSL().security_style =
312 SetSecurityStyle(controller, content::SECURITY_STYLE_UNKNOWN)); 302 content::SECURITY_STYLE_UNKNOWN;
313 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false)); 303 EXPECT_FALSE(toolbar_model->WouldPerformSearchTermReplacement(false));
314 } 304 }
315 305
316 // When the Google base URL is overridden on the command line, we should extract 306 // When the Google base URL is overridden on the command line, we should extract
317 // search terms from URLs that start with that base URL even when they're not 307 // search terms from URLs that start with that base URL even when they're not
318 // secure. 308 // secure.
319 TEST_F(ToolbarModelTest, GoogleBaseURL) { 309 TEST_F(ToolbarModelTest, GoogleBaseURL) {
320 search::EnableQueryExtractionForTesting(); 310 search::EnableQueryExtractionForTesting();
321 AddTab(browser(), GURL(url::kAboutBlankURL)); 311 AddTab(browser(), GURL(url::kAboutBlankURL));
322 312
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 355
366 // Disabling URL replacement should reset to only showing URLs. 356 // Disabling URL replacement should reset to only showing URLs.
367 browser()->toolbar_model()->set_url_replacement_enabled(false); 357 browser()->toolbar_model()->set_url_replacement_enabled(false);
368 for (size_t i = 0; i < arraysize(test_items); ++i) { 358 for (size_t i = 0; i < arraysize(test_items); ++i) {
369 const TestItem& test_item = test_items[i]; 359 const TestItem& test_item = test_items[i];
370 NavigateAndCheckText(test_item.url, 360 NavigateAndCheckText(test_item.url,
371 test_item.expected_text_url_replacement_inactive, 361 test_item.expected_text_url_replacement_inactive,
372 false, test_item.should_display_url); 362 false, test_item.should_display_url);
373 } 363 }
374 } 364 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_model_impl.cc ('k') | chrome/browser/ui/views/location_bar/location_bar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698