Commit 67a3ccaa authored by Maggie Cai's avatar Maggie Cai Committed by Commit Bot

Don't show the intent picker icon when there is no app found.

Currently, if we have a website that redirects from a link that is in
the scope of a installed PWA, to a link that is not in the scope of a
PWA, the intent picker icon will show, and clicking it will show no
bubble. This is a issue where we don't reset the intent picker icon view
when we try to update the visual and found the app list we queried is
empty. This CL fixes this issue and add a test for it.

BUG=967296

Change-Id: I58184b70d739ba5b4b5ff9e3d4826327a485bde8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1631153Reviewed-by: default avatarDominick Ng <dominickn@chromium.org>
Reviewed-by: default avatarDavid Jacobo <djacobo@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664689}
parent 6997e00e
...@@ -344,8 +344,11 @@ void AppsNavigationThrottle::ShowIntentPickerForApps( ...@@ -344,8 +344,11 @@ void AppsNavigationThrottle::ShowIntentPickerForApps(
const GURL& url, const GURL& url,
std::vector<IntentPickerAppInfo> apps, std::vector<IntentPickerAppInfo> apps,
IntentPickerResponse callback) { IntentPickerResponse callback) {
if (apps.empty()) if (apps.empty()) {
IntentPickerTabHelper::SetShouldShowIcon(web_contents, false);
ui_displayed_ = false;
return; return;
}
Browser* browser = chrome::FindBrowserWithWebContents(web_contents); Browser* browser = chrome::FindBrowserWithWebContents(web_contents);
if (!browser) if (!browser)
return; return;
......
...@@ -258,22 +258,24 @@ void BookmarkAppNavigationBrowserTest::SetUpOnMainThread() { ...@@ -258,22 +258,24 @@ void BookmarkAppNavigationBrowserTest::SetUpOnMainThread() {
} }
void BookmarkAppNavigationBrowserTest::InstallTestBookmarkApp() { void BookmarkAppNavigationBrowserTest::InstallTestBookmarkApp() {
test_bookmark_app_ = InstallTestBookmarkApp(GetAppUrlHost()); test_bookmark_app_ =
InstallTestBookmarkApp(GetAppUrlHost(), GetAppScopePath());
} }
void BookmarkAppNavigationBrowserTest::InstallOtherTestBookmarkApp() { void BookmarkAppNavigationBrowserTest::InstallOtherTestBookmarkApp() {
InstallTestBookmarkApp(GetOtherAppUrlHost()); InstallTestBookmarkApp(GetOtherAppUrlHost(), GetAppScopePath());
} }
const Extension* BookmarkAppNavigationBrowserTest::InstallTestBookmarkApp( const Extension* BookmarkAppNavigationBrowserTest::InstallTestBookmarkApp(
const std::string& app_host) { const std::string& app_host,
const std::string& app_scope) {
if (!https_server_.Started()) { if (!https_server_.Started()) {
CHECK(https_server_.Start()); CHECK(https_server_.Start());
} }
WebApplicationInfo web_app_info; WebApplicationInfo web_app_info;
web_app_info.app_url = https_server_.GetURL(app_host, GetAppUrlPath()); web_app_info.app_url = https_server_.GetURL(app_host, GetAppUrlPath());
web_app_info.scope = https_server_.GetURL(app_host, GetAppScopePath()); web_app_info.scope = https_server_.GetURL(app_host, app_scope);
web_app_info.title = base::UTF8ToUTF16(GetAppName()); web_app_info.title = base::UTF8ToUTF16(GetAppName());
web_app_info.description = base::UTF8ToUTF16("Test description"); web_app_info.description = base::UTF8ToUTF16("Test description");
web_app_info.open_as_window = true; web_app_info.open_as_window = true;
......
...@@ -107,7 +107,8 @@ class BookmarkAppNavigationBrowserTest : public ExtensionBrowserTest { ...@@ -107,7 +107,8 @@ class BookmarkAppNavigationBrowserTest : public ExtensionBrowserTest {
void InstallTestBookmarkApp(); void InstallTestBookmarkApp();
void InstallOtherTestBookmarkApp(); void InstallOtherTestBookmarkApp();
const Extension* InstallTestBookmarkApp(const std::string& app_host); const Extension* InstallTestBookmarkApp(const std::string& app_host,
const std::string& app_scope);
// Installs a Bookmark App that immediately redirects to a URL with // Installs a Bookmark App that immediately redirects to a URL with
// |target_host| and |target_path|. // |target_host| and |target_path|.
......
...@@ -126,7 +126,7 @@ IN_PROC_BROWSER_TEST_F(ChromeNewWindowClientBrowserTest, IncognitoDisabled) { ...@@ -126,7 +126,7 @@ IN_PROC_BROWSER_TEST_F(ChromeNewWindowClientBrowserTest, IncognitoDisabled) {
} }
IN_PROC_BROWSER_TEST_F(ChromeNewWindowClientWebAppBrowserTest, OpenWebApp) { IN_PROC_BROWSER_TEST_F(ChromeNewWindowClientWebAppBrowserTest, OpenWebApp) {
InstallTestBookmarkApp(GetAppUrlHost()); InstallTestBookmarkApp();
const GURL app_url = https_server().GetURL(GetAppUrlHost(), GetAppUrlPath()); const GURL app_url = https_server().GetURL(GetAppUrlHost(), GetAppUrlPath());
const char* key = const char* key =
arc::ArcWebContentsData::ArcWebContentsData::kArcTransitionFlag; arc::ArcWebContentsData::ArcWebContentsData::kArcTransitionFlag;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "chrome/browser/ui/views/location_bar/location_bar_view.h" #include "chrome/browser/ui/views/location_bar/location_bar_view.h"
#include "chrome/browser/ui/views/page_action/omnibox_page_action_icon_container_view.h" #include "chrome/browser/ui/views/page_action/omnibox_page_action_icon_container_view.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
#include "chrome/common/web_application_info.h"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -247,6 +248,33 @@ IN_PROC_BROWSER_TEST_P(IntentPickerBubbleViewBrowserTest, ...@@ -247,6 +248,33 @@ IN_PROC_BROWSER_TEST_P(IntentPickerBubbleViewBrowserTest,
EXPECT_TRUE(intent_picker_view->GetVisible()); EXPECT_TRUE(intent_picker_view->GetVisible());
} }
// Tests that the intent picker icon is not visible if the navigatation
// redirects to a URL that doesn't have an installed PWA.
IN_PROC_BROWSER_TEST_P(IntentPickerBubbleViewBrowserTest,
DoesNotShowIntentPickerWhenRedirectedOutOfScope) {
InstallTestBookmarkApp(GetOtherAppUrlHost(), /*app_scope=*/"/");
const GURL out_of_scope_url =
https_server().GetURL(GetAppUrlHost(), GetOutOfScopeUrlPath());
const GURL in_scope_url = https_server().GetURL(GetOtherAppUrlHost(), "/");
const GURL redirect_url = https_server().GetURL(
GetOtherAppUrlHost(), CreateServerRedirect(out_of_scope_url));
PageActionIconView* intent_picker_view =
BrowserView::GetBrowserViewForBrowser(browser())
->toolbar_button_provider()
->GetOmniboxPageActionIconContainerView()
->GetPageActionIconView(PageActionIconType::kIntentPicker);
OpenNewTab(in_scope_url);
EXPECT_TRUE(intent_picker_view->GetVisible());
ClickLinkAndWaitForURL(browser()->tab_strip_model()->GetActiveWebContents(),
redirect_url, out_of_scope_url, LinkTarget::SELF,
GetParam());
EXPECT_FALSE(intent_picker_view->GetVisible());
}
INSTANTIATE_TEST_SUITE_P( INSTANTIATE_TEST_SUITE_P(
/* no prefix */, /* no prefix */,
IntentPickerBubbleViewBrowserTest, IntentPickerBubbleViewBrowserTest,
......
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