Commit 9c40479a authored by Giovanni Ortuño Urquidi's avatar Giovanni Ortuño Urquidi Committed by Commit Bot

desktop-pwas: Clean up and add new location bar tests

Changes tests to use embedded test servers so that URLs can be loaded
successfully. This deflakes tests and allows us to test more cases e.g.
pages with mixed content, pages with invalid certificates etc.

Also adds tests for mixed content and invalid certificates.

Based on https://crrev.com/c/923226 by mgiuca.

Bug: 825713, 814400
Change-Id: I8603f3e6340eebbbc2faed594825745aed10bb0a
Reviewed-on: https://chromium-review.googlesource.com/994553Reviewed-by: default avatarBen Wells <benwells@chromium.org>
Reviewed-by: default avatarMatt Giuca <mgiuca@chromium.org>
Commit-Queue: Giovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548718}
parent 023aea51
...@@ -38,7 +38,11 @@ ...@@ -38,7 +38,11 @@
#include "chrome/browser/ui/toolbar/app_menu_model.h" #include "chrome/browser/ui/toolbar/app_menu_model.h"
#include "chrome/browser/web_applications/web_app.h" #include "chrome/browser/web_applications/web_app.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "components/security_interstitials/core/controller_client.h"
#include "content/public/browser/interstitial_page.h"
#include "content/public/browser/interstitial_page_delegate.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
...@@ -96,22 +100,43 @@ enum class AppType { ...@@ -96,22 +100,43 @@ enum class AppType {
const auto kAppTypeValues = const auto kAppTypeValues =
::testing::Values(AppType::HOSTED_APP, AppType::BOOKMARK_APP); ::testing::Values(AppType::HOSTED_APP, AppType::BOOKMARK_APP);
void NavigateToURLAndWait(Browser* browser, const GURL& url) { // If |proceed_through_interstitial| is true, asserts that a security
content::TestNavigationObserver observer( // interstitial is shown, and clicks through it, before returning.
browser->tab_strip_model()->GetActiveWebContents(), void NavigateToURLAndWait(Browser* browser,
content::MessageLoopRunner::QuitMode::DEFERRED); const GURL& url,
NavigateParams params(browser, url, ui::PAGE_TRANSITION_LINK); bool proceed_through_interstitial = false) {
ui_test_utils::NavigateToURL(&params); WebContents* web_contents =
observer.Wait(); browser->tab_strip_model()->GetActiveWebContents();
{
content::TestNavigationObserver observer(
web_contents, content::MessageLoopRunner::QuitMode::DEFERRED);
NavigateParams params(browser, url, ui::PAGE_TRANSITION_LINK);
ui_test_utils::NavigateToURL(&params);
observer.WaitForNavigationFinished();
}
if (!proceed_through_interstitial)
return;
content::InterstitialPage* interstitial = web_contents->GetInterstitialPage();
{
// Need a second TestNavigationObserver; the above one is spent.
content::TestNavigationObserver observer(
web_contents, content::MessageLoopRunner::QuitMode::DEFERRED);
ASSERT_TRUE(interstitial);
interstitial->GetDelegateForTesting()->CommandReceived(
base::IntToString(security_interstitials::CMD_PROCEED));
observer.Wait();
}
} }
// Used by ShouldLocationBarForXXX. Performs a navigation and then checks that // Used by ShouldLocationBarForXXX. Performs a navigation and then checks that
// the location bar visibility is as expcted. // the location bar visibility is as expcted.
void NavigateAndCheckForLocationBar(Browser* browser, void NavigateAndCheckForLocationBar(Browser* browser,
const std::string& url_string, const GURL& url,
bool expected_visibility) { bool expected_visibility,
GURL url(url_string); bool proceed_through_interstitial = false) {
NavigateToURLAndWait(browser, url); NavigateToURLAndWait(browser, url, proceed_through_interstitial);
EXPECT_EQ(expected_visibility, EXPECT_EQ(expected_visibility,
browser->hosted_app_controller()->ShouldShowLocationBar()); browser->hosted_app_controller()->ShouldShowLocationBar());
} }
...@@ -206,7 +231,11 @@ class HostedAppTest ...@@ -206,7 +231,11 @@ class HostedAppTest
scoped_feature_list_.InitAndEnableFeature(features::kDesktopPWAWindowing); scoped_feature_list_.InitAndEnableFeature(features::kDesktopPWAWindowing);
} else { } else {
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
scoped_feature_list_.InitAndEnableFeature(features::kBookmarkApps); scoped_feature_list_.InitWithFeatures({features::kBookmarkApps},
{features::kDesktopPWAWindowing});
#else
scoped_feature_list_.InitAndDisableFeature(
features::kDesktopPWAWindowing);
#endif #endif
} }
...@@ -214,6 +243,15 @@ class HostedAppTest ...@@ -214,6 +243,15 @@ class HostedAppTest
} }
protected: protected:
void SetupAppWithURL(const GURL& app_url) {
// TODO(ortuno): Use InstallBookmarkApp instead of loading a manifest,
// if |app_type_ == BOOKMARK_APP|.
extensions::TestExtensionDir test_app_dir;
test_app_dir.WriteManifest(
base::StringPrintf(kAppDotComManifest, app_url.spec().c_str()));
SetupApp(test_app_dir.UnpackedPath());
}
void SetupApp(const std::string& app_folder) { void SetupApp(const std::string& app_folder) {
SetupApp(test_data_dir_.AppendASCII(app_folder)); SetupApp(test_data_dir_.AppendASCII(app_folder));
} }
...@@ -325,6 +363,10 @@ class HostedAppTest ...@@ -325,6 +363,10 @@ class HostedAppTest
net::EmbeddedTestServer* https_server() { return &https_server_; } net::EmbeddedTestServer* https_server() { return &https_server_; }
CertVerifierBrowserTest::CertVerifier* cert_verifier() {
return &cert_verifier_;
}
private: private:
class EmptyAcceleratorProvider : public ui::AcceleratorProvider { class EmptyAcceleratorProvider : public ui::AcceleratorProvider {
public: public:
...@@ -454,67 +496,98 @@ IN_PROC_BROWSER_TEST_P(HostedAppTest, WebContentsPrefsOpenInChrome) { ...@@ -454,67 +496,98 @@ IN_PROC_BROWSER_TEST_P(HostedAppTest, WebContentsPrefsOpenInChrome) {
// Check that the location bar is shown correctly. // Check that the location bar is shown correctly.
IN_PROC_BROWSER_TEST_P(HostedAppTest, ShouldShowLocationBar) { IN_PROC_BROWSER_TEST_P(HostedAppTest, ShouldShowLocationBar) {
SetupApp("https_app"); ASSERT_TRUE(https_server()->Start());
const GURL app_url = https_server()->GetURL("app.com", "/simple.html");
SetupAppWithURL(app_url);
// Navigate to the app's launch page; the location bar should be hidden. // Navigate to the app's launch page; the location bar should be hidden.
NavigateAndCheckForLocationBar(app_browser_, NavigateAndCheckForLocationBar(app_browser_, app_url, false);
"https://www.example.com/empty.html", false);
// Navigate to another page on the same origin; the location bar should still // Navigate to another page on the same origin; the location bar should still
// hidden. // hidden.
NavigateAndCheckForLocationBar(app_browser_, "https://www.example.com/blah", NavigateAndCheckForLocationBar(
false); app_browser_, https_server()->GetURL("app.com", "/empty.html"), false);
// Navigate to different origin; the location bar should now be visible. // Navigate to different origin; the location bar should now be visible.
NavigateAndCheckForLocationBar(app_browser_, "https://www.foo.com/blah", NavigateAndCheckForLocationBar(
true); app_browser_, https_server()->GetURL("foo.com", "/simple.html"), true);
} }
// Check that the location bar is shown correctly for HTTP apps when they IN_PROC_BROWSER_TEST_P(HostedAppTest, ShouldShowLocationBarMixedContent) {
// navigate to a HTTPS page on the same origin. ASSERT_TRUE(https_server()->Start());
//
// TODO(mgiuca): Disabled on Windows and macOS for being flaky: const GURL app_url = https_server()->GetURL("app.com", "/");
// https://crbug.com/814400
#if defined(OS_WIN) || defined(OS_MACOSX) SetupAppWithURL(app_url);
#define MAYBE_ShouldShowLocationBarForHTTPApp \
DISABLED_ShouldShowLocationBarForHTTPApp // Navigate to another page on the same origin, but with mixed content; the
#else // location bar should be hidden.
#define MAYBE_ShouldShowLocationBarForHTTPApp ShouldShowLocationBarForHTTPApp // TODO(ortuno): Make the location bar visible.
#endif NavigateAndCheckForLocationBar(
IN_PROC_BROWSER_TEST_P(HostedAppTest, MAYBE_ShouldShowLocationBarForHTTPApp) { app_browser_,
SetupApp("app"); https_server()->GetURL("app.com",
"/ssl/page_displays_insecure_content.html"),
false);
}
IN_PROC_BROWSER_TEST_P(HostedAppTest,
ShouldShowLocationBarForHTTPAppSameOrigin) {
ASSERT_TRUE(embedded_test_server()->Start());
const GURL app_url =
embedded_test_server()->GetURL("app.com", "/simple.html");
SetupAppWithURL(app_url);
// Navigate to the app's launch page; the location bar should be visible, even // Navigate to the app's launch page; the location bar should be visible, even
// though it exactly matches the site, because it is not secure. // though it exactly matches the site, because it is not secure.
NavigateAndCheckForLocationBar(app_browser_, NavigateAndCheckForLocationBar(app_browser_, app_url, true);
"http://www.example.com/empty.html", true); }
IN_PROC_BROWSER_TEST_P(HostedAppTest, ShouldShowLocationBarForHTTPAppHTTPSUrl) {
ASSERT_TRUE(https_server()->Start());
const GURL app_url = https_server()->GetURL("app.com", "/simple.html");
GURL::Replacements scheme_http;
scheme_http.SetSchemeStr("http");
// Create an app that has the same port and origin as `app_url` but with a
// "http" scheme.
SetupAppWithURL(app_url.ReplaceComponents(scheme_http));
// Navigate to the https version of the site; the location bar should // Navigate to the https version of the site; the location bar should
// be hidden, as it is a more secure version of the site. // be hidden, as it is a more secure version of the site.
NavigateAndCheckForLocationBar( NavigateAndCheckForLocationBar(app_browser_, app_url, false);
app_browser_, "https://www.example.com/blah", false); }
IN_PROC_BROWSER_TEST_P(HostedAppTest,
ShouldShowLocationBarForHTTPSAppSameOrigin) {
ASSERT_TRUE(https_server()->Start());
const GURL app_url = https_server()->GetURL("app.com", "/simple.html");
SetupAppWithURL(app_url);
// Navigate to the app's launch page; the location bar should be hidden.
NavigateAndCheckForLocationBar(app_browser_, app_url, false);
} }
// TODO(mgiuca): Disabled on Windows for being flaky: https://crbug.com/815246
#if defined(OS_WIN)
#define MAYBE_ShouldShowLocationBarForHTTPSApp \
DISABLED_ShouldShowLocationBarForHTTPSApp
#else
#define MAYBE_ShouldShowLocationBarForHTTPSApp ShouldShowLocationBarForHTTPSApp
#endif
// Check that the location bar is shown correctly for HTTPS apps when they // Check that the location bar is shown correctly for HTTPS apps when they
// navigate to a HTTP page on the same origin. // navigate to a HTTP page on the same origin.
IN_PROC_BROWSER_TEST_P(HostedAppTest, MAYBE_ShouldShowLocationBarForHTTPSApp) { IN_PROC_BROWSER_TEST_P(HostedAppTest, ShouldShowLocationBarForHTTPSAppHTTPUrl) {
SetupApp("https_app"); ASSERT_TRUE(https_server()->Start());
// Navigate to the app's launch page; the location bar should be hidden. const GURL app_url = https_server()->GetURL("app.com", "/simple.html");
NavigateAndCheckForLocationBar( SetupAppWithURL(app_url);
app_browser_, "https://www.example.com/empty.html", false);
GURL::Replacements scheme_http;
scheme_http.SetSchemeStr("http");
// Navigate to the http version of the site; the location bar should // Navigate to the http version of the site; the location bar should
// be visible for the https version as it is not secure. // be visible for the https version as it is not secure.
NavigateAndCheckForLocationBar( NavigateAndCheckForLocationBar(app_browser_,
app_browser_, "http://www.example.com/blah", true); app_url.ReplaceComponents(scheme_http), true);
} }
// Check that location bar is not shown for apps hosted within extensions pages. // Check that location bar is not shown for apps hosted within extensions pages.
...@@ -555,26 +628,75 @@ IN_PROC_BROWSER_TEST_P(HostedAppTest, ShouldShowLocationBarForExtensionPage) { ...@@ -555,26 +628,75 @@ IN_PROC_BROWSER_TEST_P(HostedAppTest, ShouldShowLocationBarForExtensionPage) {
// Navigate to the app's launch page; the location bar should not be visible, // Navigate to the app's launch page; the location bar should not be visible,
// because extensions pages are secure. // because extensions pages are secure.
NavigateAndCheckForLocationBar(app_browser_, popup_url.spec(), false); NavigateAndCheckForLocationBar(app_browser_, popup_url, false);
} }
// Check that the location bar is shown correctly for apps that specify start // Check that the location bar is shown correctly for apps that specify start
// URLs without the 'www.' prefix. // URLs without the 'www.' prefix.
IN_PROC_BROWSER_TEST_P(HostedAppTest, ShouldShowLocationBarForAppWithoutWWW) { IN_PROC_BROWSER_TEST_P(HostedAppTest, ShouldShowLocationBarForAppWithoutWWW) {
SetupApp("https_app_no_www"); ASSERT_TRUE(https_server()->Start());
const GURL app_url = https_server()->GetURL("app.com", "/simple.html");
SetupAppWithURL(app_url);
// Navigate to the app's launch page; the location bar should be hidden. // Navigate to the app's launch page; the location bar should be hidden.
NavigateAndCheckForLocationBar(app_browser_, "https://example.com/empty.html", NavigateAndCheckForLocationBar(app_browser_, app_url, false);
false);
// Navigate to the app's launch page with the 'www.' prefis; the location bar // Navigate to the app's launch page with the 'www.' prefix; the location bar
// should be hidden. // should be hidden.
NavigateAndCheckForLocationBar(app_browser_, NavigateAndCheckForLocationBar(
"https://www.example.com/empty.html", false); app_browser_, https_server()->GetURL("www.app.com", "/simple.html"),
false);
// Navigate to different origin; the location bar should now be visible. // Navigate to different origin; the location bar should now be visible.
NavigateAndCheckForLocationBar(app_browser_, "https://www.foo.com/blah", NavigateAndCheckForLocationBar(
true); app_browser_, https_server()->GetURL("www.foo.com", "/simple.html"),
true);
}
// Checks that the location bar is shown for an HTTPS app with an invalid
// certificate, if the user has previously proceeded through the interstitial.
IN_PROC_BROWSER_TEST_P(HostedAppTest, ShouldShowLocationBarDangerous) {
// If DesktopPWAWindowing and CommittedInterstitials are enabled, we will
// never load a dangerous app. Opening dangerous apps will always show an
// interstitial and proceeding through it will redirect the navigation to a
// tab.
if (base::FeatureList::IsEnabled(features::kDesktopPWAWindowing) &&
base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kCommittedInterstitials)) {
return;
}
ASSERT_TRUE(https_server()->Start());
const GURL app_url = https_server()->GetURL("app.com", "/simple.html");
SetupAppWithURL(app_url);
cert_verifier()->set_default_result(net::ERR_CERT_DATE_INVALID);
// When DesktopPWAWindowing is enabled, proceeding through an interstitial
// results in the navigation being redirected to a regular tab. So we need
// to open the app again.
bool proceed_through_interstitial = true;
if (base::FeatureList::IsEnabled(features::kDesktopPWAWindowing)) {
// Proceed through the interstitial once.
NavigateToURLAndWait(app_browser_, app_url,
/*proceed_through_interstitial=*/true);
ASSERT_NE(app_browser_, chrome::FindLastActive());
app_browser_ = LaunchAppBrowser(app_);
NavigateToURLAndWait(app_browser_, app_url,
/*proceed_through_interstitial=*/false);
// There should be no interstitial shown because we previously proceeded
// through it.
ASSERT_FALSE(app_browser_->tab_strip_model()
->GetActiveWebContents()
->GetInterstitialPage());
proceed_through_interstitial = false;
}
NavigateAndCheckForLocationBar(app_browser_, app_url, true,
proceed_through_interstitial);
} }
// Check that a subframe on a regular web page can navigate to a URL that // Check that a subframe on a regular web page can navigate to a URL that
......
{
"name": "App Test",
"version": "1",
"manifest_version": 2,
"app": {
"launch": {
"web_url": "https://example.com/"
}
}
}
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