Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 typedef std::map<content::RenderViewHost*, Sizes> RenderViewSizes; | 309 typedef std::map<content::RenderViewHost*, Sizes> RenderViewSizes; |
| 310 RenderViewSizes render_view_sizes_; | 310 RenderViewSizes render_view_sizes_; |
| 311 // Enlarge WebContentsView by this size insets in | 311 // Enlarge WebContentsView by this size insets in |
| 312 // DidStartNavigationToPendingEntry. | 312 // DidStartNavigationToPendingEntry. |
| 313 gfx::Size wcv_resize_insets_; | 313 gfx::Size wcv_resize_insets_; |
| 314 BrowserWindow* browser_window_; // Weak ptr. | 314 BrowserWindow* browser_window_; // Weak ptr. |
| 315 | 315 |
| 316 DISALLOW_COPY_AND_ASSIGN(RenderViewSizeObserver); | 316 DISALLOW_COPY_AND_ASSIGN(RenderViewSizeObserver); |
| 317 }; | 317 }; |
| 318 | 318 |
| 319 void ProceedThroughInterstitial(content::WebContents* web_contents) { | |
| 320 InterstitialPage* interstitial_page = web_contents->GetInterstitialPage(); | |
| 321 ASSERT_TRUE(interstitial_page); | |
| 322 | |
| 323 content::WindowedNotificationObserver observer( | |
| 324 content::NOTIFICATION_LOAD_STOP, | |
| 325 content::Source<NavigationController>(&web_contents->GetController())); | |
| 326 interstitial_page->Proceed(); | |
| 327 observer.Wait(); | |
| 328 } | |
| 329 | |
| 330 static bool GetFilePathWithHostAndPortReplacement( | |
|
Peter Kasting
2015/06/03 23:59:34
Nit: This doesn't need "static" as it's already in
lgarron
2015/06/04 00:26:34
Done.
| |
| 331 const std::string& original_file_path, | |
| 332 const net::HostPortPair& host_port_pair, | |
| 333 std::string* replacement_path) { | |
| 334 std::vector<net::SpawnedTestServer::StringPair> replacement_text; | |
| 335 replacement_text.push_back( | |
| 336 make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString())); | |
| 337 return net::SpawnedTestServer::GetFilePathWithReplacements( | |
| 338 original_file_path, replacement_text, replacement_path); | |
| 339 } | |
| 340 | |
| 341 // A WebContentsObserver useful for testing the |SecurityStyleChanged| | |
|
Peter Kasting
2015/06/03 23:59:34
Nit: || go around data members, not function names
lgarron
2015/06/04 00:26:35
Done.
| |
| 342 // method: it keeps track of the latest security style that was fired. | |
| 343 class SecurityStyleTestObserver : public WebContentsObserver { | |
| 344 public: | |
| 345 explicit SecurityStyleTestObserver(content::WebContents* web_contents) | |
| 346 : content::WebContentsObserver(web_contents), | |
| 347 latest_security_style_(content::SECURITY_STYLE_UNKNOWN) {} | |
| 348 ~SecurityStyleTestObserver() override {} | |
| 349 | |
| 350 void SecurityStyleChanged(content::SecurityStyle security_style) override { | |
| 351 latest_security_style_ = security_style; | |
| 352 } | |
| 353 | |
| 354 content::SecurityStyle latest_security_style() { | |
|
Peter Kasting
2015/06/03 23:59:34
Nit: const
lgarron
2015/06/04 00:26:35
Done.
| |
| 355 return latest_security_style_; | |
| 356 } | |
| 357 | |
| 358 private: | |
| 359 content::SecurityStyle latest_security_style_; | |
| 360 | |
| 361 DISALLOW_COPY_AND_ASSIGN(SecurityStyleTestObserver); | |
| 362 }; | |
| 363 | |
| 319 } // namespace | 364 } // namespace |
| 320 | 365 |
| 321 class BrowserTest : public ExtensionBrowserTest { | 366 class BrowserTest : public ExtensionBrowserTest { |
| 322 protected: | 367 protected: |
| 323 // In RTL locales wrap the page title with RTL embedding characters so that it | 368 // In RTL locales wrap the page title with RTL embedding characters so that it |
| 324 // matches the value returned by GetWindowTitle(). | 369 // matches the value returned by GetWindowTitle(). |
| 325 base::string16 LocaleWindowCaptionFromPageTitle( | 370 base::string16 LocaleWindowCaptionFromPageTitle( |
| 326 const base::string16& expected_title) { | 371 const base::string16& expected_title) { |
| 327 base::string16 page_title = WindowCaptionFromPageTitle(expected_title); | 372 base::string16 page_title = WindowCaptionFromPageTitle(expected_title); |
| 328 #if defined(OS_WIN) | 373 #if defined(OS_WIN) |
| (...skipping 2429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2758 // Don't proceed and wait for interstitial to detach. This doesn't | 2803 // Don't proceed and wait for interstitial to detach. This doesn't |
| 2759 // destroy |contents|. | 2804 // destroy |contents|. |
| 2760 interstitial->DontProceed(); | 2805 interstitial->DontProceed(); |
| 2761 content::WaitForInterstitialDetach(web_contents); | 2806 content::WaitForInterstitialDetach(web_contents); |
| 2762 // interstitial is deleted now. | 2807 // interstitial is deleted now. |
| 2763 | 2808 |
| 2764 EXPECT_TRUE(chrome::CanDuplicateTab(browser())); | 2809 EXPECT_TRUE(chrome::CanDuplicateTab(browser())); |
| 2765 EXPECT_TRUE(chrome::CanDuplicateTabAt(browser(), 0)); | 2810 EXPECT_TRUE(chrome::CanDuplicateTabAt(browser(), 0)); |
| 2766 EXPECT_TRUE(chrome::CanDuplicateTabAt(browser(), 1)); | 2811 EXPECT_TRUE(chrome::CanDuplicateTabAt(browser(), 1)); |
| 2767 } | 2812 } |
| 2813 | |
| 2814 // Test that the WebContentsObserver::SecurityStyleChanged event fires | |
| 2815 // with the current style on HTTPS, broken HTTPS, and valid HTTPS pages. | |
|
Peter Kasting
2015/06/03 23:59:34
Nit: First HTTPS should maybe be HTTP?
lgarron
2015/06/04 00:26:35
Done.
| |
| 2816 IN_PROC_BROWSER_TEST_F(BrowserTest, SecurityStyleChangedObserver) { | |
| 2817 // Create an HTTPS server for testing a valid security style. | |
|
Peter Kasting
2015/06/03 23:59:34
Nit: Seems like this block does more than just thi
lgarron
2015/06/04 00:26:34
I've removed the comment.
| |
| 2818 net::SpawnedTestServer https_test_server(net::SpawnedTestServer::TYPE_HTTPS, | |
| 2819 net::SpawnedTestServer::kLocalhost, | |
| 2820 base::FilePath(kDocRoot)); | |
| 2821 net::SpawnedTestServer https_test_server_expired( | |
| 2822 net::SpawnedTestServer::TYPE_HTTPS, | |
| 2823 net::SpawnedTestServer::SSLOptions( | |
| 2824 net::SpawnedTestServer::SSLOptions::CERT_EXPIRED), | |
| 2825 base::FilePath(kDocRoot)); | |
| 2826 ASSERT_TRUE(https_test_server.Start()); | |
| 2827 ASSERT_TRUE(https_test_server_expired.Start()); | |
| 2828 ASSERT_TRUE(test_server()->Start()); | |
| 2829 | |
| 2830 content::WebContents* web_contents = | |
| 2831 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 2832 SecurityStyleTestObserver observer(web_contents); | |
| 2833 | |
| 2834 // Visit an HTTP url. | |
| 2835 GURL http_url(test_server()->GetURL(std::string())); | |
| 2836 ui_test_utils::NavigateToURL(browser(), http_url); | |
| 2837 EXPECT_EQ(content::SECURITY_STYLE_UNAUTHENTICATED, | |
| 2838 observer.latest_security_style()); | |
| 2839 | |
| 2840 // Visit a valid HTTPS url. | |
| 2841 GURL valid_https_url(https_test_server.GetURL(std::string())); | |
| 2842 ui_test_utils::NavigateToURL(browser(), valid_https_url); | |
| 2843 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED, | |
| 2844 observer.latest_security_style()); | |
| 2845 | |
| 2846 // Visit an (otherwise valid) HTTPS page that displays mixed content. | |
| 2847 std::string replacement_path; | |
| 2848 ASSERT_TRUE(GetFilePathWithHostAndPortReplacement( | |
| 2849 "files/ssl/page_displays_insecure_content.html", | |
| 2850 test_server()->host_port_pair(), &replacement_path)); | |
| 2851 | |
| 2852 GURL mixed_content_url(https_test_server.GetURL(replacement_path)); | |
| 2853 ui_test_utils::NavigateToURL(browser(), mixed_content_url); | |
| 2854 EXPECT_EQ(content::SECURITY_STYLE_WARNING, observer.latest_security_style()); | |
| 2855 | |
| 2856 // Visit a broken HTTPS url. Other conditions cannot be tested after | |
| 2857 // this one because once the interstitial is clicked through, all URLs | |
| 2858 // for this host will remain in a broken state. | |
| 2859 GURL expired_url(https_test_server_expired.GetURL(std::string())); | |
| 2860 ui_test_utils::NavigateToURL(browser(), expired_url); | |
| 2861 | |
| 2862 ProceedThroughInterstitial(web_contents); | |
| 2863 EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATION_BROKEN, | |
| 2864 observer.latest_security_style()); | |
| 2865 } | |
| OLD | NEW |