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

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

Issue 2380093002: [Offline Pages] SnapshotController support for delay after onLoadCompleted and also parameterized c… (Closed)
Patch Set: Fixed a comment Created 4 years, 2 months 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/recent_tab_helper.h" 5 #include "chrome/browser/android/offline_pages/recent_tab_helper.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/strings/string16.h" 9 #include "base/strings/string16.h"
10 #include "base/test/scoped_feature_list.h" 10 #include "base/test/scoped_feature_list.h"
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 205
206 TEST_F(RecentTabHelperTest, Basic) { 206 TEST_F(RecentTabHelperTest, Basic) {
207 base::test::ScopedFeatureList scoped_feature_list; 207 base::test::ScopedFeatureList scoped_feature_list;
208 scoped_feature_list.Init(); 208 scoped_feature_list.Init();
209 EXPECT_NE(nullptr, recent_tab_helper()); 209 EXPECT_NE(nullptr, recent_tab_helper());
210 } 210 }
211 211
212 TEST_F(RecentTabHelperTest, SimpleCapture) { 212 TEST_F(RecentTabHelperTest, SimpleCapture) {
213 NavigateAndCommit(kTestPageUrl); 213 NavigateAndCommit(kTestPageUrl);
214 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 214 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
215 FastForwardSnapshotController();
215 RunUntilIdle(); 216 RunUntilIdle();
216 EXPECT_TRUE(model()->is_loaded()); 217 EXPECT_TRUE(model()->is_loaded());
217 GetAllPages(); 218 GetAllPages();
218 EXPECT_EQ(1U, all_pages().size()); 219 EXPECT_EQ(1U, all_pages().size());
219 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 220 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
220 } 221 }
221 222
222 TEST_F(RecentTabHelperTest, NoTabIdNoCapture) { 223 TEST_F(RecentTabHelperTest, NoTabIdNoCapture) {
223 // Create delegate that returns 'false' as TabId retrieval result. 224 // Create delegate that returns 'false' as TabId retrieval result.
224 recent_tab_helper()->SetDelegate(base::MakeUnique<TestDelegate>( 225 recent_tab_helper()->SetDelegate(base::MakeUnique<TestDelegate>(
225 this, task_runner(), kTabId, false)); 226 this, task_runner(), kTabId, false));
226 227
227 NavigateAndCommit(kTestPageUrl); 228 NavigateAndCommit(kTestPageUrl);
228 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 229 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
230 FastForwardSnapshotController();
229 RunUntilIdle(); 231 RunUntilIdle();
230 EXPECT_TRUE(model()->is_loaded()); 232 EXPECT_TRUE(model()->is_loaded());
231 GetAllPages(); 233 GetAllPages();
232 // No page should be captured. 234 // No page should be captured.
233 EXPECT_EQ(0U, all_pages().size()); 235 EXPECT_EQ(0U, all_pages().size());
234 } 236 }
235 237
236 // Should end up with 1 page. 238 // Should end up with 1 page.
237 TEST_F(RecentTabHelperTest, TwoCapturesSameUrl) { 239 TEST_F(RecentTabHelperTest, TwoCapturesSameUrl) {
238 NavigateAndCommit(kTestPageUrl); 240 NavigateAndCommit(kTestPageUrl);
239 // Triggers snapshot after a time delay. 241 // Triggers snapshot after a time delay.
240 recent_tab_helper()->DocumentAvailableInMainFrame(); 242 recent_tab_helper()->DocumentAvailableInMainFrame();
241 RunUntilIdle(); 243 RunUntilIdle();
242 EXPECT_TRUE(model()->is_loaded()); 244 EXPECT_TRUE(model()->is_loaded());
243 EXPECT_EQ(0U, model_changed_count()); 245 EXPECT_EQ(0U, model_changed_count());
244 // Move the snapshot controller's time forward so it gets past timeouts. 246 // Move the snapshot controller's time forward so it gets past timeouts.
245 FastForwardSnapshotController(); 247 FastForwardSnapshotController();
246 RunUntilIdle(); 248 RunUntilIdle();
247 EXPECT_EQ(1U, model_changed_count()); 249 EXPECT_EQ(1U, model_changed_count());
248 EXPECT_EQ(0U, model_removed_count()); 250 EXPECT_EQ(0U, model_removed_count());
249 GetAllPages(); 251 GetAllPages();
250 EXPECT_EQ(1U, all_pages().size()); 252 EXPECT_EQ(1U, all_pages().size());
251 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 253 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
252 254
253 // Triggers snapshot immediately; 255 // Triggers snapshot after a time delay.
254 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 256 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
257 // Move the snapshot controller's time forward so it gets past timeouts.
258 FastForwardSnapshotController();
255 RunUntilIdle(); 259 RunUntilIdle();
256 EXPECT_EQ(2U, model_changed_count()); 260 EXPECT_EQ(2U, model_changed_count());
257 EXPECT_EQ(1U, model_removed_count()); 261 EXPECT_EQ(1U, model_removed_count());
258 // the same page should be simply overridden. 262 // the same page should be simply overridden.
259 GetAllPages(); 263 GetAllPages();
260 EXPECT_EQ(1U, all_pages().size()); 264 EXPECT_EQ(1U, all_pages().size());
261 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 265 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
262 } 266 }
263 267
264 // Should end up with 1 page. 268 // Should end up with 1 page.
265 TEST_F(RecentTabHelperTest, TwoCapturesDifferentUrls) { 269 TEST_F(RecentTabHelperTest, TwoCapturesDifferentUrls) {
266 NavigateAndCommit(kTestPageUrl); 270 NavigateAndCommit(kTestPageUrl);
267 // Triggers snapshot after a time delay. 271 // Triggers snapshot after a time delay.
268 recent_tab_helper()->DocumentAvailableInMainFrame(); 272 recent_tab_helper()->DocumentAvailableInMainFrame();
269 RunUntilIdle(); 273 RunUntilIdle();
270 EXPECT_TRUE(model()->is_loaded()); 274 EXPECT_TRUE(model()->is_loaded());
271 EXPECT_EQ(0U, model_changed_count()); 275 EXPECT_EQ(0U, model_changed_count());
272 // Move the snapshot controller's time forward so it gets past timeouts. 276 // Move the snapshot controller's time forward so it gets past timeouts.
273 FastForwardSnapshotController(); 277 FastForwardSnapshotController();
274 RunUntilIdle(); 278 RunUntilIdle();
275 EXPECT_EQ(1U, model_changed_count()); 279 EXPECT_EQ(1U, model_changed_count());
276 EXPECT_EQ(0U, model_removed_count()); 280 EXPECT_EQ(0U, model_removed_count());
277 GetAllPages(); 281 GetAllPages();
278 EXPECT_EQ(1U, all_pages().size()); 282 EXPECT_EQ(1U, all_pages().size());
279 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 283 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
280 284
281 NavigateAndCommit(kTestPageUrlOther); 285 NavigateAndCommit(kTestPageUrlOther);
282 // Triggers snapshot immediately; 286 // Triggers snapshot after a time delay.
283 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 287 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
288 // Move the snapshot controller's time forward so it gets past timeouts.
289 FastForwardSnapshotController();
284 RunUntilIdle(); 290 RunUntilIdle();
285 EXPECT_EQ(2U, model_changed_count()); 291 EXPECT_EQ(2U, model_changed_count());
286 EXPECT_EQ(1U, model_removed_count()); 292 EXPECT_EQ(1U, model_removed_count());
287 // the same page should be simply overridden. 293 // the same page should be simply overridden.
288 GetAllPages(); 294 GetAllPages();
289 EXPECT_EQ(1U, all_pages().size()); 295 EXPECT_EQ(1U, all_pages().size());
290 EXPECT_EQ(kTestPageUrlOther, all_pages()[0].url); 296 EXPECT_EQ(kTestPageUrlOther, all_pages()[0].url);
291 } 297 }
292 298
293 TEST_F(RecentTabHelperTest, NoCaptureOnErrorPage) { 299 TEST_F(RecentTabHelperTest, NoCaptureOnErrorPage) {
294 FailLoad(kTestPageUrl); 300 FailLoad(kTestPageUrl);
295 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 301 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
302 FastForwardSnapshotController();
296 RunUntilIdle(); 303 RunUntilIdle();
297 EXPECT_TRUE(model()->is_loaded()); 304 EXPECT_TRUE(model()->is_loaded());
298 GetAllPages(); 305 GetAllPages();
299 EXPECT_EQ(0U, all_pages().size()); 306 EXPECT_EQ(0U, all_pages().size());
300 } 307 }
301 308
302 TEST_F(RecentTabHelperTest, FeatureNotEnabled) { 309 TEST_F(RecentTabHelperTest, FeatureNotEnabled) {
303 base::test::ScopedFeatureList scoped_feature_list; 310 base::test::ScopedFeatureList scoped_feature_list;
304 scoped_feature_list.Init(); 311 scoped_feature_list.Init();
305 NavigateAndCommit(kTestPageUrl); 312 NavigateAndCommit(kTestPageUrl);
306 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 313 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
314 FastForwardSnapshotController();
307 RunUntilIdle(); 315 RunUntilIdle();
308 EXPECT_TRUE(model()->is_loaded()); 316 EXPECT_TRUE(model()->is_loaded());
309 GetAllPages(); 317 GetAllPages();
310 // No page should be captured. 318 // No page should be captured.
311 EXPECT_EQ(0U, all_pages().size()); 319 EXPECT_EQ(0U, all_pages().size());
312 } 320 }
313 321
314 TEST_F(RecentTabHelperTest, DISABLED_DownloadRequest) { 322 TEST_F(RecentTabHelperTest, DISABLED_DownloadRequest) {
315 NavigateAndCommit(kTestPageUrl); 323 NavigateAndCommit(kTestPageUrl);
316 recent_tab_helper()->ObserveAndDownloadCurrentPage( 324 recent_tab_helper()->ObserveAndDownloadCurrentPage(
317 ClientId("download", "id1"), 153l); 325 ClientId("download", "id1"), 153l);
318 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 326 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
319 RunUntilIdle(); 327 RunUntilIdle();
320 EXPECT_TRUE(model()->is_loaded()); 328 EXPECT_TRUE(model()->is_loaded());
321 GetAllPages(); 329 GetAllPages();
322 EXPECT_EQ(1U, all_pages().size()); 330 EXPECT_EQ(1U, all_pages().size());
323 const OfflinePageItem& page = all_pages()[0]; 331 const OfflinePageItem& page = all_pages()[0];
324 EXPECT_EQ(kTestPageUrl, page.url); 332 EXPECT_EQ(kTestPageUrl, page.url);
325 EXPECT_EQ("download", page.client_id.name_space); 333 EXPECT_EQ("download", page.client_id.name_space);
326 EXPECT_EQ("id1", page.client_id.id); 334 EXPECT_EQ("id1", page.client_id.id);
327 EXPECT_EQ(153l, page.offline_id); 335 EXPECT_EQ(153l, page.offline_id);
328 } 336 }
329 337
330 } // namespace offline_pages 338 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/prerendering_loader_unittest.cc ('k') | components/offline_pages/snapshot_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698