| 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 29 matching lines...) Expand all Loading... |
| 40 namespace { | 40 namespace { |
| 41 | 41 |
| 42 const GURL kTestPage1Url("http://test.org/page1"); | 42 const GURL kTestPage1Url("http://test.org/page1"); |
| 43 const GURL kTestPage2Url("http://test.org/page2"); | 43 const GURL kTestPage2Url("http://test.org/page2"); |
| 44 const GURL kTestPage3Url("http://test.org/page3"); | 44 const GURL kTestPage3Url("http://test.org/page3"); |
| 45 const GURL kTestPage4Url("http://test.org/page4"); | 45 const GURL kTestPage4Url("http://test.org/page4"); |
| 46 const int64_t kTestFileSize = 876543LL; | 46 const int64_t kTestFileSize = 876543LL; |
| 47 const char* kTestPage1ClientId = "1234"; | 47 const char* kTestPage1ClientId = "1234"; |
| 48 const char* kTestPage2ClientId = "5678"; | 48 const char* kTestPage2ClientId = "5678"; |
| 49 const char* kTestPage3ClientId = "7890"; | 49 const char* kTestPage3ClientId = "7890"; |
| 50 const char* kTestPage4ClientId = "9876"; | |
| 51 | 50 |
| 52 void HasDuplicatesCallback(bool* out_has_duplicates, | 51 void HasDuplicatesCallback(bool* out_has_duplicates, |
| 53 base::Time* out_latest_saved_time, | 52 base::Time* out_latest_saved_time, |
| 54 bool has_duplicates, | 53 bool has_duplicates, |
| 55 const base::Time& latest_saved_time) { | 54 const base::Time& latest_saved_time) { |
| 56 DCHECK(out_has_duplicates); | 55 DCHECK(out_has_duplicates); |
| 57 DCHECK(out_latest_saved_time); | 56 DCHECK(out_latest_saved_time); |
| 58 *out_has_duplicates = has_duplicates; | 57 *out_has_duplicates = has_duplicates; |
| 59 *out_latest_saved_time = latest_saved_time; | 58 *out_latest_saved_time = latest_saved_time; |
| 60 } | 59 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 } | 160 } |
| 162 | 161 |
| 163 void OfflinePageUtilsTest::OnGetURLDone(const GURL& url) { | 162 void OfflinePageUtilsTest::OnGetURLDone(const GURL& url) { |
| 164 url_ = url; | 163 url_ = url; |
| 165 } | 164 } |
| 166 | 165 |
| 167 void OfflinePageUtilsTest::SetLastPathCreatedByArchiver( | 166 void OfflinePageUtilsTest::SetLastPathCreatedByArchiver( |
| 168 const base::FilePath& file_path) {} | 167 const base::FilePath& file_path) {} |
| 169 | 168 |
| 170 void OfflinePageUtilsTest::CreateOfflinePages() { | 169 void OfflinePageUtilsTest::CreateOfflinePages() { |
| 171 OfflinePageModel* model = | |
| 172 OfflinePageModelFactory::GetForBrowserContext(profile()); | |
| 173 | |
| 174 // Create page 1. | 170 // Create page 1. |
| 175 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( | 171 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( |
| 176 kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); | 172 kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); |
| 177 offline_pages::ClientId client_id; | 173 offline_pages::ClientId client_id; |
| 178 client_id.name_space = kDownloadNamespace; | 174 client_id.name_space = kDownloadNamespace; |
| 179 client_id.id = kTestPage1ClientId; | 175 client_id.id = kTestPage1ClientId; |
| 180 SavePage(kTestPage1Url, client_id, std::move(archiver)); | 176 SavePage(kTestPage1Url, client_id, std::move(archiver)); |
| 181 | 177 |
| 182 // Create page 2. | 178 // Create page 2. |
| 183 archiver = BuildArchiver(kTestPage2Url, | 179 archiver = BuildArchiver(kTestPage2Url, |
| 184 base::FilePath(FILE_PATH_LITERAL("page2.mhtml"))); | 180 base::FilePath(FILE_PATH_LITERAL("page2.mhtml"))); |
| 185 client_id.id = kTestPage2ClientId; | 181 client_id.id = kTestPage2ClientId; |
| 186 SavePage(kTestPage2Url, client_id, std::move(archiver)); | 182 SavePage(kTestPage2Url, client_id, std::move(archiver)); |
| 187 | |
| 188 // Create page 4 - expired page. | |
| 189 archiver = BuildArchiver(kTestPage4Url, | |
| 190 base::FilePath(FILE_PATH_LITERAL("page4.mhtml"))); | |
| 191 client_id.id = kTestPage4ClientId; | |
| 192 SavePage(kTestPage4Url, client_id, std::move(archiver)); | |
| 193 RunUntilIdle(); | |
| 194 model->ExpirePages( | |
| 195 std::vector<int64_t>({offline_id()}), base::Time::Now(), | |
| 196 base::Bind(&OfflinePageUtilsTest::OnExpirePageDone, AsWeakPtr())); | |
| 197 RunUntilIdle(); | |
| 198 } | 183 } |
| 199 | 184 |
| 200 void OfflinePageUtilsTest::CreateRequests() { | 185 void OfflinePageUtilsTest::CreateRequests() { |
| 201 RequestCoordinator* request_coordinator = | 186 RequestCoordinator* request_coordinator = |
| 202 RequestCoordinatorFactory::GetForBrowserContext(profile()); | 187 RequestCoordinatorFactory::GetForBrowserContext(profile()); |
| 203 | 188 |
| 204 offline_pages::ClientId client_id; | 189 offline_pages::ClientId client_id; |
| 205 client_id.name_space = kDownloadNamespace; | 190 client_id.name_space = kDownloadNamespace; |
| 206 client_id.id = kTestPage3ClientId; | 191 client_id.id = kTestPage3ClientId; |
| 207 request_coordinator->SavePageLater( | 192 request_coordinator->SavePageLater( |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 GURL("http://example.com/"), GURL("http://example.com/#test"))); | 254 GURL("http://example.com/"), GURL("http://example.com/#test"))); |
| 270 EXPECT_TRUE(OfflinePageUtils::EqualsIgnoringFragment( | 255 EXPECT_TRUE(OfflinePageUtils::EqualsIgnoringFragment( |
| 271 GURL("http://example.com/#test"), GURL("http://example.com/"))); | 256 GURL("http://example.com/#test"), GURL("http://example.com/"))); |
| 272 EXPECT_TRUE(OfflinePageUtils::EqualsIgnoringFragment( | 257 EXPECT_TRUE(OfflinePageUtils::EqualsIgnoringFragment( |
| 273 GURL("http://example.com/#test"), GURL("http://example.com/#test2"))); | 258 GURL("http://example.com/#test"), GURL("http://example.com/#test2"))); |
| 274 EXPECT_FALSE(OfflinePageUtils::EqualsIgnoringFragment( | 259 EXPECT_FALSE(OfflinePageUtils::EqualsIgnoringFragment( |
| 275 GURL("http://example.com/"), GURL("http://test.com/#test"))); | 260 GURL("http://example.com/"), GURL("http://test.com/#test"))); |
| 276 } | 261 } |
| 277 | 262 |
| 278 } // namespace offline_pages | 263 } // namespace offline_pages |
| OLD | NEW |