Commit 7254ad8e authored by Eric Willigers's avatar Eric Willigers Committed by Commit Bot

Desktop PWAs: ContextMenuBrowserTest supports web apps

ContextMenuBrowserTest was previously calling the extensions system
to create bookmark apps. We now use web_app:: methods instead.

Bug: 1052722
Change-Id: I631e71e38e31f995f9706afe940bffb15dca2f37
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2061574
Commit-Queue: Eric Willigers <ericwilligers@chromium.org>
Reviewed-by: default avatarAlexey Baskakov <loyso@chromium.org>
Reviewed-by: default avatarIstiaque Ahmed <lazyboy@chromium.org>
Auto-Submit: Eric Willigers <ericwilligers@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743346}
parent cb022270
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/bind_test_util.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/threading/thread_restrictions.h" #include "base/threading/thread_restrictions.h"
#include "build/build_config.h" #include "build/build_config.h"
...@@ -25,7 +26,6 @@ ...@@ -25,7 +26,6 @@
#include "chrome/browser/apps/app_service/app_launch_params.h" #include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/browser_process.h" #include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/extensions/browsertest_util.h"
#include "chrome/browser/pdf/pdf_extension_test_util.h" #include "chrome/browser/pdf/pdf_extension_test_util.h"
#include "chrome/browser/profiles/profile_attributes_entry.h" #include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_attributes_storage.h" #include "chrome/browser/profiles/profile_attributes_storage.h"
...@@ -35,9 +35,10 @@ ...@@ -35,9 +35,10 @@
#include "chrome/browser/search_engines/template_url_service_factory.h" #include "chrome/browser/search_engines/template_url_service_factory.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.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/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/web_applications/extensions/bookmark_app_util.h" #include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/web_applications/components/install_finalizer.h"
#include "chrome/browser/web_applications/components/web_app_provider_base.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_render_frame.mojom.h" #include "chrome/common/chrome_render_frame.mojom.h"
#include "chrome/common/render_messages.h" #include "chrome/common/render_messages.h"
...@@ -65,8 +66,6 @@ ...@@ -65,8 +66,6 @@
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "extensions/browser/api/extensions_api_client.h" #include "extensions/browser/api/extensions_api_client.h"
#include "extensions/browser/extension_registry.h"
#include "extensions/browser/extension_system.h"
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h" #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest.h"
#include "extensions/browser/guest_view/mime_handler_view/test_mime_handler_view_guest.h" #include "extensions/browser/guest_view/mime_handler_view/test_mime_handler_view_guest.h"
#include "media/base/media_switches.h" #include "media/base/media_switches.h"
...@@ -92,6 +91,8 @@ ...@@ -92,6 +91,8 @@
using content::WebContents; using content::WebContents;
using extensions::MimeHandlerViewGuest; using extensions::MimeHandlerViewGuest;
using extensions::TestMimeHandlerViewGuest; using extensions::TestMimeHandlerViewGuest;
using web_app::AppId;
using web_app::WebAppProviderBase;
namespace { namespace {
...@@ -174,24 +175,21 @@ class ContextMenuBrowserTest : public InProcessBrowserTest { ...@@ -174,24 +175,21 @@ class ContextMenuBrowserTest : public InProcessBrowserTest {
return profile_manager->GetProfile(profile_path); return profile_manager->GetProfile(profile_path);
} }
const extensions::Extension* InstallTestBookmarkApp( AppId InstallTestWebApp(const GURL& app_url, bool open_as_window = true) {
const GURL& app_url, auto web_app_info = std::make_unique<WebApplicationInfo>();
bool open_as_window = true) { web_app_info->app_url = app_url;
WebApplicationInfo web_app_info; web_app_info->scope = app_url;
web_app_info.app_url = app_url; web_app_info->title = base::UTF8ToUTF16("Test app \xF0\x9F\x90\x90");
web_app_info.scope = app_url; web_app_info->description =
web_app_info.title = base::UTF8ToUTF16("Test app \xF0\x9F\x90\x90");
web_app_info.description =
base::UTF8ToUTF16("Test description \xF0\x9F\x90\x90"); base::UTF8ToUTF16("Test description \xF0\x9F\x90\x90");
web_app_info.open_as_window = open_as_window; web_app_info->open_as_window = open_as_window;
return extensions::browsertest_util::InstallBookmarkApp( return web_app::InstallWebApp(browser()->profile(),
browser()->profile(), web_app_info); std::move(web_app_info));
} }
Browser* OpenTestBookmarkApp(const extensions::Extension* bookmark_app) { Browser* OpenTestWebApp(const AppId& app_id) {
return extensions::browsertest_util::LaunchAppBrowser(browser()->profile(), return web_app::LaunchWebAppBrowser(browser()->profile(), app_id);
bookmark_app);
} }
}; };
...@@ -330,8 +328,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenEntryPresentForNormalURLs) { ...@@ -330,8 +328,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenEntryPresentForNormalURLs) {
} }
IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
OpenInAppPresentForURLsInScopeOfBookmarkApp) { OpenInAppPresentForURLsInScopeOfWebApp) {
InstallTestBookmarkApp(GURL(kAppUrl1)); InstallTestWebApp(GURL(kAppUrl1));
std::unique_ptr<TestRenderViewContextMenu> menu = std::unique_ptr<TestRenderViewContextMenu> menu =
CreateContextMenuMediaTypeNone(GURL(kAppUrl1), GURL(kAppUrl1)); CreateContextMenuMediaTypeNone(GURL(kAppUrl1), GURL(kAppUrl1));
...@@ -346,8 +344,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ...@@ -346,8 +344,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
} }
IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
OpenInAppPresentForURLsInScopeOfNonWindowedBookmarkApp) { OpenInAppPresentForURLsInScopeOfNonWindowedWebApp) {
InstallTestBookmarkApp(GURL(kAppUrl1), false); InstallTestWebApp(GURL(kAppUrl1), false);
std::unique_ptr<TestRenderViewContextMenu> menu = std::unique_ptr<TestRenderViewContextMenu> menu =
CreateContextMenuMediaTypeNone(GURL(kAppUrl1), GURL(kAppUrl1)); CreateContextMenuMediaTypeNone(GURL(kAppUrl1), GURL(kAppUrl1));
...@@ -362,8 +360,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ...@@ -362,8 +360,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
} }
IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
OpenEntryInAppAbsentForURLsOutOfScopeOfBookmarkApp) { OpenEntryInAppAbsentForURLsOutOfScopeOfWebApp) {
InstallTestBookmarkApp(GURL(kAppUrl1)); InstallTestWebApp(GURL(kAppUrl1));
std::unique_ptr<TestRenderViewContextMenu> menu = std::unique_ptr<TestRenderViewContextMenu> menu =
CreateContextMenuMediaTypeNone(GURL("http://www.example.com/"), CreateContextMenuMediaTypeNone(GURL("http://www.example.com/"),
...@@ -380,14 +378,29 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ...@@ -380,14 +378,29 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
OpenInAppAbsentForURLsInNonLocallyInstalledApp) { OpenInAppAbsentForURLsInNonLocallyInstalledApp) {
const extensions::Extension* app = InstallTestBookmarkApp(GURL(kAppUrl1)); const AppId app_id = InstallTestWebApp(GURL(kAppUrl1));
// Part of the installation process (setting that this is a locally installed // Part of the installation process (setting that this is a locally installed
// app) runs asynchronously. Wait for that to complete before setting locally // app) runs asynchronously. Wait for that to complete before setting locally
// installed to false. // installed to false.
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
SetBookmarkAppIsLocallyInstalled(browser()->profile(), app,
false /* is_locally_installed */); {
WebAppProviderBase* const provider =
WebAppProviderBase::GetProviderBase(browser()->profile());
base::RunLoop run_loop;
ASSERT_TRUE(
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();
base::RunLoop().RunUntilIdle();
}
std::unique_ptr<TestRenderViewContextMenu> menu = std::unique_ptr<TestRenderViewContextMenu> menu =
CreateContextMenuMediaTypeNone(GURL(kAppUrl1), GURL(kAppUrl1)); CreateContextMenuMediaTypeNone(GURL(kAppUrl1), GURL(kAppUrl1));
...@@ -403,9 +416,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ...@@ -403,9 +416,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
InAppOpenEntryPresentForRegularURLs) { InAppOpenEntryPresentForRegularURLs) {
const extensions::Extension* bookmark_app = const AppId app_id = InstallTestWebApp(GURL(kAppUrl1));
InstallTestBookmarkApp(GURL(kAppUrl1)); Browser* app_window = OpenTestWebApp(app_id);
Browser* app_window = OpenTestBookmarkApp(bookmark_app);
std::unique_ptr<TestRenderViewContextMenu> menu = std::unique_ptr<TestRenderViewContextMenu> menu =
CreateContextMenuMediaTypeNoneInWebContents( CreateContextMenuMediaTypeNoneInWebContents(
...@@ -423,9 +435,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ...@@ -423,9 +435,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
InAppOpenEntryPresentForSameAppURLs) { InAppOpenEntryPresentForSameAppURLs) {
const extensions::Extension* bookmark_app = const AppId app_id = InstallTestWebApp(GURL(kAppUrl1));
InstallTestBookmarkApp(GURL(kAppUrl1)); Browser* app_window = OpenTestWebApp(app_id);
Browser* app_window = OpenTestBookmarkApp(bookmark_app);
std::unique_ptr<TestRenderViewContextMenu> menu = std::unique_ptr<TestRenderViewContextMenu> menu =
CreateContextMenuMediaTypeNoneInWebContents( CreateContextMenuMediaTypeNoneInWebContents(
...@@ -443,11 +454,10 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ...@@ -443,11 +454,10 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest,
InAppOpenEntryPresentForOtherAppURLs) { InAppOpenEntryPresentForOtherAppURLs) {
const extensions::Extension* bookmark_app = const AppId app_id = InstallTestWebApp(GURL(kAppUrl1));
InstallTestBookmarkApp(GURL(kAppUrl1)); InstallTestWebApp(GURL(kAppUrl2));
InstallTestBookmarkApp(GURL(kAppUrl2));
Browser* app_window = OpenTestBookmarkApp(bookmark_app); Browser* app_window = OpenTestWebApp(app_id);
std::unique_ptr<TestRenderViewContextMenu> menu = std::unique_ptr<TestRenderViewContextMenu> menu =
CreateContextMenuMediaTypeNoneInWebContents( CreateContextMenuMediaTypeNoneInWebContents(
...@@ -715,8 +725,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenIncognitoNoneReferrer) { ...@@ -715,8 +725,8 @@ IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenIncognitoNoneReferrer) {
} }
// Verify that "Open link in [App Name]" opens a new App window. // Verify that "Open link in [App Name]" opens a new App window.
IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenLinkInBookmarkApp) { IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, OpenLinkInWebApp) {
InstallTestBookmarkApp(GURL(kAppUrl1)); InstallTestWebApp(GURL(kAppUrl1));
ASSERT_TRUE(embedded_test_server()->Start()); ASSERT_TRUE(embedded_test_server()->Start());
......
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