| 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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 OfflinePageModel* model = | 148 OfflinePageModel* model = |
| 149 OfflinePageModelFactory::GetForBrowserContext(profile()); | 149 OfflinePageModelFactory::GetForBrowserContext(profile()); |
| 150 | 150 |
| 151 // Create page 1. | 151 // Create page 1. |
| 152 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( | 152 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( |
| 153 kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); | 153 kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); |
| 154 offline_pages::ClientId client_id; | 154 offline_pages::ClientId client_id; |
| 155 client_id.name_space = kBookmarkNamespace; | 155 client_id.name_space = kBookmarkNamespace; |
| 156 client_id.id = kTestPage1ClientId; | 156 client_id.id = kTestPage1ClientId; |
| 157 model->SavePage( | 157 model->SavePage( |
| 158 kTestPage1Url, client_id, std::move(archiver), | 158 kTestPage1Url, client_id, 0ul, std::move(archiver), |
| 159 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr())); | 159 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr())); |
| 160 RunUntilIdle(); | 160 RunUntilIdle(); |
| 161 offline_url_page_1_ = | 161 offline_url_page_1_ = |
| 162 model->MaybeGetPageByOfflineId(offline_id())->GetOfflineURL(); | 162 model->MaybeGetPageByOfflineId(offline_id())->GetOfflineURL(); |
| 163 | 163 |
| 164 // Create page 2. | 164 // Create page 2. |
| 165 archiver = BuildArchiver(kTestPage2Url, | 165 archiver = BuildArchiver(kTestPage2Url, |
| 166 base::FilePath(FILE_PATH_LITERAL("page2.mhtml"))); | 166 base::FilePath(FILE_PATH_LITERAL("page2.mhtml"))); |
| 167 client_id.id = kTestPage2ClientId; | 167 client_id.id = kTestPage2ClientId; |
| 168 model->SavePage( | 168 model->SavePage( |
| 169 kTestPage2Url, client_id, std::move(archiver), | 169 kTestPage2Url, client_id, 0ul, std::move(archiver), |
| 170 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr())); | 170 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr())); |
| 171 RunUntilIdle(); | 171 RunUntilIdle(); |
| 172 offline_url_page_2_ = | 172 offline_url_page_2_ = |
| 173 model->MaybeGetPageByOfflineId(offline_id())->GetOfflineURL(); | 173 model->MaybeGetPageByOfflineId(offline_id())->GetOfflineURL(); |
| 174 | 174 |
| 175 // Page 3 is not created, as it is missing. | 175 // Page 3 is not created, as it is missing. |
| 176 // Create a file path that is not associated with any offline page. | 176 // Create a file path that is not associated with any offline page. |
| 177 offline_url_missing_ = net::FilePathToFileURL( | 177 offline_url_missing_ = net::FilePathToFileURL( |
| 178 profile() | 178 profile() |
| 179 ->GetPath() | 179 ->GetPath() |
| 180 .Append(chrome::kOfflinePageArchivesDirname) | 180 .Append(chrome::kOfflinePageArchivesDirname) |
| 181 .Append(FILE_PATH_LITERAL("missing_file.mhtml"))); | 181 .Append(FILE_PATH_LITERAL("missing_file.mhtml"))); |
| 182 | 182 |
| 183 // Create page 4 - expired page. | 183 // Create page 4 - expired page. |
| 184 archiver = BuildArchiver(kTestPage4Url, | 184 archiver = BuildArchiver(kTestPage4Url, |
| 185 base::FilePath(FILE_PATH_LITERAL("page4.mhtml"))); | 185 base::FilePath(FILE_PATH_LITERAL("page4.mhtml"))); |
| 186 client_id.id = kTestPage4ClientId; | 186 client_id.id = kTestPage4ClientId; |
| 187 model->SavePage( | 187 model->SavePage( |
| 188 kTestPage4Url, client_id, std::move(archiver), | 188 kTestPage4Url, client_id, 0ul, std::move(archiver), |
| 189 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr())); | 189 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr())); |
| 190 RunUntilIdle(); | 190 RunUntilIdle(); |
| 191 const OfflinePageItem* page_4 = model->MaybeGetPageByOfflineId(offline_id()); | 191 const OfflinePageItem* page_4 = model->MaybeGetPageByOfflineId(offline_id()); |
| 192 offline_url_expired_ = page_4->GetOfflineURL(); | 192 offline_url_expired_ = page_4->GetOfflineURL(); |
| 193 model->ExpirePages( | 193 model->ExpirePages( |
| 194 std::vector<int64_t>({offline_id()}), base::Time::Now(), | 194 std::vector<int64_t>({offline_id()}), base::Time::Now(), |
| 195 base::Bind(&OfflinePageUtilsTest::OnExpirePageDone, AsWeakPtr())); | 195 base::Bind(&OfflinePageUtilsTest::OnExpirePageDone, AsWeakPtr())); |
| 196 RunUntilIdle(); | 196 RunUntilIdle(); |
| 197 } | 197 } |
| 198 | 198 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 EXPECT_FALSE( | 234 EXPECT_FALSE( |
| 235 OfflinePageUtils::IsOfflinePage(profile(), offline_url_missing())); | 235 OfflinePageUtils::IsOfflinePage(profile(), offline_url_missing())); |
| 236 EXPECT_TRUE( | 236 EXPECT_TRUE( |
| 237 OfflinePageUtils::IsOfflinePage(profile(), offline_url_expired())); | 237 OfflinePageUtils::IsOfflinePage(profile(), offline_url_expired())); |
| 238 EXPECT_FALSE(OfflinePageUtils::IsOfflinePage(profile(), kTestPage1Url)); | 238 EXPECT_FALSE(OfflinePageUtils::IsOfflinePage(profile(), kTestPage1Url)); |
| 239 EXPECT_FALSE(OfflinePageUtils::IsOfflinePage(profile(), kTestPage2Url)); | 239 EXPECT_FALSE(OfflinePageUtils::IsOfflinePage(profile(), kTestPage2Url)); |
| 240 EXPECT_FALSE(OfflinePageUtils::IsOfflinePage(profile(), kTestPage4Url)); | 240 EXPECT_FALSE(OfflinePageUtils::IsOfflinePage(profile(), kTestPage4Url)); |
| 241 } | 241 } |
| 242 | 242 |
| 243 } // namespace offline_pages | 243 } // namespace offline_pages |
| OLD | NEW |