Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Unified Diff: components/reading_list/core/offline_url_utils_unittest.cc

Issue 2763233003: Move ReadingList model to components/reading_list/core (Closed)
Patch Set: feedback Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « components/reading_list/core/offline_url_utils.cc ('k') | components/reading_list/core/proto/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/reading_list/core/offline_url_utils_unittest.cc
diff --git a/components/reading_list/core/offline_url_utils_unittest.cc b/components/reading_list/core/offline_url_utils_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cf5b8bc95d59d8bf95a836a497640daf664d9639
--- /dev/null
+++ b/components/reading_list/core/offline_url_utils_unittest.cc
@@ -0,0 +1,85 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/reading_list/core/offline_url_utils.h"
+
+#include <string>
+
+#include "base/files/file_path.h"
+#include "base/strings/stringprintf.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+// Checks the root directory of offline pages.
+TEST(OfflineURLUtilsTest, OfflineRootDirectoryPathTest) {
+ base::FilePath::StringType separator(&base::FilePath::kSeparators[0], 1);
+ base::FilePath profile_path(FILE_PATH_LITERAL("profile_path"));
+ base::FilePath offline_directory =
+ reading_list::OfflineRootDirectoryPath(profile_path);
+ // Expected value: profile_path/Offline
+ std::string expected =
+ base::StringPrintf("profile_path%" PRIsFP "Offline", separator.c_str());
+ EXPECT_EQ(expected, offline_directory.AsUTF8Unsafe());
+}
+
+// Checks the offline page directory is the MD5 of the URL
+TEST(OfflineURLUtilsTest, OfflineURLDirectoryIDTest) {
+ GURL url("http://www.google.com/test");
+ // MD5 of "http://www.google.com/test"
+ std::string md5 = "0090071ef710946a1263c276284bb3b8";
+ std::string directory_id = reading_list::OfflineURLDirectoryID(url);
+ EXPECT_EQ(md5, directory_id);
+}
+
+// Checks the offline page directory is
+// |profile_path|/Offline/OfflineURLDirectoryID;
+TEST(OfflineURLUtilsTest, OfflineURLDirectoryAbsolutePathTest) {
+ base::FilePath::StringType separator(&base::FilePath::kSeparators[0], 1);
+ base::FilePath profile_path(FILE_PATH_LITERAL("profile_path"));
+ GURL url("http://www.google.com/test");
+ base::FilePath offline_directory =
+ reading_list::OfflineURLDirectoryAbsolutePath(profile_path, url);
+ // Expected value: profile_path/Offline/0090071ef710946a1263c276284bb3b8
+ std::string expected =
+ base::StringPrintf("profile_path%" PRIsFP "Offline%" PRIsFP
+ "0090071ef710946a1263c276284bb3b8",
+ separator.c_str(), separator.c_str());
+ EXPECT_EQ(expected, offline_directory.AsUTF8Unsafe());
+}
+
+// Checks the offline page directory is
+// |profile_path|/Offline/OfflineURLDirectoryID;
+TEST(OfflineURLUtilsTest, AbsolutePathForRelativePathTest) {
+ base::FilePath::StringType separator(&base::FilePath::kSeparators[0], 1);
+ base::FilePath profile_path(FILE_PATH_LITERAL("profile_path"));
+ base::FilePath relative_path(FILE_PATH_LITERAL("relative"));
+ relative_path = relative_path.Append(FILE_PATH_LITERAL("path"));
+ base::FilePath absolute_path =
+ reading_list::OfflineURLAbsolutePathFromRelativePath(profile_path,
+ relative_path);
+ // Expected value: profile_path/Offline/relative/path
+ std::string expected = base::StringPrintf(
+ "profile_path%" PRIsFP "Offline%" PRIsFP "relative%" PRIsFP "path",
+ separator.c_str(), separator.c_str(), separator.c_str());
+ EXPECT_EQ(expected, absolute_path.AsUTF8Unsafe());
+}
+
+// Checks the offline page path is OfflineURLDirectoryID/page.html;
+TEST(OfflineURLUtilsTest, OfflinePagePathTest) {
+ base::FilePath::StringType separator(&base::FilePath::kSeparators[0], 1);
+ GURL url("http://www.google.com/test");
+ base::FilePath offline_page =
+ reading_list::OfflinePagePath(url, reading_list::OFFLINE_TYPE_HTML);
+ // Expected value: 0090071ef710946a1263c276284bb3b8/page.html
+ std::string expected_html =
+ base::StringPrintf("0090071ef710946a1263c276284bb3b8%" PRIsFP "page.html",
+ separator.c_str());
+ EXPECT_EQ(expected_html, offline_page.AsUTF8Unsafe());
+ offline_page =
+ reading_list::OfflinePagePath(url, reading_list::OFFLINE_TYPE_PDF);
+ // Expected value: 0090071ef710946a1263c276284bb3b8/file.pdf
+ std::string expected_pdf = base::StringPrintf(
+ "0090071ef710946a1263c276284bb3b8%" PRIsFP "file.pdf", separator.c_str());
+ EXPECT_EQ(expected_pdf, offline_page.AsUTF8Unsafe());
+}
« no previous file with comments | « components/reading_list/core/offline_url_utils.cc ('k') | components/reading_list/core/proto/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698