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

Side by Side Diff: chrome/service/cloud_print/printer_job_handler_unittest.cc

Issue 1167163002: chrome: Remove use of MessageLoopProxy and deprecated MessageLoop APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added some missing message_loop.h includes. Created 5 years, 6 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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/files/file_path.h" 5 #include "base/files/file_path.h"
6 #include "base/location.h"
6 #include "base/md5.h" 7 #include "base/md5.h"
7 #include "base/memory/ref_counted.h" 8 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "base/message_loop/message_loop_proxy.h" 11 #include "base/single_thread_task_runner.h"
11 #include "base/strings/stringprintf.h" 12 #include "base/strings/stringprintf.h"
13 #include "base/thread_task_runner_handle.h"
12 #include "chrome/common/cloud_print/cloud_print_constants.h" 14 #include "chrome/common/cloud_print/cloud_print_constants.h"
13 #include "chrome/service/cloud_print/cloud_print_service_helpers.h" 15 #include "chrome/service/cloud_print/cloud_print_service_helpers.h"
14 #include "chrome/service/cloud_print/cloud_print_token_store.h" 16 #include "chrome/service/cloud_print/cloud_print_token_store.h"
15 #include "chrome/service/cloud_print/print_system.h" 17 #include "chrome/service/cloud_print/print_system.h"
16 #include "chrome/service/cloud_print/printer_job_handler.h" 18 #include "chrome/service/cloud_print/printer_job_handler.h"
17 #include "net/http/http_response_headers.h" 19 #include "net/http/http_response_headers.h"
18 #include "net/http/http_status_code.h" 20 #include "net/http/http_status_code.h"
19 #include "net/url_request/test_url_fetcher_factory.h" 21 #include "net/url_request/test_url_fetcher_factory.h"
20 #include "net/url_request/url_request_status.h" 22 #include "net/url_request/url_request_status.h"
21 #include "net/url_request/url_request_test_util.h" 23 #include "net/url_request/url_request_test_util.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 status_string, 242 status_string,
241 job_num, 243 job_num,
242 status_string); 244 status_string);
243 } 245 }
244 246
245 } // namespace 247 } // namespace
246 248
247 class CloudPrintURLFetcherNoServiceProcess 249 class CloudPrintURLFetcherNoServiceProcess
248 : public CloudPrintURLFetcher { 250 : public CloudPrintURLFetcher {
249 public: 251 public:
250 CloudPrintURLFetcherNoServiceProcess() : 252 CloudPrintURLFetcherNoServiceProcess()
251 context_getter_(new net::TestURLRequestContextGetter( 253 : context_getter_(new net::TestURLRequestContextGetter(
252 base::MessageLoopProxy::current())) {} 254 base::ThreadTaskRunnerHandle::Get())) {}
255
253 protected: 256 protected:
254 net::URLRequestContextGetter* GetRequestContextGetter() override { 257 net::URLRequestContextGetter* GetRequestContextGetter() override {
255 return context_getter_.get(); 258 return context_getter_.get();
256 } 259 }
257 260
258 ~CloudPrintURLFetcherNoServiceProcess() override {} 261 ~CloudPrintURLFetcherNoServiceProcess() override {}
259 262
260 private: 263 private:
261 scoped_refptr<net::URLRequestContextGetter> context_getter_; 264 scoped_refptr<net::URLRequestContextGetter> context_getter_;
262 }; 265 };
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 net::URLRequestStatus::SUCCESS); 518 net::URLRequestStatus::SUCCESS);
516 } 519 }
517 520
518 void PrinterJobHandlerTest::MessageLoopQuitNowHelper( 521 void PrinterJobHandlerTest::MessageLoopQuitNowHelper(
519 base::MessageLoop* message_loop) { 522 base::MessageLoop* message_loop) {
520 message_loop->QuitWhenIdle(); 523 message_loop->QuitWhenIdle();
521 } 524 }
522 525
523 void PrinterJobHandlerTest::MessageLoopQuitSoonHelper( 526 void PrinterJobHandlerTest::MessageLoopQuitSoonHelper(
524 base::MessageLoop* message_loop) { 527 base::MessageLoop* message_loop) {
525 message_loop->message_loop_proxy()->PostTask( 528 message_loop->task_runner()->PostTask(
526 FROM_HERE, base::Bind(&MessageLoopQuitNowHelper, message_loop)); 529 FROM_HERE, base::Bind(&MessageLoopQuitNowHelper, message_loop));
527 } 530 }
528 531
529 PrinterJobHandlerTest::PrinterJobHandlerTest() 532 PrinterJobHandlerTest::PrinterJobHandlerTest()
530 : factory_(NULL, base::Bind(&TestURLFetcherCallback::CreateURLFetcher, 533 : factory_(NULL, base::Bind(&TestURLFetcherCallback::CreateURLFetcher,
531 base::Unretained(&url_callback_))) { 534 base::Unretained(&url_callback_))) {
532 } 535 }
533 536
534 bool PrinterJobHandlerTest::PostSpoolSuccess() { 537 bool PrinterJobHandlerTest::PostSpoolSuccess() {
535 base::MessageLoop::current()->PostTask( 538 base::ThreadTaskRunnerHandle::Get()->PostTask(
536 FROM_HERE, 539 FROM_HERE,
537 base::Bind(&PrinterJobHandler::OnJobSpoolSucceeded, job_handler_, 0)); 540 base::Bind(&PrinterJobHandler::OnJobSpoolSucceeded, job_handler_, 0));
538 541
539 // Everything that would be posted on the printer thread queue 542 // Everything that would be posted on the printer thread queue
540 // has been posted, we can tell the main message loop to quit when idle 543 // has been posted, we can tell the main message loop to quit when idle
541 // and not worry about it idling while the print thread does work 544 // and not worry about it idling while the print thread does work
542 base::MessageLoop::current()->PostTask( 545 base::ThreadTaskRunnerHandle::Get()->PostTask(
543 FROM_HERE, base::Bind(&MessageLoopQuitSoonHelper, &loop_)); 546 FROM_HERE, base::Bind(&MessageLoopQuitSoonHelper, &loop_));
544 return true; 547 return true;
545 } 548 }
546 549
547 void PrinterJobHandlerTest::AddMimeHeader(const GURL& url, 550 void PrinterJobHandlerTest::AddMimeHeader(const GURL& url,
548 net::FakeURLFetcher* fetcher) { 551 net::FakeURLFetcher* fetcher) {
549 scoped_refptr<net::HttpResponseHeaders> download_headers = 552 scoped_refptr<net::HttpResponseHeaders> download_headers =
550 new net::HttpResponseHeaders(kExampleJobDownloadResponseHeaders); 553 new net::HttpResponseHeaders(kExampleJobDownloadResponseHeaders);
551 fetcher->set_response_headers(download_headers); 554 fetcher->set_response_headers(download_headers);
552 } 555 }
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 OnRequestCreate(JobListURI(kJobFetchReasonRetry), _)) 765 OnRequestCreate(JobListURI(kJobFetchReasonRetry), _))
763 .Times(AtLeast(1)); 766 .Times(AtLeast(1));
764 767
765 SetUpJobSuccessTest(1); 768 SetUpJobSuccessTest(1);
766 769
767 factory_.SetFakeResponse(TicketURI(1), 770 factory_.SetFakeResponse(TicketURI(1),
768 std::string(), 771 std::string(),
769 net::HTTP_INTERNAL_SERVER_ERROR, 772 net::HTTP_INTERNAL_SERVER_ERROR,
770 net::URLRequestStatus::FAILED); 773 net::URLRequestStatus::FAILED);
771 774
772 loop_.PostDelayedTask(FROM_HERE, 775 loop_.task_runner()->PostDelayedTask(
773 base::Bind(&net::FakeURLFetcherFactory::SetFakeResponse, 776 FROM_HERE,
774 base::Unretained(&factory_), 777 base::Bind(&net::FakeURLFetcherFactory::SetFakeResponse,
775 TicketURI(1), 778 base::Unretained(&factory_), TicketURI(1), kExamplePrintTicket,
776 kExamplePrintTicket, 779 net::HTTP_OK, net::URLRequestStatus::SUCCESS),
777 net::HTTP_OK, 780 base::TimeDelta::FromSeconds(1));
778 net::URLRequestStatus::SUCCESS),
779 base::TimeDelta::FromSeconds(1));
780
781 781
782 BeginTest(5); 782 BeginTest(5);
783 } 783 }
784 784
785 785
786 // TODO(noamsml): Figure out how to make this test not take ~64-~2048 (depending 786 // TODO(noamsml): Figure out how to make this test not take ~64-~2048 (depending
787 // constant values) seconds and re-enable it 787 // constant values) seconds and re-enable it
788 TEST_F(PrinterJobHandlerTest, DISABLED_CompleteFailureTest) { 788 TEST_F(PrinterJobHandlerTest, DISABLED_CompleteFailureTest) {
789 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), 789 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup),
790 JobListResponse(1), net::HTTP_OK, 790 JobListResponse(1), net::HTTP_OK,
(...skipping 27 matching lines...) Expand all
818 .WillOnce(InvokeWithoutArgs( 818 .WillOnce(InvokeWithoutArgs(
819 this, &PrinterJobHandlerTest::MakeJobFetchReturnNoJobs)); 819 this, &PrinterJobHandlerTest::MakeJobFetchReturnNoJobs));
820 820
821 EXPECT_CALL(url_callback_, OnRequestCreate(TicketURI(1), _)) 821 EXPECT_CALL(url_callback_, OnRequestCreate(TicketURI(1), _))
822 .Times(AtLeast(kNumRetriesBeforeAbandonJob)); 822 .Times(AtLeast(kNumRetriesBeforeAbandonJob));
823 823
824 BeginTest(70); 824 BeginTest(70);
825 } 825 }
826 826
827 } // namespace cloud_print 827 } // namespace cloud_print
OLDNEW
« no previous file with comments | « chrome/service/cloud_print/printer_job_handler.cc ('k') | chrome/service/net/service_url_request_context_getter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698