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

dPWA: Implement testing journey 151.

 * Refactor LaunchInternal to handle both tabbed and windowed
   display modes.
 * Implement set_open_in_tab_internal and assert_tab_created.
 * Refactor ExecuteAction() to use LaunchInternal() for all
   launch actions.
 * Refactor ExecuteAction() to use SetOpenInTabInternal()
   for both the internal and non-internal versions of the
   action.
 * Add a test case for journey 151 from the spreadsheet.

Journeys spreadsheet: https://docs.google.com/spreadsheets/d/1d3iAOAnojp4_WrPky9exz1-mjkeulOJVUav5QYG99MQ/edit#gid=1894585254

Bug: 1156730, 1156375
Change-Id: I92d34a595ffe5caf4651a37577fa715c3a789710
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2601318
Commit-Queue: Jarryd Goodman <jarrydg@chromium.org>
Reviewed-by: default avatarDaniel Murphy <dmurph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#843282}
parent c2a568ae
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#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"
#include "third_party/blink/public/mojom/manifest/display_mode.mojom-shared.h"
#include "third_party/re2/src/re2/re2.h" #include "third_party/re2/src/re2/re2.h"
namespace { namespace {
...@@ -231,7 +232,7 @@ class WebAppIntegrationBrowserTest ...@@ -231,7 +232,7 @@ class WebAppIntegrationBrowserTest
InstallCreateShortcutTabbed(); InstallCreateShortcutTabbed();
} else if (action_string == "install_omnibox_or_menu") { } else if (action_string == "install_omnibox_or_menu") {
InstallOmniboxOrMenu(); InstallOmniboxOrMenu();
} else if (base::StartsWith(action_string, "launch_internal")) { } else if (action_string == "launch_internal") {
LaunchInternal(); LaunchInternal();
} else if (action_string == "list_apps_internal") { } else if (action_string == "list_apps_internal") {
ListAppsInternal(); ListAppsInternal();
...@@ -243,6 +244,8 @@ class WebAppIntegrationBrowserTest ...@@ -243,6 +244,8 @@ class WebAppIntegrationBrowserTest
NavigateToSite(browser(), GetNonInstallableAppURL()); NavigateToSite(browser(), GetNonInstallableAppURL());
} else if (action_string == "remove_policy_app") { } else if (action_string == "remove_policy_app") {
RemovePolicyApp(); RemovePolicyApp();
} else if (base::StartsWith(action_string, "set_open_in_tab_internal")) {
SetOpenInTabInternal();
} else if (action_string == "set_open_in_window_internal") { } else if (action_string == "set_open_in_window_internal") {
SetOpenInWindowInternal(); SetOpenInWindowInternal();
} else if (action_string == "uninstall_from_menu") { } else if (action_string == "uninstall_from_menu") {
...@@ -262,6 +265,8 @@ class WebAppIntegrationBrowserTest ...@@ -262,6 +265,8 @@ class WebAppIntegrationBrowserTest
} 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_no_crash") {
} else if (action_string == "assert_tab_created") {
AssertTabCreated();
} else if (action_string == "assert_window_created") { } else if (action_string == "assert_window_created") {
AssertWindowCreated(); AssertWindowCreated();
} else { } else {
...@@ -272,11 +277,10 @@ class WebAppIntegrationBrowserTest ...@@ -272,11 +277,10 @@ class WebAppIntegrationBrowserTest
// Automated Testing Actions // Automated Testing Actions
void AddPolicyAppInternalTabbed() { void AddPolicyAppInternalTabbed() {
GURL url = GetInstallableAppURL(); GURL url = GetInstallableAppURL();
auto* web_app_registrar = WebAppProvider::Get(browser()->profile()) auto* web_app_registrar =
->registrar() WebAppProvider::Get(profile())->registrar().AsWebAppRegistrar();
.AsWebAppRegistrar();
base::RunLoop run_loop; base::RunLoop run_loop;
WebAppInstallObserver observer(browser()->profile()); WebAppInstallObserver observer(profile());
observer.SetWebAppInstalledDelegate( observer.SetWebAppInstalledDelegate(
base::BindLambdaForTesting([&](const AppId& app_id) { base::BindLambdaForTesting([&](const AppId& app_id) {
bool is_installed = web_app_registrar->IsInstalled(app_id); bool is_installed = web_app_registrar->IsInstalled(app_id);
...@@ -292,7 +296,7 @@ class WebAppIntegrationBrowserTest ...@@ -292,7 +296,7 @@ class WebAppIntegrationBrowserTest
item.SetKey(kUrlKey, base::Value(url.spec())); item.SetKey(kUrlKey, base::Value(url.spec()));
item.SetKey(kDefaultLaunchContainerKey, item.SetKey(kDefaultLaunchContainerKey,
base::Value(kDefaultLaunchContainerTabValue)); base::Value(kDefaultLaunchContainerTabValue));
ListPrefUpdate update(browser()->profile()->GetPrefs(), ListPrefUpdate update(profile()->GetPrefs(),
prefs::kWebAppInstallForceList); prefs::kWebAppInstallForceList);
update->Append(item.Clone()); update->Append(item.Clone());
} }
...@@ -308,7 +312,7 @@ class WebAppIntegrationBrowserTest ...@@ -308,7 +312,7 @@ class WebAppIntegrationBrowserTest
void InstallCreateShortcutTabbed() { void InstallCreateShortcutTabbed() {
chrome::SetAutoAcceptWebAppDialogForTesting(/*auto_accept=*/true, chrome::SetAutoAcceptWebAppDialogForTesting(/*auto_accept=*/true,
/*auto_open_in_window=*/false); /*auto_open_in_window=*/false);
WebAppInstallObserver observer(browser()->profile()); WebAppInstallObserver observer(profile());
CHECK(chrome::ExecuteCommand(browser(), IDC_CREATE_SHORTCUT)); CHECK(chrome::ExecuteCommand(browser(), IDC_CREATE_SHORTCUT));
app_id_ = observer.AwaitNextInstall(); app_id_ = observer.AwaitNextInstall();
chrome::SetAutoAcceptWebAppDialogForTesting(false, false); chrome::SetAutoAcceptWebAppDialogForTesting(false, false);
...@@ -339,16 +343,28 @@ class WebAppIntegrationBrowserTest ...@@ -339,16 +343,28 @@ class WebAppIntegrationBrowserTest
return app_id; return app_id;
} }
Browser* LaunchInternal() { void LaunchInternal() {
app_browser_ = LaunchWebAppBrowserAndWait( auto* web_app_provider = WebAppProvider::Get(profile());
ProfileManager::GetActiveUserProfile(), app_id_); AppRegistrar& app_registrar = web_app_provider->registrar();
return app_browser_; DisplayMode display_mode =
app_registrar.GetAppEffectiveDisplayMode(app_id_);
if (display_mode == blink::mojom::DisplayMode::kStandalone) {
app_browser_ = LaunchWebAppBrowserAndWait(
ProfileManager::GetActiveUserProfile(), app_id_);
} else {
ui_test_utils::UrlLoadObserver url_observer(
WebAppProviderBase::GetProviderBase(profile())
->registrar()
.GetAppLaunchUrl(app_id_),
content::NotificationService::AllSources());
LaunchBrowserForWebAppInTab(profile(), app_id_);
url_observer.Wait();
}
} }
void ListAppsInternal() { void ListAppsInternal() {
auto* web_app_registrar = WebAppProvider::Get(browser()->profile()) auto* web_app_registrar =
->registrar() WebAppProvider::Get(profile())->registrar().AsWebAppRegistrar();
.AsWebAppRegistrar();
app_ids_ = web_app_registrar->GetAppIds(); app_ids_ = web_app_registrar->GetAppIds();
} }
...@@ -369,7 +385,7 @@ class WebAppIntegrationBrowserTest ...@@ -369,7 +385,7 @@ class WebAppIntegrationBrowserTest
void RemovePolicyApp() { void RemovePolicyApp() {
GURL url = GetInstallableAppURL(); GURL url = GetInstallableAppURL();
base::RunLoop run_loop; base::RunLoop run_loop;
WebAppInstallObserver observer(browser()->profile()); WebAppInstallObserver observer(profile());
observer.SetWebAppUninstalledDelegate( observer.SetWebAppUninstalledDelegate(
base::BindLambdaForTesting([&](const AppId& app_id) { base::BindLambdaForTesting([&](const AppId& app_id) {
if (app_id_ == app_id) { if (app_id_ == app_id) {
...@@ -377,7 +393,7 @@ class WebAppIntegrationBrowserTest ...@@ -377,7 +393,7 @@ class WebAppIntegrationBrowserTest
} }
})); }));
{ {
ListPrefUpdate update(browser()->profile()->GetPrefs(), ListPrefUpdate update(profile()->GetPrefs(),
prefs::kWebAppInstallForceList); prefs::kWebAppInstallForceList);
update->EraseListValueIf([&](const base::Value& item) { update->EraseListValueIf([&](const base::Value& item) {
const base::Value* url_value = item.FindKey(kUrlKey); const base::Value* url_value = item.FindKey(kUrlKey);
...@@ -387,9 +403,16 @@ class WebAppIntegrationBrowserTest ...@@ -387,9 +403,16 @@ class WebAppIntegrationBrowserTest
run_loop.Run(); run_loop.Run();
} }
void SetOpenInTabInternal() {
auto& app_registry_controller =
WebAppProvider::Get(profile())->registry_controller();
app_registry_controller.SetAppUserDisplayMode(
app_id_, blink::mojom::DisplayMode::kBrowser, true);
}
void SetOpenInWindowInternal() { void SetOpenInWindowInternal() {
auto& app_registry_controller = auto& app_registry_controller =
WebAppProvider::Get(browser()->profile())->registry_controller(); WebAppProvider::Get(profile())->registry_controller();
app_registry_controller.SetAppUserDisplayMode( app_registry_controller.SetAppUserDisplayMode(
app_id_, blink::mojom::DisplayMode::kStandalone, true); app_id_, blink::mojom::DisplayMode::kStandalone, true);
} }
...@@ -398,7 +421,7 @@ class WebAppIntegrationBrowserTest ...@@ -398,7 +421,7 @@ class WebAppIntegrationBrowserTest
void UninstallFromMenu() { void UninstallFromMenu() {
DCHECK(app_browser_); DCHECK(app_browser_);
base::RunLoop run_loop; base::RunLoop run_loop;
WebAppInstallObserver observer(browser()->profile()); WebAppInstallObserver observer(profile());
observer.SetWebAppUninstalledDelegate( observer.SetWebAppUninstalledDelegate(
base::BindLambdaForTesting([&](const AppId& app_id) { base::BindLambdaForTesting([&](const AppId& app_id) {
if (app_id == app_id_) { if (app_id == app_id_) {
...@@ -430,7 +453,7 @@ class WebAppIntegrationBrowserTest ...@@ -430,7 +453,7 @@ class WebAppIntegrationBrowserTest
void UninstallInternal() { void UninstallInternal() {
WebAppProviderBase* const provider = WebAppProviderBase* const provider =
WebAppProviderBase::GetProviderBase(browser()->profile()); WebAppProviderBase::GetProviderBase(profile());
base::RunLoop run_loop; base::RunLoop run_loop;
DCHECK(provider->install_finalizer().CanUserUninstallExternalApp(app_id_)); DCHECK(provider->install_finalizer().CanUserUninstallExternalApp(app_id_));
...@@ -467,6 +490,14 @@ class WebAppIntegrationBrowserTest ...@@ -467,6 +490,14 @@ class WebAppIntegrationBrowserTest
kNotPresent); kNotPresent);
} }
void AssertTabCreated() {
auto* tab_strip_model = browser()->tab_strip_model();
EXPECT_TRUE(tab_strip_model->count() == 2);
auto* web_contents = tab_strip_model->GetActiveWebContents();
const GURL& url = web_contents->GetLastCommittedURL();
EXPECT_EQ(GetInstallableAppURL(), url);
}
void AssertWindowCreated() { EXPECT_TRUE(app_browser_); } void AssertWindowCreated() { EXPECT_TRUE(app_browser_); }
GURL GetInstallableAppURL() { GURL GetInstallableAppURL() {
...@@ -489,6 +520,7 @@ class WebAppIntegrationBrowserTest ...@@ -489,6 +520,7 @@ class WebAppIntegrationBrowserTest
return browser->tab_strip_model()->GetActiveWebContents(); return browser->tab_strip_model()->GetActiveWebContents();
} }
Profile* profile() { return browser()->profile(); }
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_; }
......
...@@ -4,5 +4,7 @@ navigate_installable,assert_installable,install_omnibox_or_menu, navigate_browse ...@@ -4,5 +4,7 @@ navigate_installable,assert_installable,install_omnibox_or_menu, navigate_browse
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, 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,
add_policy_app_internal_tabbed, remove_policy_app, list_apps_internal, assert_app_not_in_list, add_policy_app_internal_tabbed, remove_policy_app, list_apps_internal, assert_app_not_in_list,
# Journey 151
navigate_installable, install_omnibox_or_menu, list_apps_internal, set_open_in_tab_internal, launch_internal, assert_tab_created,
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, 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