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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_utils_unittest.cc

Issue 2484223005: Store original request URL in offline page metadata table (Closed)
Patch Set: Address feedback Created 4 years, 1 month 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
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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 : public testing::Test, 54 : public testing::Test,
55 public OfflinePageTestArchiver::Observer, 55 public OfflinePageTestArchiver::Observer,
56 public base::SupportsWeakPtr<OfflinePageUtilsTest> { 56 public base::SupportsWeakPtr<OfflinePageUtilsTest> {
57 public: 57 public:
58 OfflinePageUtilsTest(); 58 OfflinePageUtilsTest();
59 ~OfflinePageUtilsTest() override; 59 ~OfflinePageUtilsTest() override;
60 60
61 void SetUp() override; 61 void SetUp() override;
62 void RunUntilIdle(); 62 void RunUntilIdle();
63 63
64 void SavePage(const GURL& url,
65 const ClientId& client_id,
66 std::unique_ptr<OfflinePageArchiver> archiver);
67
64 // Necessary callbacks for the offline page model. 68 // Necessary callbacks for the offline page model.
65 void OnSavePageDone(SavePageResult result, int64_t offlineId); 69 void OnSavePageDone(SavePageResult result, int64_t offlineId);
66 void OnClearAllDone(); 70 void OnClearAllDone();
67 void OnExpirePageDone(bool success); 71 void OnExpirePageDone(bool success);
68 void OnGetURLDone(const GURL& url); 72 void OnGetURLDone(const GURL& url);
69 73
70 // OfflinePageTestArchiver::Observer implementation: 74 // OfflinePageTestArchiver::Observer implementation:
71 void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override; 75 void SetLastPathCreatedByArchiver(const base::FilePath& file_path) override;
72 76
73 TestingProfile* profile() { return &profile_; } 77 TestingProfile* profile() { return &profile_; }
(...skipping 30 matching lines...) Expand all
104 108
105 // Make sure the store contains the right offline pages before the load 109 // Make sure the store contains the right offline pages before the load
106 // happens. 110 // happens.
107 CreateOfflinePages(); 111 CreateOfflinePages();
108 } 112 }
109 113
110 void OfflinePageUtilsTest::RunUntilIdle() { 114 void OfflinePageUtilsTest::RunUntilIdle() {
111 base::RunLoop().RunUntilIdle(); 115 base::RunLoop().RunUntilIdle();
112 } 116 }
113 117
118 void OfflinePageUtilsTest::SavePage(
119 const GURL& url,
120 const ClientId& client_id,
121 std::unique_ptr<OfflinePageArchiver> archiver) {
122 OfflinePageModel::SavePageParams save_page_params;
123 save_page_params.url = url;
124 save_page_params.client_id = client_id;
125 OfflinePageModelFactory::GetForBrowserContext(profile())->SavePage(
126 save_page_params,
127 std::move(archiver),
128 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr()));
129 RunUntilIdle();
130 }
131
114 void OfflinePageUtilsTest::OnSavePageDone(SavePageResult result, 132 void OfflinePageUtilsTest::OnSavePageDone(SavePageResult result,
115 int64_t offline_id) { 133 int64_t offline_id) {
116 offline_id_ = offline_id; 134 offline_id_ = offline_id;
117 } 135 }
118 136
119 void OfflinePageUtilsTest::OnExpirePageDone(bool success) { 137 void OfflinePageUtilsTest::OnExpirePageDone(bool success) {
120 // Result ignored here. 138 // Result ignored here.
121 } 139 }
122 140
123 void OfflinePageUtilsTest::OnClearAllDone() { 141 void OfflinePageUtilsTest::OnClearAllDone() {
(...skipping 10 matching lines...) Expand all
134 void OfflinePageUtilsTest::CreateOfflinePages() { 152 void OfflinePageUtilsTest::CreateOfflinePages() {
135 OfflinePageModel* model = 153 OfflinePageModel* model =
136 OfflinePageModelFactory::GetForBrowserContext(profile()); 154 OfflinePageModelFactory::GetForBrowserContext(profile());
137 155
138 // Create page 1. 156 // Create page 1.
139 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver( 157 std::unique_ptr<OfflinePageTestArchiver> archiver(BuildArchiver(
140 kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml")))); 158 kTestPage1Url, base::FilePath(FILE_PATH_LITERAL("page1.mhtml"))));
141 offline_pages::ClientId client_id; 159 offline_pages::ClientId client_id;
142 client_id.name_space = kDownloadNamespace; 160 client_id.name_space = kDownloadNamespace;
143 client_id.id = kTestPage1ClientId; 161 client_id.id = kTestPage1ClientId;
144 model->SavePage( 162 SavePage(kTestPage1Url, client_id, std::move(archiver));
145 kTestPage1Url, client_id, 0l, std::move(archiver),
146 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr()));
147 RunUntilIdle();
148 163
149 // Create page 2. 164 // Create page 2.
150 archiver = BuildArchiver(kTestPage2Url, 165 archiver = BuildArchiver(kTestPage2Url,
151 base::FilePath(FILE_PATH_LITERAL("page2.mhtml"))); 166 base::FilePath(FILE_PATH_LITERAL("page2.mhtml")));
152 client_id.id = kTestPage2ClientId; 167 client_id.id = kTestPage2ClientId;
153 model->SavePage( 168 SavePage(kTestPage2Url, client_id, std::move(archiver));
154 kTestPage2Url, client_id, 0l, std::move(archiver),
155 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr()));
156 RunUntilIdle();
157 169
158 // Create page 4 - expired page. 170 // Create page 4 - expired page.
159 archiver = BuildArchiver(kTestPage4Url, 171 archiver = BuildArchiver(kTestPage4Url,
160 base::FilePath(FILE_PATH_LITERAL("page4.mhtml"))); 172 base::FilePath(FILE_PATH_LITERAL("page4.mhtml")));
161 client_id.id = kTestPage4ClientId; 173 client_id.id = kTestPage4ClientId;
162 model->SavePage( 174 SavePage(kTestPage4Url, client_id, std::move(archiver));
163 kTestPage4Url, client_id, 0l, std::move(archiver),
164 base::Bind(&OfflinePageUtilsTest::OnSavePageDone, AsWeakPtr()));
165 RunUntilIdle(); 175 RunUntilIdle();
166 model->ExpirePages( 176 model->ExpirePages(
167 std::vector<int64_t>({offline_id()}), base::Time::Now(), 177 std::vector<int64_t>({offline_id()}), base::Time::Now(),
168 base::Bind(&OfflinePageUtilsTest::OnExpirePageDone, AsWeakPtr())); 178 base::Bind(&OfflinePageUtilsTest::OnExpirePageDone, AsWeakPtr()));
169 RunUntilIdle(); 179 RunUntilIdle();
170 } 180 }
171 181
172 std::unique_ptr<OfflinePageTestArchiver> OfflinePageUtilsTest::BuildArchiver( 182 std::unique_ptr<OfflinePageTestArchiver> OfflinePageUtilsTest::BuildArchiver(
173 const GURL& url, 183 const GURL& url,
174 const base::FilePath& file_name) { 184 const base::FilePath& file_name) {
(...skipping 14 matching lines...) Expand all
189 EXPECT_TRUE(page_exists); 199 EXPECT_TRUE(page_exists);
190 // This one should be missing 200 // This one should be missing
191 OfflinePageUtils::CheckExistenceOfPagesWithURL( 201 OfflinePageUtils::CheckExistenceOfPagesWithURL(
192 profile(), kDownloadNamespace, kTestPage3Url, 202 profile(), kDownloadNamespace, kTestPage3Url,
193 base::Bind(&BoolCallback, base::Unretained(&page_exists))); 203 base::Bind(&BoolCallback, base::Unretained(&page_exists)));
194 RunUntilIdle(); 204 RunUntilIdle();
195 EXPECT_FALSE(page_exists); 205 EXPECT_FALSE(page_exists);
196 } 206 }
197 207
198 } // namespace offline_pages 208 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698