Commit 352492fd authored by Danyao Wang's avatar Danyao Wang Committed by Commit Bot

[ios] Always notify WebStateObservers on navigation item title change.

The short circuit skips WebStateImpl->OnTitleChanged() incorrectly on
back/forward navigation because although the title in the navigation
item doesn't need changing, the visible navigation item has changed.

This only affects navigating to native content from web content because
web state title for web content is updated separately in
|-webViewTitleDidChange|.

Bug: 864601
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ifd74f87aff0276394def154a8410b3dd1ce6c1c8
Reviewed-on: https://chromium-review.googlesource.com/1148693
Commit-Queue: Danyao Wang <danyao@chromium.org>
Reviewed-by: default avatarKurt Horimoto <kkhorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577967}
parent d6287383
...@@ -1290,9 +1290,6 @@ GURL URLEscapedForHistory(const GURL& url) { ...@@ -1290,9 +1290,6 @@ GURL URLEscapedForHistory(const GURL& url) {
return; return;
base::string16 newTitle = base::SysNSStringToUTF16(title); base::string16 newTitle = base::SysNSStringToUTF16(title);
if (item->GetTitle() == newTitle)
return;
item->SetTitle(newTitle); item->SetTitle(newTitle);
// TODO(crbug.com/546218): See if this can be removed; it's not clear that // TODO(crbug.com/546218): See if this can be removed; it's not clear that
// other platforms send this (tab sync triggers need to be compared against // other platforms send this (tab sync triggers need to be compared against
......
...@@ -1089,10 +1089,18 @@ TEST_P(CRWWebControllerTitleTest, TitleChange) { ...@@ -1089,10 +1089,18 @@ TEST_P(CRWWebControllerTitleTest, TitleChange) {
scoped_observer.Add(web_state()); scoped_observer.Add(web_state());
ASSERT_EQ(0, observer.title_change_count()); ASSERT_EQ(0, observer.title_change_count());
// Expect TitleWasSet callback after the page is loaded. int initial_title_change_count = 0;
if (web::GetWebClient()->IsSlimNavigationManagerEnabled()) {
// WKBasedNavigationManager produces an extra call to TitleWasSet because it
// loads New Tab Page in web view.
initial_title_change_count += 1;
}
// Expect TitleWasSet callback after the page is loaded and due to WKWebView
// title change KVO.
LoadHtml(@"<title>Title1</title>"); LoadHtml(@"<title>Title1</title>");
EXPECT_EQ("Title1", base::UTF16ToUTF8(web_state()->GetTitle())); EXPECT_EQ("Title1", base::UTF16ToUTF8(web_state()->GetTitle()));
EXPECT_EQ(1, observer.title_change_count()); EXPECT_EQ(initial_title_change_count + 2, observer.title_change_count());
// Expect at least one more TitleWasSet callback after changing title via // Expect at least one more TitleWasSet callback after changing title via
// JavaScript. On iOS 10 WKWebView fires 3 callbacks after JS excucution // JavaScript. On iOS 10 WKWebView fires 3 callbacks after JS excucution
...@@ -1101,7 +1109,7 @@ TEST_P(CRWWebControllerTitleTest, TitleChange) { ...@@ -1101,7 +1109,7 @@ TEST_P(CRWWebControllerTitleTest, TitleChange) {
// Fix expecteation when WKWebView stops sending extra KVO calls. // Fix expecteation when WKWebView stops sending extra KVO calls.
ExecuteJavaScript(@"window.document.title = 'Title2';"); ExecuteJavaScript(@"window.document.title = 'Title2';");
EXPECT_EQ("Title2", base::UTF16ToUTF8(web_state()->GetTitle())); EXPECT_EQ("Title2", base::UTF16ToUTF8(web_state()->GetTitle()));
EXPECT_GE(observer.title_change_count(), 2); EXPECT_GE(observer.title_change_count(), initial_title_change_count + 3);
}; };
// Tests that fragment change navigations use title from the previous page. // Tests that fragment change navigations use title from the previous page.
......
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