| 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" |
| 11 #include "base/test/gtest_util.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "url/gurl.h" | 13 #include "url/gurl.h" |
| 12 | 14 |
| 13 // 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; |
| 14 TEST(OfflineURLUtilsTest, DistilledURLForPathTest) { | 16 TEST(OfflineURLUtilsTest, DistilledURLForPathTest) { |
| 15 base::FilePath page_path("MD5/page.html"); | 17 base::FilePath page_path("MD5/page.html"); |
| 16 GURL distilled_url = reading_list::DistilledURLForPath(page_path, GURL()); | 18 GURL distilled_url = reading_list::DistilledURLForPath(page_path, GURL()); |
| 17 EXPECT_EQ("chrome://offline/MD5/page.html", distilled_url.spec()); | 19 EXPECT_EQ("chrome://offline/MD5/page.html", distilled_url.spec()); |
| 18 } | 20 } |
| 19 | 21 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 EXPECT_EQ("/profile_path/Offline/MD5/page.html", file_url.path()); | 63 EXPECT_EQ("/profile_path/Offline/MD5/page.html", file_url.path()); |
| 62 | 64 |
| 63 GURL resource_url; | 65 GURL resource_url; |
| 64 file_url = reading_list::FileURLForDistilledURL(distilled_url, offline_path, | 66 file_url = reading_list::FileURLForDistilledURL(distilled_url, offline_path, |
| 65 &resource_url); | 67 &resource_url); |
| 66 EXPECT_TRUE(resource_url.is_valid()); | 68 EXPECT_TRUE(resource_url.is_valid()); |
| 67 EXPECT_TRUE(resource_url.SchemeIsFile()); | 69 EXPECT_TRUE(resource_url.SchemeIsFile()); |
| 68 EXPECT_EQ("/profile_path/Offline/MD5/", resource_url.path()); | 70 EXPECT_EQ("/profile_path/Offline/MD5/", resource_url.path()); |
| 69 } | 71 } |
| 70 | 72 |
| 73 // Checks that the offline URLs are correctly detected by |IsOfflineURL|. |
| 71 TEST(OfflineURLUtilsTest, IsOfflineURL) { | 74 TEST(OfflineURLUtilsTest, IsOfflineURL) { |
| 72 EXPECT_FALSE(reading_list::IsOfflineURL(GURL())); | 75 EXPECT_FALSE(reading_list::IsOfflineURL(GURL())); |
| 73 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("chrome://"))); | 76 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("chrome://"))); |
| 74 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("chrome://offline-foobar"))); | 77 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("chrome://offline-foobar"))); |
| 75 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("http://offline/"))); | 78 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("http://offline/"))); |
| 76 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("http://chrome://offline/"))); | 79 EXPECT_FALSE(reading_list::IsOfflineURL(GURL("http://chrome://offline/"))); |
| 77 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline"))); | 80 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline"))); |
| 78 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline/"))); | 81 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline/"))); |
| 79 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline/foobar"))); | 82 EXPECT_TRUE(reading_list::IsOfflineURL(GURL("chrome://offline/foobar"))); |
| 80 EXPECT_TRUE( | 83 EXPECT_TRUE( |
| 81 reading_list::IsOfflineURL(GURL("chrome://offline/foobar?foo=bar"))); | 84 reading_list::IsOfflineURL(GURL("chrome://offline/foobar?foo=bar"))); |
| 82 } | 85 } |
| 86 |
| 87 // Checks that https:// scheme is correctly removed by |
| 88 // StripSchemeFromOnlineURLTest. |
| 89 TEST(OfflineURLUtilsTest, StripSchemeFromOnlineURLTest) { |
| 90 size_t removed_size; |
| 91 base::string16 empty_url; |
| 92 EXPECT_EQ(reading_list::StripSchemeFromOnlineURL(empty_url, &removed_size), |
| 93 empty_url); |
| 94 EXPECT_EQ(removed_size, 0u); |
| 95 |
| 96 base::string16 https_url = base::UTF8ToUTF16("https://www.chromium.org/"); |
| 97 base::string16 trimmed_https_url = base::UTF8ToUTF16("www.chromium.org/"); |
| 98 EXPECT_EQ(reading_list::StripSchemeFromOnlineURL(https_url, &removed_size), |
| 99 trimmed_https_url); |
| 100 EXPECT_EQ(removed_size, 8u); |
| 101 base::string16 http_url = base::UTF8ToUTF16("http://www.chromium.org/"); |
| 102 EXPECT_DCHECK_DEATH( |
| 103 reading_list::StripSchemeFromOnlineURL(http_url, &removed_size)); |
| 104 |
| 105 base::string16 other_scheme_url = |
| 106 base::UTF8ToUTF16("scheme://www.chromium.org/"); |
| 107 EXPECT_EQ( |
| 108 reading_list::StripSchemeFromOnlineURL(other_scheme_url, &removed_size), |
| 109 other_scheme_url); |
| 110 EXPECT_EQ(removed_size, 0u); |
| 111 |
| 112 base::string16 no_scheme_url = base::UTF8ToUTF16("www.chromium.org/"); |
| 113 EXPECT_EQ( |
| 114 reading_list::StripSchemeFromOnlineURL(no_scheme_url, &removed_size), |
| 115 no_scheme_url); |
| 116 EXPECT_EQ(removed_size, 0u); |
| 117 } |
| OLD | NEW |