Commit afecf795 authored by Jay Harris's avatar Jay Harris Committed by Commit Bot

Displays the app title instead of page title when off scope.

Previously, we would always display the current page's title in the
window title. This updates the logic so we display the app name when
off scope (the page title will be displayed in the custom tab bar).


Bug: 853593
Change-Id: Id24d3104386a5334c331599480f0b1ce269ba9e1
Reviewed-on: https://chromium-review.googlesource.com/c/1319214Reviewed-by: default avatarMatt Giuca <mgiuca@chromium.org>
Commit-Queue: Jay Harris <harrisjay@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606736}
parent 0bc2c598
......@@ -5,6 +5,7 @@
#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/engagement/site_engagement_service.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/extensions/tab_helper.h"
......@@ -278,6 +279,16 @@ base::Optional<SkColor> HostedAppBrowserController::GetThemeColor() const {
}
base::string16 HostedAppBrowserController::GetTitle() const {
// When showing the location bar, display the name of the app, instead of the
// current page as the title.
// Note: We only do this when the CustomTab UI is enabled, as otherwise the
// title of the current page will not be displayed anywhere.
if (ShouldShowLocationBar() &&
base::FeatureList::IsEnabled(features::kDesktopPWAsCustomTabUI)) {
const Extension* extension = GetExtension();
return base::UTF8ToUTF16(extension->name());
}
content::WebContents* web_contents =
browser_->tab_strip_model()->GetActiveWebContents();
if (!web_contents)
......
......@@ -874,6 +874,78 @@ IN_PROC_BROWSER_TEST_P(HostedAppTest, MixedContentInBookmarkApp) {
CheckMixedContentLoaded(app_browser_);
}
// Ensure that hosted app windows with blank titles don't display the URL as a
// default window title.
IN_PROC_BROWSER_TEST_P(HostedAppTest, EmptyTitlesDoNotDisplayUrl) {
ASSERT_TRUE(https_server()->Start());
GURL url = https_server()->GetURL("app.site.com", "/empty.html");
WebApplicationInfo web_app_info;
web_app_info.app_url = url;
const extensions::Extension* app = InstallBookmarkApp(web_app_info);
Browser* app_browser = LaunchAppBrowser(app);
content::WebContents* web_contents =
app_browser->tab_strip_model()->GetActiveWebContents();
content::WaitForLoadStop(web_contents);
EXPECT_EQ(base::string16(), app_browser->GetWindowTitleForCurrentTab(false));
NavigateToURLAndWait(app_browser,
https_server()->GetURL("app.site.com", "/simple.html"));
EXPECT_EQ(base::ASCIIToUTF16("OK"),
app_browser->GetWindowTitleForCurrentTab(false));
}
// Ensure that hosted app windows display the app title instead of the page
// title when off scope.
IN_PROC_BROWSER_TEST_P(HostedAppTest, OffScopeUrlsDisplayAppTitle) {
ASSERT_TRUE(https_server()->Start());
GURL url = GetSecureAppURL();
WebApplicationInfo web_app_info;
web_app_info.app_url = url;
web_app_info.scope = url.GetWithoutFilename();
web_app_info.title = base::ASCIIToUTF16("A Hosted App");
const extensions::Extension* app = InstallBookmarkApp(web_app_info);
Browser* app_browser = LaunchAppBrowser(app);
content::WebContents* web_contents =
app_browser->tab_strip_model()->GetActiveWebContents();
content::WaitForLoadStop(web_contents);
// When we are within scope, show the page title.
EXPECT_EQ(base::ASCIIToUTF16("Google"),
app_browser->GetWindowTitleForCurrentTab(false));
NavigateToURLAndWait(app_browser,
https_server()->GetURL("app.site.com", "/simple.html"));
// When we are off scope, show the app title.
EXPECT_EQ(base::ASCIIToUTF16("A Hosted App"),
app_browser->GetWindowTitleForCurrentTab(false));
}
// Ensure that hosted app windows display the app title instead of the page
// title when using http.
IN_PROC_BROWSER_TEST_P(HostedAppTest, InScopeHttpUrlsDisplayAppTitle) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url = embedded_test_server()->GetURL("app.site.com", "/simple.html");
WebApplicationInfo web_app_info;
web_app_info.app_url = url;
web_app_info.title = base::ASCIIToUTF16("A Hosted App");
const extensions::Extension* app = InstallBookmarkApp(web_app_info);
Browser* app_browser = LaunchAppBrowser(app);
content::WebContents* web_contents =
app_browser->tab_strip_model()->GetActiveWebContents();
content::WaitForLoadStop(web_contents);
// The page title is "OK" but the page is being served over HTTP, so the app
// title should be used instead.
EXPECT_EQ(base::ASCIIToUTF16("A Hosted App"),
app_browser->GetWindowTitleForCurrentTab(false));
}
using HostedAppPWAOnlyTest = HostedAppTest;
// Tests that the command for popping a tab out to a PWA window is disabled in
......@@ -2626,26 +2698,6 @@ IN_PROC_BROWSER_TEST_P(BookmarkAppOnlyTest,
NavigateAndCheckForLocationBar(app_browser_, popup_url, false);
}
// Ensure that hosted app windows with blank titles don't display the URL as a
// default window title.
IN_PROC_BROWSER_TEST_P(BookmarkAppOnlyTest, Title) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url = embedded_test_server()->GetURL("app.site.com", "/empty.html");
WebApplicationInfo web_app_info;
web_app_info.app_url = url;
const extensions::Extension* app = InstallBookmarkApp(web_app_info);
Browser* app_browser = LaunchAppBrowser(app);
content::WebContents* web_contents =
app_browser->tab_strip_model()->GetActiveWebContents();
content::WaitForLoadStop(web_contents);
EXPECT_EQ(base::string16(), app_browser->GetWindowTitleForCurrentTab(false));
NavigateToURLAndWait(app_browser, embedded_test_server()->GetURL(
"app.site.com", "/simple.html"));
EXPECT_EQ(base::ASCIIToUTF16("OK"),
app_browser->GetWindowTitleForCurrentTab(false));
}
INSTANTIATE_TEST_CASE_P(/* no prefix */,
HostedAppTest,
::testing::Combine(kAppTypeValues, ::testing::Bool()));
......
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