Commit da575a5c authored by Jiewei Qian's avatar Jiewei Qian Committed by Commit Bot

system-web-apps: consolidate browsertest app launching logic

In System Web App related browsertests, we have three different App
launching methods that do the same thing, this CL consolidates these
methods:
- LaunchApp
- WaitForSystemAppInstallAndLoad
- WaitForSystemAppInstallAndLaunch

The new LaunchApp method handles the launch, and waits for load stop
by default. LaunchAppWithoutWaiting does the same thing, but doesn't
wait for load stop, which is useful to test certain defaults (e.g.
browser window size, toolbar visibility, window title).

Bug: TBD
Change-Id: I38f74a3faef83b3902a7af2387f2e31fe78127e1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2294879
Commit-Queue: Jiewei Qian  <qjw@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Reviewed-by: default avatarTrent Apted <tapted@chromium.org>
Cr-Commit-Position: refs/heads/master@{#790717}
parent 41f18f56
...@@ -46,7 +46,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2) { ...@@ -46,7 +46,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2) {
// Test that the Help App is searchable by additional strings. // Test that the Help App is searchable by additional strings.
IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2SearchInLauncher) { IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2SearchInLauncher) {
WaitForSystemAppInstallAndLaunch(web_app::SystemAppType::HELP); WaitForTestSystemAppInstall();
EXPECT_EQ( EXPECT_EQ(
std::vector<std::string>({"Get Help", "Perks", "Offers"}), std::vector<std::string>({"Get Help", "Perks", "Offers"}),
GetManager().GetAdditionalSearchTerms(web_app::SystemAppType::HELP)); GetManager().GetAdditionalSearchTerms(web_app::SystemAppType::HELP));
...@@ -54,7 +54,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2SearchInLauncher) { ...@@ -54,7 +54,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2SearchInLauncher) {
// Test that the Help App has a minimum window size of 600x320. // Test that the Help App has a minimum window size of 600x320.
IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2MinWindowSize) { IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2MinWindowSize) {
WaitForSystemAppInstallAndLaunch(web_app::SystemAppType::HELP); WaitForTestSystemAppInstall();
auto app_id = LaunchParamsForApp(web_app::SystemAppType::HELP).app_id; auto app_id = LaunchParamsForApp(web_app::SystemAppType::HELP).app_id;
EXPECT_EQ(GetManager().GetMinimumWindowSize(app_id), gfx::Size(600, 320)); EXPECT_EQ(GetManager().GetMinimumWindowSize(app_id), gfx::Size(600, 320));
} }
...@@ -62,8 +62,9 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2MinWindowSize) { ...@@ -62,8 +62,9 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2MinWindowSize) {
// Test that the Help App has a default size of 960x600 and is in the center of // Test that the Help App has a default size of 960x600 and is in the center of
// the screen. // the screen.
IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2DefaultWindowBounds) { IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2DefaultWindowBounds) {
auto* browser = WaitForTestSystemAppInstall();
WaitForSystemAppInstallAndLaunch(web_app::SystemAppType::HELP); Browser* browser;
LaunchApp(web_app::SystemAppType::HELP, &browser);
gfx::Rect work_area = gfx::Rect work_area =
display::Screen::GetScreen()->GetDisplayForNewWindows().work_area(); display::Screen::GetScreen()->GetDisplayForNewWindows().work_area();
int x = (work_area.width() - 960) / 2; int x = (work_area.width() - 960) / 2;
...@@ -93,8 +94,9 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2AppServiceMetrics) { ...@@ -93,8 +94,9 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2AppServiceMetrics) {
// Test that the Help App can log metrics in the untrusted frame. // Test that the Help App can log metrics in the untrusted frame.
IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2InAppMetrics) { IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2InAppMetrics) {
content::WebContents* web_contents = WaitForTestSystemAppInstall();
WaitForSystemAppInstallAndLoad(web_app::SystemAppType::HELP); content::WebContents* web_contents = LaunchApp(web_app::SystemAppType::HELP);
base::UserActionTester user_action_tester; base::UserActionTester user_action_tester;
constexpr char kScript[] = R"( constexpr char kScript[] = R"(
......
...@@ -193,9 +193,10 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest, MediaAppLaunchWithFile) { ...@@ -193,9 +193,10 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest, MediaAppLaunchWithFile) {
EXPECT_EQ("800x600", WaitForImageAlt(app, kFilePng800x600)); EXPECT_EQ("800x600", WaitForImageAlt(app, kFilePng800x600));
// Relaunch with a different file. This currently re-uses the existing window. // Relaunch with a different file. This currently re-uses the existing window,
// so we don't wait for page load here.
params.launch_files = {TestFile(kFileJpeg640x480)}; params.launch_files = {TestFile(kFileJpeg640x480)};
LaunchApp(params); LaunchAppWithoutWaiting(params);
EXPECT_EQ("640x480", WaitForImageAlt(app, kFileJpeg640x480)); EXPECT_EQ("640x480", WaitForImageAlt(app, kFileJpeg640x480));
} }
...@@ -247,8 +248,8 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest, ...@@ -247,8 +248,8 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest,
TrustedContextReportsConsoleErrors) { TrustedContextReportsConsoleErrors) {
MockCrashEndpoint endpoint(embedded_test_server()); MockCrashEndpoint endpoint(embedded_test_server());
content::WebContents* web_ui = WaitForTestSystemAppInstall();
WaitForSystemAppInstallAndLoad(web_app::SystemAppType::MEDIA); content::WebContents* web_ui = LaunchApp(web_app::SystemAppType::MEDIA);
// Pass multiple arguments to console.error() to also check they are parsed // Pass multiple arguments to console.error() to also check they are parsed
// and captured in the error message correctly. // and captured in the error message correctly.
...@@ -268,8 +269,8 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest, ...@@ -268,8 +269,8 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest,
TrustedContextReportsDomExceptions) { TrustedContextReportsDomExceptions) {
MockCrashEndpoint endpoint(embedded_test_server()); MockCrashEndpoint endpoint(embedded_test_server());
content::WebContents* web_ui = WaitForTestSystemAppInstall();
WaitForSystemAppInstallAndLoad(web_app::SystemAppType::MEDIA); content::WebContents* web_ui = LaunchApp(web_app::SystemAppType::MEDIA);
EXPECT_EQ(true, ExecuteScript(web_ui, kDomExceptionScript)); EXPECT_EQ(true, ExecuteScript(web_ui, kDomExceptionScript));
auto report = endpoint.WaitForReport(); auto report = endpoint.WaitForReport();
...@@ -284,8 +285,8 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest, ...@@ -284,8 +285,8 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest,
UntrustedContextReportsDomExceptions) { UntrustedContextReportsDomExceptions) {
MockCrashEndpoint endpoint(embedded_test_server()); MockCrashEndpoint endpoint(embedded_test_server());
content::WebContents* app = WaitForTestSystemAppInstall();
WaitForSystemAppInstallAndLoad(web_app::SystemAppType::MEDIA); content::WebContents* app = LaunchApp(web_app::SystemAppType::MEDIA);
EXPECT_EQ(true, EXPECT_EQ(true,
MediaAppUiBrowserTest::EvalJsInAppFrame(app, kDomExceptionScript)); MediaAppUiBrowserTest::EvalJsInAppFrame(app, kDomExceptionScript));
...@@ -300,8 +301,8 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest, ...@@ -300,8 +301,8 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest,
TrustedContextReportsUnhandledExceptions) { TrustedContextReportsUnhandledExceptions) {
MockCrashEndpoint endpoint(embedded_test_server()); MockCrashEndpoint endpoint(embedded_test_server());
content::WebContents* web_ui = WaitForTestSystemAppInstall();
WaitForSystemAppInstallAndLoad(web_app::SystemAppType::MEDIA); content::WebContents* web_ui = LaunchApp(web_app::SystemAppType::MEDIA);
EXPECT_EQ(true, ExecuteScript(web_ui, kUnhandledRejectionScript)); EXPECT_EQ(true, ExecuteScript(web_ui, kUnhandledRejectionScript));
auto report = endpoint.WaitForReport(); auto report = endpoint.WaitForReport();
...@@ -316,8 +317,8 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest, ...@@ -316,8 +317,8 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest,
UntrustedContextReportsUnhandledExceptions) { UntrustedContextReportsUnhandledExceptions) {
MockCrashEndpoint endpoint(embedded_test_server()); MockCrashEndpoint endpoint(embedded_test_server());
content::WebContents* app = WaitForTestSystemAppInstall();
WaitForSystemAppInstallAndLoad(web_app::SystemAppType::MEDIA); content::WebContents* app = LaunchApp(web_app::SystemAppType::MEDIA);
EXPECT_EQ(true, MediaAppUiBrowserTest::EvalJsInAppFrame( EXPECT_EQ(true, MediaAppUiBrowserTest::EvalJsInAppFrame(
app, kUnhandledRejectionScript)); app, kUnhandledRejectionScript));
...@@ -330,8 +331,9 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest, ...@@ -330,8 +331,9 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest,
IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest, IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest,
TrustedContextReportsTypeErrors) { TrustedContextReportsTypeErrors) {
MockCrashEndpoint endpoint(embedded_test_server()); MockCrashEndpoint endpoint(embedded_test_server());
content::WebContents* web_ui =
WaitForSystemAppInstallAndLoad(web_app::SystemAppType::MEDIA); WaitForTestSystemAppInstall();
content::WebContents* web_ui = LaunchApp(web_app::SystemAppType::MEDIA);
EXPECT_EQ(true, ExecuteScript(web_ui, kTypeErrorScript)); EXPECT_EQ(true, ExecuteScript(web_ui, kTypeErrorScript));
auto report = endpoint.WaitForReport(); auto report = endpoint.WaitForReport();
...@@ -346,8 +348,9 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest, ...@@ -346,8 +348,9 @@ IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest,
IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest, IN_PROC_BROWSER_TEST_P(MediaAppIntegrationTest,
UntrustedContextReportsTypeErrors) { UntrustedContextReportsTypeErrors) {
MockCrashEndpoint endpoint(embedded_test_server()); MockCrashEndpoint endpoint(embedded_test_server());
content::WebContents* app =
WaitForSystemAppInstallAndLoad(web_app::SystemAppType::MEDIA); WaitForTestSystemAppInstall();
content::WebContents* app = LaunchApp(web_app::SystemAppType::MEDIA);
EXPECT_EQ(true, EXPECT_EQ(true,
MediaAppUiBrowserTest::EvalJsInAppFrame(app, kTypeErrorScript)); MediaAppUiBrowserTest::EvalJsInAppFrame(app, kTypeErrorScript));
......
...@@ -36,8 +36,14 @@ IN_PROC_BROWSER_TEST_P(SettingsAppIntegrationTest, SettingsAppDisabled) { ...@@ -36,8 +36,14 @@ IN_PROC_BROWSER_TEST_P(SettingsAppIntegrationTest, SettingsAppDisabled) {
ASSERT_FALSE(GetManager() ASSERT_FALSE(GetManager()
.GetAppIdForSystemApp(web_app::SystemAppType::SETTINGS) .GetAppIdForSystemApp(web_app::SystemAppType::SETTINGS)
.has_value()); .has_value());
Browser* app_browser =
WaitForSystemAppInstallAndLaunch(web_app::SystemAppType::SETTINGS); WaitForTestSystemAppInstall();
// Don't wait for load here, because we navigate to chrome error page instead.
// The App's launch URL won't be loaded.
Browser* app_browser;
LaunchAppWithoutWaiting(web_app::SystemAppType::SETTINGS, &app_browser);
ASSERT_TRUE(GetManager() ASSERT_TRUE(GetManager()
.GetAppIdForSystemApp(web_app::SystemAppType::SETTINGS) .GetAppIdForSystemApp(web_app::SystemAppType::SETTINGS)
.has_value()); .has_value());
......
...@@ -29,7 +29,14 @@ void SystemWebAppIntegrationTest::ExpectSystemWebAppValid( ...@@ -29,7 +29,14 @@ void SystemWebAppIntegrationTest::ExpectSystemWebAppValid(
web_app::SystemAppType app_type, web_app::SystemAppType app_type,
const GURL& url, const GURL& url,
const std::string& title) { const std::string& title) {
Browser* app_browser = WaitForSystemAppInstallAndLaunch(app_type); WaitForTestSystemAppInstall();
// Launch but don't wait for page load here because we want to check the
// browser window's title is set before the page loads.
// TODO(crbug.com/1107285): This isn't a strong guarantee that we check the
// title before the page loads. We should improve this.
Browser* app_browser;
LaunchAppWithoutWaiting(app_type, &app_browser);
web_app::AppId app_id = app_browser->app_controller()->GetAppId(); web_app::AppId app_id = app_browser->app_controller()->GetAppId();
EXPECT_EQ(GetManager().GetAppIdForSystemApp(app_type), app_id); EXPECT_EQ(GetManager().GetAppIdForSystemApp(app_type), app_id);
......
...@@ -309,7 +309,9 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppSessionRestoreTestChromeOS, ...@@ -309,7 +309,9 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppSessionRestoreTestChromeOS,
PRE_OmitSystemWebApps) { PRE_OmitSystemWebApps) {
// Wait for the app to install, launch, and load, otherwise the app might not // Wait for the app to install, launch, and load, otherwise the app might not
// be restored. // be restored.
WaitForSystemAppInstallAndLoad(GetMockAppType()); WaitForTestSystemAppInstall();
LaunchApp(GetMockAppType());
auto app_params = Browser::CreateParams::CreateForApp( auto app_params = Browser::CreateParams::CreateForApp(
test_app_name1, true, gfx::Rect(), browser()->profile(), true); test_app_name1, true, gfx::Rect(), browser()->profile(), true);
Browser* app_browser = new Browser(app_params); Browser* app_browser = new Browser(app_params);
......
...@@ -18,8 +18,9 @@ using SystemWebAppNonClientFrameViewBrowserTest = ...@@ -18,8 +18,9 @@ using SystemWebAppNonClientFrameViewBrowserTest =
// System Web Apps don't get the web app menu button. // System Web Apps don't get the web app menu button.
IN_PROC_BROWSER_TEST_P(SystemWebAppNonClientFrameViewBrowserTest, IN_PROC_BROWSER_TEST_P(SystemWebAppNonClientFrameViewBrowserTest,
HideWebAppMenuButton) { HideWebAppMenuButton) {
Browser* app_browser = WaitForTestSystemAppInstall();
WaitForSystemAppInstallAndLaunch(web_app::SystemAppType::SETTINGS); Browser* app_browser;
LaunchApp(web_app::SystemAppType::SETTINGS, &app_browser);
EXPECT_EQ(nullptr, BrowserView::GetBrowserViewForBrowser(app_browser) EXPECT_EQ(nullptr, BrowserView::GetBrowserViewForBrowser(app_browser)
->frame() ->frame()
->GetFrameView() ->GetFrameView()
...@@ -30,8 +31,9 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppNonClientFrameViewBrowserTest, ...@@ -30,8 +31,9 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppNonClientFrameViewBrowserTest,
// Regression test for https://crbug.com/1090169. // Regression test for https://crbug.com/1090169.
IN_PROC_BROWSER_TEST_P(SystemWebAppNonClientFrameViewBrowserTest, IN_PROC_BROWSER_TEST_P(SystemWebAppNonClientFrameViewBrowserTest,
HideNativeFileSystemAccessPageAction) { HideNativeFileSystemAccessPageAction) {
Browser* app_browser = WaitForTestSystemAppInstall();
WaitForSystemAppInstallAndLaunch(web_app::SystemAppType::SETTINGS); Browser* app_browser;
LaunchApp(web_app::SystemAppType::SETTINGS, &app_browser);
WebAppFrameToolbarView* toolbar = WebAppFrameToolbarView* toolbar =
BrowserView::GetBrowserViewForBrowser(app_browser) BrowserView::GetBrowserViewForBrowser(app_browser)
->frame() ->frame()
......
...@@ -93,32 +93,6 @@ void SystemWebAppManagerBrowserTestBase::WaitForTestSystemAppInstall() { ...@@ -93,32 +93,6 @@ void SystemWebAppManagerBrowserTestBase::WaitForTestSystemAppInstall() {
proxy->FlushMojoCallsForTesting(); proxy->FlushMojoCallsForTesting();
} }
content::WebContents*
SystemWebAppManagerBrowserTestBase::WaitForSystemAppInstallAndLoad(
SystemAppType system_app_type) {
WaitForTestSystemAppInstall();
apps::AppLaunchParams params = LaunchParamsForApp(system_app_type);
content::TestNavigationObserver navigation_observer(
GetLaunchURL(system_app_type));
navigation_observer.StartWatchingNewWebContents();
content::WebContents* web_contents = LaunchApp(params);
navigation_observer.Wait();
return web_contents;
}
Browser* SystemWebAppManagerBrowserTestBase::WaitForSystemAppInstallAndLaunch(
SystemAppType system_app_type) {
WaitForTestSystemAppInstall();
apps::AppLaunchParams params = LaunchParamsForApp(system_app_type);
content::WebContents* web_contents = LaunchApp(params);
Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
EXPECT_EQ(web_app::GetAppIdFromApplicationName(browser->app_name()),
params.app_id);
return browser;
}
apps::AppLaunchParams SystemWebAppManagerBrowserTestBase::LaunchParamsForApp( apps::AppLaunchParams SystemWebAppManagerBrowserTestBase::LaunchParamsForApp(
SystemAppType system_app_type) { SystemAppType system_app_type) {
base::Optional<AppId> app_id = base::Optional<AppId> app_id =
...@@ -131,20 +105,59 @@ apps::AppLaunchParams SystemWebAppManagerBrowserTestBase::LaunchParamsForApp( ...@@ -131,20 +105,59 @@ apps::AppLaunchParams SystemWebAppManagerBrowserTestBase::LaunchParamsForApp(
} }
content::WebContents* SystemWebAppManagerBrowserTestBase::LaunchApp( content::WebContents* SystemWebAppManagerBrowserTestBase::LaunchApp(
const apps::AppLaunchParams& params) { const apps::AppLaunchParams& params,
return apps::AppServiceProxyFactory::GetForProfile(browser()->profile()) bool wait_for_load,
->BrowserAppLauncher() Browser** out_browser) {
->LaunchAppWithParams(params); content::TestNavigationObserver navigation_observer(GetLaunchURL(params));
navigation_observer.StartWatchingNewWebContents();
content::WebContents* web_contents =
apps::AppServiceProxyFactory::GetForProfile(browser()->profile())
->BrowserAppLauncher()
->LaunchAppWithParams(params);
if (wait_for_load)
navigation_observer.Wait();
if (out_browser)
*out_browser = chrome::FindBrowserWithWebContents(web_contents);
return web_contents;
}
content::WebContents* SystemWebAppManagerBrowserTestBase::LaunchApp(
const apps::AppLaunchParams& params,
Browser** browser) {
return LaunchApp(params, /* wait_for_load */ true, browser);
}
content::WebContents* SystemWebAppManagerBrowserTestBase::LaunchApp(
SystemAppType type,
Browser** browser) {
return LaunchApp(LaunchParamsForApp(type), browser);
}
content::WebContents*
SystemWebAppManagerBrowserTestBase::LaunchAppWithoutWaiting(
const apps::AppLaunchParams& params,
Browser** browser) {
return LaunchApp(params, /* wait_for_load */ false, browser);
}
content::WebContents*
SystemWebAppManagerBrowserTestBase::LaunchAppWithoutWaiting(
web_app::SystemAppType type,
Browser** browser) {
return LaunchAppWithoutWaiting(LaunchParamsForApp(type), browser);
} }
const GURL& SystemWebAppManagerBrowserTestBase::GetLaunchURL( const GURL& SystemWebAppManagerBrowserTestBase::GetLaunchURL(
SystemAppType system_app_type) { const apps::AppLaunchParams& params) {
base::Optional<AppId> app_id = return params.override_url.is_valid()
GetManager().GetAppIdForSystemApp(system_app_type).value(); ? params.override_url
CHECK(app_id.has_value()); : WebAppProvider::Get(browser()->profile())
return WebAppProvider::Get(browser()->profile()) ->registrar()
->registrar() .GetAppLaunchURL(params.app_id);
.GetAppLaunchURL(app_id.value());
} }
SystemWebAppManagerBrowserTest::SystemWebAppManagerBrowserTest( SystemWebAppManagerBrowserTest::SystemWebAppManagerBrowserTest(
...@@ -188,7 +201,12 @@ SystemWebAppManagerWebAppInfoBrowserTest:: ...@@ -188,7 +201,12 @@ SystemWebAppManagerWebAppInfoBrowserTest::
// Test that System Apps install correctly with a manifest. // Test that System Apps install correctly with a manifest.
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerWebAppInfoBrowserTest, Install) { IN_PROC_BROWSER_TEST_P(SystemWebAppManagerWebAppInfoBrowserTest, Install) {
Browser* app_browser = WaitForSystemAppInstallAndLaunch(GetMockAppType()); WaitForTestSystemAppInstall();
// Don't wait for page load because we want to verify AppController identifies
// the System Web App before when the app loads.
Browser* app_browser;
LaunchAppWithoutWaiting(GetMockAppType(), &app_browser);
AppId app_id = app_browser->app_controller()->GetAppId(); AppId app_id = app_browser->app_controller()->GetAppId();
EXPECT_EQ(GetManager().GetAppIdForSystemApp(GetMockAppType()), app_id); EXPECT_EQ(GetManager().GetAppIdForSystemApp(GetMockAppType()), app_id);
...@@ -242,7 +260,13 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerWebAppInfoBrowserTest, Install) { ...@@ -242,7 +260,13 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerWebAppInfoBrowserTest, Install) {
// scheme but is shown off the chrome:// scheme. // scheme but is shown off the chrome:// scheme.
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerWebAppInfoBrowserTest, IN_PROC_BROWSER_TEST_P(SystemWebAppManagerWebAppInfoBrowserTest,
ToolbarVisibilityForSystemWebApp) { ToolbarVisibilityForSystemWebApp) {
Browser* app_browser = WaitForSystemAppInstallAndLaunch(GetMockAppType()); WaitForTestSystemAppInstall();
// Don't wait for page load because we want to verify the toolbar is hidden
// when the window first opens.
Browser* app_browser;
LaunchAppWithoutWaiting(GetMockAppType(), &app_browser);
// In scope, the toolbar should not be visible. // In scope, the toolbar should not be visible.
EXPECT_FALSE(app_browser->app_controller()->ShouldShowCustomTabBar()); EXPECT_FALSE(app_browser->app_controller()->ShouldShowCustomTabBar());
...@@ -302,22 +326,16 @@ class SystemWebAppManagerFileHandlingBrowserTestBase ...@@ -302,22 +326,16 @@ class SystemWebAppManagerFileHandlingBrowserTestBase
params.source = apps::mojom::AppLaunchSource::kSourceChromeInternal; params.source = apps::mojom::AppLaunchSource::kSourceChromeInternal;
params.launch_files = launch_files; params.launch_files = launch_files;
content::TestNavigationObserver navigation_observer( return SystemWebAppManagerBrowserTestBase::LaunchApp(params);
GetLaunchURL(GetMockAppType()));
navigation_observer.StartWatchingNewWebContents();
content::WebContents* web_contents =
SystemWebAppManagerBrowserTestBase::LaunchApp(params);
if (wait_for_load)
navigation_observer.Wait();
return web_contents;
} }
content::WebContents* LaunchAppWithoutWaiting( content::WebContents* LaunchAppWithoutWaiting(
const std::vector<base::FilePath> launch_files) { const std::vector<base::FilePath> launch_files) {
return LaunchApp(launch_files, /* wait_for_load */ false); apps::AppLaunchParams params = LaunchParamsForApp(GetMockAppType());
params.source = apps::mojom::AppLaunchSource::kSourceChromeInternal;
params.launch_files = launch_files;
return SystemWebAppManagerBrowserTestBase::LaunchAppWithoutWaiting(params);
} }
// Must be called before WaitAndExposeLaunchParamsToWindow. This sets up the // Must be called before WaitAndExposeLaunchParamsToWindow. This sets up the
...@@ -855,13 +873,7 @@ class SystemWebAppManagerFileHandlingOriginTrialsBrowserTest ...@@ -855,13 +873,7 @@ class SystemWebAppManagerFileHandlingOriginTrialsBrowserTest
params.source = apps::mojom::AppLaunchSource::kSourceChromeInternal; params.source = apps::mojom::AppLaunchSource::kSourceChromeInternal;
params.launch_files = {temp_file_path}; params.launch_files = {temp_file_path};
content::TestNavigationObserver navigation_observer( return SystemWebAppManagerBrowserTestBase::LaunchApp(params);
GetLaunchURL(GetMockAppType()));
navigation_observer.StartWatchingNewWebContents();
content::WebContents* web_contents = LaunchApp(params);
navigation_observer.Wait();
return web_contents;
} }
bool WaitForLaunchParam(content::WebContents* web_contents) { bool WaitForLaunchParam(content::WebContents* web_contents) {
...@@ -899,7 +911,8 @@ class SystemWebAppManagerNotShownInLauncherTest ...@@ -899,7 +911,8 @@ class SystemWebAppManagerNotShownInLauncherTest
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerNotShownInLauncherTest, IN_PROC_BROWSER_TEST_P(SystemWebAppManagerNotShownInLauncherTest,
NotShownInLauncher) { NotShownInLauncher) {
WaitForSystemAppInstallAndLaunch(GetMockAppType()); WaitForTestSystemAppInstall();
AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value(); AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value();
// OS Integration only relevant for Chrome OS. // OS Integration only relevant for Chrome OS.
...@@ -934,7 +947,7 @@ class SystemWebAppManagerNotShownInSearchTest ...@@ -934,7 +947,7 @@ class SystemWebAppManagerNotShownInSearchTest
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerNotShownInSearchTest, IN_PROC_BROWSER_TEST_P(SystemWebAppManagerNotShownInSearchTest,
NotShownInSearch) { NotShownInSearch) {
WaitForSystemAppInstallAndLaunch(GetMockAppType()); WaitForTestSystemAppInstall();
AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value(); AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value();
// OS Integration only relevant for Chrome OS. // OS Integration only relevant for Chrome OS.
...@@ -960,7 +973,7 @@ class SystemWebAppManagerAdditionalSearchTermsTest ...@@ -960,7 +973,7 @@ class SystemWebAppManagerAdditionalSearchTermsTest
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerAdditionalSearchTermsTest, IN_PROC_BROWSER_TEST_P(SystemWebAppManagerAdditionalSearchTermsTest,
AdditionalSearchTerms) { AdditionalSearchTerms) {
WaitForSystemAppInstallAndLaunch(GetMockAppType()); WaitForTestSystemAppInstall();
AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value(); AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value();
apps::AppServiceProxy* proxy = apps::AppServiceProxy* proxy =
...@@ -1084,7 +1097,13 @@ class SystemWebAppManagerChromeUntrustedTest ...@@ -1084,7 +1097,13 @@ class SystemWebAppManagerChromeUntrustedTest
}; };
IN_PROC_BROWSER_TEST_P(SystemWebAppManagerChromeUntrustedTest, Install) { IN_PROC_BROWSER_TEST_P(SystemWebAppManagerChromeUntrustedTest, Install) {
Browser* app_browser = WaitForSystemAppInstallAndLaunch(GetMockAppType()); WaitForTestSystemAppInstall();
// Don't wait for page load because we want to verify AppController identifies
// the System Web App before the app loads.
Browser* app_browser;
LaunchAppWithoutWaiting(GetMockAppType(), &app_browser);
AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value(); AppId app_id = GetManager().GetAppIdForSystemApp(GetMockAppType()).value();
EXPECT_EQ(app_id, app_browser->app_controller()->GetAppId()); EXPECT_EQ(app_id, app_browser->app_controller()->GetAppId());
EXPECT_TRUE(GetManager().IsSystemWebApp(app_id)); EXPECT_TRUE(GetManager().IsSystemWebApp(app_id));
......
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
#include "chrome/browser/web_applications/test/web_app_test.h" #include "chrome/browser/web_applications/test/web_app_test.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
class Browser;
class KeyedService; class KeyedService;
namespace apps { namespace apps {
...@@ -48,26 +47,39 @@ class SystemWebAppManagerBrowserTestBase : public InProcessBrowserTest { ...@@ -48,26 +47,39 @@ class SystemWebAppManagerBrowserTestBase : public InProcessBrowserTest {
// Returns SystemAppType of mocked app, only valid if |install_mock| is true. // Returns SystemAppType of mocked app, only valid if |install_mock| is true.
SystemAppType GetMockAppType(); SystemAppType GetMockAppType();
// Returns the the launch URL for an installed |system_app_type|. // Returns the launch URL for based on the given |params|.
const GURL& GetLaunchURL(SystemAppType system_app_type); const GURL& GetLaunchURL(const apps::AppLaunchParams& params);
void WaitForTestSystemAppInstall(); void WaitForTestSystemAppInstall();
// Waits for system apps to install, then launches one. Waits for launched app
// to load.
content::WebContents* WaitForSystemAppInstallAndLoad(
SystemAppType system_app_type);
// Waits for system apps to install, then launches one. Returns the browser
// that contains it.
Browser* WaitForSystemAppInstallAndLaunch(SystemAppType system_app_type);
// Creates a default AppLaunchParams for |system_app_type|. Launches a window. // Creates a default AppLaunchParams for |system_app_type|. Launches a window.
// Uses kSourceTest as the AppLaunchSource. // Uses kSourceTest as the AppLaunchSource.
apps::AppLaunchParams LaunchParamsForApp(SystemAppType system_app_type); apps::AppLaunchParams LaunchParamsForApp(SystemAppType system_app_type);
// Invokes OpenApplication() using the test's Profile. // Launch the given System App from |params|, and wait for the application to
content::WebContents* LaunchApp(const apps::AppLaunchParams& params); // finish loading. If |browser| is not nullptr, it will store the Browser*
// that hosts the launched application.
content::WebContents* LaunchApp(const apps::AppLaunchParams& params,
Browser** browser = nullptr);
// Launch the given System App |type| with default AppLaunchParams, and wait
// for the application to finish loading. If |browser| is not nullptr, it will
// store the Browser* that hosts the launched application.
content::WebContents* LaunchApp(web_app::SystemAppType type,
Browser** browser = nullptr);
// Launch the given System App from |params|, without waiting for the
// application to finish loading. If |browser| is not nullptr, it will store
// the Browser* that hosts the launched application.
content::WebContents* LaunchAppWithoutWaiting(
const apps::AppLaunchParams& params,
Browser** browser = nullptr);
// Launch the given System App |type| with default AppLaunchParams, without
// waiting for the application to finish loading. If |browser| is not nullptr,
// it will store the Browser* that hosts the launched application.
content::WebContents* LaunchAppWithoutWaiting(web_app::SystemAppType type,
Browser** browser = nullptr);
protected: protected:
std::unique_ptr<TestSystemWebAppInstallation> maybe_installation_; std::unique_ptr<TestSystemWebAppInstallation> maybe_installation_;
...@@ -75,6 +87,14 @@ class SystemWebAppManagerBrowserTestBase : public InProcessBrowserTest { ...@@ -75,6 +87,14 @@ class SystemWebAppManagerBrowserTestBase : public InProcessBrowserTest {
private: private:
std::unique_ptr<KeyedService> CreateWebAppProvider(Profile* profile); std::unique_ptr<KeyedService> CreateWebAppProvider(Profile* profile);
// Invokes OpenApplication() using the test's Profile. If |wait_for_load| is
// true, returns after the application finishes loading. Otherwise, returns
// immediately. If |browser| is not nullptr, it will store the Browser* that
// hosts the launched application.
content::WebContents* LaunchApp(const apps::AppLaunchParams& params,
bool wait_for_load,
Browser** out_browser);
base::test::ScopedFeatureList scoped_feature_list_; base::test::ScopedFeatureList scoped_feature_list_;
DISALLOW_COPY_AND_ASSIGN(SystemWebAppManagerBrowserTestBase); DISALLOW_COPY_AND_ASSIGN(SystemWebAppManagerBrowserTestBase);
......
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