Commit 20995bec authored by jianli's avatar jianli Committed by Commit bot

Match offline page url with fragment identifier stripped

BUG=647872
TEST=new test added

Review-Url: https://codereview.chromium.org/2353813002
Cr-Commit-Position: refs/heads/master@{#423025}
parent c7c97a5c
......@@ -608,9 +608,23 @@ void OfflinePageModelImpl::GetPagesByOnlineURLWhenLoadDone(
const MultipleOfflinePageItemCallback& callback) const {
std::vector<OfflinePageItem> result;
GURL::Replacements remove_params;
remove_params.ClearRef();
GURL online_url_without_fragment =
online_url.ReplaceComponents(remove_params);
for (const auto& id_page_pair : offline_pages_) {
if (id_page_pair.second.url == online_url &&
!id_page_pair.second.IsExpired()) {
if (id_page_pair.second.IsExpired())
continue;
if (online_url == id_page_pair.second.url) {
result.push_back(id_page_pair.second);
continue;
}
// If the full URL does not match, try with the fragment identifier
// stripped.
if (online_url_without_fragment ==
id_page_pair.second.url.ReplaceComponents(remove_params)) {
result.push_back(id_page_pair.second);
}
}
......
......@@ -45,6 +45,9 @@ const GURL kTestUrl2("http://other.page.com");
const GURL kTestUrl3("http://test.xyz");
const GURL kTestUrl4("http://page.net");
const GURL kFileUrl("file:///foo");
const GURL kTestUrlWithFragment("http://example.com#frag");
const GURL kTestUrl2WithFragment("http://other.page.com#frag");
const GURL kTestUrl2WithFragment2("http://other.page.com#frag2");
const ClientId kTestClientId1(kTestClientNamespace, "1234");
const ClientId kTestClientId2(kTestClientNamespace, "5678");
const ClientId kTestClientId3(kTestClientNamespace, "42");
......@@ -931,6 +934,27 @@ TEST_F(OfflinePageModelImplTest, GetPagesByOnlineURL) {
EXPECT_EQ(0U, pages.size());
}
TEST_F(OfflinePageModelImplTest, GetPagesByOnlineURLWithFragment) {
SavePage(kTestUrl, kTestClientId1);
SavePage(kTestUrl2WithFragment, kTestClientId2);
MultipleOfflinePageItemResult pages =
GetPagesByOnlineURL(kTestUrlWithFragment);
EXPECT_EQ(1U, pages.size());
EXPECT_EQ(kTestUrl, pages[0].url);
EXPECT_EQ(kTestClientId1, pages[0].client_id);
pages = GetPagesByOnlineURL(kTestUrl2);
EXPECT_EQ(1U, pages.size());
EXPECT_EQ(kTestUrl2WithFragment, pages[0].url);
EXPECT_EQ(kTestClientId2, pages[0].client_id);
pages = GetPagesByOnlineURL(kTestUrl2WithFragment2);
EXPECT_EQ(1U, pages.size());
EXPECT_EQ(kTestUrl2WithFragment, pages[0].url);
EXPECT_EQ(kTestClientId2, pages[0].client_id);
}
TEST_F(OfflinePageModelImplTest, CheckPagesExistOffline) {
SavePage(kTestUrl, kTestClientId1);
SavePage(kTestUrl2, kTestClientId2);
......
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