Commit 82246f9b authored by Joe DeBlasio's avatar Joe DeBlasio Committed by Commit Bot

Assert contents of page in interstitials tests.

This CL allows the interstitials browser tests to verify that displayed
interstitials are the ones expected. Previously, tests only compared the
page titles, which were often shared between different interstitials.

Bug: 891096
Change-Id: Ieb5e9f9a90739cf35f2357655d5e0c31a2a68c91
Reviewed-on: https://chromium-review.googlesource.com/c/1297578Reviewed-by: default avatarCarlos IL <carlosil@chromium.org>
Commit-Queue: Joe DeBlasio <jdeblasio@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602463}
parent 0ceb353a
...@@ -11,9 +11,11 @@ ...@@ -11,9 +11,11 @@
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/strings/grit/components_strings.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_navigation_observer.h"
#include "ui/base/l10n/l10n_util.h"
class InterstitialUITest : public InProcessBrowserTest { class InterstitialUITest : public InProcessBrowserTest {
public: public:
...@@ -21,7 +23,14 @@ class InterstitialUITest : public InProcessBrowserTest { ...@@ -21,7 +23,14 @@ class InterstitialUITest : public InProcessBrowserTest {
~InterstitialUITest() override {} ~InterstitialUITest() override {}
protected: protected:
void TestInterstitial(GURL url, const std::string& page_title) { // Tests interstitial displayed at url to verify that it has the given
// page title and body content that is expected.
//
// page_title must be an exact match, while body content may appear anywhere
// in the rendered page. Thus an empty body_text never fails.
void TestInterstitial(GURL url,
const std::string& page_title,
const base::string16& body_text) {
ui_test_utils::NavigateToURL(browser(), url); ui_test_utils::NavigateToURL(browser(), url);
EXPECT_EQ( EXPECT_EQ(
base::ASCIIToUTF16(page_title), base::ASCIIToUTF16(page_title),
...@@ -32,6 +41,30 @@ class InterstitialUITest : public InProcessBrowserTest { ...@@ -32,6 +41,30 @@ class InterstitialUITest : public InProcessBrowserTest {
DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true); DevToolsWindowTesting::OpenDevToolsWindowSync(browser(), true);
EXPECT_TRUE(window); EXPECT_TRUE(window);
DevToolsWindowTesting::CloseDevToolsWindowSync(window); DevToolsWindowTesting::CloseDevToolsWindowSync(window);
if (body_text.empty())
return;
content::WebContents* contents =
browser()->tab_strip_model()->GetActiveWebContents();
EXPECT_GE(ui_test_utils::FindInPage(contents, body_text, true, true,
nullptr, nullptr),
1);
}
// Convenience function to test interstitial pages without provided body_text.
void TestInterstitial(GURL url,
const std::string& page_title) {
TestInterstitial(url, page_title, base::string16());
}
// Convenience function to test interstitial pages with l10n message_ids as
// body_text strings.
void TestInterstitial(GURL url,
const std::string& page_title,
int message_id) {
TestInterstitial(url, page_title, l10n_util::GetStringUTF16(message_id));
} }
}; };
...@@ -57,94 +90,88 @@ IN_PROC_BROWSER_TEST_F(InterstitialUITest, ...@@ -57,94 +90,88 @@ IN_PROC_BROWSER_TEST_F(InterstitialUITest,
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, SSLInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, SSLInterstitial) {
TestInterstitial( TestInterstitial(GURL("chrome://interstitials/ssl"), "Privacy error",
GURL("chrome://interstitials/ssl"), IDS_SSL_V2_HEADING);
"Privacy error");
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, SuperfishInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, SuperfishInterstitial) {
TestInterstitial(GURL("chrome://interstitials/superfish-ssl"), TestInterstitial(GURL("chrome://interstitials/superfish-ssl"),
"Privacy error"); "Privacy error", IDS_SSL_SUPERFISH_HEADING);
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, MITMSoftwareInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, MITMSoftwareInterstitial) {
TestInterstitial(GURL("chrome://interstitials/mitm-software-ssl"), TestInterstitial(GURL("chrome://interstitials/mitm-software-ssl"),
"Privacy error"); "Privacy error", IDS_MITM_SOFTWARE_HEADING);
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, PinnedCertInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, PinnedCertInterstitial) {
TestInterstitial(GURL("chrome://interstitials/ssl?type=hpkp_failure"), TestInterstitial(
"Privacy error"); GURL("chrome://interstitials/ssl?type=hpkp_failure"),
"Privacy error",
base::ASCIIToUTF16("NET::ERR_SSL_PINNED_KEY_NOT_IN_CERT_CHAIN"));
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, CTInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, CTInterstitial) {
TestInterstitial(GURL("chrome://interstitials/ssl?type=ct_failure"), TestInterstitial(
"Privacy error"); GURL("chrome://interstitials/ssl?type=ct_failure"),
bool found_ct_error = false; "Privacy error",
EXPECT_TRUE(content::ExecuteScriptAndExtractBool( base::ASCIIToUTF16("NET::ERR_CERTIFICATE_TRANSPARENCY_REQUIRED"));
browser()->tab_strip_model()->GetActiveWebContents(),
"window.domAutomationController.send(document.body.textContent.indexOf('"
"CERTIFICATE_TRANSPARENCY') != -1);",
&found_ct_error));
EXPECT_TRUE(found_ct_error);
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, MalwareInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, MalwareInterstitial) {
TestInterstitial( TestInterstitial(GURL("chrome://interstitials/safebrowsing?type=malware"),
GURL("chrome://interstitials/safebrowsing?type=malware"), "Security error", IDS_MALWARE_V3_HEADING);
"Security error");
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, PhishingInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, PhishingInterstitial) {
TestInterstitial( TestInterstitial(GURL("chrome://interstitials/safebrowsing?type=phishing"),
GURL("chrome://interstitials/safebrowsing?type=phishing"), "Security error", IDS_PHISHING_V4_HEADING);
"Security error");
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, UnwantedSoftwareInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, UnwantedSoftwareInterstitial) {
TestInterstitial(GURL("chrome://interstitials/safebrowsing?type=unwanted"), TestInterstitial(GURL("chrome://interstitials/safebrowsing?type=unwanted"),
"Security error"); "Security error", IDS_HARMFUL_V3_HEADING);
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, MalwareInterstitialQuiet) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, MalwareInterstitialQuiet) {
TestInterstitial( TestInterstitial(
GURL("chrome://interstitials/quietsafebrowsing?type=malware"), GURL("chrome://interstitials/quietsafebrowsing?type=malware"),
"Security error"); "Security error", IDS_MALWARE_WEBVIEW_HEADING);
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, PhishingInterstitialQuiet) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, PhishingInterstitialQuiet) {
TestInterstitial( TestInterstitial(
GURL("chrome://interstitials/quietsafebrowsing?type=phishing"), GURL("chrome://interstitials/quietsafebrowsing?type=phishing"),
"Security error"); "Security error", IDS_PHISHING_WEBVIEW_HEADING);
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, UnwantedSoftwareInterstitialQuiet) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, UnwantedSoftwareInterstitialQuiet) {
TestInterstitial( TestInterstitial(
GURL("chrome://interstitials/quietsafebrowsing?type=unwanted"), GURL("chrome://interstitials/quietsafebrowsing?type=unwanted"),
"Security error"); "Security error", IDS_HARMFUL_WEBVIEW_HEADING);
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, BillingInterstitialQuiet) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, BillingInterstitialQuiet) {
TestInterstitial( TestInterstitial(
GURL("chrome://interstitials/quietsafebrowsing?type=billing"), GURL("chrome://interstitials/quietsafebrowsing?type=billing"),
"Security error"); "Security error", IDS_BILLING_WEBVIEW_HEADING);
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, ClientsideMalwareInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, ClientsideMalwareInterstitial) {
TestInterstitial( TestInterstitial(
GURL("chrome://interstitials/safebrowsing?type=clientside_malware"), GURL("chrome://interstitials/safebrowsing?type=clientside_malware"),
"Security error"); "Security error", IDS_MALWARE_V3_HEADING);
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, ClientsidePhishingInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, ClientsidePhishingInterstitial) {
TestInterstitial( TestInterstitial(
GURL("chrome://interstitials/safebrowsing?type=clientside_phishing"), GURL("chrome://interstitials/safebrowsing?type=clientside_phishing"),
"Security error"); "Security error", IDS_PHISHING_V4_HEADING);
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, BillingInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, BillingInterstitial) {
TestInterstitial(GURL("chrome://interstitials/safebrowsing?type=billing"), TestInterstitial(GURL("chrome://interstitials/safebrowsing?type=billing"),
"Security error"); "Security error", IDS_BILLING_HEADING);
} }
IN_PROC_BROWSER_TEST_F(InterstitialUITest, CaptivePortalInterstitial) { IN_PROC_BROWSER_TEST_F(InterstitialUITest, CaptivePortalInterstitial) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment