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

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: 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 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 EXPECT_FALSE(recent_tab_helper()->is_page_ready_for_snapshot()); 214 EXPECT_FALSE(recent_tab_helper()->is_page_ready_for_snapshot());
215 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 215 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
216 FastForwardSnapshotController();
216 RunUntilIdle(); 217 RunUntilIdle();
217 EXPECT_TRUE(recent_tab_helper()->is_page_ready_for_snapshot()); 218 EXPECT_TRUE(recent_tab_helper()->is_page_ready_for_snapshot());
218 EXPECT_TRUE(model()->is_loaded()); 219 EXPECT_TRUE(model()->is_loaded());
219 GetAllPages(); 220 GetAllPages();
220 EXPECT_EQ(1U, all_pages().size()); 221 EXPECT_EQ(1U, all_pages().size());
221 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 222 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
222 } 223 }
223 224
224 TEST_F(RecentTabHelperTest, NoTabIdNoCapture) { 225 TEST_F(RecentTabHelperTest, NoTabIdNoCapture) {
225 // Create delegate that returns 'false' as TabId retrieval result. 226 // Create delegate that returns 'false' as TabId retrieval result.
226 recent_tab_helper()->SetDelegate(base::MakeUnique<TestDelegate>( 227 recent_tab_helper()->SetDelegate(base::MakeUnique<TestDelegate>(
227 this, task_runner(), kTabId, false)); 228 this, task_runner(), kTabId, false));
228 229
229 NavigateAndCommit(kTestPageUrl); 230 NavigateAndCommit(kTestPageUrl);
230 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 231 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
232 FastForwardSnapshotController();
231 RunUntilIdle(); 233 RunUntilIdle();
232 EXPECT_TRUE(model()->is_loaded()); 234 EXPECT_TRUE(model()->is_loaded());
233 GetAllPages(); 235 GetAllPages();
234 // No page should be captured. 236 // No page should be captured.
235 EXPECT_EQ(0U, all_pages().size()); 237 EXPECT_EQ(0U, all_pages().size());
236 } 238 }
237 239
238 // Should end up with 1 page. 240 // Should end up with 1 page.
239 TEST_F(RecentTabHelperTest, TwoCapturesSameUrl) { 241 TEST_F(RecentTabHelperTest, TwoCapturesSameUrl) {
240 NavigateAndCommit(kTestPageUrl); 242 NavigateAndCommit(kTestPageUrl);
241 // Triggers snapshot after a time delay. 243 // Triggers snapshot after a time delay.
242 recent_tab_helper()->DocumentAvailableInMainFrame(); 244 recent_tab_helper()->DocumentAvailableInMainFrame();
243 RunUntilIdle(); 245 RunUntilIdle();
244 EXPECT_TRUE(model()->is_loaded()); 246 EXPECT_TRUE(model()->is_loaded());
245 EXPECT_EQ(0U, model_changed_count()); 247 EXPECT_EQ(0U, model_changed_count());
246 // Move the snapshot controller's time forward so it gets past timeouts. 248 // Move the snapshot controller's time forward so it gets past timeouts.
247 FastForwardSnapshotController(); 249 FastForwardSnapshotController();
248 RunUntilIdle(); 250 RunUntilIdle();
249 EXPECT_EQ(1U, model_changed_count()); 251 EXPECT_EQ(1U, model_changed_count());
250 EXPECT_EQ(0U, model_removed_count()); 252 EXPECT_EQ(0U, model_removed_count());
251 GetAllPages(); 253 GetAllPages();
252 EXPECT_EQ(1U, all_pages().size()); 254 EXPECT_EQ(1U, all_pages().size());
253 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 255 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
254 256
255 // Triggers snapshot immediately; 257 // Triggers snapshot after a time delay.
256 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 258 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
259 // Move the snapshot controller's time forward so it gets past timeouts.
260 FastForwardSnapshotController();
257 RunUntilIdle(); 261 RunUntilIdle();
258 EXPECT_EQ(2U, model_changed_count()); 262 EXPECT_EQ(2U, model_changed_count());
259 EXPECT_EQ(1U, model_removed_count()); 263 EXPECT_EQ(1U, model_removed_count());
260 // the same page should be simply overridden. 264 // the same page should be simply overridden.
261 GetAllPages(); 265 GetAllPages();
262 EXPECT_EQ(1U, all_pages().size()); 266 EXPECT_EQ(1U, all_pages().size());
263 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 267 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
264 } 268 }
265 269
266 // Should end up with 1 page. 270 // Should end up with 1 page.
267 TEST_F(RecentTabHelperTest, TwoCapturesDifferentUrls) { 271 TEST_F(RecentTabHelperTest, TwoCapturesDifferentUrls) {
268 NavigateAndCommit(kTestPageUrl); 272 NavigateAndCommit(kTestPageUrl);
269 // Triggers snapshot after a time delay. 273 // Triggers snapshot after a time delay.
270 recent_tab_helper()->DocumentAvailableInMainFrame(); 274 recent_tab_helper()->DocumentAvailableInMainFrame();
271 RunUntilIdle(); 275 RunUntilIdle();
272 EXPECT_TRUE(model()->is_loaded()); 276 EXPECT_TRUE(model()->is_loaded());
273 EXPECT_EQ(0U, model_changed_count()); 277 EXPECT_EQ(0U, model_changed_count());
274 // Move the snapshot controller's time forward so it gets past timeouts. 278 // Move the snapshot controller's time forward so it gets past timeouts.
275 FastForwardSnapshotController(); 279 FastForwardSnapshotController();
276 RunUntilIdle(); 280 RunUntilIdle();
277 EXPECT_EQ(1U, model_changed_count()); 281 EXPECT_EQ(1U, model_changed_count());
278 EXPECT_EQ(0U, model_removed_count()); 282 EXPECT_EQ(0U, model_removed_count());
279 GetAllPages(); 283 GetAllPages();
280 EXPECT_EQ(1U, all_pages().size()); 284 EXPECT_EQ(1U, all_pages().size());
281 EXPECT_EQ(kTestPageUrl, all_pages()[0].url); 285 EXPECT_EQ(kTestPageUrl, all_pages()[0].url);
282 286
283 NavigateAndCommit(kTestPageUrlOther); 287 NavigateAndCommit(kTestPageUrlOther);
284 // Triggers snapshot immediately; 288 // Triggers snapshot after a time delay.
285 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 289 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
290 // Move the snapshot controller's time forward so it gets past timeouts.
291 FastForwardSnapshotController();
286 RunUntilIdle(); 292 RunUntilIdle();
287 EXPECT_EQ(2U, model_changed_count()); 293 EXPECT_EQ(2U, model_changed_count());
288 EXPECT_EQ(1U, model_removed_count()); 294 EXPECT_EQ(1U, model_removed_count());
289 // the same page should be simply overridden. 295 // the same page should be simply overridden.
290 GetAllPages(); 296 GetAllPages();
291 EXPECT_EQ(1U, all_pages().size()); 297 EXPECT_EQ(1U, all_pages().size());
292 EXPECT_EQ(kTestPageUrlOther, all_pages()[0].url); 298 EXPECT_EQ(kTestPageUrlOther, all_pages()[0].url);
293 } 299 }
294 300
295 TEST_F(RecentTabHelperTest, NoCaptureOnErrorPage) { 301 TEST_F(RecentTabHelperTest, NoCaptureOnErrorPage) {
296 FailLoad(kTestPageUrl); 302 FailLoad(kTestPageUrl);
297 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 303 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
304 FastForwardSnapshotController();
298 RunUntilIdle(); 305 RunUntilIdle();
299 EXPECT_TRUE(model()->is_loaded()); 306 EXPECT_TRUE(model()->is_loaded());
300 GetAllPages(); 307 GetAllPages();
301 EXPECT_EQ(0U, all_pages().size()); 308 EXPECT_EQ(0U, all_pages().size());
302 } 309 }
303 310
304 TEST_F(RecentTabHelperTest, FeatureNotEnabled) { 311 TEST_F(RecentTabHelperTest, FeatureNotEnabled) {
305 base::test::ScopedFeatureList scoped_feature_list; 312 base::test::ScopedFeatureList scoped_feature_list;
306 scoped_feature_list.Init(); 313 scoped_feature_list.Init();
307 NavigateAndCommit(kTestPageUrl); 314 NavigateAndCommit(kTestPageUrl);
308 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame(); 315 recent_tab_helper()->DocumentOnLoadCompletedInMainFrame();
316 FastForwardSnapshotController();
309 RunUntilIdle(); 317 RunUntilIdle();
310 EXPECT_TRUE(model()->is_loaded()); 318 EXPECT_TRUE(model()->is_loaded());
311 GetAllPages(); 319 GetAllPages();
312 // No page should be captured. 320 // No page should be captured.
313 EXPECT_EQ(0U, all_pages().size()); 321 EXPECT_EQ(0U, all_pages().size());
314 } 322 }
315 323
316 } // namespace offline_pages 324 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698