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

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

Issue 2149773002: PrerenderingOffliner will abort background load if it sees chrome transitioning to foreground on lo… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Revise some comments wrt app listener setting/clearing Created 4 years, 5 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/prerendering_offliner.h" 5 #include "chrome/browser/android/offline_pages/prerendering_offliner.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/sys_info.h"
11 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
12 #include "chrome/browser/android/offline_pages/prerendering_loader.h" 13 #include "chrome/browser/android/offline_pages/prerendering_loader.h"
13 #include "chrome/test/base/testing_profile.h" 14 #include "chrome/test/base/testing_profile.h"
14 #include "components/offline_pages/background/offliner.h" 15 #include "components/offline_pages/background/offliner.h"
15 #include "components/offline_pages/background/save_page_request.h" 16 #include "components/offline_pages/background/save_page_request.h"
16 #include "components/offline_pages/stub_offline_page_model.h" 17 #include "components/offline_pages/stub_offline_page_model.h"
17 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
18 #include "content/public/test/web_contents_tester.h" 19 #include "content/public/test/web_contents_tester.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 322
322 loader()->CompleteLoadingAsCanceled(); 323 loader()->CompleteLoadingAsCanceled();
323 PumpLoop(); 324 PumpLoop();
324 EXPECT_TRUE(completion_callback_called()); 325 EXPECT_TRUE(completion_callback_called());
325 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED, request_status()); 326 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED, request_status());
326 EXPECT_FALSE(loader()->IsLoaded()); 327 EXPECT_FALSE(loader()->IsLoaded());
327 // Note: save still in progress since it does not support canceling. 328 // Note: save still in progress since it does not support canceling.
328 EXPECT_TRUE(SaveInProgress()); 329 EXPECT_TRUE(SaveInProgress());
329 } 330 }
330 331
332 TEST_F(PrerenderingOfflinerTest, ForegroundTransitionCancelsOnLowEndDevice) {
333 offliner()->SetLowEndDeviceForTesting(true);
334
335 base::Time creation_time = base::Time::Now();
336 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time);
337 EXPECT_TRUE(offliner()->LoadAndSave(request, callback()));
338 EXPECT_FALSE(loader()->IsIdle());
339
340 offliner()->SetApplicationStateForTesting(
341 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES);
342
343 // Loading canceled on low-end device.
344 EXPECT_TRUE(loader()->IsIdle());
345 EXPECT_EQ(Offliner::RequestStatus::FOREGROUND_CANCELED, request_status());
346 }
347
348 TEST_F(PrerenderingOfflinerTest, ForegroundTransitionIgnoredOnHighEndDevice) {
349 offliner()->SetLowEndDeviceForTesting(false);
350
351 base::Time creation_time = base::Time::Now();
352 SavePageRequest request(kRequestId, kHttpUrl, kClientId, creation_time);
353 EXPECT_TRUE(offliner()->LoadAndSave(request, callback()));
354 EXPECT_FALSE(loader()->IsIdle());
355
356 offliner()->SetApplicationStateForTesting(
357 base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES);
358
359 // Loader still loading since not low-end device.
360 EXPECT_FALSE(loader()->IsIdle());
361 }
362
331 } // namespace offline_pages 363 } // namespace offline_pages
OLDNEW
« no previous file with comments | « chrome/browser/android/offline_pages/prerendering_offliner.cc ('k') | components/offline_pages/background/offliner.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698