Commit 236f3073 authored by Jarryd's avatar Jarryd Committed by Chromium LUCI CQ

dPWA: Implement test framework MVP that handles text input.

 * Add a parameterized test that takes a collection of strings, each
     of which is a comma-separated list of testing actions.
 * Add a ParseParams() method that will split each input string into
     a collection of testing action strings
 * Add an ExecuteAction method that will call the appropriate testing
     action implementation for each testing action
 * Add ActionNotImplemented method to handle unrecognized or not yet
     implemented testing action strings
 * Implement new testing actions:
    - uninstall_from_menu
    - assert_installable
    - assert_install_icon_shown
    - assert_install_icon_not_shown
    - assert_launch_icon_shown
    - assert_launch_icon_not_shown

Design Doc: https://docs.google.com/document/d/1Gd14fjwA4VKoRzL2TAvi9paXwyh36ehlS4gbpUmUeeI/edit?pli=1#

Bug: 1145240,1156354,1156358,1156339,1156341,1156359
Change-Id: Ic2190e59ddc1d9a4ae4360dfc7ce12e5666af39e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2586187
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837895}
parent 936df057
...@@ -14,18 +14,50 @@ ...@@ -14,18 +14,50 @@
#include "chrome/browser/ui/views/page_action/page_action_icon_view.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/test/web_app_browsertest_util.h"
#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h" #include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
#include "chrome/browser/ui/web_applications/web_app_menu_model.h"
#include "chrome/browser/web_applications/components/install_finalizer.h"
#include "chrome/browser/web_applications/components/os_integration_manager.h"
#include "chrome/browser/web_applications/components/web_app_id.h" #include "chrome/browser/web_applications/components/web_app_id.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/browser/web_applications/test/web_app_install_observer.h" #include "chrome/browser/web_applications/test/web_app_install_observer.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.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 "content/public/test/browser_test.h" #include "content/public/test/browser_test.h"
#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_navigation_observer.h"
#include "extensions/browser/extension_dialog_auto_confirm.h"
#include "net/dns/mock_host_resolver.h" #include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h" #include "net/test/embedded_test_server/embedded_test_server.h"
#include "services/network/public/cpp/network_switches.h" #include "services/network/public/cpp/network_switches.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
namespace {
std::vector<std::string> test_cases = {
#if BUILDFLAG(IS_CHROMEOS_ASH)
"navigate_installable,assert_install_icon_shown,"
"assert_launch_icon_not_shown",
"navigate_not_installable,assert_install_icon_not_shown",
"navigate_installable,assert_installable,install_omnibox_or_menu,"
"navigate_browser_in_scope,assert_launch_icon_shown,"
"assert_install_icon_not_shown",
"navigate_installable,install_omnibox_or_menu,launch_internal,"
"uninstall_internal,navigate_browser_in_scope,"
"assert_install_icon_shown,assert_launch_icon_not_shown"};
#else
"navigate_installable,assert_install_icon_shown,"
"assert_launch_icon_not_shown",
"navigate_not_installable,assert_install_icon_not_shown",
"navigate_installable,assert_installable,install_omnibox_or_menu,"
"navigate_browser_in_scope,assert_launch_icon_shown,"
"assert_install_icon_not_shown",
"navigate_installable,install_omnibox_or_menu,launch_internal,"
"uninstall_from_menu,navigate_browser_in_scope,"
"assert_install_icon_shown,assert_launch_icon_not_shown"};
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
} // anonymous namespace
namespace web_app { namespace web_app {
struct NavigateToSiteResult { struct NavigateToSiteResult {
...@@ -34,7 +66,9 @@ struct NavigateToSiteResult { ...@@ -34,7 +66,9 @@ struct NavigateToSiteResult {
bool installable; bool installable;
}; };
class WebAppIntegrationBrowserTest : public InProcessBrowserTest { class WebAppIntegrationBrowserTest
: public InProcessBrowserTest,
public testing::WithParamInterface<std::string> {
public: public:
WebAppIntegrationBrowserTest() WebAppIntegrationBrowserTest()
: https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {} : https_server_(net::EmbeddedTestServer::TYPE_HTTPS) {}
...@@ -56,6 +90,8 @@ class WebAppIntegrationBrowserTest : public InProcessBrowserTest { ...@@ -56,6 +90,8 @@ class WebAppIntegrationBrowserTest : public InProcessBrowserTest {
// BrowserTestBase // BrowserTestBase
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
os_hooks_suppress_ =
OsIntegrationManager::ScopedSuppressOsHooksForTesting();
pwa_install_view_ = pwa_install_view_ =
BrowserView::GetBrowserViewForBrowser(browser()) BrowserView::GetBrowserViewForBrowser(browser())
->toolbar_button_provider() ->toolbar_button_provider()
...@@ -70,6 +106,44 @@ class WebAppIntegrationBrowserTest : public InProcessBrowserTest { ...@@ -70,6 +106,44 @@ class WebAppIntegrationBrowserTest : public InProcessBrowserTest {
GetInstallableAppURL().GetOrigin().spec()); GetInstallableAppURL().GetOrigin().spec());
} }
// Test Framework
void ParseParams() {
std::string action_strings = GetParam();
testing_actions_ = base::SplitString(
action_strings, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
}
void ExecuteAction(const std::string& action_string) {
if (action_string == "navigate_installable") {
NavigateToSite(browser(), GetInstallableAppURL());
} else if (action_string == "navigate_browser_in_scope") {
NavigateToSite(browser(), GetInScopeURL());
} else if (action_string == "navigate_not_installable") {
NavigateToSite(browser(), GetOutOfScopeURL());
} else if (action_string == "install_omnibox_or_menu") {
ExecutePwaInstallIcon();
} else if (action_string == "launch_internal") {
LaunchInternal();
} else if (action_string == "uninstall_from_menu") {
UninstallFromMenu();
} else if (action_string == "uninstall_internal") {
UninstallInternal();
} else if (action_string == "assert_installable") {
AssertInstallable();
} else if (action_string == "assert_install_icon_shown") {
AssertInstallIconShown();
} else if (action_string == "assert_install_icon_not_shown") {
AssertInstallIconNotShown();
} else if (action_string == "assert_launch_icon_shown") {
AssertLaunchIconShown();
} else if (action_string == "assert_launch_icon_not_shown") {
AssertLaunchIconNotShown();
} else {
FAIL() << "Unimplemented action: " << action_string;
}
}
// Automated Testing Actions
NavigateToSiteResult NavigateToSite(Browser* browser, const GURL& url) { NavigateToSiteResult NavigateToSite(Browser* browser, const GURL& url) {
content::WebContents* web_contents = GetCurrentTab(browser); content::WebContents* web_contents = GetCurrentTab(browser);
auto* app_banner_manager = auto* app_banner_manager =
...@@ -79,13 +153,23 @@ class WebAppIntegrationBrowserTest : public InProcessBrowserTest { ...@@ -79,13 +153,23 @@ class WebAppIntegrationBrowserTest : public InProcessBrowserTest {
ui_test_utils::NavigateToURL(browser, url); ui_test_utils::NavigateToURL(browser, url);
bool installable = app_banner_manager->WaitForInstallableCheck(); bool installable = app_banner_manager->WaitForInstallableCheck();
return NavigateToSiteResult{web_contents, app_banner_manager, installable}; last_navigation_result_ =
NavigateToSiteResult{web_contents, app_banner_manager, installable};
return last_navigation_result_;
} }
GURL GetInstallableAppURL() { GURL GetInstallableAppURL() {
return https_server_.GetURL("/banners/manifest_test_page.html"); return https_server_.GetURL("/banners/manifest_test_page.html");
} }
GURL GetInScopeURL() {
return https_server_.GetURL("/banners/manifest_test_page.html");
}
GURL GetOutOfScopeURL() {
return https_server_.GetURL("/out_of_scope/index.html");
}
content::WebContents* GetCurrentTab(Browser* browser) { content::WebContents* GetCurrentTab(Browser* browser) {
return browser->tab_strip_model()->GetActiveWebContents(); return browser->tab_strip_model()->GetActiveWebContents();
} }
...@@ -113,17 +197,86 @@ class WebAppIntegrationBrowserTest : public InProcessBrowserTest { ...@@ -113,17 +197,86 @@ class WebAppIntegrationBrowserTest : public InProcessBrowserTest {
} }
Browser* LaunchInternal() { Browser* LaunchInternal() {
return LaunchWebAppBrowserAndWait(ProfileManager::GetActiveUserProfile(), app_browser_ = LaunchWebAppBrowserAndWait(
app_id_); ProfileManager::GetActiveUserProfile(), app_id_);
return app_browser_;
}
// TODO(https://crbug.com/1159651): Support this action on CrOS.
void UninstallFromMenu() {
DCHECK(app_browser_);
base::RunLoop run_loop;
WebAppInstallObserver observer(browser()->profile());
observer.SetWebAppUninstalledDelegate(
base::BindLambdaForTesting([&](const AppId& app_id) {
if (app_id == app_id_) {
run_loop.Quit();
}
}));
extensions::ScopedTestDialogAutoConfirm auto_confirm(
extensions::ScopedTestDialogAutoConfirm::ACCEPT);
auto app_menu_model =
std::make_unique<WebAppMenuModel>(nullptr, app_browser_);
app_menu_model->Init();
ui::MenuModel* model = app_menu_model.get();
int index = -1;
const bool found = app_menu_model->GetModelAndIndexForCommandId(
WebAppMenuModel::kUninstallAppCommandId, &model, &index);
EXPECT_TRUE(found);
EXPECT_TRUE(model->IsEnabledAt(index));
app_menu_model->ExecuteCommand(WebAppMenuModel::kUninstallAppCommandId,
/*event_flags=*/0);
run_loop.Run();
} }
protected: void UninstallInternal() {
WebAppProviderBase* const provider =
WebAppProviderBase::GetProviderBase(browser()->profile());
base::RunLoop run_loop;
DCHECK(provider->install_finalizer().CanUserUninstallExternalApp(app_id_));
provider->install_finalizer().UninstallExternalAppByUser(
app_id_, base::BindLambdaForTesting([&](bool uninstalled) {
EXPECT_TRUE(uninstalled);
run_loop.Quit();
}));
run_loop.Run();
}
// Assert Actions
void AssertInstallable() { EXPECT_TRUE(last_navigation_result_.installable); }
void AssertInstallIconShown() {
EXPECT_EQ(GetAppMenuCommandState(IDC_INSTALL_PWA, browser()), kEnabled);
EXPECT_TRUE(pwa_install_view()->GetVisible());
}
void AssertInstallIconNotShown() {
EXPECT_EQ(GetAppMenuCommandState(IDC_INSTALL_PWA, browser()), kNotPresent);
EXPECT_FALSE(pwa_install_view()->GetVisible());
}
void AssertLaunchIconShown() {
EXPECT_EQ(GetAppMenuCommandState(IDC_OPEN_IN_PWA_WINDOW, browser()),
kEnabled);
}
void AssertLaunchIconNotShown() {
EXPECT_EQ(GetAppMenuCommandState(IDC_OPEN_IN_PWA_WINDOW, browser()),
kNotPresent);
}
Browser* app_browser() { return app_browser_; }
std::vector<std::string>& testing_actions() { return testing_actions_; }
PageActionIconView* pwa_install_view() { return pwa_install_view_; } PageActionIconView* pwa_install_view() { return pwa_install_view_; }
private: private:
Browser* app_browser_ = nullptr;
std::vector<std::string> testing_actions_;
NavigateToSiteResult last_navigation_result_;
AppId app_id_; AppId app_id_;
net::EmbeddedTestServer https_server_; net::EmbeddedTestServer https_server_;
PageActionIconView* pwa_install_view_ = nullptr; PageActionIconView* pwa_install_view_ = nullptr;
ScopedOsHooksSuppress os_hooks_suppress_;
}; };
// Tests that installing a PWA will cause the install icon to be hidden, and // Tests that installing a PWA will cause the install icon to be hidden, and
...@@ -157,4 +310,16 @@ IN_PROC_BROWSER_TEST_F(WebAppIntegrationBrowserTest, LaunchInternal) { ...@@ -157,4 +310,16 @@ IN_PROC_BROWSER_TEST_F(WebAppIntegrationBrowserTest, LaunchInternal) {
DCHECK(app_browser); DCHECK(app_browser);
} }
IN_PROC_BROWSER_TEST_P(WebAppIntegrationBrowserTest, Default) {
ParseParams();
for (auto& action : testing_actions()) {
ExecuteAction(action);
}
}
INSTANTIATE_TEST_SUITE_P(All,
WebAppIntegrationBrowserTest,
testing::ValuesIn(test_cases));
} // namespace web_app } // namespace web_app
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