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 "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "url/gurl.h" | 11 #include "url/gurl.h" |
12 | 12 |
13 // Checks the root directory of offline pages. | |
14 TEST(OfflineURLUtilsTest, OfflineRootDirectoryPathTest) { | |
15 base::FilePath profile_path("/profile_path"); | |
16 base::FilePath offline_directory = | |
17 reading_list::OfflineRootDirectoryPath(profile_path); | |
18 EXPECT_EQ("/profile_path/Offline", offline_directory.value()); | |
19 } | |
20 | |
21 // Checks the offline page directory is the MD5 of the URL | |
22 TEST(OfflineURLUtilsTest, OfflineURLDirectoryIDTest) { | |
23 GURL url("http://www.google.com/test"); | |
24 // MD5 of "http://www.google.com/test" | |
25 std::string md5 = "0090071ef710946a1263c276284bb3b8"; | |
26 std::string directory_id = reading_list::OfflineURLDirectoryID(url); | |
27 EXPECT_EQ(md5, directory_id); | |
28 } | |
29 | |
30 // Checks the offline page directory is | |
31 // |profile_path|/Offline/OfflineURLDirectoryID; | |
32 TEST(OfflineURLUtilsTest, OfflineURLDirectoryAbsolutePathTest) { | |
33 base::FilePath profile_path("/profile_path"); | |
34 GURL url("http://www.google.com/test"); | |
35 base::FilePath offline_directory = | |
36 reading_list::OfflineURLDirectoryAbsolutePath(profile_path, url); | |
37 EXPECT_EQ("/profile_path/Offline/0090071ef710946a1263c276284bb3b8", | |
38 offline_directory.value()); | |
39 } | |
40 | |
41 // Checks the offline page absolute path is | |
42 // |profile_path|/Offline/OfflineURLDirectoryID/page.html; | |
43 TEST(OfflineURLUtilsTest, OfflinePageAbsolutePathTest) { | |
44 base::FilePath profile_path("/profile_path"); | |
45 GURL url("http://www.google.com/test"); | |
46 base::FilePath offline_page = | |
47 reading_list::OfflinePageAbsolutePath(profile_path, url); | |
48 EXPECT_EQ("/profile_path/Offline/0090071ef710946a1263c276284bb3b8/page.html", | |
49 offline_page.value()); | |
50 } | |
51 | |
52 // Checks the offline page path is OfflineURLDirectoryID/page.html; | |
53 TEST(OfflineURLUtilsTest, OfflinePagePathTest) { | |
54 GURL url("http://www.google.com/test"); | |
55 base::FilePath offline_page = reading_list::OfflinePagePath(url); | |
56 EXPECT_EQ("0090071ef710946a1263c276284bb3b8/page.html", offline_page.value()); | |
57 } | |
58 | |
59 // Checks the distilled URL for the page is chrome://offline/MD5/page.html; | 13 // Checks the distilled URL for the page is chrome://offline/MD5/page.html; |
60 TEST(OfflineURLUtilsTest, DistilledURLForPathTest) { | 14 TEST(OfflineURLUtilsTest, DistilledURLForPathTest) { |
61 base::FilePath page_path("MD5/page.html"); | 15 base::FilePath page_path("MD5/page.html"); |
62 GURL distilled_url = reading_list::DistilledURLForPath(page_path); | 16 GURL distilled_url = reading_list::DistilledURLForPath(page_path); |
63 EXPECT_EQ("chrome://offline/MD5/page.html", distilled_url.spec()); | 17 EXPECT_EQ("chrome://offline/MD5/page.html", distilled_url.spec()); |
64 } | 18 } |
65 | 19 |
66 // Checks the file path for chrome://offline/MD5/page.html is | 20 // Checks the file path for chrome://offline/MD5/page.html is |
67 // file://profile_path/Offline/MD5/page.html. | 21 // file://profile_path/Offline/MD5/page.html. |
68 // Checks the resource root for chrome://offline/MD5/page.html is | 22 // Checks the resource root for chrome://offline/MD5/page.html is |
(...skipping 11 matching lines...) Expand all Loading... |
80 EXPECT_TRUE(file_url.SchemeIsFile()); | 34 EXPECT_TRUE(file_url.SchemeIsFile()); |
81 EXPECT_EQ("/profile_path/Offline/MD5/page.html", file_url.path()); | 35 EXPECT_EQ("/profile_path/Offline/MD5/page.html", file_url.path()); |
82 | 36 |
83 GURL resource_url; | 37 GURL resource_url; |
84 file_url = reading_list::FileURLForDistilledURL(distilled_url, profile_path, | 38 file_url = reading_list::FileURLForDistilledURL(distilled_url, profile_path, |
85 &resource_url); | 39 &resource_url); |
86 EXPECT_TRUE(resource_url.is_valid()); | 40 EXPECT_TRUE(resource_url.is_valid()); |
87 EXPECT_TRUE(resource_url.SchemeIsFile()); | 41 EXPECT_TRUE(resource_url.SchemeIsFile()); |
88 EXPECT_EQ("/profile_path/Offline/MD5/", resource_url.path()); | 42 EXPECT_EQ("/profile_path/Offline/MD5/", resource_url.path()); |
89 } | 43 } |
OLD | NEW |