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 | 9 |
9 #include "base/callback.h" | 10 #include "base/callback.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/files/file.h" | 12 #include "base/files/file.h" |
12 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
14 #include "base/test/test_simple_task_runner.h" | 15 #include "base/test/test_simple_task_runner.h" |
15 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
16 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" | 17 #include "chrome/browser/android/offline_pages/offline_page_model_factory.h" |
17 #include "chrome/browser/android/offline_pages/test_offline_page_model_builder.h
" | 18 #include "chrome/browser/android/offline_pages/test_offline_page_model_builder.h
" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 } | 115 } |
115 | 116 |
116 void OfflinePageUtilsTest::SetLastPathCreatedByArchiver( | 117 void OfflinePageUtilsTest::SetLastPathCreatedByArchiver( |
117 const base::FilePath& file_path) {} | 118 const base::FilePath& file_path) {} |
118 | 119 |
119 void OfflinePageUtilsTest::CreateOfflinePages() { | 120 void OfflinePageUtilsTest::CreateOfflinePages() { |
120 OfflinePageModel* model = | 121 OfflinePageModel* model = |
121 OfflinePageModelFactory::GetForBrowserContext(profile()); | 122 OfflinePageModelFactory::GetForBrowserContext(profile()); |
122 | 123 |
123 // Create page 1. | 124 // Create page 1. |
124 scoped_ptr<OfflinePageTestArchiver> archiver( | 125 scoped_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( |
125 BuildArchiver(kTestPage1Url, | 126 kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); |
126 base::FilePath(FILE_PATH_LITERAL("page1.mhtml"))) | |
127 .Pass()); | |
128 model->SavePage( | 127 model->SavePage( |
129 kTestPage1Url, kTestPage1BookmarkId, archiver.Pass(), | 128 kTestPage1Url, kTestPage1BookmarkId, std::move(archiver), |
130 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr())); | 129 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr())); |
131 RunUntilIdle(); | 130 RunUntilIdle(); |
132 | 131 |
133 // Create page 2. | 132 // Create page 2. |
134 archiver = BuildArchiver(kTestPage2Url, | 133 archiver = BuildArchiver(kTestPage2Url, |
135 base::FilePath(FILE_PATH_LITERAL("page2.mhtml"))) | 134 base::FilePath(FILE_PATH_LITERAL("page2.mhtml"))); |
136 .Pass(); | |
137 model->SavePage( | 135 model->SavePage( |
138 kTestPage2Url, kTestPage2BookmarkId, archiver.Pass(), | 136 kTestPage2Url, kTestPage2BookmarkId, std::move(archiver), |
139 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr())); | 137 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr())); |
140 RunUntilIdle(); | 138 RunUntilIdle(); |
141 | 139 |
142 // Make a copy of local paths of the two pages stored in the model. | 140 // Make a copy of local paths of the two pages stored in the model. |
143 offline_url_page_1_ = | 141 offline_url_page_1_ = |
144 model->GetPageByBookmarkId(kTestPage1BookmarkId)->GetOfflineURL(); | 142 model->GetPageByBookmarkId(kTestPage1BookmarkId)->GetOfflineURL(); |
145 offline_url_page_2_ = | 143 offline_url_page_2_ = |
146 model->GetPageByBookmarkId(kTestPage2BookmarkId)->GetOfflineURL(); | 144 model->GetPageByBookmarkId(kTestPage2BookmarkId)->GetOfflineURL(); |
147 // Create a file path that is not associated with any offline page. | 145 // Create a file path that is not associated with any offline page. |
148 offline_url_missing_ = net::FilePathToFileURL( | 146 offline_url_missing_ = net::FilePathToFileURL( |
149 profile() | 147 profile() |
150 ->GetPath() | 148 ->GetPath() |
151 .Append(chrome::kOfflinePageArchviesDirname) | 149 .Append(chrome::kOfflinePageArchviesDirname) |
152 .Append(FILE_PATH_LITERAL("missing_file.mhtml"))); | 150 .Append(FILE_PATH_LITERAL("missing_file.mhtml"))); |
153 } | 151 } |
154 | 152 |
155 scoped_ptr<OfflinePageTestArchiver> OfflinePageUtilsTest::BuildArchiver( | 153 scoped_ptr<OfflinePageTestArchiver> OfflinePageUtilsTest::BuildArchiver( |
156 const GURL& url, | 154 const GURL& url, |
157 const base::FilePath& file_name) { | 155 const base::FilePath& file_name) { |
158 scoped_ptr<OfflinePageTestArchiver> archiver(new OfflinePageTestArchiver( | 156 scoped_ptr<OfflinePageTestArchiver> archiver(new OfflinePageTestArchiver( |
159 this, url, OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED, | 157 this, url, OfflinePageArchiver::ArchiverResult::SUCCESSFULLY_CREATED, |
160 kTestFileSize, base::ThreadTaskRunnerHandle::Get())); | 158 kTestFileSize, base::ThreadTaskRunnerHandle::Get())); |
161 archiver->set_filename(file_name); | 159 archiver->set_filename(file_name); |
162 return archiver.Pass(); | 160 return archiver; |
163 } | 161 } |
164 | 162 |
165 // Simple test for offline page model having any pages loaded. | 163 // Simple test for offline page model having any pages loaded. |
166 TEST_F(OfflinePageUtilsTest, HasOfflinePages) { | 164 TEST_F(OfflinePageUtilsTest, HasOfflinePages) { |
167 EXPECT_TRUE(OfflinePageUtils::HasOfflinePages(profile())); | 165 EXPECT_TRUE(OfflinePageUtils::HasOfflinePages(profile())); |
168 | 166 |
169 OfflinePageModelFactory::GetForBrowserContext(profile())->ClearAll( | 167 OfflinePageModelFactory::GetForBrowserContext(profile())->ClearAll( |
170 base::Bind(&OfflinePageUtilsTest::OnClearAllDone, AsWeakPtr())); | 168 base::Bind(&OfflinePageUtilsTest::OnClearAllDone, AsWeakPtr())); |
171 RunUntilIdle(); | 169 RunUntilIdle(); |
172 | 170 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 TEST_F(OfflinePageUtilsTest, HasOfflinePageForOnlineURL) { | 221 TEST_F(OfflinePageUtilsTest, HasOfflinePageForOnlineURL) { |
224 EXPECT_TRUE( | 222 EXPECT_TRUE( |
225 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage1Url)); | 223 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage1Url)); |
226 EXPECT_TRUE( | 224 EXPECT_TRUE( |
227 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage2Url)); | 225 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage2Url)); |
228 EXPECT_FALSE( | 226 EXPECT_FALSE( |
229 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage3Url)); | 227 OfflinePageUtils::HasOfflinePageForOnlineURL(profile(), kTestPage3Url)); |
230 } | 228 } |
231 | 229 |
232 } // namespace offline_pages | 230 } // namespace offline_pages |
OLD | NEW |