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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_utils_unittest.cc

Issue 2059513002: Remove obsoleted function and add test (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove backup file Created 4 years, 6 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/android/offline_pages/offline_page_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "chrome/browser/android/offline_pages/offline_page_utils.h" 5 #include "chrome/browser/android/offline_pages/offline_page_utils.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 class OfflinePageUtilsTest 46 class OfflinePageUtilsTest
47 : public testing::Test, 47 : public testing::Test,
48 public OfflinePageTestArchiver::Observer, 48 public OfflinePageTestArchiver::Observer,
49 public base::SupportsWeakPtr<OfflinePageUtilsTest> { 49 public base::SupportsWeakPtr<OfflinePageUtilsTest> {
50 public: 50 public:
51 OfflinePageUtilsTest(); 51 OfflinePageUtilsTest();
52 ~OfflinePageUtilsTest() override; 52 ~OfflinePageUtilsTest() override;
53 53
54 void SetUp() override; 54 void SetUp() override;
55 void RunUntilIdle(); 55 void RunUntilIdle();
56 GURL GetOfflineURLForOnlineURL(GURL online_url,
57 base::Callback<void(const GURL&)> callback);
56 58
57 // Necessary callbacks for the offline page model. 59 // Necessary callbacks for the offline page model.
58 void OnSavePageDone(SavePageResult result, int64_t offlineId); 60 void OnSavePageDone(SavePageResult result, int64_t offlineId);
59 void OnClearAllDone(); 61 void OnClearAllDone();
60 void OnExpirePageDone(bool success); 62 void OnExpirePageDone(bool success);
63 void OnGetURLDone(const GURL& url);
61 64
62 // OfflinePageTestArchiver::Observer implementation: 65 // OfflinePageTestArchiver::Observer implementation:
63 void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override; 66 void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override;
64 67
65 // Offline page URL for the first page. 68 // Offline page URL for the first page.
66 const GURL& offline_url_page_1() const { return offline_url_page_1_; } 69 const GURL& offline_url_page_1() const { return offline_url_page_1_; }
67 // Offline page URL for the second page. 70 // Offline page URL for the second page.
68 const GURL& offline_url_page_2() const { return offline_url_page_2_; } 71 const GURL& offline_url_page_2() const { return offline_url_page_2_; }
69 // Offline page URL not related to any page. 72 // Offline page URL not related to any page.
70 const GURL& offline_url_missing() const { return offline_url_missing_; } 73 const GURL& offline_url_missing() const { return offline_url_missing_; }
71 // Offline page URL for expired page. 74 // Offline page URL for expired page.
72 const GURL& offline_url_expired() const { return offline_url_expired_; } 75 const GURL& offline_url_expired() const { return offline_url_expired_; }
73 76
74 TestingProfile* profile() { return &profile_; } 77 TestingProfile* profile() { return &profile_; }
75 78
76 int64_t offline_id() const { return offline_id_; } 79 int64_t offline_id() const { return offline_id_; }
77 80
81 const GURL& url() const { return url_; }
dewittj 2016/06/10 17:46:10 I think this is unused... can remove it.
Vivian 2016/06/10 17:58:52 Done.
82
78 private: 83 private:
79 void CreateOfflinePages(); 84 void CreateOfflinePages();
80 std::unique_ptr<OfflinePageTestArchiver> BuildArchiver( 85 std::unique_ptr<OfflinePageTestArchiver> BuildArchiver(
81 const GURL& url, 86 const GURL& url,
82 const base::FilePath& file_name); 87 const base::FilePath& file_name);
83 88
84 GURL offline_url_page_1_; 89 GURL offline_url_page_1_;
85 GURL offline_url_page_2_; 90 GURL offline_url_page_2_;
86 GURL offline_url_missing_; 91 GURL offline_url_missing_;
87 GURL offline_url_expired_; 92 GURL offline_url_expired_;
88 93
89 int64_t offline_id_; 94 int64_t offline_id_;
95 GURL url_;
90 96
91 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 97 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
92 base::ThreadTaskRunnerHandle task_runner_handle_; 98 base::ThreadTaskRunnerHandle task_runner_handle_;
93 TestingProfile profile_; 99 TestingProfile profile_;
94 }; 100 };
95 101
96 OfflinePageUtilsTest::OfflinePageUtilsTest() 102 OfflinePageUtilsTest::OfflinePageUtilsTest()
97 : task_runner_(new base::TestSimpleTaskRunner), 103 : task_runner_(new base::TestSimpleTaskRunner),
98 task_runner_handle_(task_runner_) {} 104 task_runner_handle_(task_runner_) {}
99 105
(...skipping 28 matching lines...) Expand all
128 } 134 }
129 135
130 void OfflinePageUtilsTest::OnExpirePageDone(bool success) { 136 void OfflinePageUtilsTest::OnExpirePageDone(bool success) {
131 // Result ignored here. 137 // Result ignored here.
132 } 138 }
133 139
134 void OfflinePageUtilsTest::OnClearAllDone() { 140 void OfflinePageUtilsTest::OnClearAllDone() {
135 // Result ignored here. 141 // Result ignored here.
136 } 142 }
137 143
144 void OfflinePageUtilsTest::OnGetURLDone(const GURL& url) {
145 url_ = url;
146 }
147
148 GURL OfflinePageUtilsTest::GetOfflineURLForOnlineURL(
149 GURL online_url,
150 base::Callback<void(const GURL&)> callback) {
dewittj 2016/06/10 17:46:10 No need to pass in callback, you can just refer to
Vivian 2016/06/10 17:58:52 Done.
151 OfflinePageUtils::GetOfflineURLForOnlineURL(profile(), online_url, callback);
152 RunUntilIdle();
153 return url_;
154 }
155
138 void OfflinePageUtilsTest::SetLastPathCreatedByArchiver( 156 void OfflinePageUtilsTest::SetLastPathCreatedByArchiver(
139 const base::FilePath& file_path) {} 157 const base::FilePath& file_path) {}
140 158
141 void OfflinePageUtilsTest::CreateOfflinePages() { 159 void OfflinePageUtilsTest::CreateOfflinePages() {
142 OfflinePageModel* model = 160 OfflinePageModel* model =
143 OfflinePageModelFactory::GetForBrowserContext(profile()); 161 OfflinePageModelFactory::GetForBrowserContext(profile());
144 162
145 // Create page 1. 163 // Create page 1.
146 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( 164 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
147 kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); 165 kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml"))));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // URL is invalid. 222 // URL is invalid.
205 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("/test.mhtml"))); 223 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("/test.mhtml")));
206 // Scheme is not file. 224 // Scheme is not file.
207 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("http://test.com/"))); 225 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("http://test.com/")));
208 // Does not end with .mhtml. 226 // Does not end with .mhtml.
209 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("file:///test.txt"))); 227 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("file:///test.txt")));
210 // Might still be an offline page. 228 // Might still be an offline page.
211 EXPECT_TRUE(OfflinePageUtils::MightBeOfflineURL(GURL("file:///test.mhtml"))); 229 EXPECT_TRUE(OfflinePageUtils::MightBeOfflineURL(GURL("file:///test.mhtml")));
212 } 230 }
213 231
214 TEST_F(OfflinePageUtilsTest, MaybeGetOfflineURLForOnlineURL) { 232 TEST_F(OfflinePageUtilsTest, GetOfflineURLForOnlineURL) {
215 EXPECT_EQ(offline_url_page_1(), 233 EXPECT_EQ(offline_url_page_1(),
216 OfflinePageUtils::MaybeGetOfflineURLForOnlineURL(profile(), 234 OfflinePageUtilsTest::GetOfflineURLForOnlineURL(
217 kTestPage1Url)); 235 kTestPage1Url,
236 base::Bind(&OfflinePageUtilsTest::OnGetURLDone, AsWeakPtr())));
237
218 EXPECT_EQ(offline_url_page_2(), 238 EXPECT_EQ(offline_url_page_2(),
219 OfflinePageUtils::MaybeGetOfflineURLForOnlineURL(profile(), 239 OfflinePageUtilsTest::GetOfflineURLForOnlineURL(
220 kTestPage2Url)); 240 kTestPage2Url,
221 EXPECT_EQ(GURL::EmptyGURL(), OfflinePageUtils::MaybeGetOfflineURLForOnlineURL( 241 base::Bind(&OfflinePageUtilsTest::OnGetURLDone, AsWeakPtr())));
222 profile(), kTestPage3Url)); 242
223 EXPECT_EQ(GURL::EmptyGURL(), OfflinePageUtils::MaybeGetOfflineURLForOnlineURL( 243 EXPECT_EQ(GURL::EmptyGURL(),
224 profile(), kTestPage4Url)); 244 OfflinePageUtilsTest::GetOfflineURLForOnlineURL(
245 kTestPage3Url,
246 base::Bind(&OfflinePageUtilsTest::OnGetURLDone, AsWeakPtr())));
247
248 EXPECT_EQ(GURL::EmptyGURL(),
249 OfflinePageUtilsTest::GetOfflineURLForOnlineURL(
250 kTestPage4Url,
251 base::Bind(&OfflinePageUtilsTest::OnGetURLDone, AsWeakPtr())));
225 } 252 }
226 253
227 TEST_F(OfflinePageUtilsTest, MaybeGetOnlineURLForOfflineURL) { 254 TEST_F(OfflinePageUtilsTest, MaybeGetOnlineURLForOfflineURL) {
228 EXPECT_EQ(kTestPage1Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( 255 EXPECT_EQ(kTestPage1Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
229 profile(), offline_url_page_1())); 256 profile(), offline_url_page_1()));
230 EXPECT_EQ(kTestPage2Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( 257 EXPECT_EQ(kTestPage2Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
231 profile(), offline_url_page_2())); 258 profile(), offline_url_page_2()));
232 EXPECT_EQ(GURL::EmptyGURL(), OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( 259 EXPECT_EQ(GURL::EmptyGURL(), OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
233 profile(), offline_url_missing())); 260 profile(), offline_url_missing()));
234 EXPECT_EQ(kTestPage4Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( 261 EXPECT_EQ(kTestPage4Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
(...skipping 17 matching lines...) Expand all
252 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage1Url)); 279 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage1Url));
253 EXPECT_TRUE( 280 EXPECT_TRUE(
254 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage2Url)); 281 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage2Url));
255 EXPECT_FALSE( 282 EXPECT_FALSE(
256 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage3Url)); 283 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage3Url));
257 EXPECT_FALSE( 284 EXPECT_FALSE(
258 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage4Url)); 285 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage4Url));
259 } 286 }
260 287
261 } // namespace offline_pages 288 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/offline_page_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698