Commit 54ae7725 authored by Jarryd's avatar Jarryd Committed by Chromium LUCI CQ

dPWA: Implement testing journey 7.

 * Implement new testing actions:
  - |add_policy_app_internal_tabbed|
  - |remove_policy_app|
  - |list_apps_internal|
  - |assert_app_not_in_list|
 * Reorder testing action implementations lexicographically
 * Rename ExecutePwaInstallIcon() to InstallOmniboxOrMenu()

Change-Id: I167b4b00b4028f31702813a611d5616f7bc6c040
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2598638
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842303}
parent 4dc283d0
...@@ -24,13 +24,19 @@ ...@@ -24,13 +24,19 @@
#include "chrome/browser/web_applications/components/app_registry_controller.h" #include "chrome/browser/web_applications/components/app_registry_controller.h"
#include "chrome/browser/web_applications/components/install_finalizer.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/os_integration_manager.h"
#include "chrome/browser/web_applications/components/policy/web_app_policy_constants.h"
#include "chrome/browser/web_applications/components/policy/web_app_policy_manager.h"
#include "chrome/browser/web_applications/components/web_app_constants.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/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/browser/web_applications/web_app_provider.h" #include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/pref_names.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/prefs/scoped_user_pref_update.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 "extensions/browser/extension_dialog_auto_confirm.h"
...@@ -214,27 +220,37 @@ class WebAppIntegrationBrowserTest ...@@ -214,27 +220,37 @@ class WebAppIntegrationBrowserTest
action_strings, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); action_strings, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
} }
// Non-assert actions implemented before assert actions. Implemented in
// alphabetical order.
void ExecuteAction(const std::string& action_string) { void ExecuteAction(const std::string& action_string) {
if (base::StartsWith(action_string, "navigate_installable")) { if (action_string == "add_policy_app_internal_tabbed") {
NavigateToSite(browser(), GetInstallableAppURL()); AddPolicyAppInternalTabbed();
} else if (action_string == "navigate_browser_in_scope") { } else if (action_string == "close_pwa") {
NavigateToSite(browser(), GetInScopeURL()); ClosePWA();
} else if (action_string == "navigate_not_installable") { } else if (action_string == "install_create_shortcut_tabbed") {
NavigateToSite(browser(), GetOutOfScopeURL()); InstallCreateShortcutTabbed();
} else if (action_string == "install_omnibox_or_menu") { } else if (action_string == "install_omnibox_or_menu") {
ExecutePwaInstallIcon(); InstallOmniboxOrMenu();
} else if (base::StartsWith(action_string, "launch_internal")) { } else if (base::StartsWith(action_string, "launch_internal")) {
LaunchInternal(); LaunchInternal();
} else if (action_string == "list_apps_internal") {
ListAppsInternal();
} else if (action_string == "navigate_browser_in_scope") {
NavigateToSite(browser(), GetInScopeURL());
} else if (base::StartsWith(action_string, "navigate_installable")) {
NavigateToSite(browser(), GetInstallableAppURL());
} else if (action_string == "navigate_not_installable") {
NavigateToSite(browser(), GetNonInstallableAppURL());
} else if (action_string == "remove_policy_app") {
RemovePolicyApp();
} else if (action_string == "set_open_in_window_internal") {
SetOpenInWindowInternal();
} else if (action_string == "uninstall_from_menu") { } else if (action_string == "uninstall_from_menu") {
UninstallFromMenu(); UninstallFromMenu();
} else if (action_string == "uninstall_internal") { } else if (action_string == "uninstall_internal") {
UninstallInternal(); UninstallInternal();
} else if (action_string == "install_create_shortcut_tabbed") { } else if (action_string == "assert_app_not_in_list") {
InstallCreateShortcutTabbed(); AssertAppNotInList();
} else if (action_string == "set_open_in_window_internal") {
SetOpenInWindowInternal();
} else if (action_string == "close_pwa") {
ClosePWA();
} else if (action_string == "assert_installable") { } else if (action_string == "assert_installable") {
AssertInstallable(); AssertInstallable();
} else if (action_string == "assert_install_icon_shown") { } else if (action_string == "assert_install_icon_shown") {
...@@ -245,46 +261,60 @@ class WebAppIntegrationBrowserTest ...@@ -245,46 +261,60 @@ class WebAppIntegrationBrowserTest
AssertLaunchIconShown(); AssertLaunchIconShown();
} else if (action_string == "assert_launch_icon_not_shown") { } else if (action_string == "assert_launch_icon_not_shown") {
AssertLaunchIconNotShown(); AssertLaunchIconNotShown();
} else if (action_string == "assert_no_crash") {
} else if (action_string == "assert_window_created") { } else if (action_string == "assert_window_created") {
AssertWindowCreated(); AssertWindowCreated();
} else if (action_string == "assert_no_crash") {
} else { } else {
FAIL() << "Unimplemented action: " << action_string; FAIL() << "Unimplemented action: " << action_string;
} }
} }
// Automated Testing Actions // Automated Testing Actions
NavigateToSiteResult NavigateToSite(Browser* browser, const GURL& url) { void AddPolicyAppInternalTabbed() {
content::WebContents* web_contents = GetCurrentTab(browser); GURL url = GetInstallableAppURL();
auto* app_banner_manager = auto* web_app_registrar = WebAppProvider::Get(browser()->profile())
webapps::TestAppBannerManagerDesktop::FromWebContents(web_contents); ->registrar()
DCHECK(!app_banner_manager->WaitForInstallableCheck()); .AsWebAppRegistrar();
base::RunLoop run_loop;
ui_test_utils::NavigateToURL(browser, url); WebAppInstallObserver observer(browser()->profile());
bool installable = app_banner_manager->WaitForInstallableCheck(); observer.SetWebAppInstalledDelegate(
base::BindLambdaForTesting([&](const AppId& app_id) {
last_navigation_result_ = bool is_installed = web_app_registrar->IsInstalled(app_id);
NavigateToSiteResult{web_contents, app_banner_manager, installable}; GURL installed_url = web_app_registrar->GetAppStartUrl(app_id);
return last_navigation_result_; if (is_installed && installed_url.is_valid() &&
installed_url.spec() == url.spec()) {
app_id_ = app_id;
run_loop.Quit();
} }
}));
GURL GetInstallableAppURL() { {
return https_server_.GetURL("/banners/manifest_test_page.html"); base::Value item(base::Value::Type::DICTIONARY);
item.SetKey(kUrlKey, base::Value(url.spec()));
item.SetKey(kDefaultLaunchContainerKey,
base::Value(kDefaultLaunchContainerTabValue));
ListPrefUpdate update(browser()->profile()->GetPrefs(),
prefs::kWebAppInstallForceList);
update->Append(item.Clone());
} }
run_loop.Run();
GURL GetInScopeURL() {
return https_server_.GetURL("/banners/manifest_test_page.html");
} }
GURL GetOutOfScopeURL() { void ClosePWA() {
return https_server_.GetURL("/out_of_scope/index.html"); DCHECK(app_browser_);
app_browser_->window()->Close();
ui_test_utils::WaitForBrowserToClose(app_browser_);
} }
content::WebContents* GetCurrentTab(Browser* browser) { void InstallCreateShortcutTabbed() {
return browser->tab_strip_model()->GetActiveWebContents(); chrome::SetAutoAcceptWebAppDialogForTesting(/*auto_accept=*/true,
/*auto_open_in_window=*/false);
WebAppInstallObserver observer(browser()->profile());
CHECK(chrome::ExecuteCommand(browser(), IDC_CREATE_SHORTCUT));
app_id_ = observer.AwaitNextInstall();
chrome::SetAutoAcceptWebAppDialogForTesting(false, false);
} }
web_app::AppId ExecutePwaInstallIcon() { web_app::AppId InstallOmniboxOrMenu() {
chrome::SetAutoAcceptPWAInstallConfirmationForTesting(true); chrome::SetAutoAcceptPWAInstallConfirmationForTesting(true);
web_app::AppId app_id; web_app::AppId app_id;
...@@ -315,6 +345,55 @@ class WebAppIntegrationBrowserTest ...@@ -315,6 +345,55 @@ class WebAppIntegrationBrowserTest
return app_browser_; return app_browser_;
} }
void ListAppsInternal() {
auto* web_app_registrar = WebAppProvider::Get(browser()->profile())
->registrar()
.AsWebAppRegistrar();
app_ids_ = web_app_registrar->GetAppIds();
}
NavigateToSiteResult NavigateToSite(Browser* browser, const GURL& url) {
content::WebContents* web_contents = GetCurrentTab(browser);
auto* app_banner_manager =
webapps::TestAppBannerManagerDesktop::FromWebContents(web_contents);
DCHECK(!app_banner_manager->WaitForInstallableCheck());
ui_test_utils::NavigateToURL(browser, url);
bool installable = app_banner_manager->WaitForInstallableCheck();
last_navigation_result_ =
NavigateToSiteResult{web_contents, app_banner_manager, installable};
return last_navigation_result_;
}
void RemovePolicyApp() {
GURL url = GetInstallableAppURL();
base::RunLoop run_loop;
WebAppInstallObserver observer(browser()->profile());
observer.SetWebAppUninstalledDelegate(
base::BindLambdaForTesting([&](const AppId& app_id) {
if (app_id_ == app_id) {
run_loop.Quit();
}
}));
{
ListPrefUpdate update(browser()->profile()->GetPrefs(),
prefs::kWebAppInstallForceList);
update->EraseListValueIf([&](const base::Value& item) {
const base::Value* url_value = item.FindKey(kUrlKey);
return url_value && url_value->GetString() == url.spec();
});
}
run_loop.Run();
}
void SetOpenInWindowInternal() {
auto& app_registry_controller =
WebAppProvider::Get(browser()->profile())->registry_controller();
app_registry_controller.SetAppUserDisplayMode(
app_id_, blink::mojom::DisplayMode::kStandalone, true);
}
// TODO(https://crbug.com/1159651): Support this action on CrOS. // TODO(https://crbug.com/1159651): Support this action on CrOS.
void UninstallFromMenu() { void UninstallFromMenu() {
DCHECK(app_browser_); DCHECK(app_browser_);
...@@ -364,42 +443,25 @@ class WebAppIntegrationBrowserTest ...@@ -364,42 +443,25 @@ class WebAppIntegrationBrowserTest
run_loop.Run(); run_loop.Run();
} }
void InstallCreateShortcutTabbed() {
chrome::SetAutoAcceptWebAppDialogForTesting(/*auto_accept=*/true,
/*auto_open_in_window=*/false);
WebAppInstallObserver observer(browser()->profile());
CHECK(chrome::ExecuteCommand(browser(), IDC_CREATE_SHORTCUT));
app_id_ = observer.AwaitNextInstall();
chrome::SetAutoAcceptWebAppDialogForTesting(false, false);
}
void SetOpenInWindowInternal() {
auto& app_registry_controller =
WebAppProvider::Get(browser()->profile())->registry_controller();
app_registry_controller.SetAppUserDisplayMode(
app_id_, blink::mojom::DisplayMode::kStandalone, true);
}
void ClosePWA() {
DCHECK(app_browser_);
app_browser_->window()->Close();
ui_test_utils::WaitForBrowserToClose(app_browser_);
}
// Assert Actions // Assert Actions
void AssertAppNotInList() { EXPECT_FALSE(base::Contains(app_ids_, app_id_)); }
void AssertInstallable() { EXPECT_TRUE(last_navigation_result_.installable); } void AssertInstallable() { EXPECT_TRUE(last_navigation_result_.installable); }
void AssertInstallIconShown() { void AssertInstallIconShown() {
EXPECT_EQ(GetAppMenuCommandState(IDC_INSTALL_PWA, browser()), kEnabled); EXPECT_EQ(GetAppMenuCommandState(IDC_INSTALL_PWA, browser()), kEnabled);
EXPECT_TRUE(pwa_install_view()->GetVisible()); EXPECT_TRUE(pwa_install_view()->GetVisible());
} }
void AssertInstallIconNotShown() { void AssertInstallIconNotShown() {
EXPECT_EQ(GetAppMenuCommandState(IDC_INSTALL_PWA, browser()), kNotPresent); EXPECT_EQ(GetAppMenuCommandState(IDC_INSTALL_PWA, browser()), kNotPresent);
EXPECT_FALSE(pwa_install_view()->GetVisible()); EXPECT_FALSE(pwa_install_view()->GetVisible());
} }
void AssertLaunchIconShown() { void AssertLaunchIconShown() {
EXPECT_EQ(GetAppMenuCommandState(IDC_OPEN_IN_PWA_WINDOW, browser()), EXPECT_EQ(GetAppMenuCommandState(IDC_OPEN_IN_PWA_WINDOW, browser()),
kEnabled); kEnabled);
} }
void AssertLaunchIconNotShown() { void AssertLaunchIconNotShown() {
EXPECT_EQ(GetAppMenuCommandState(IDC_OPEN_IN_PWA_WINDOW, browser()), EXPECT_EQ(GetAppMenuCommandState(IDC_OPEN_IN_PWA_WINDOW, browser()),
kNotPresent); kNotPresent);
...@@ -407,12 +469,33 @@ class WebAppIntegrationBrowserTest ...@@ -407,12 +469,33 @@ class WebAppIntegrationBrowserTest
void AssertWindowCreated() { EXPECT_TRUE(app_browser_); } void AssertWindowCreated() { EXPECT_TRUE(app_browser_); }
GURL GetInstallableAppURL() {
return https_server_.GetURL("/banners/manifest_test_page.html");
}
GURL GetNonInstallableAppURL() {
return https_server_.GetURL("/banners/no_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) {
return browser->tab_strip_model()->GetActiveWebContents();
}
Browser* app_browser() { return app_browser_; } Browser* app_browser() { return app_browser_; }
std::vector<std::string>& testing_actions() { return testing_actions_; } 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; Browser* app_browser_ = nullptr;
std::vector<AppId> app_ids_;
std::vector<std::string> testing_actions_; std::vector<std::string> testing_actions_;
NavigateToSiteResult last_navigation_result_; NavigateToSiteResult last_navigation_result_;
AppId app_id_; AppId app_id_;
...@@ -435,7 +518,7 @@ IN_PROC_BROWSER_TEST_F(WebAppIntegrationBrowserTest, ...@@ -435,7 +518,7 @@ IN_PROC_BROWSER_TEST_F(WebAppIntegrationBrowserTest,
EXPECT_EQ(GetAppMenuCommandState(IDC_OPEN_IN_PWA_WINDOW, browser()), EXPECT_EQ(GetAppMenuCommandState(IDC_OPEN_IN_PWA_WINDOW, browser()),
kNotPresent); kNotPresent);
ExecutePwaInstallIcon(); InstallOmniboxOrMenu();
chrome::NewTab(browser()); chrome::NewTab(browser());
NavigateToSite(browser(), GetInstallableAppURL()); NavigateToSite(browser(), GetInstallableAppURL());
...@@ -450,7 +533,7 @@ IN_PROC_BROWSER_TEST_F(WebAppIntegrationBrowserTest, LaunchInternal) { ...@@ -450,7 +533,7 @@ IN_PROC_BROWSER_TEST_F(WebAppIntegrationBrowserTest, LaunchInternal) {
EXPECT_EQ(1U, browser_list->size()); EXPECT_EQ(1U, browser_list->size());
EXPECT_FALSE(AppBrowserController::IsWebApp(browser_list->GetLastActive())); EXPECT_FALSE(AppBrowserController::IsWebApp(browser_list->GetLastActive()));
NavigateToSite(browser(), GetInstallableAppURL()); NavigateToSite(browser(), GetInstallableAppURL());
ExecutePwaInstallIcon(); InstallOmniboxOrMenu();
EXPECT_EQ(2U, browser_list->size()); EXPECT_EQ(2U, browser_list->size());
EXPECT_TRUE(AppBrowserController::IsWebApp(browser_list->GetLastActive())); EXPECT_TRUE(AppBrowserController::IsWebApp(browser_list->GetLastActive()));
ClosePWA(); ClosePWA();
......
...@@ -2,6 +2,7 @@ navigate_installable,assert_install_icon_shown, assert_launch_icon_not_shown, ...@@ -2,6 +2,7 @@ navigate_installable,assert_install_icon_shown, assert_launch_icon_not_shown,
navigate_not_installable,assert_install_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,assert_installable,install_omnibox_or_menu, navigate_browser_in_scope,assert_launch_icon_shown, assert_install_icon_not_shown,
navigate_installable, install_create_shortcut_tabbed, set_open_in_window_internal, launch_internal, assert_window_created, navigate_installable, install_create_shortcut_tabbed, set_open_in_window_internal, launch_internal, assert_window_created,
navigate_installable_site_a, assert_install_icon_shown, install_omnibox_or_menu, assert_window_created, launch_internal_site_a, close_pwa, assert_no_crash, navigate_installable_site_a, assert_install_icon_shown, install_omnibox_or_menu, assert_window_created, launch_internal, close_pwa, assert_no_crash,
navigate_installable,install_omnibox_or_menu,launch_internal, uninstall_from_menu,navigate_browser_in_scope, assert_install_icon_shown,assert_launch_icon_not_shown, add_policy_app_internal_tabbed, remove_policy_app, list_apps_internal, assert_app_not_in_list,
Linux, Mac, Win | navigate_installable,install_omnibox_or_menu,launch_internal, uninstall_from_menu,navigate_browser_in_scope, assert_install_icon_shown,assert_launch_icon_not_shown,
ChromeOS | navigate_installable,install_omnibox_or_menu,launch_internal, uninstall_internal,navigate_browser_in_scope, assert_install_icon_shown,assert_launch_icon_not_shown, ChromeOS | navigate_installable,install_omnibox_or_menu,launch_internal, uninstall_internal,navigate_browser_in_scope, assert_install_icon_shown,assert_launch_icon_not_shown,
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