Commit 6728ff6b authored by eugenebut's avatar eugenebut Committed by Commit bot

Fixed NavigationItemImpl::GetDisplayTitleForURL for 'file://' URL.

Use full URL spec if it ends with /

BUG=719982

Review-Url: https://codereview.chromium.org/2876053002
Cr-Commit-Position: refs/heads/master@{#471105}
parent 9a2b08a2
......@@ -297,7 +297,7 @@ base::string16 NavigationItemImpl::GetDisplayTitleForURL(const GURL& url) {
// For file:// URLs use the filename as the title, not the full path.
if (url.SchemeIsFile()) {
base::string16::size_type slashpos = title.rfind('/');
if (slashpos != base::string16::npos)
if (slashpos != base::string16::npos && slashpos != (title.size() - 1))
title = title.substr(slashpos + 1);
}
......
......@@ -148,5 +148,19 @@ TEST_F(NavigationItemTest, VirtualURLTest) {
EXPECT_EQ(original_url, item_->GetURL());
}
// Tests NavigationItemImpl::GetDisplayTitleForURL method.
TEST_F(NavigationItemTest, GetDisplayTitleForURL) {
base::string16 title;
title = NavigationItemImpl::GetDisplayTitleForURL(GURL("http://foo.org/"));
EXPECT_EQ("foo.org", base::UTF16ToUTF8(title));
title = NavigationItemImpl::GetDisplayTitleForURL(GURL("file://foo.org/"));
EXPECT_EQ("file://foo.org/", base::UTF16ToUTF8(title));
title = NavigationItemImpl::GetDisplayTitleForURL(GURL("file://foo/1.gz"));
EXPECT_EQ("1.gz", base::UTF16ToUTF8(title));
}
} // namespace
} // namespace web
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