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

Side by Side Diff: components/offline_pages/background/request_coordinator_unittest.cc

Issue 2104393002: Adds UMA for PrerenderingOffliner request processing result status. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix rename in unittest (from merge). 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 "components/offline_pages/background/request_coordinator.h" 5 #include "components/offline_pages/background/request_coordinator.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 base::Bind(callback, request, Offliner::RequestStatus::SAVED)); 82 base::Bind(callback, request, Offliner::RequestStatus::SAVED));
83 } 83 }
84 return true; 84 return true;
85 } 85 }
86 86
87 // Clears the currently processing request, if any. Must have called 87 // Clears the currently processing request, if any. Must have called
88 // LoadAndSave first to set the callback and request. 88 // LoadAndSave first to set the callback and request.
89 // Clears the currently processing request, if any. 89 // Clears the currently processing request, if any.
90 void Cancel() override { 90 void Cancel() override {
91 base::ThreadTaskRunnerHandle::Get()->PostTask( 91 base::ThreadTaskRunnerHandle::Get()->PostTask(
92 FROM_HERE, 92 FROM_HERE, base::Bind(callback_, request_,
93 base::Bind(callback_, request_, Offliner::RequestStatus::CANCELED)); 93 Offliner::RequestStatus::PRERENDERING_CANCELED));
94 } 94 }
95 95
96 void enable_callback(bool enable) { 96 void enable_callback(bool enable) {
97 enable_callback_ = enable; 97 enable_callback_ = enable;
98 } 98 }
99 99
100 private: 100 private:
101 CompletionCallback callback_; 101 CompletionCallback callback_;
102 SavePageRequest request_; 102 SavePageRequest request_;
103 bool enable_callback_; 103 bool enable_callback_;
104 }; 104 };
105 105
106 class OfflinerFactoryStub : public OfflinerFactory { 106 class OfflinerFactoryStub : public OfflinerFactory {
107 public: 107 public:
108
109 OfflinerFactoryStub() : offliner_(nullptr) {} 108 OfflinerFactoryStub() : offliner_(nullptr) {}
110 109
111 Offliner* GetOffliner(const OfflinerPolicy* policy) override { 110 Offliner* GetOffliner(const OfflinerPolicy* policy) override {
112 if (offliner_.get() == nullptr) { 111 if (offliner_.get() == nullptr) {
113 offliner_.reset(new OfflinerStub()); 112 offliner_.reset(new OfflinerStub());
114 } 113 }
115 return offliner_.get(); 114 return offliner_.get();
116 } 115 }
117 116
118 private: 117 private:
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // We need to give a callback to the request. 348 // We need to give a callback to the request.
350 base::Callback<void(bool)> callback = 349 base::Callback<void(bool)> callback =
351 base::Bind( 350 base::Bind(
352 &RequestCoordinatorTest::EmptyCallbackFunction, 351 &RequestCoordinatorTest::EmptyCallbackFunction,
353 base::Unretained(this)); 352 base::Unretained(this));
354 coordinator()->SetProcessingCallbackForTest(callback); 353 coordinator()->SetProcessingCallbackForTest(callback);
355 354
356 // Call the OfflinerDoneCallback to simulate the request failed, wait 355 // Call the OfflinerDoneCallback to simulate the request failed, wait
357 // for callbacks. 356 // for callbacks.
358 EnableOfflinerCallback(true); 357 EnableOfflinerCallback(true);
359 SendOfflinerDoneCallback(request, Offliner::RequestStatus::FAILED); 358 SendOfflinerDoneCallback(request,
359 Offliner::RequestStatus::PRERENDERING_FAILED);
360 PumpLoop(); 360 PumpLoop();
361 361
362 // Verify the request is not removed from the queue, and wait for callbacks. 362 // Verify the request is not removed from the queue, and wait for callbacks.
363 coordinator()->queue()->GetRequests( 363 coordinator()->queue()->GetRequests(
364 base::Bind(&RequestCoordinatorTest::GetRequestsDone, 364 base::Bind(&RequestCoordinatorTest::GetRequestsDone,
365 base::Unretained(this))); 365 base::Unretained(this)));
366 PumpLoop(); 366 PumpLoop();
367 367
368 // Still one request in the queue. 368 // Still one request in the queue.
369 EXPECT_EQ(1UL, last_requests().size()); 369 EXPECT_EQ(1UL, last_requests().size());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 PumpLoop(); 427 PumpLoop();
428 428
429 // Now we cancel it while the prerenderer is busy. 429 // Now we cancel it while the prerenderer is busy.
430 coordinator()->StopProcessing(); 430 coordinator()->StopProcessing();
431 431
432 // Let the async callbacks in the cancel run. 432 // Let the async callbacks in the cancel run.
433 PumpLoop(); 433 PumpLoop();
434 434
435 // OfflinerDoneCallback will not end up getting called with status SAVED, 435 // OfflinerDoneCallback will not end up getting called with status SAVED,
436 // Since we cancelled the event before it called offliner_->LoadAndSave(). 436 // Since we cancelled the event before it called offliner_->LoadAndSave().
437 EXPECT_EQ(Offliner::RequestStatus::CANCELED, last_offlining_status()); 437 EXPECT_EQ(Offliner::RequestStatus::PRERENDERING_CANCELED,
438 last_offlining_status());
438 } 439 }
439 440
440 TEST_F(RequestCoordinatorTest, PrerendererTimeout) { 441 TEST_F(RequestCoordinatorTest, PrerendererTimeout) {
441 // Build a request to use with the pre-renderer, and put it on the queue. 442 // Build a request to use with the pre-renderer, and put it on the queue.
442 offline_pages::SavePageRequest request( 443 offline_pages::SavePageRequest request(
443 kRequestId, kUrl, kClientId, base::Time::Now()); 444 kRequestId, kUrl, kClientId, base::Time::Now());
444 coordinator()->queue()->AddRequest( 445 coordinator()->queue()->AddRequest(
445 request, 446 request,
446 base::Bind(&RequestCoordinatorTest::AddRequestDone, 447 base::Bind(&RequestCoordinatorTest::AddRequestDone,
447 base::Unretained(this))); 448 base::Unretained(this)));
(...skipping 23 matching lines...) Expand all
471 AdvanceClockBy(base::TimeDelta::FromSeconds(kTestTimeoutSeconds + 1)); 472 AdvanceClockBy(base::TimeDelta::FromSeconds(kTestTimeoutSeconds + 1));
472 PumpLoop(); 473 PumpLoop();
473 474
474 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner 475 // Wait for timeout to expire. Use a TaskRunner with a DelayedTaskRunner
475 // which won't time out immediately, so the watchdog thread doesn't kill valid 476 // which won't time out immediately, so the watchdog thread doesn't kill valid
476 // tasks too soon. 477 // tasks too soon.
477 WaitForCallback(); 478 WaitForCallback();
478 PumpLoop(); 479 PumpLoop();
479 480
480 // Now trying to start processing on another request should return false. 481 // Now trying to start processing on another request should return false.
481 EXPECT_EQ(Offliner::RequestStatus::CANCELED, last_offlining_status()); 482 EXPECT_EQ(Offliner::RequestStatus::REQUEST_COORDINATOR_CANCELED,
483 last_offlining_status());
482 } 484 }
483 485
484 } // namespace offline_pages 486 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698