forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement launch handling route_to behaviour
This CL implements the app launch behaviour of launch_handler.route_to values "auto", "new-client" and "existing-client". Explainer: https://github.com/WICG/sw-launch/blob/main/launch_handler.md#launch_handler-manifest-member The old code used NEW_FOREGROUND_TAB like a sentinel value to identify whether the launch came from AppsNavigationThrottle::CaptureWebAppScopeNavigations() capturing links for tabbed web app windows. It worked because it was the only callsite that did this window capturing. Now with route_to there any disposition can capture so this code has been updated to check IsTabbedWindowModeEnabled() directly instead of testing for NEW_FOREGROUND_TAB. Bug: 1250222 Change-Id: I9001144d2ea1f68e3023e390eab286b66e426726 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3162688 Commit-Queue: Alan Cutter <alancutter@chromium.org> Reviewed-by: Glen Robertson <glenrob@chromium.org> Cr-Commit-Position: refs/heads/main@{#931888}
- Loading branch information
1 parent
ca6e209
commit b36e0f7
Showing
7 changed files
with
172 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
chrome/browser/ui/web_applications/web_app_launch_handling_browsertest.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "base/test/scoped_feature_list.h" | ||
#include "chrome/browser/ui/browser.h" | ||
#include "chrome/browser/ui/browser_navigator.h" | ||
#include "chrome/browser/ui/browser_navigator_params.h" | ||
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h" | ||
#include "chrome/browser/web_applications/os_integration_manager.h" | ||
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h" | ||
#include "chrome/browser/web_applications/web_app.h" | ||
#include "chrome/browser/web_applications/web_app_provider.h" | ||
#include "chrome/browser/web_applications/web_app_registrar.h" | ||
#include "chrome/test/base/in_process_browser_test.h" | ||
#include "content/public/test/browser_test.h" | ||
#include "third_party/blink/public/common/features.h" | ||
#include "ui/base/page_transition_types.h" | ||
|
||
namespace web_app { | ||
|
||
using RouteTo = LaunchHandler::RouteTo; | ||
using NavigateExistingClient = LaunchHandler::NavigateExistingClient; | ||
|
||
class WebAppLaunchHanderBrowserTest : public InProcessBrowserTest { | ||
public: | ||
WebAppLaunchHanderBrowserTest() = default; | ||
~WebAppLaunchHanderBrowserTest() override = default; | ||
|
||
// InProcessBrowserTest: | ||
void SetUpOnMainThread() override { | ||
InProcessBrowserTest::SetUpOnMainThread(); | ||
ASSERT_TRUE(embedded_test_server()->Start()); | ||
web_app::test::WaitUntilReady( | ||
web_app::WebAppProvider::GetForTest(profile())); | ||
} | ||
|
||
protected: | ||
Profile* profile() { return browser()->profile(); } | ||
|
||
absl::optional<LaunchHandler> GetLaunchHandler(const AppId& app_id) { | ||
return WebAppProvider::GetForTest(profile()) | ||
->registrar() | ||
.GetAppById(app_id) | ||
->launch_handler(); | ||
} | ||
|
||
private: | ||
base::test::ScopedFeatureList enable_launch_handler{ | ||
blink::features::kWebAppEnableLaunchHandler}; | ||
ScopedOsHooksSuppress os_hooks_suppress_{ | ||
OsIntegrationManager::ScopedSuppressOsHooksForTesting()}; | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(WebAppLaunchHanderBrowserTest, RouteToEmpty) { | ||
AppId app_id = InstallWebAppFromPage( | ||
browser(), embedded_test_server()->GetURL("/web_apps/basic.html")); | ||
EXPECT_EQ(GetLaunchHandler(app_id), absl::nullopt); | ||
|
||
Browser* browser_1 = LaunchWebAppBrowser(profile(), app_id); | ||
Browser* browser_2 = LaunchWebAppBrowser(profile(), app_id); | ||
EXPECT_NE(browser_1, browser_2); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(WebAppLaunchHanderBrowserTest, RouteToAuto) { | ||
AppId app_id = InstallWebAppFromPage( | ||
browser(), embedded_test_server()->GetURL( | ||
"/web_apps/get_manifest.html?route_to_auto.json")); | ||
EXPECT_EQ(GetLaunchHandler(app_id), | ||
(LaunchHandler{RouteTo::kAuto, NavigateExistingClient::kAlways})); | ||
|
||
Browser* browser_1 = LaunchWebAppBrowser(profile(), app_id); | ||
Browser* browser_2 = LaunchWebAppBrowser(profile(), app_id); | ||
EXPECT_NE(browser_1, browser_2); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(WebAppLaunchHanderBrowserTest, RouteToNewClient) { | ||
AppId app_id = InstallWebAppFromPage( | ||
browser(), embedded_test_server()->GetURL( | ||
"/web_apps/get_manifest.html?route_to_new_client.json")); | ||
EXPECT_EQ( | ||
GetLaunchHandler(app_id), | ||
(LaunchHandler{RouteTo::kNewClient, NavigateExistingClient::kAlways})); | ||
|
||
Browser* browser_1 = LaunchWebAppBrowser(profile(), app_id); | ||
Browser* browser_2 = LaunchWebAppBrowser(profile(), app_id); | ||
EXPECT_NE(browser_1, browser_2); | ||
} | ||
|
||
IN_PROC_BROWSER_TEST_F(WebAppLaunchHanderBrowserTest, RouteToExistingClient) { | ||
AppId app_id = InstallWebAppFromPage( | ||
browser(), | ||
embedded_test_server()->GetURL( | ||
"/web_apps/" | ||
"get_manifest.html?route_to_existing_client_navigate_empty.json")); | ||
EXPECT_EQ(GetLaunchHandler(app_id), | ||
(LaunchHandler{RouteTo::kExistingClient, | ||
NavigateExistingClient::kAlways})); | ||
|
||
Browser* browser_1 = LaunchWebAppBrowser(profile(), app_id); | ||
content::WebContents* web_contents = | ||
browser_1->tab_strip_model()->GetActiveWebContents(); | ||
GURL start_url = embedded_test_server()->GetURL("/web_apps/"); | ||
EXPECT_EQ(web_contents->GetVisibleURL(), start_url); | ||
|
||
// Navigate window away from start_url to check that the next launch navs to | ||
// start_url again. | ||
NavigateParams navigate_params(browser_1, GURL("about:blank"), | ||
ui::PAGE_TRANSITION_LINK); | ||
ASSERT_TRUE(Navigate(&navigate_params)); | ||
EXPECT_EQ(web_contents->GetVisibleURL(), GURL("about:blank")); | ||
|
||
Browser* browser_2 = LaunchWebAppBrowser(profile(), app_id); | ||
EXPECT_EQ(browser_1, browser_2); | ||
EXPECT_EQ(web_contents->GetVisibleURL(), start_url); | ||
} | ||
|
||
} // namespace web_app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "route_to: auto", | ||
"start_url": ".", | ||
"display": "standalone", | ||
"launch_handler": { | ||
"route_to": "auto" | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
chrome/test/data/web_apps/route_to_existing_client_navigate_empty.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "route_to: existing-client", | ||
"start_url": ".", | ||
"display": "standalone", | ||
"launch_handler": { | ||
"route_to": "existing-client" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"name": "route_to: new-client", | ||
"start_url": ".", | ||
"display": "standalone", | ||
"launch_handler": { | ||
"route_to": "new-client" | ||
} | ||
} |