Commit e02aeb0b authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

Desktop PWAs: PWAMixedContentBrowserTest without extensions dependency

Two mixed content (http+https) desktop PWA tests have been ported
to no longer have any dependency on Extensions code, so they are
ready to run with BMO, when WebAppLaunchManager is complete.

See https://chromium-review.googlesource.com/c/chromium/src/+/2035819/
for remaining work.

Bug: 1026080
Change-Id: Ibcd690e44cc1949d352e16a11af5084a0abd2127
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2038195Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738489}
parent 3cc2505d
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/banners/test_app_banner_manager_desktop.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/web_applications/test/ssl_test_utils.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/ui/web_applications/web_app_controller_browsertest.h"
#include "chrome/browser/web_applications/components/app_registrar.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "url/gurl.h"
namespace web_app {
class PWAMixedContentBrowserTest : public WebAppControllerBrowserTest {
public:
GURL GetMixedContentAppURL() {
return https_server()->GetURL("app.com",
"/ssl/page_displays_insecure_content.html");
}
// Launches the app, waits for the app url to load.
Browser* LaunchWebAppBrowserAndWait(const AppId& app_id) {
ui_test_utils::UrlLoadObserver url_observer(
WebAppProvider::Get(profile())->registrar().GetAppLaunchURL(app_id),
content::NotificationService::AllSources());
Browser* const app_browser = LaunchWebAppBrowser(app_id);
url_observer.Wait();
return app_browser;
}
};
// Tests that mixed content is not loaded inside PWA windows.
IN_PROC_BROWSER_TEST_P(PWAMixedContentBrowserTest, MixedContentInPWA) {
ASSERT_TRUE(https_server()->Start());
ASSERT_TRUE(embedded_test_server()->Start());
const GURL app_url = GetMixedContentAppURL();
const AppId app_id = InstallPWA(app_url);
Browser* const app_browser = LaunchWebAppBrowserAndWait(app_id);
CHECK(app_browser);
web_app::CheckMixedContentFailedToLoad(app_browser);
}
// Tests that creating a shortcut app but not installing a PWA is available for
// a non-installable site.
IN_PROC_BROWSER_TEST_P(PWAMixedContentBrowserTest,
ShortcutMenuOptionsForNonInstallableSite) {
auto* manager = banners::TestAppBannerManagerDesktop::CreateForWebContents(
browser()->tab_strip_model()->GetActiveWebContents());
ASSERT_TRUE(https_server()->Start());
NavigateToURLAndWait(browser(), GetMixedContentAppURL());
EXPECT_FALSE(manager->WaitForInstallableCheck());
EXPECT_EQ(GetAppMenuCommandState(IDC_CREATE_SHORTCUT, browser()), kEnabled);
EXPECT_EQ(GetAppMenuCommandState(IDC_INSTALL_PWA, browser()), kNotPresent);
}
// TODO(crbug.com/1026080): Also test kUnifiedControllerWithWebApp.
INSTANTIATE_TEST_SUITE_P(
All,
PWAMixedContentBrowserTest,
::testing::Values(ControllerType::kHostedAppController,
ControllerType::kUnifiedControllerWithBookmarkApp),
ControllerTypeParamToString);
} // namespace web_app
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/web_applications/test/ssl_test_utils.h"
#include "chrome/browser/ssl/ssl_browsertest_util.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "components/security_state/core/security_state.h"
namespace web_app {
void CheckMixedContentLoaded(Browser* browser) {
DCHECK(browser);
ssl_test_util::CheckSecurityState(
browser->tab_strip_model()->GetActiveWebContents(),
ssl_test_util::CertError::NONE, security_state::NONE,
ssl_test_util::AuthState::DISPLAYED_INSECURE_CONTENT);
}
void CheckMixedContentFailedToLoad(Browser* browser) {
DCHECK(browser);
ssl_test_util::CheckSecurityState(
browser->tab_strip_model()->GetActiveWebContents(),
ssl_test_util::CertError::NONE, security_state::SECURE,
ssl_test_util::AuthState::NONE);
}
} // namespace web_app
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_WEB_APPLICATIONS_TEST_SSL_TEST_UTILS_H_
#define CHROME_BROWSER_UI_WEB_APPLICATIONS_TEST_SSL_TEST_UTILS_H_
class Browser;
namespace web_app {
// Checks that the active tab's authentication state indicates insecure content.
void CheckMixedContentLoaded(Browser* browser);
// Checks that the active tab's authentication state indicates only secure
// content is shown.
void CheckMixedContentFailedToLoad(Browser* browser);
} // namespace web_app
#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_TEST_SSL_TEST_UTILS_H_
...@@ -9,8 +9,11 @@ ...@@ -9,8 +9,11 @@
#include "chrome/browser/apps/app_service/app_launch_params.h" #include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/launch_service/launch_service.h" #include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/installable/installable_metrics.h" #include "chrome/browser/installable/installable_metrics.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator_params.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/app_menu_model.h"
#include "chrome/browser/web_applications/components/external_install_options.h" #include "chrome/browser/web_applications/components/external_install_options.h"
#include "chrome/browser/web_applications/components/pending_app_manager.h" #include "chrome/browser/web_applications/components/pending_app_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
...@@ -18,7 +21,14 @@ ...@@ -18,7 +21,14 @@
#include "chrome/browser/web_applications/components/web_app_provider_base.h" #include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/browser/web_applications/components/web_app_tab_helper_base.h" #include "chrome/browser/web_applications/components/web_app_tab_helper_base.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/security_interstitials/content/security_interstitial_tab_helper.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_navigation_observer.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/models/menu_model.h"
#include "ui/base/page_transition_types.h"
namespace web_app { namespace web_app {
...@@ -108,4 +118,52 @@ InstallResultCode PendingAppManagerInstall( ...@@ -108,4 +118,52 @@ InstallResultCode PendingAppManagerInstall(
return result_code; return result_code;
} }
// If |proceed_through_interstitial| is true, asserts that a security
// interstitial is shown, and clicks through it, before returning.
void NavigateToURLAndWait(Browser* browser,
const GURL& url,
bool proceed_through_interstitial) {
content::WebContents* web_contents =
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;
{
// Need a second TestNavigationObserver; the above one is spent.
content::TestNavigationObserver observer(
web_contents, content::MessageLoopRunner::QuitMode::DEFERRED);
security_interstitials::SecurityInterstitialTabHelper* helper =
security_interstitials::SecurityInterstitialTabHelper::FromWebContents(
browser->tab_strip_model()->GetActiveWebContents());
ASSERT_TRUE(
helper &&
helper->GetBlockingPageForCurrentlyCommittedNavigationForTesting());
std::string javascript = "window.certificateErrorPageController.proceed();";
ASSERT_TRUE(content::ExecuteScript(web_contents, javascript));
observer.Wait();
}
}
AppMenuCommandState GetAppMenuCommandState(int command_id, Browser* browser) {
DCHECK(!browser->app_controller())
<< "This check only applies to regular browser windows.";
auto app_menu_model = std::make_unique<AppMenuModel>(nullptr, browser);
app_menu_model->Init();
ui::MenuModel* model = app_menu_model.get();
int index = -1;
if (!app_menu_model->GetModelAndIndexForCommandId(command_id, &model,
&index)) {
return kNotPresent;
}
return model->IsEnabledAt(index) ? kEnabled : kDisabled;
}
} // namespace web_app } // namespace web_app
...@@ -34,6 +34,21 @@ ExternalInstallOptions CreateInstallOptions(const GURL& url); ...@@ -34,6 +34,21 @@ ExternalInstallOptions CreateInstallOptions(const GURL& url);
// Synchronous version of PendingAppManager::Install. // Synchronous version of PendingAppManager::Install.
InstallResultCode PendingAppManagerInstall(Profile*, ExternalInstallOptions); InstallResultCode PendingAppManagerInstall(Profile*, ExternalInstallOptions);
// If |proceed_through_interstitial| is true, asserts that a security
// interstitial is shown, and clicks through it, before returning.
void NavigateToURLAndWait(Browser* browser,
const GURL& url,
bool proceed_through_interstitial = false);
enum AppMenuCommandState {
kEnabled,
kDisabled,
kNotPresent,
};
// For a non-app browser, determines if the command is enabled/disabled/absent.
AppMenuCommandState GetAppMenuCommandState(int command_id, Browser* browser);
} // namespace web_app } // namespace web_app
#endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_TEST_WEB_APP_BROWSERTEST_UTIL_H_ #endif // CHROME_BROWSER_UI_WEB_APPLICATIONS_TEST_WEB_APP_BROWSERTEST_UTIL_H_
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_provider.h" #include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.h"
#include "chrome/test/base/ui_test_utils.h" #include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
...@@ -127,6 +128,8 @@ void WebAppControllerBrowserTest::TearDownInProcessBrowserTestFixture() { ...@@ -127,6 +128,8 @@ void WebAppControllerBrowserTest::TearDownInProcessBrowserTestFixture() {
void WebAppControllerBrowserTest::SetUpCommandLine( void WebAppControllerBrowserTest::SetUpCommandLine(
base::CommandLine* command_line) { base::CommandLine* command_line) {
extensions::ExtensionBrowserTest::SetUpCommandLine(command_line); extensions::ExtensionBrowserTest::SetUpCommandLine(command_line);
// Browser will both run and display insecure content.
command_line->AppendSwitch(switches::kAllowRunningInsecureContent);
cert_verifier_.SetUpCommandLine(command_line); cert_verifier_.SetUpCommandLine(command_line);
} }
......
...@@ -42,17 +42,6 @@ ...@@ -42,17 +42,6 @@
namespace { namespace {
void NavigateToURLAndWait(Browser* browser, const GURL& url) {
content::WebContents* web_contents =
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();
}
GURL GetUrlForSuffix(const std::string& prefix, int suffix) { GURL GetUrlForSuffix(const std::string& prefix, int suffix) {
return GURL(prefix + base::NumberToString(suffix) + ".com/"); return GURL(prefix + base::NumberToString(suffix) + ".com/");
} }
......
...@@ -367,6 +367,8 @@ static_library("test_support") { ...@@ -367,6 +367,8 @@ static_library("test_support") {
"../browser/extensions/extension_browsertest.h", "../browser/extensions/extension_browsertest.h",
"../browser/extensions/permissions_test_util.cc", "../browser/extensions/permissions_test_util.cc",
"../browser/extensions/permissions_test_util.h", "../browser/extensions/permissions_test_util.h",
"../browser/ui/web_applications/test/ssl_test_utils.cc",
"../browser/ui/web_applications/test/ssl_test_utils.h",
"../browser/ui/web_applications/test/web_app_browsertest_util.cc", "../browser/ui/web_applications/test/web_app_browsertest_util.cc",
"../browser/ui/web_applications/test/web_app_browsertest_util.h", "../browser/ui/web_applications/test/web_app_browsertest_util.h",
"../browser/ui/web_applications/web_app_controller_browsertest.cc", "../browser/ui/web_applications/web_app_controller_browsertest.cc",
...@@ -1345,6 +1347,7 @@ if (!is_android) { ...@@ -1345,6 +1347,7 @@ if (!is_android) {
"../browser/ui/views/webauthn/authenticator_qr_code_test.cc", "../browser/ui/views/webauthn/authenticator_qr_code_test.cc",
"../browser/ui/views/webview_accessibility_browsertest.cc", "../browser/ui/views/webview_accessibility_browsertest.cc",
"../browser/ui/web_applications/app_browser_controller_browsertest.cc", "../browser/ui/web_applications/app_browser_controller_browsertest.cc",
"../browser/ui/web_applications/pwa_mixed_content_browsertest.cc",
"../browser/ui/web_applications/web_app_badging_browsertest.cc", "../browser/ui/web_applications/web_app_badging_browsertest.cc",
"../browser/ui/web_applications/web_app_browsertest.cc", "../browser/ui/web_applications/web_app_browsertest.cc",
"../browser/ui/web_applications/web_app_engagement_browsertest.cc", "../browser/ui/web_applications/web_app_engagement_browsertest.cc",
......
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