Commit 29f2a4c7 authored by Aran Gilman's avatar Aran Gilman Committed by Commit Bot

Display title suffix in tab strip but not the page contents.

Bug: 1069635
Change-Id: I53b8bad02b26ed86d7941e8c0229d932d539cfd9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2144620Reviewed-by: default avatarKatie Dektar <katie@chromium.org>
Commit-Queue: Aran Gilman <gilmanmh@google.com>
Cr-Commit-Position: refs/heads/master@{#759780}
parent f3de774b
......@@ -47,10 +47,11 @@ namespace {
const char* kSimpleArticlePath = "/dom_distiller/simple_article.html";
const char* kOriginalArticleTitle = "Test Page Title";
const char* kExpectedArticleHeading = "Test Page Title";
#if defined(OS_ANDROID)
const char* kExpectedArticleTitle = "Test Page Title";
const char* kExpectedDocumentTitle = "Test Page Title";
#else // Desktop. This test is in chrome/ and is not run on iOS.
const char* kExpectedArticleTitle = "Test Page Title - Reader Mode";
const char* kExpectedDocumentTitle = "Test Page Title - Reader Mode";
#endif // defined(OS_ANDROID)
const char* kDistillablePageHistogram =
"DomDistiller.Time.ActivelyViewingArticleBeforeDistilling";
......@@ -200,12 +201,19 @@ class DomDistillerTabUtilsBrowserTest : public InProcessBrowserTest {
}
const GURL& article_url() const { return article_url_; }
std::string GetPageTitle(content::WebContents* web_contents) const {
std::string GetDocumentTitle(content::WebContents* web_contents) const {
return content::ExecuteScriptAndGetValue(web_contents->GetMainFrame(),
"document.title")
.GetString();
}
std::string GetArticleHeading(content::WebContents* web_contents) const {
return content::ExecuteScriptAndGetValue(
web_contents->GetMainFrame(),
"document.getElementById('title-holder').textContent")
.GetString();
}
std::unique_ptr<net::EmbeddedTestServer> https_server_;
private:
......@@ -240,7 +248,8 @@ IN_PROC_BROWSER_TEST_F(DomDistillerTabUtilsBrowserTest,
EXPECT_NE(initial_web_contents, after_web_contents);
EXPECT_TRUE(
after_web_contents->GetLastCommittedURL().SchemeIs(kDomDistillerScheme));
EXPECT_EQ(kExpectedArticleTitle, GetPageTitle(after_web_contents));
EXPECT_EQ(kExpectedDocumentTitle, GetDocumentTitle(after_web_contents));
EXPECT_EQ(kExpectedArticleHeading, GetArticleHeading(after_web_contents));
}
// TODO(1061928): Make this test more robust by using a TestMockTimeTaskRunner
......@@ -301,12 +310,14 @@ IN_PROC_BROWSER_TEST_F(DomDistillerTabUtilsBrowserTest,
// Verify that the source WebContents is showing the original article.
EXPECT_EQ(article_url(), source_web_contents->GetLastCommittedURL());
EXPECT_EQ(kOriginalArticleTitle, GetPageTitle(source_web_contents));
EXPECT_EQ(kOriginalArticleTitle, GetDocumentTitle(source_web_contents));
// Verify the destination WebContents is showing distilled content.
EXPECT_TRUE(destination_web_contents->GetLastCommittedURL().SchemeIs(
kDomDistillerScheme));
EXPECT_EQ(kExpectedArticleTitle, GetPageTitle(destination_web_contents));
EXPECT_EQ(kExpectedDocumentTitle, GetDocumentTitle(destination_web_contents));
EXPECT_EQ(kExpectedArticleHeading,
GetArticleHeading(destination_web_contents));
content::WebContentsDestroyedWatcher destroyed_watcher(
destination_web_contents);
......
......@@ -54,9 +54,13 @@ function showLoadingIndicator(isLastPage) {
}
// Sets the title.
function setTitle(title) {
function setTitle(title, documentTitleSuffix) {
$('title-holder').textContent = title;
document.title = title;
if (documentTitleSuffix) {
document.title = title + documentTitleSuffix;
} else {
document.title = title;
}
}
// Set the text direction of the document ('ltr', 'rtl', or 'auto').
......
......@@ -175,15 +175,18 @@ const std::string GetErrorPageJs() {
const std::string GetSetTitleJs(std::string title) {
#if defined(OS_ANDROID) || defined(OS_IOS)
base::Value value(title);
base::Value suffixValue("");
#else // Desktop
std::string suffix(
l10n_util::GetStringUTF8(IDS_DOM_DISTILLER_VIEWER_TITLE_SUFFIX));
base::Value value(title + " - " + suffix);
base::Value suffixValue(" - " + suffix);
#endif
std::string output;
base::JSONWriter::Write(value, &output);
return "setTitle(" + output + ");";
base::Value titleValue(title);
std::string suffixJs;
base::JSONWriter::Write(suffixValue, &suffixJs);
std::string titleJs;
base::JSONWriter::Write(titleValue, &titleJs);
return "setTitle(" + titleJs + ", " + suffixJs + ");";
}
const std::string GetSetTextDirectionJs(const std::string& direction) {
......
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