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

Unified Diff: chrome/browser/ui/browser_browsertest.cc

Issue 1162663004: Introduce browser-side plumbing for sending the lock icon status to DevTools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased onto latest master. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/browser_browsertest.cc
diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc
index 9cf66fa789c6debc3f70fd713a11b14051e92f17..2185ad85facae646e7742cc2be8845e046dad69d 100644
--- a/chrome/browser/ui/browser_browsertest.cc
+++ b/chrome/browser/ui/browser_browsertest.cc
@@ -316,6 +316,51 @@ class RenderViewSizeObserver : public content::WebContentsObserver {
DISALLOW_COPY_AND_ASSIGN(RenderViewSizeObserver);
};
+void ProceedThroughInterstitial(content::WebContents* web_contents) {
+ InterstitialPage* interstitial_page = web_contents->GetInterstitialPage();
+ ASSERT_TRUE(interstitial_page);
+
+ content::WindowedNotificationObserver observer(
+ content::NOTIFICATION_LOAD_STOP,
+ content::Source<NavigationController>(&web_contents->GetController()));
+ interstitial_page->Proceed();
+ observer.Wait();
+}
+
+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.
+ const std::string& original_file_path,
+ const net::HostPortPair& host_port_pair,
+ std::string* replacement_path) {
+ std::vector<net::SpawnedTestServer::StringPair> replacement_text;
+ replacement_text.push_back(
+ make_pair("REPLACE_WITH_HOST_AND_PORT", host_port_pair.ToString()));
+ return net::SpawnedTestServer::GetFilePathWithReplacements(
+ original_file_path, replacement_text, replacement_path);
+}
+
+// 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.
+// method: it keeps track of the latest security style that was fired.
+class SecurityStyleTestObserver : public WebContentsObserver {
+ public:
+ explicit SecurityStyleTestObserver(content::WebContents* web_contents)
+ : content::WebContentsObserver(web_contents),
+ latest_security_style_(content::SECURITY_STYLE_UNKNOWN) {}
+ ~SecurityStyleTestObserver() override {}
+
+ void SecurityStyleChanged(content::SecurityStyle security_style) override {
+ latest_security_style_ = security_style;
+ }
+
+ content::SecurityStyle latest_security_style() {
Peter Kasting 2015/06/03 23:59:34 Nit: const
lgarron 2015/06/04 00:26:35 Done.
+ return latest_security_style_;
+ }
+
+ private:
+ content::SecurityStyle latest_security_style_;
+
+ DISALLOW_COPY_AND_ASSIGN(SecurityStyleTestObserver);
+};
+
} // namespace
class BrowserTest : public ExtensionBrowserTest {
@@ -2765,3 +2810,56 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, CanDuplicateTab) {
EXPECT_TRUE(chrome::CanDuplicateTabAt(browser(), 0));
EXPECT_TRUE(chrome::CanDuplicateTabAt(browser(), 1));
}
+
+// Test that the WebContentsObserver::SecurityStyleChanged event fires
+// 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.
+IN_PROC_BROWSER_TEST_F(BrowserTest, SecurityStyleChangedObserver) {
+ // 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.
+ net::SpawnedTestServer https_test_server(net::SpawnedTestServer::TYPE_HTTPS,
+ net::SpawnedTestServer::kLocalhost,
+ base::FilePath(kDocRoot));
+ net::SpawnedTestServer https_test_server_expired(
+ net::SpawnedTestServer::TYPE_HTTPS,
+ net::SpawnedTestServer::SSLOptions(
+ net::SpawnedTestServer::SSLOptions::CERT_EXPIRED),
+ base::FilePath(kDocRoot));
+ ASSERT_TRUE(https_test_server.Start());
+ ASSERT_TRUE(https_test_server_expired.Start());
+ ASSERT_TRUE(test_server()->Start());
+
+ content::WebContents* web_contents =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ SecurityStyleTestObserver observer(web_contents);
+
+ // Visit an HTTP url.
+ GURL http_url(test_server()->GetURL(std::string()));
+ ui_test_utils::NavigateToURL(browser(), http_url);
+ EXPECT_EQ(content::SECURITY_STYLE_UNAUTHENTICATED,
+ observer.latest_security_style());
+
+ // Visit a valid HTTPS url.
+ GURL valid_https_url(https_test_server.GetURL(std::string()));
+ ui_test_utils::NavigateToURL(browser(), valid_https_url);
+ EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATED,
+ observer.latest_security_style());
+
+ // Visit an (otherwise valid) HTTPS page that displays mixed content.
+ std::string replacement_path;
+ ASSERT_TRUE(GetFilePathWithHostAndPortReplacement(
+ "files/ssl/page_displays_insecure_content.html",
+ test_server()->host_port_pair(), &replacement_path));
+
+ GURL mixed_content_url(https_test_server.GetURL(replacement_path));
+ ui_test_utils::NavigateToURL(browser(), mixed_content_url);
+ EXPECT_EQ(content::SECURITY_STYLE_WARNING, observer.latest_security_style());
+
+ // Visit a broken HTTPS url. Other conditions cannot be tested after
+ // this one because once the interstitial is clicked through, all URLs
+ // for this host will remain in a broken state.
+ GURL expired_url(https_test_server_expired.GetURL(std::string()));
+ ui_test_utils::NavigateToURL(browser(), expired_url);
+
+ ProceedThroughInterstitial(web_contents);
+ EXPECT_EQ(content::SECURITY_STYLE_AUTHENTICATION_BROKEN,
+ observer.latest_security_style());
+}

Powered by Google App Engine
This is Rietveld 408576698