Commit 723fca66 authored by Alan Cutter's avatar Alan Cutter Committed by Commit Bot

Remove dependency on Extensions for SystemWebAppManager browser_tests

This CL rewrites some of the SystemWebAppManagerBrowserTest code to use
web_app::AppRegistrar instead of the Extension interface.
This is necessary to migrate web apps off the Extension system.

Bug: 1052348, 876576
Change-Id: If75fdbb1c25b089961b40f47a48d09a8f3ffcdd0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2059356
Commit-Queue: Alan Cutter <alancutter@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@{#742517}
parent 2b23b83e
...@@ -13,9 +13,6 @@ ...@@ -13,9 +13,6 @@
#include "chrome/browser/web_applications/system_web_app_manager.h" #include "chrome/browser/web_applications/system_web_app_manager.h"
#include "content/public/browser/web_ui.h" #include "content/public/browser/web_ui.h"
#include "content/public/test/test_navigation_observer.h" #include "content/public/test/test_navigation_observer.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
...@@ -33,24 +30,19 @@ void SystemWebAppIntegrationTest::ExpectSystemWebAppValid( ...@@ -33,24 +30,19 @@ void SystemWebAppIntegrationTest::ExpectSystemWebAppValid(
const GURL& url, const GURL& url,
const std::string& title) { const std::string& title) {
Browser* app_browser = WaitForSystemAppInstallAndLaunch(app_type); Browser* app_browser = WaitForSystemAppInstallAndLaunch(app_type);
base::Optional<web_app::AppId> app_id =
web_app::FindInstalledAppWithUrlInScope(profile(), url);
// TODO(crbug.com/1052711): Avoid dependence on Extensions.
const extensions::Extension* installed_app =
extensions::ExtensionRegistry::Get(profile())->GetInstalledExtension(
*app_id);
EXPECT_TRUE(GetManager().IsSystemWebApp(installed_app->id())); web_app::AppId app_id = app_browser->app_controller()->GetAppId();
EXPECT_TRUE(installed_app->from_bookmark()); EXPECT_EQ(GetManager().GetAppIdForSystemApp(app_type), app_id);
EXPECT_TRUE(GetManager().IsSystemWebApp(app_id));
EXPECT_EQ(title, installed_app->name()); web_app::AppRegistrar& registrar =
web_app::WebAppProviderBase::GetProviderBase(profile())->registrar();
EXPECT_EQ(title, registrar.GetAppShortName(app_id));
EXPECT_EQ(base::ASCIIToUTF16(title), EXPECT_EQ(base::ASCIIToUTF16(title),
app_browser->window()->GetNativeWindow()->GetTitle()); app_browser->window()->GetNativeWindow()->GetTitle());
EXPECT_EQ(extensions::Manifest::EXTERNAL_COMPONENT, EXPECT_TRUE(registrar.HasExternalAppWithInstallSource(
installed_app->location()); app_id, web_app::ExternalInstallSource::kSystemInstalled));
// The installed app should match the opened app window.
EXPECT_EQ(installed_app, GetExtensionForAppBrowser(app_browser));
content::WebContents* web_contents = content::WebContents* web_contents =
app_browser->tab_strip_model()->GetActiveWebContents(); app_browser->tab_strip_model()->GetActiveWebContents();
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <string> #include <string>
#include "chrome/browser/web_applications/extensions/system_web_app_manager_browsertest.h" #include "chrome/browser/web_applications/system_web_app_manager_browsertest.h"
#include "url/gurl.h" #include "url/gurl.h"
namespace web_app { namespace web_app {
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
#include "chrome/browser/ui/views/location_bar/custom_tab_bar_view.h" #include "chrome/browser/ui/views/location_bar/custom_tab_bar_view.h"
#include "chrome/browser/ui/views/toolbar/toolbar_view.h" #include "chrome/browser/ui/views/toolbar/toolbar_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/web_applications/extensions/system_web_app_manager_browsertest.h"
#include "chrome/browser/web_applications/system_web_app_manager.h" #include "chrome/browser/web_applications/system_web_app_manager.h"
#include "chrome/browser/web_applications/system_web_app_manager_browsertest.h"
#include "chrome/common/web_application_info.h" #include "chrome/common/web_application_info.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"
......
...@@ -216,6 +216,8 @@ source_set("web_applications_browser_tests") { ...@@ -216,6 +216,8 @@ source_set("web_applications_browser_tests") {
sources = [ sources = [
"manifest_update_manager_browsertest.cc", "manifest_update_manager_browsertest.cc",
"pending_app_manager_impl_browsertest.cc", "pending_app_manager_impl_browsertest.cc",
"system_web_app_manager_browsertest.cc",
"system_web_app_manager_browsertest.h",
"web_app_icon_manager_browsertest.cc", "web_app_icon_manager_browsertest.cc",
"web_app_migration_manager_browsertest.cc", "web_app_migration_manager_browsertest.cc",
] ]
...@@ -232,6 +234,7 @@ source_set("web_applications_browser_tests") { ...@@ -232,6 +234,7 @@ source_set("web_applications_browser_tests") {
"//chrome/browser/web_applications/components", "//chrome/browser/web_applications/components",
"//chrome/test:test_support", "//chrome/test:test_support",
"//chrome/test:test_support_ui", "//chrome/test:test_support_ui",
"//components/permissions:permissions",
] ]
} }
......
...@@ -83,8 +83,6 @@ source_set("browser_tests") { ...@@ -83,8 +83,6 @@ source_set("browser_tests") {
sources = [ sources = [
"bookmark_app_registrar_browsertest.cc", "bookmark_app_registrar_browsertest.cc",
"system_web_app_manager_browsertest.cc",
"system_web_app_manager_browsertest.h",
"web_app_audio_focus_browsertest.cc", "web_app_audio_focus_browsertest.cc",
] ]
...@@ -103,7 +101,6 @@ source_set("browser_tests") { ...@@ -103,7 +101,6 @@ source_set("browser_tests") {
"//chrome/browser/web_applications/components", "//chrome/browser/web_applications/components",
"//chrome/test:test_support", "//chrome/test:test_support",
"//chrome/test:test_support_ui", "//chrome/test:test_support_ui",
"//components/permissions:permissions",
"//extensions:test_support", "//extensions:test_support",
"//extensions/browser", "//extensions/browser",
"//extensions/common", "//extensions/common",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/web_applications/extensions/system_web_app_manager_browsertest.h" #include "chrome/browser/web_applications/system_web_app_manager_browsertest.h"
#include <string> #include <string>
#include <utility> #include <utility>
...@@ -14,17 +14,14 @@ ...@@ -14,17 +14,14 @@
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chrome/browser/apps/app_service/app_launch_params.h" #include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/launch_service/launch_service.h" #include "chrome/browser/apps/launch_service/launch_service.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/native_file_system/native_file_system_permission_request_manager.h" #include "chrome/browser/native_file_system/native_file_system_permission_request_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/extensions/application_launch.h"
#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
#include "chrome/browser/web_applications/components/web_app_constants.h" #include "chrome/browser/web_applications/components/web_app_constants.h"
#include "chrome/browser/web_applications/components/web_app_helpers.h" #include "chrome/browser/web_applications/components/web_app_helpers.h"
#include "chrome/browser/web_applications/test/test_system_web_app_installation.h" #include "chrome/browser/web_applications/test/test_system_web_app_installation.h"
#include "chrome/browser/web_applications/test/test_web_app_provider.h" #include "chrome/browser/web_applications/test/test_web_app_provider.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/extensions/manifest_handlers/app_theme_color_info.h"
#include "chrome/common/webui_url_constants.h" #include "chrome/common/webui_url_constants.h"
#include "components/permissions/permission_util.h" #include "components/permissions/permission_util.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
...@@ -54,14 +51,6 @@ SystemWebAppManagerBrowserTest::SystemWebAppManagerBrowserTest( ...@@ -54,14 +51,6 @@ SystemWebAppManagerBrowserTest::SystemWebAppManagerBrowserTest(
SystemWebAppManagerBrowserTest::~SystemWebAppManagerBrowserTest() = default; SystemWebAppManagerBrowserTest::~SystemWebAppManagerBrowserTest() = default;
// static
const extensions::Extension*
SystemWebAppManagerBrowserTest::GetExtensionForAppBrowser(Browser* browser) {
return static_cast<extensions::HostedAppBrowserController*>(
browser->app_controller())
->GetExtensionForTesting();
}
SystemWebAppManager& SystemWebAppManagerBrowserTest::GetManager() { SystemWebAppManager& SystemWebAppManagerBrowserTest::GetManager() {
return WebAppProvider::Get(browser()->profile())->system_web_app_manager(); return WebAppProvider::Get(browser()->profile())->system_web_app_manager();
} }
...@@ -129,20 +118,31 @@ content::EvalJsResult EvalJs(content::WebContents* web_contents, ...@@ -129,20 +118,31 @@ content::EvalJsResult EvalJs(content::WebContents* web_contents,
// Test that System Apps install correctly with a manifest. // Test that System Apps install correctly with a manifest.
IN_PROC_BROWSER_TEST_F(SystemWebAppManagerBrowserTest, Install) { IN_PROC_BROWSER_TEST_F(SystemWebAppManagerBrowserTest, Install) {
const extensions::Extension* app = GetExtensionForAppBrowser( Browser* app_browser = WaitForSystemAppInstallAndLaunch(GetMockAppType());
WaitForSystemAppInstallAndLaunch(GetMockAppType()));
EXPECT_EQ("Test System App", app->name()); AppId app_id = app_browser->app_controller()->GetAppId();
EXPECT_EQ(SkColorSetRGB(0, 0xFF, 0), EXPECT_EQ(GetManager().GetAppIdForSystemApp(GetMockAppType()), app_id);
extensions::AppThemeColorInfo::GetThemeColor(app)); EXPECT_TRUE(GetManager().IsSystemWebApp(app_id));
EXPECT_TRUE(app->from_bookmark());
EXPECT_EQ(extensions::Manifest::EXTERNAL_COMPONENT, app->location()); Profile* profile = app_browser->profile();
AppRegistrar& registrar =
// The app should be a PWA. WebAppProviderBase::GetProviderBase(profile)->registrar();
base::Optional<AppId> app_id = web_app::FindInstalledAppWithUrlInScope(
browser()->profile(), content::GetWebUIURL("test-system-app/")); EXPECT_EQ("Test System App", registrar.GetAppShortName(app_id));
DCHECK(app_id); EXPECT_EQ(SkColorSetRGB(0, 0xFF, 0), registrar.GetAppThemeColor(app_id));
EXPECT_EQ(*app_id, app->id()); EXPECT_TRUE(registrar.HasExternalAppWithInstallSource(
EXPECT_TRUE(GetManager().IsSystemWebApp(app->id())); app_id, web_app::ExternalInstallSource::kSystemInstalled));
EXPECT_EQ(
registrar.FindAppWithUrlInScope(content::GetWebUIURL("test-system-app/")),
app_id);
if (!base::FeatureList::IsEnabled(features::kDesktopPWAsWithoutExtensions)) {
const extensions::Extension* extension =
extensions::ExtensionRegistry::Get(profile)->GetInstalledExtension(
app_id);
EXPECT_TRUE(extension->from_bookmark());
EXPECT_EQ(extensions::Manifest::EXTERNAL_COMPONENT, extension->location());
}
} }
// Check the toolbar is not shown for system web apps for pages on the chrome:// // Check the toolbar is not shown for system web apps for pages on the chrome://
...@@ -198,7 +198,7 @@ IN_PROC_BROWSER_TEST_F(SystemWebAppManagerBrowserTest, ...@@ -198,7 +198,7 @@ IN_PROC_BROWSER_TEST_F(SystemWebAppManagerBrowserTest,
content::TestNavigationObserver navigation_observer(launch_url); content::TestNavigationObserver navigation_observer(launch_url);
navigation_observer.StartWatchingNewWebContents(); navigation_observer.StartWatchingNewWebContents();
content::WebContents* web_contents = content::WebContents* web_contents =
OpenApplication(browser()->profile(), params); apps::LaunchService::Get(browser()->profile())->OpenApplication(params);
navigation_observer.Wait(); navigation_observer.Wait();
// Set up a Promise that resolves to launchParams, when launchQueue's consumer // Set up a Promise that resolves to launchParams, when launchQueue's consumer
...@@ -235,7 +235,7 @@ IN_PROC_BROWSER_TEST_F(SystemWebAppManagerBrowserTest, ...@@ -235,7 +235,7 @@ IN_PROC_BROWSER_TEST_F(SystemWebAppManagerBrowserTest,
&temp_file_path2)); &temp_file_path2));
params.launch_files = {temp_file_path2}; params.launch_files = {temp_file_path2};
content::WebContents* web_contents2 = content::WebContents* web_contents2 =
OpenApplication(browser()->profile(), params); apps::LaunchService::Get(browser()->profile())->OpenApplication(params);
// WebContents* should be the same because we are passing launchParams to the // WebContents* should be the same because we are passing launchParams to the
// opened application. // opened application.
...@@ -292,7 +292,7 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerLaunchFilesBrowserTest, ...@@ -292,7 +292,7 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerLaunchFilesBrowserTest,
content::TestNavigationObserver navigation_observer(launch_url); content::TestNavigationObserver navigation_observer(launch_url);
navigation_observer.StartWatchingNewWebContents(); navigation_observer.StartWatchingNewWebContents();
content::WebContents* web_contents = content::WebContents* web_contents =
OpenApplication(browser()->profile(), params); apps::LaunchService::Get(browser()->profile())->OpenApplication(params);
navigation_observer.Wait(); navigation_observer.Wait();
// Set up a Promise that resolves to launchParams, when launchQueue's consumer // Set up a Promise that resolves to launchParams, when launchQueue's consumer
...@@ -356,7 +356,7 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerLaunchFilesBrowserTest, ...@@ -356,7 +356,7 @@ IN_PROC_BROWSER_TEST_P(SystemWebAppManagerLaunchFilesBrowserTest,
&temp_file_path2)); &temp_file_path2));
params.launch_files = {temp_file_path2}; params.launch_files = {temp_file_path2};
content::WebContents* web_contents2 = content::WebContents* web_contents2 =
OpenApplication(browser()->profile(), params); apps::LaunchService::Get(browser()->profile())->OpenApplication(params);
// WebContents* should be the same because we are passing launchParams to the // WebContents* should be the same because we are passing launchParams to the
// opened application. // opened application.
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_WEB_APPLICATIONS_EXTENSIONS_SYSTEM_WEB_APP_MANAGER_BROWSERTEST_H_ #ifndef CHROME_BROWSER_WEB_APPLICATIONS_SYSTEM_WEB_APP_MANAGER_BROWSERTEST_H_
#define CHROME_BROWSER_WEB_APPLICATIONS_EXTENSIONS_SYSTEM_WEB_APP_MANAGER_BROWSERTEST_H_ #define CHROME_BROWSER_WEB_APPLICATIONS_SYSTEM_WEB_APP_MANAGER_BROWSERTEST_H_
#include <memory> #include <memory>
...@@ -24,10 +24,6 @@ namespace content { ...@@ -24,10 +24,6 @@ namespace content {
class WebContents; class WebContents;
} }
namespace extensions {
class Extension;
}
namespace web_app { namespace web_app {
enum class SystemAppType; enum class SystemAppType;
...@@ -42,11 +38,6 @@ class SystemWebAppManagerBrowserTest : public InProcessBrowserTest { ...@@ -42,11 +38,6 @@ class SystemWebAppManagerBrowserTest : public InProcessBrowserTest {
~SystemWebAppManagerBrowserTest() override; ~SystemWebAppManagerBrowserTest() override;
// Gets the Extension* from the HostedAppBrowserController associated with
// |browser|.
static const extensions::Extension* GetExtensionForAppBrowser(
Browser* browser);
// Returns the SystemWebAppManager for browser()->profile(). This will be a // Returns the SystemWebAppManager for browser()->profile(). This will be a
// TestSystemWebAppManager if initialized with |install_mock| true. // TestSystemWebAppManager if initialized with |install_mock| true.
SystemWebAppManager& GetManager(); SystemWebAppManager& GetManager();
...@@ -80,4 +71,4 @@ class SystemWebAppManagerBrowserTest : public InProcessBrowserTest { ...@@ -80,4 +71,4 @@ class SystemWebAppManagerBrowserTest : public InProcessBrowserTest {
} // namespace web_app } // namespace web_app
#endif // CHROME_BROWSER_WEB_APPLICATIONS_EXTENSIONS_SYSTEM_WEB_APP_MANAGER_BROWSERTEST_H_ #endif // CHROME_BROWSER_WEB_APPLICATIONS_SYSTEM_WEB_APP_MANAGER_BROWSERTEST_H_
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