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

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: Edit parameter of helper function 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);
56 57
57 // Necessary callbacks for the offline page model. 58 // Necessary callbacks for the offline page model.
58 void OnSavePageDone(SavePageResult result, int64_t offlineId); 59 void OnSavePageDone(SavePageResult result, int64_t offlineId);
59 void OnClearAllDone(); 60 void OnClearAllDone();
60 void OnExpirePageDone(bool success); 61 void OnExpirePageDone(bool success);
62 void OnGetURLDone(const GURL& url);
61 63
62 // OfflinePageTestArchiver::Observer implementation: 64 // OfflinePageTestArchiver::Observer implementation:
63 void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override; 65 void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override;
64 66
65 // Offline page URL for the first page. 67 // Offline page URL for the first page.
66 const GURL& offline_url_page_1() const { return offline_url_page_1_; } 68 const GURL& offline_url_page_1() const { return offline_url_page_1_; }
67 // Offline page URL for the second page. 69 // Offline page URL for the second page.
68 const GURL& offline_url_page_2() const { return offline_url_page_2_; } 70 const GURL& offline_url_page_2() const { return offline_url_page_2_; }
69 // Offline page URL not related to any page. 71 // Offline page URL not related to any page.
70 const GURL& offline_url_missing() const { return offline_url_missing_; } 72 const GURL& offline_url_missing() const { return offline_url_missing_; }
71 // Offline page URL for expired page. 73 // Offline page URL for expired page.
72 const GURL& offline_url_expired() const { return offline_url_expired_; } 74 const GURL& offline_url_expired() const { return offline_url_expired_; }
73 75
74 TestingProfile* profile() { return &profile_; } 76 TestingProfile* profile() { return &profile_; }
75 77
76 int64_t offline_id() const { return offline_id_; } 78 int64_t offline_id() const { return offline_id_; }
77 79
78 private: 80 private:
79 void CreateOfflinePages(); 81 void CreateOfflinePages();
80 std::unique_ptr<OfflinePageTestArchiver> BuildArchiver( 82 std::unique_ptr<OfflinePageTestArchiver> BuildArchiver(
81 const GURL& url, 83 const GURL& url,
82 const base::FilePath& file_name); 84 const base::FilePath& file_name);
83 85
84 GURL offline_url_page_1_; 86 GURL offline_url_page_1_;
85 GURL offline_url_page_2_; 87 GURL offline_url_page_2_;
86 GURL offline_url_missing_; 88 GURL offline_url_missing_;
87 GURL offline_url_expired_; 89 GURL offline_url_expired_;
88 90
89 int64_t offline_id_; 91 int64_t offline_id_;
92 GURL url_;
90 93
91 scoped_refptr<base::TestSimpleTaskRunner> task_runner_; 94 scoped_refptr<base::TestSimpleTaskRunner> task_runner_;
92 base::ThreadTaskRunnerHandle task_runner_handle_; 95 base::ThreadTaskRunnerHandle task_runner_handle_;
93 TestingProfile profile_; 96 TestingProfile profile_;
94 }; 97 };
95 98
96 OfflinePageUtilsTest::OfflinePageUtilsTest() 99 OfflinePageUtilsTest::OfflinePageUtilsTest()
97 : task_runner_(new base::TestSimpleTaskRunner), 100 : task_runner_(new base::TestSimpleTaskRunner),
98 task_runner_handle_(task_runner_) {} 101 task_runner_handle_(task_runner_) {}
99 102
(...skipping 28 matching lines...) Expand all
128 } 131 }
129 132
130 void OfflinePageUtilsTest::OnExpirePageDone(bool success) { 133 void OfflinePageUtilsTest::OnExpirePageDone(bool success) {
131 // Result ignored here. 134 // Result ignored here.
132 } 135 }
133 136
134 void OfflinePageUtilsTest::OnClearAllDone() { 137 void OfflinePageUtilsTest::OnClearAllDone() {
135 // Result ignored here. 138 // Result ignored here.
136 } 139 }
137 140
141 void OfflinePageUtilsTest::OnGetURLDone(const GURL& url) {
142 url_ = url;
143 }
144
145 GURL OfflinePageUtilsTest::GetOfflineURLForOnlineURL(GURL online_url) {
146 OfflinePageUtils::GetOfflineURLForOnlineURL(
147 profile(), online_url,
148 base::Bind(&OfflinePageUtilsTest::OnGetURLDone, AsWeakPtr()));
149 RunUntilIdle();
150 return url_;
151 }
152
138 void OfflinePageUtilsTest::SetLastPathCreatedByArchiver( 153 void OfflinePageUtilsTest::SetLastPathCreatedByArchiver(
139 const base::FilePath& file_path) {} 154 const base::FilePath& file_path) {}
140 155
141 void OfflinePageUtilsTest::CreateOfflinePages() { 156 void OfflinePageUtilsTest::CreateOfflinePages() {
142 OfflinePageModel* model = 157 OfflinePageModel* model =
143 OfflinePageModelFactory::GetForBrowserContext(profile()); 158 OfflinePageModelFactory::GetForBrowserContext(profile());
144 159
145 // Create page 1. 160 // Create page 1.
146 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( 161 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
147 kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); 162 kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml"))));
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 // URL is invalid. 219 // URL is invalid.
205 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("/test.mhtml"))); 220 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("/test.mhtml")));
206 // Scheme is not file. 221 // Scheme is not file.
207 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("http://test.com/"))); 222 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("http://test.com/")));
208 // Does not end with .mhtml. 223 // Does not end with .mhtml.
209 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("file:///test.txt"))); 224 EXPECT_FALSE(OfflinePageUtils::MightBeOfflineURL(GURL("file:///test.txt")));
210 // Might still be an offline page. 225 // Might still be an offline page.
211 EXPECT_TRUE(OfflinePageUtils::MightBeOfflineURL(GURL("file:///test.mhtml"))); 226 EXPECT_TRUE(OfflinePageUtils::MightBeOfflineURL(GURL("file:///test.mhtml")));
212 } 227 }
213 228
214 TEST_F(OfflinePageUtilsTest, MaybeGetOfflineURLForOnlineURL) { 229 TEST_F(OfflinePageUtilsTest, GetOfflineURLForOnlineURL) {
215 EXPECT_EQ(offline_url_page_1(), 230 EXPECT_EQ(offline_url_page_1(),
216 OfflinePageUtils::MaybeGetOfflineURLForOnlineURL(profile(), 231 OfflinePageUtilsTest::GetOfflineURLForOnlineURL(kTestPage1Url));
217 kTestPage1Url)); 232
fgorski 2016/06/10 18:03:47 nit: you don't need empty lines. Other tests are w
Vivian 2016/06/10 19:47:31 Done.
218 EXPECT_EQ(offline_url_page_2(), 233 EXPECT_EQ(offline_url_page_2(),
219 OfflinePageUtils::MaybeGetOfflineURLForOnlineURL(profile(), 234 OfflinePageUtilsTest::GetOfflineURLForOnlineURL(kTestPage2Url));
220 kTestPage2Url)); 235
221 EXPECT_EQ(GURL::EmptyGURL(), OfflinePageUtils::MaybeGetOfflineURLForOnlineURL( 236 EXPECT_EQ(GURL::EmptyGURL(),
222 profile(), kTestPage3Url)); 237 OfflinePageUtilsTest::GetOfflineURLForOnlineURL(kTestPage3Url));
223 EXPECT_EQ(GURL::EmptyGURL(), OfflinePageUtils::MaybeGetOfflineURLForOnlineURL( 238
224 profile(), kTestPage4Url)); 239 EXPECT_EQ(GURL::EmptyGURL(),
240 OfflinePageUtilsTest::GetOfflineURLForOnlineURL(kTestPage4Url));
225 } 241 }
226 242
227 TEST_F(OfflinePageUtilsTest, MaybeGetOnlineURLForOfflineURL) { 243 TEST_F(OfflinePageUtilsTest, MaybeGetOnlineURLForOfflineURL) {
228 EXPECT_EQ(kTestPage1Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( 244 EXPECT_EQ(kTestPage1Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
229 profile(), offline_url_page_1())); 245 profile(), offline_url_page_1()));
230 EXPECT_EQ(kTestPage2Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( 246 EXPECT_EQ(kTestPage2Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
231 profile(), offline_url_page_2())); 247 profile(), offline_url_page_2()));
232 EXPECT_EQ(GURL::EmptyGURL(), OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( 248 EXPECT_EQ(GURL::EmptyGURL(), OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
233 profile(), offline_url_missing())); 249 profile(), offline_url_missing()));
234 EXPECT_EQ(kTestPage4Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL( 250 EXPECT_EQ(kTestPage4Url, OfflinePageUtils::MaybeGetOnlineURLForOfflineURL(
(...skipping 17 matching lines...) Expand all
252 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage1Url)); 268 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage1Url));
253 EXPECT_TRUE( 269 EXPECT_TRUE(
254 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage2Url)); 270 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage2Url));
255 EXPECT_FALSE( 271 EXPECT_FALSE(
256 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage3Url)); 272 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage3Url));
257 EXPECT_FALSE( 273 EXPECT_FALSE(
258 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage4Url)); 274 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage4Url));
259 } 275 }
260 276
261 } // namespace offline_pages 277 } // 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