| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ios/chrome/browser/reading_list/offline_url_utils.h" | 5 #include "ios/chrome/browser/reading_list/offline_url_utils.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/test/gtest_util.h" | 11 #include "base/test/gtest_util.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 14 | 14 |
| 15 // Checks the distilled URL for the page is chrome://offline/MD5/page.html; | 15 // Checks the distilled URL for the page is chrome://offline/MD5/page.html; |
| 16 TEST(OfflineURLUtilsTest, DistilledURLForPathTest) { | 16 TEST(OfflineURLUtilsTest, DistilledURLForPathTest) { |
| 17 base::FilePath page_path("MD5/page.html"); | 17 base::FilePath page_path("MD5/page.html"); |
| 18 GURL distilled_url = reading_list::DistilledURLForPath(page_path, GURL()); | 18 GURL distilled_url = |
| 19 reading_list::OfflineURLForPath(page_path, GURL(), GURL()); |
| 19 EXPECT_EQ("chrome://offline/MD5/page.html", distilled_url.spec()); | 20 EXPECT_EQ("chrome://offline/MD5/page.html", distilled_url.spec()); |
| 20 } | 21 } |
| 21 | 22 |
| 22 // Checks the distilled URL for the page with an onlineURL is | 23 // Checks the distilled URL for the page with an onlineURL is |
| 23 // chrome://offline/MD5/page.html?virtualURL=encorded%20URL; | 24 // chrome://offline/MD5/page.html?entryURL=...&virtualURL=... |
| 24 TEST(OfflineURLUtilsTest, DistilledURLForPathWithVirtualURLTest) { | 25 TEST(OfflineURLUtilsTest, OfflineURLForPathWithEntryURLAndVirtualURLTest) { |
| 25 base::FilePath page_path("MD5/page.html"); | 26 base::FilePath page_path("MD5/page.html"); |
| 26 GURL online_url = GURL("http://foo.bar"); | 27 GURL entry_url = GURL("http://foo.bar"); |
| 27 GURL distilled_url = reading_list::DistilledURLForPath(page_path, online_url); | 28 GURL virtual_url = GURL("http://foo.bar/virtual"); |
| 28 EXPECT_EQ("chrome://offline/MD5/page.html?virtualURL=http%3A%2F%2Ffoo.bar%2F", | 29 GURL distilled_url = |
| 29 distilled_url.spec()); | 30 reading_list::OfflineURLForPath(page_path, entry_url, virtual_url); |
| 31 EXPECT_EQ( |
| 32 "chrome://offline/MD5/page.html?" |
| 33 "entryURL=http%3A%2F%2Ffoo.bar%2F&" |
| 34 "virtualURL=http%3A%2F%2Ffoo.bar%2Fvirtual", |
| 35 distilled_url.spec()); |
| 30 } | 36 } |
| 31 | 37 |
| 32 // Checks the distilled URL for the page is chrome://offline/MD5/page.html; | 38 // Checks the parsing of offline URL chrome://offline/MD5/page.html. |
| 33 TEST(OfflineURLUtilsTest, VirtualURLForDistilledURLTest) { | 39 // As entryURL and virtualURL are absent, they should return the offline URL. |
| 40 TEST(OfflineURLUtilsTest, ParseOfflineURLTest) { |
| 34 GURL distilled_url("chrome://offline/MD5/page.html"); | 41 GURL distilled_url("chrome://offline/MD5/page.html"); |
| 35 GURL virtual_url = reading_list::VirtualURLForDistilledURL(distilled_url); | 42 GURL entry_url = reading_list::EntryURLForOfflineURL(distilled_url); |
| 43 EXPECT_EQ("chrome://offline/MD5/page.html", entry_url.spec()); |
| 44 GURL virtual_url = reading_list::VirtualURLForOfflineURL(distilled_url); |
| 36 EXPECT_EQ("chrome://offline/MD5/page.html", virtual_url.spec()); | 45 EXPECT_EQ("chrome://offline/MD5/page.html", virtual_url.spec()); |
| 37 } | 46 } |
| 38 | 47 |
| 39 // Checks the distilled URL for the page with an onlineURL is | 48 // Checks the parsing of offline URL |
| 40 // chrome://offline/MD5/page.html?virtualURL=encorded%20URL; | 49 // chrome://offline/MD5/page.html?entryURL=encorded%20URL |
| 41 TEST(OfflineURLUtilsTest, VirtualURLForDistilledURLWithVirtualURLTest) { | 50 // As entryURL is present, it should be returned correctly. |
| 42 GURL distilled_url( | 51 // As virtualURL is absent, it should return the entryURL. |
| 52 TEST(OfflineURLUtilsTest, ParseOfflineURLWithEntryURLTest) { |
| 53 GURL offline_url( |
| 54 "chrome://offline/MD5/page.html?entryURL=http%3A%2F%2Ffoo.bar%2F"); |
| 55 GURL entry_url = reading_list::EntryURLForOfflineURL(offline_url); |
| 56 EXPECT_EQ("http://foo.bar/", entry_url.spec()); |
| 57 GURL virtual_url = reading_list::VirtualURLForOfflineURL(offline_url); |
| 58 EXPECT_EQ("http://foo.bar/", virtual_url.spec()); |
| 59 } |
| 60 |
| 61 // Checks the parsing of offline URL |
| 62 // chrome://offline/MD5/page.html?virtualURL=encorded%20URL |
| 63 // As entryURL is absent, it should return the offline URL. |
| 64 // As virtualURL is present, it should be returned correctly. |
| 65 TEST(OfflineURLUtilsTest, ParseOfflineURLWithVirtualURLTest) { |
| 66 GURL offline_url( |
| 43 "chrome://offline/MD5/page.html?virtualURL=http%3A%2F%2Ffoo.bar%2F"); | 67 "chrome://offline/MD5/page.html?virtualURL=http%3A%2F%2Ffoo.bar%2F"); |
| 44 GURL virtual_url = reading_list::VirtualURLForDistilledURL(distilled_url); | 68 GURL entry_url = reading_list::EntryURLForOfflineURL(offline_url); |
| 69 EXPECT_EQ(offline_url, entry_url); |
| 70 GURL virtual_url = reading_list::VirtualURLForOfflineURL(offline_url); |
| 45 EXPECT_EQ("http://foo.bar/", virtual_url.spec()); | 71 EXPECT_EQ("http://foo.bar/", virtual_url.spec()); |
| 46 } | 72 } |
| 47 | 73 |
| 74 // Checks the parsing of offline URL |
| 75 // chrome://offline/MD5/page.html?entryURL=...&virtualURL=... |
| 76 // As entryURL is present, it should be returned correctly. |
| 77 // As virtualURL is present, it should be returned correctly. |
| 78 TEST(OfflineURLUtilsTest, ParseOfflineURLWithVirtualAndEntryURLTest) { |
| 79 GURL offline_url( |
| 80 "chrome://offline/MD5/" |
| 81 "page.html?virtualURL=http%3A%2F%2Ffoo.bar%2Fvirtual&entryURL=http%3A%2F%" |
| 82 "2Ffoo.bar%2Fentry"); |
| 83 GURL entry_url = reading_list::EntryURLForOfflineURL(offline_url); |
| 84 EXPECT_EQ("http://foo.bar/entry", entry_url.spec()); |
| 85 GURL virtual_url = reading_list::VirtualURLForOfflineURL(offline_url); |
| 86 EXPECT_EQ("http://foo.bar/virtual", virtual_url.spec()); |
| 87 } |
| 88 |
| 48 // Checks the file path for chrome://offline/MD5/page.html is | 89 // Checks the file path for chrome://offline/MD5/page.html is |
| 49 // file://profile_path/Offline/MD5/page.html. | 90 // file://profile_path/Offline/MD5/page.html. |
| 50 // Checks the resource root for chrome://offline/MD5/page.html is | 91 // Checks the resource root for chrome://offline/MD5/page.html is |
| 51 // file://profile_path/Offline/MD5 | 92 // file://profile_path/Offline/MD5 |
| 52 TEST(OfflineURLUtilsTest, FileURLForDistilledURLTest) { | 93 TEST(OfflineURLUtilsTest, FileURLForDistilledURLTest) { |
| 53 base::FilePath offline_path("/profile_path/Offline"); | 94 base::FilePath offline_path("/profile_path/Offline"); |
| 54 GURL file_url = | 95 GURL file_url = |
| 55 reading_list::FileURLForDistilledURL(GURL(), offline_path, nullptr); | 96 reading_list::FileURLForDistilledURL(GURL(), offline_path, nullptr); |
| 56 EXPECT_FALSE(file_url.is_valid()); | 97 EXPECT_FALSE(file_url.is_valid()); |
| 57 | 98 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 77 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("chrome://offline-foobar"))); | 118 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("chrome://offline-foobar"))); |
| 78 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("http://offline/"))); | 119 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("http://offline/"))); |
| 79 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("http://chrome://offline/"))); | 120 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("http://chrome://offline/"))); |
| 80 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline"))); | 121 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline"))); |
| 81 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline/"))); | 122 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline/"))); |
| 82 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline/foobar"))); | 123 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline/foobar"))); |
| 83 EXPECT_TRUE( | 124 EXPECT_TRUE( |
| 84 reading_list::IsOfflineURL(GURL("chrome://offline/foobar?foo=bar"))); | 125 reading_list::IsOfflineURL(GURL("chrome://offline/foobar?foo=bar"))); |
| 85 } | 126 } |
| 86 | 127 |
| OLD | NEW |