OLD | NEW |
---|---|
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 23 matching lines...) Expand all Loading... | |
34 namespace offline_pages { | 34 namespace offline_pages { |
35 namespace { | 35 namespace { |
36 | 36 |
37 const GURL kTestPage1Url("http://test.org/page1"); | 37 const GURL kTestPage1Url("http://test.org/page1"); |
38 const GURL kTestPage2Url("http://test.org/page2"); | 38 const GURL kTestPage2Url("http://test.org/page2"); |
39 const GURL kTestPage3Url("http://test.org/page3"); | 39 const GURL kTestPage3Url("http://test.org/page3"); |
40 const GURL kTestPage4Url("http://test.org/page4"); | 40 const GURL kTestPage4Url("http://test.org/page4"); |
41 const int64_t kTestFileSize = 876543LL; | 41 const int64_t kTestFileSize = 876543LL; |
42 const char* kTestPage1ClientId = "1234"; | 42 const char* kTestPage1ClientId = "1234"; |
43 const char* kTestPage2ClientId = "5678"; | 43 const char* kTestPage2ClientId = "5678"; |
44 const char* kTestPage4ClientId = "9876"; | |
45 | 44 |
46 void BoolCallback(bool* actual_result, bool call_result) { | 45 void BoolCallback(bool* actual_result, bool call_result) { |
47 DCHECK(actual_result); | 46 DCHECK(actual_result); |
48 *actual_result = call_result; | 47 *actual_result = call_result; |
49 } | 48 } |
50 | 49 |
51 } // namespace | 50 } // namespace |
52 | 51 |
53 class OfflinePageUtilsTest | 52 class OfflinePageUtilsTest |
54 : public testing::Test, | 53 : public testing::Test, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 client_id.name_space = kDownloadNamespace; | 159 client_id.name_space = kDownloadNamespace; |
161 client_id.id = kTestPage1ClientId; | 160 client_id.id = kTestPage1ClientId; |
162 SavePage(kTestPage1Url, client_id, std::move(archiver)); | 161 SavePage(kTestPage1Url, client_id, std::move(archiver)); |
163 | 162 |
164 // Create page 2. | 163 // Create page 2. |
165 archiver = BuildArchiver(kTestPage2Url, | 164 archiver = BuildArchiver(kTestPage2Url, |
166 base::FilePath(FILE_PATH_LITERAL("page2.mhtml"))); | 165 base::FilePath(FILE_PATH_LITERAL("page2.mhtml"))); |
167 client_id.id = kTestPage2ClientId; | 166 client_id.id = kTestPage2ClientId; |
168 SavePage(kTestPage2Url, client_id, std::move(archiver)); | 167 SavePage(kTestPage2Url, client_id, std::move(archiver)); |
169 | 168 |
170 // Create page 4 - expired page. | |
171 archiver = BuildArchiver(kTestPage4Url, | |
172 base::FilePath(FILE_PATH_LITERAL("page4.mhtml"))); | |
173 client_id.id = kTestPage4ClientId; | |
174 SavePage(kTestPage4Url, client_id, std::move(archiver)); | |
175 RunUntilIdle(); | |
176 model->ExpirePages( | |
177 std::vector<int64_t>({offline_id()}), base::Time::Now(), | |
178 base::Bind(&OfflinePageUtilsTest::OnExpirePageDone, AsWeakPtr())); | |
179 RunUntilIdle(); | 169 RunUntilIdle(); |
jianli
2016/11/18 00:15:48
This line can also be removed since SavePage waits
romax
2016/11/18 20:50:48
Done.
| |
180 } | 170 } |
181 | 171 |
182 std::unique_ptr<OfflinePageTestArchiver> OfflinePageUtilsTest::BuildArchiver( | 172 std::unique_ptr<OfflinePageTestArchiver> OfflinePageUtilsTest::BuildArchiver( |
183 const GURL& url, | 173 const GURL& url, |
184 const base::FilePath& file_name) { | 174 const base::FilePath& file_name) { |
185 std::unique_ptr<OfflinePageTestArchiver> archiver(new OfflinePageTestArchiver( | 175 std::unique_ptr<OfflinePageTestArchiver> archiver(new OfflinePageTestArchiver( |
186 this, url, OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED, | 176 this, url, OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED, |
187 base::string16(), kTestFileSize, base::ThreadTaskRunnerHandle::Get())); | 177 base::string16(), kTestFileSize, base::ThreadTaskRunnerHandle::Get())); |
188 archiver->set_filename(file_name); | 178 archiver->set_filename(file_name); |
189 return archiver; | 179 return archiver; |
190 } | 180 } |
191 | 181 |
192 TEST_F(OfflinePageUtilsTest, CheckExistenceOfPagesWithURL) { | 182 TEST_F(OfflinePageUtilsTest, CheckExistenceOfPagesWithURL) { |
193 bool page_exists = false; | 183 bool page_exists = false; |
194 // This page should be available. | 184 // This page should be available. |
195 OfflinePageUtils::CheckExistenceOfPagesWithURL( | 185 OfflinePageUtils::CheckExistenceOfPagesWithURL( |
196 profile(), kDownloadNamespace, kTestPage1Url, | 186 profile(), kDownloadNamespace, kTestPage1Url, |
197 base::Bind(&BoolCallback, base::Unretained(&page_exists))); | 187 base::Bind(&BoolCallback, base::Unretained(&page_exists))); |
198 RunUntilIdle(); | 188 RunUntilIdle(); |
199 EXPECT_TRUE(page_exists); | 189 EXPECT_TRUE(page_exists); |
200 // This one should be missing | 190 // This one should be missing |
201 OfflinePageUtils::CheckExistenceOfPagesWithURL( | 191 OfflinePageUtils::CheckExistenceOfPagesWithURL( |
202 profile(), kDownloadNamespace, kTestPage3Url, | 192 profile(), kDownloadNamespace, kTestPage3Url, |
203 base::Bind(&BoolCallback, base::Unretained(&page_exists))); | 193 base::Bind(&BoolCallback, base::Unretained(&page_exists))); |
204 RunUntilIdle(); | 194 RunUntilIdle(); |
205 EXPECT_FALSE(page_exists); | 195 EXPECT_FALSE(page_exists); |
206 } | 196 } |
207 | 197 |
208 } // namespace offline_pages | 198 } // namespace offline_pages |
OLD | NEW |