Commit d39b5b07 authored by Jarryd's avatar Jarryd Committed by Chromium LUCI CQ

dPWA: Add integration browser test suite.

This change is the beginning of the implementation of the
integration test system for the desktop PWA system.

Design doc:
https://docs.google.com/document/u/1/d/1Gd14fjwA4VKoRzL2TAvi9paXwyh36ehlS4gbpUmUeeI/edit#

Bug: 1145240
Change-Id: Iaa6f7620e40d137ab8e771446bcead23ad7f93ca
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2536138Reviewed-by: default avatarCharlene Yan <cyan@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Auto-Submit: Jarryd Goodman <jarrydg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833859}
parent ab8160eb
// 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 "base/test/bind.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/banners/test_app_banner_manager_desktop.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/browser/ui/views/frame/toolbar_button_provider.h"
#include "chrome/browser/ui/views/page_action/page_action_icon_view.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
#include "chrome/browser/web_applications/components/web_app_id.h"
#include "chrome/browser/web_applications/test/web_app_install_observer.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_navigation_observer.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/network/public/cpp/network_switches.h"
#include "testing/gmock/include/gmock/gmock.h"
namespace web_app {
struct NavigateToSiteResult {
content::WebContents* web_contents;
banners::TestAppBannerManagerDesktop* app_banner_manager;
bool installable;
};
class WebAppIntegrationBrowserTest : public InProcessBrowserTest {
public:
WebAppIntegrationBrowserTest()
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {}
~WebAppIntegrationBrowserTest() override = default;
WebAppIntegrationBrowserTest(const WebAppIntegrationBrowserTest&) = delete;
WebAppIntegrationBrowserTest& operator=(const WebAppIntegrationBrowserTest&) =
delete;
// InProcessBrowserTest
void SetUp() override {
https_server_.AddDefaultHandlers(GetChromeTestDataDir());
ASSERT_TRUE(https_server_.Start());
banners::TestAppBannerManagerDesktop::SetUp();
InProcessBrowserTest::SetUp();
}
// BrowserTestBase
void SetUpOnMainThread() override {
pwa_install_view_ =
BrowserView::GetBrowserViewForBrowser(browser())
->toolbar_button_provider()
->GetPageActionIconView(PageActionIconType::kPwaInstall);
ASSERT_TRUE(pwa_install_view_);
EXPECT_FALSE(pwa_install_view_->GetVisible());
}
void SetUpCommandLine(base::CommandLine* command_line) override {
command_line->AppendSwitchASCII(
network::switches::kUnsafelyTreatInsecureOriginAsSecure,
GetInstallableAppURL().GetOrigin().spec());
}
NavigateToSiteResult NavigateToSite(Browser* browser, const GURL& url) {
content::WebContents* web_contents = GetCurrentTab(browser);
auto* app_banner_manager =
banners::TestAppBannerManagerDesktop::FromWebContents(web_contents);
DCHECK(!app_banner_manager->WaitForInstallableCheck());
ui_test_utils::NavigateToURL(browser, url);
bool installable = app_banner_manager->WaitForInstallableCheck();
return NavigateToSiteResult{web_contents, app_banner_manager, installable};
}
GURL GetInstallableAppURL() {
return https_server_.GetURL("/banners/manifest_test_page.html");
}
content::WebContents* GetCurrentTab(Browser* browser) {
return browser->tab_strip_model()->GetActiveWebContents();
}
web_app::AppId ExecutePwaInstallIcon() {
chrome::SetAutoAcceptPWAInstallConfirmationForTesting(true);
web_app::AppId app_id;
base::RunLoop run_loop;
web_app::SetInstalledCallbackForTesting(base::BindLambdaForTesting(
[&app_id, &run_loop](const web_app::AppId& installed_app_id,
web_app::InstallResultCode code) {
app_id = installed_app_id;
run_loop.Quit();
}));
pwa_install_view()->ExecuteForTesting();
run_loop.Run();
chrome::SetAutoAcceptPWAInstallConfirmationForTesting(false);
return app_id;
}
protected:
PageActionIconView* pwa_install_view() { return pwa_install_view_; }
private:
net::EmbeddedTestServer https_server_;
PageActionIconView* pwa_install_view_ = nullptr;
};
// Tests that installing a PWA will cause the install icon to be hidden, and
// the launch icon to be shown.
IN_PROC_BROWSER_TEST_F(WebAppIntegrationBrowserTest,
InstallAndVerifyUIUpdates) {
bool installable =
NavigateToSite(browser(), GetInstallableAppURL()).installable;
ASSERT_TRUE(installable);
EXPECT_EQ(GetAppMenuCommandState(IDC_CREATE_SHORTCUT, browser()), kEnabled);
EXPECT_EQ(GetAppMenuCommandState(IDC_INSTALL_PWA, browser()), kEnabled);
EXPECT_TRUE(pwa_install_view()->GetVisible());
EXPECT_EQ(GetAppMenuCommandState(IDC_OPEN_IN_PWA_WINDOW, browser()),
kNotPresent);
ExecutePwaInstallIcon();
chrome::NewTab(browser());
NavigateToSite(browser(), GetInstallableAppURL());
EXPECT_EQ(GetAppMenuCommandState(IDC_INSTALL_PWA, browser()), kNotPresent);
EXPECT_FALSE(pwa_install_view()->GetVisible());
EXPECT_EQ(GetAppMenuCommandState(IDC_OPEN_IN_PWA_WINDOW, browser()),
kEnabled);
}
} // namespace web_app
...@@ -1489,6 +1489,7 @@ if (!is_android) { ...@@ -1489,6 +1489,7 @@ if (!is_android) {
"../browser/ui/views/tabs/tab_search_button_browsertest.cc", "../browser/ui/views/tabs/tab_search_button_browsertest.cc",
"../browser/ui/views/tabs/tab_strip_browsertest.cc", "../browser/ui/views/tabs/tab_strip_browsertest.cc",
"../browser/ui/views/web_apps/web_app_frame_toolbar_browsertest.cc", "../browser/ui/views/web_apps/web_app_frame_toolbar_browsertest.cc",
"../browser/ui/views/web_apps/web_app_integration_browsertest.cc",
"../browser/ui/views/web_apps/web_app_minimal_ui_test.cc", "../browser/ui/views/web_apps/web_app_minimal_ui_test.cc",
"../browser/ui/views/web_apps/web_app_tab_strip_browsertest.cc", "../browser/ui/views/web_apps/web_app_tab_strip_browsertest.cc",
"../browser/ui/views/webauthn/authenticator_dialog_view_browsertest.cc", "../browser/ui/views/webauthn/authenticator_dialog_view_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