Commit c3bc1054 authored by Rachel Carpenter's avatar Rachel Carpenter Committed by Commit Bot

Allow help app to capture navigations.

This means that folks trying to navigate to chrome://help-app in a
browser will instead get the Help app opening as a standalone window.

Change-Id: I30941dc66f4c9528edfc0ead92d3d9551bc13d81
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2398604
Commit-Queue: Rachel Carpenter <carpenterr@chromium.org>
Reviewed-by: default avatarGiovanni Ortuño Urquidi <ortuno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809669}
parent e7087f43
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/test/base/interactive_test_utils.h" #include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "chromeos/components/help_app_ui/url_constants.h" #include "chromeos/components/help_app_ui/url_constants.h"
#include "chromeos/components/web_applications/test/sandboxed_web_ui_test_base.h" #include "chromeos/components/web_applications/test/sandboxed_web_ui_test_base.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
...@@ -56,6 +57,10 @@ class HelpAppIntegrationTest : public SystemWebAppIntegrationTest { ...@@ -56,6 +57,10 @@ class HelpAppIntegrationTest : public SystemWebAppIntegrationTest {
using HelpAppAllProfilesIntegrationTest = HelpAppIntegrationTest; using HelpAppAllProfilesIntegrationTest = HelpAppIntegrationTest;
content::WebContents* GetActiveWebContents() {
return chrome::FindLastActive()->tab_strip_model()->GetActiveWebContents();
}
// Waits for and expects that the correct url is opened. // Waits for and expects that the correct url is opened.
void WaitForAppToOpen(const GURL& expected_url) { void WaitForAppToOpen(const GURL& expected_url) {
// Start with a number of browsers (may include an incognito browser). // Start with a number of browsers (may include an incognito browser).
...@@ -68,10 +73,7 @@ void WaitForAppToOpen(const GURL& expected_url) { ...@@ -68,10 +73,7 @@ void WaitForAppToOpen(const GURL& expected_url) {
// There should be another browser window for the newly opened app. // There should be another browser window for the newly opened app.
EXPECT_EQ(num_browsers + 1, chrome::GetTotalBrowserCount()); EXPECT_EQ(num_browsers + 1, chrome::GetTotalBrowserCount());
// Help app should have opened at the expected page. // Help app should have opened at the expected page.
EXPECT_EQ(expected_url, chrome::FindLastActive() EXPECT_EQ(expected_url, GetActiveWebContents()->GetVisibleURL());
->tab_strip_model()
->GetActiveWebContents()
->GetVisibleURL());
} }
// Test that the Help App installs and launches correctly. Runs some spot // Test that the Help App installs and launches correctly. Runs some spot
...@@ -163,10 +165,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppAllProfilesIntegrationTest, HelpAppV2ShowHelp) { ...@@ -163,10 +165,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppAllProfilesIntegrationTest, HelpAppV2ShowHelp) {
#else #else
EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
EXPECT_EQ(GURL(chrome::kChromeHelpViaKeyboardURL), EXPECT_EQ(GURL(chrome::kChromeHelpViaKeyboardURL),
chrome::FindLastActive() GetActiveWebContents()->GetVisibleURL());
->tab_strip_model()
->GetActiveWebContents()
->GetVisibleURL());
#endif #endif
} }
...@@ -194,13 +193,10 @@ IN_PROC_BROWSER_TEST_P(HelpAppAllProfilesIntegrationTest, ...@@ -194,13 +193,10 @@ IN_PROC_BROWSER_TEST_P(HelpAppAllProfilesIntegrationTest,
EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
// The opened window should be showing the url with attached WebUI. // The opened window should be showing the url with attached WebUI.
content::WebContents* web_contents =
chrome::FindLastActive()->tab_strip_model()->GetActiveWebContents();
// The inner frame should be the pathname for the release notes pathname. // The inner frame should be the pathname for the release notes pathname.
EXPECT_EQ("chrome-untrusted://help-app/updates", EXPECT_EQ("chrome-untrusted://help-app/updates",
SandboxedWebUiAppTestBase::EvalJsInAppFrame( SandboxedWebUiAppTestBase::EvalJsInAppFrame(
web_contents, "window.location.href")); GetActiveWebContents(), "window.location.href"));
#else #else
// Nothing should happen on non-branded builds. // Nothing should happen on non-branded builds.
EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
...@@ -328,10 +324,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2ShowParentalControls) { ...@@ -328,10 +324,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppV2ShowParentalControls) {
// Settings should be active in a new window. // Settings should be active in a new window.
EXPECT_EQ(3u, chrome::GetTotalBrowserCount()); EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
EXPECT_EQ(expected_url, chrome::FindLastActive() EXPECT_EQ(expected_url, GetActiveWebContents()->GetVisibleURL());
->tab_strip_model()
->GetActiveWebContents()
->GetVisibleURL());
} }
// Test that the Help App opens when Gesture help requested. // Test that the Help App opens when Gesture help requested.
...@@ -362,10 +355,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppOpenKeyboardShortcut) { ...@@ -362,10 +355,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppOpenKeyboardShortcut) {
#if defined(OS_CHROMEOS) && BUILDFLAG(GOOGLE_CHROME_BRANDING) #if defined(OS_CHROMEOS) && BUILDFLAG(GOOGLE_CHROME_BRANDING)
// Default browser tab and Help app are open. // Default browser tab and Help app are open.
EXPECT_EQ(2u, chrome::GetTotalBrowserCount()); EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
EXPECT_EQ("chrome://help-app/", chrome::FindLastActive() EXPECT_EQ("chrome://help-app/", GetActiveWebContents()->GetVisibleURL());
->tab_strip_model()
->GetActiveWebContents()
->GetVisibleURL());
// The HELP app is 18, see DefaultAppName in // The HELP app is 18, see DefaultAppName in
// src/chrome/browser/apps/app_service/app_service_metrics.cc // src/chrome/browser/apps/app_service/app_service_metrics.cc
histogram_tester.ExpectUniqueSample("Apps.DefaultAppLaunch.FromKeyboard", 18, histogram_tester.ExpectUniqueSample("Apps.DefaultAppLaunch.FromKeyboard", 18,
...@@ -374,10 +364,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppOpenKeyboardShortcut) { ...@@ -374,10 +364,7 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppOpenKeyboardShortcut) {
// We just have the one browser. Navigates chrome. // We just have the one browser. Navigates chrome.
EXPECT_EQ(1u, chrome::GetTotalBrowserCount()); EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
EXPECT_EQ(GURL(chrome::kChromeHelpViaKeyboardURL), EXPECT_EQ(GURL(chrome::kChromeHelpViaKeyboardURL),
chrome::FindLastActive() GetActiveWebContents()->GetVisibleURL());
->tab_strip_model()
->GetActiveWebContents()
->GetVisibleURL());
// The HELP app is 18, see DefaultAppName in // The HELP app is 18, see DefaultAppName in
// src/chrome/browser/apps/app_service/app_service_metrics.cc // src/chrome/browser/apps/app_service/app_service_metrics.cc
histogram_tester.ExpectUniqueSample("Apps.DefaultAppLaunch.FromKeyboard", 18, histogram_tester.ExpectUniqueSample("Apps.DefaultAppLaunch.FromKeyboard", 18,
...@@ -385,6 +372,25 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppOpenKeyboardShortcut) { ...@@ -385,6 +372,25 @@ IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest, HelpAppOpenKeyboardShortcut) {
#endif #endif
} }
// Test that the Help App opens in a new window if try to navigate there in a
// browser.
IN_PROC_BROWSER_TEST_P(HelpAppIntegrationTest,
HelpAppCapturesBrowserNavigation) {
WaitForTestSystemAppInstall();
content::TestNavigationObserver navigation_observer(
GURL("chrome://help-app"));
navigation_observer.StartWatchingNewWebContents();
ASSERT_EQ(1u, chrome::GetTotalBrowserCount());
// Try to navigate to the help app in the browser.
ui_test_utils::SendToOmniboxAndSubmit(browser(), "chrome://help-app");
navigation_observer.Wait();
// We now have two browsers, one for the chrome window, one for the Help app.
EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
EXPECT_EQ(GURL("chrome://help-app"), GetActiveWebContents()->GetVisibleURL());
}
INSTANTIATE_SYSTEM_WEB_APP_MANAGER_TEST_SUITE_MANIFEST_INSTALL_P( INSTANTIATE_SYSTEM_WEB_APP_MANAGER_TEST_SUITE_MANIFEST_INSTALL_P(
HelpAppIntegrationTest); HelpAppIntegrationTest);
......
...@@ -157,6 +157,7 @@ base::flat_map<SystemAppType, SystemAppInfo> CreateSystemWebApps() { ...@@ -157,6 +157,7 @@ base::flat_map<SystemAppType, SystemAppInfo> CreateSystemWebApps() {
infos.at(SystemAppType::HELP).additional_search_terms = { infos.at(SystemAppType::HELP).additional_search_terms = {
IDS_GENIUS_APP_NAME, IDS_HELP_APP_PERKS, IDS_HELP_APP_OFFERS}; IDS_GENIUS_APP_NAME, IDS_HELP_APP_PERKS, IDS_HELP_APP_OFFERS};
infos.at(SystemAppType::HELP).minimum_window_size = {600, 320}; infos.at(SystemAppType::HELP).minimum_window_size = {600, 320};
infos.at(SystemAppType::HELP).capture_navigations = true;
} }
if (SystemWebAppManager::IsAppEnabled(SystemAppType::MEDIA)) { if (SystemWebAppManager::IsAppEnabled(SystemAppType::MEDIA)) {
......
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