| OLD | NEW |
| 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/md5.h" | 6 #include "base/md5.h" |
| 7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/message_loop/message_loop_proxy.h" | 10 #include "base/message_loop/message_loop_proxy.h" |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 public: | 378 public: |
| 379 MockPrintSystem(); | 379 MockPrintSystem(); |
| 380 PrintSystem::PrintSystemResult succeed() { | 380 PrintSystem::PrintSystemResult succeed() { |
| 381 return PrintSystem::PrintSystemResult(true, "success"); | 381 return PrintSystem::PrintSystemResult(true, "success"); |
| 382 } | 382 } |
| 383 | 383 |
| 384 PrintSystem::PrintSystemResult fail() { | 384 PrintSystem::PrintSystemResult fail() { |
| 385 return PrintSystem::PrintSystemResult(false, "failure"); | 385 return PrintSystem::PrintSystemResult(false, "failure"); |
| 386 } | 386 } |
| 387 | 387 |
| 388 MockJobSpooler& JobSpooler() { | 388 MockJobSpooler& JobSpooler() { return *job_spooler_.get(); } |
| 389 return *job_spooler_; | |
| 390 } | |
| 391 | 389 |
| 392 MockPrinterWatcher& PrinterWatcher() { | 390 MockPrinterWatcher& PrinterWatcher() { return *printer_watcher_.get(); } |
| 393 return *printer_watcher_; | |
| 394 } | |
| 395 | 391 |
| 396 MockPrintServerWatcher& PrintServerWatcher() { | 392 MockPrintServerWatcher& PrintServerWatcher() { |
| 397 return *print_server_watcher_; | 393 return *print_server_watcher_.get(); |
| 398 } | 394 } |
| 399 | 395 |
| 400 MOCK_METHOD0(Init, PrintSystem::PrintSystemResult()); | 396 MOCK_METHOD0(Init, PrintSystem::PrintSystemResult()); |
| 401 MOCK_METHOD1(EnumeratePrinters, PrintSystem::PrintSystemResult( | 397 MOCK_METHOD1(EnumeratePrinters, PrintSystem::PrintSystemResult( |
| 402 printing::PrinterList* printer_list)); | 398 printing::PrinterList* printer_list)); |
| 403 | 399 |
| 404 MOCK_METHOD2( | 400 MOCK_METHOD2( |
| 405 GetPrinterCapsAndDefaults, | 401 GetPrinterCapsAndDefaults, |
| 406 void(const std::string& printer_name, | 402 void(const std::string& printer_name, |
| 407 const PrintSystem::PrinterCapsAndDefaultsCallback& callback)); | 403 const PrintSystem::PrinterCapsAndDefaultsCallback& callback)); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 484 caps_and_defaults_.printer_defaults = kExampleDefaults; | 480 caps_and_defaults_.printer_defaults = kExampleDefaults; |
| 485 caps_and_defaults_.defaults_mime_type = kExampleDefaultMimeType; | 481 caps_and_defaults_.defaults_mime_type = kExampleDefaultMimeType; |
| 486 | 482 |
| 487 print_system_ = new NiceMock<MockPrintSystem>(); | 483 print_system_ = new NiceMock<MockPrintSystem>(); |
| 488 | 484 |
| 489 token_store_.SetToken(kExampleCloudPrintOAuthToken); | 485 token_store_.SetToken(kExampleCloudPrintOAuthToken); |
| 490 | 486 |
| 491 ON_CALL(print_system_->PrinterWatcher(), GetCurrentPrinterInfo(_)) | 487 ON_CALL(print_system_->PrinterWatcher(), GetCurrentPrinterInfo(_)) |
| 492 .WillByDefault(Invoke(this, &PrinterJobHandlerTest::GetPrinterInfo)); | 488 .WillByDefault(Invoke(this, &PrinterJobHandlerTest::GetPrinterInfo)); |
| 493 | 489 |
| 494 ON_CALL(*print_system_, GetPrinterCapsAndDefaults(_, _)) | 490 ON_CALL(*print_system_.get(), GetPrinterCapsAndDefaults(_, _)) |
| 495 .WillByDefault(Invoke(this, &PrinterJobHandlerTest::SendCapsAndDefaults)); | 491 .WillByDefault(Invoke(this, &PrinterJobHandlerTest::SendCapsAndDefaults)); |
| 496 | 492 |
| 497 CloudPrintURLFetcher::set_factory(&cloud_print_factory_); | 493 CloudPrintURLFetcher::set_factory(&cloud_print_factory_); |
| 498 } | 494 } |
| 499 | 495 |
| 500 void PrinterJobHandlerTest::MakeJobFetchReturnNoJobs() { | 496 void PrinterJobHandlerTest::MakeJobFetchReturnNoJobs() { |
| 501 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), | 497 factory_.SetFakeResponse(JobListURI(kJobFetchReasonStartup), |
| 502 JobListResponse(0), true); | 498 JobListResponse(0), true); |
| 503 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), | 499 factory_.SetFakeResponse(JobListURI(kJobFetchReasonFailure), |
| 504 JobListResponse(0), true); | 500 JobListResponse(0), true); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 .Times(Exactly(1)); | 569 .Times(Exactly(1)); |
| 574 | 570 |
| 575 EXPECT_CALL(print_system_->JobSpooler(), | 571 EXPECT_CALL(print_system_->JobSpooler(), |
| 576 Spool(kExamplePrintTicket, _, _, _, _, _, _)) | 572 Spool(kExamplePrintTicket, _, _, _, _, _, _)) |
| 577 .Times(Exactly(1)) | 573 .Times(Exactly(1)) |
| 578 .WillOnce(InvokeWithoutArgs(this, | 574 .WillOnce(InvokeWithoutArgs(this, |
| 579 &PrinterJobHandlerTest::PostSpoolSuccess)); | 575 &PrinterJobHandlerTest::PostSpoolSuccess)); |
| 580 } | 576 } |
| 581 | 577 |
| 582 void PrinterJobHandlerTest::BeginTest(int timeout_seconds) { | 578 void PrinterJobHandlerTest::BeginTest(int timeout_seconds) { |
| 583 job_handler_ = new PrinterJobHandler(basic_info_, info_from_cloud_, | 579 job_handler_ = new PrinterJobHandler(basic_info_, |
| 580 info_from_cloud_, |
| 584 GURL(kExampleCloudPrintServerURL), | 581 GURL(kExampleCloudPrintServerURL), |
| 585 print_system_, &jobhandler_delegate_); | 582 print_system_.get(), |
| 583 &jobhandler_delegate_); |
| 586 | 584 |
| 587 job_handler_->Initialize(); | 585 job_handler_->Initialize(); |
| 588 | 586 |
| 589 base::MessageLoop::current()->PostDelayedTask( | 587 base::MessageLoop::current()->PostDelayedTask( |
| 590 FROM_HERE, | 588 FROM_HERE, |
| 591 base::Bind(&PrinterJobHandlerTest::MessageLoopQuitSoonHelper, | 589 base::Bind(&PrinterJobHandlerTest::MessageLoopQuitSoonHelper, |
| 592 base::MessageLoop::current()), | 590 base::MessageLoop::current()), |
| 593 base::TimeDelta::FromSeconds(timeout_seconds)); | 591 base::TimeDelta::FromSeconds(timeout_seconds)); |
| 594 | 592 |
| 595 base::MessageLoop::current()->Run(); | 593 base::MessageLoop::current()->Run(); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 .WillOnce(InvokeWithoutArgs( | 773 .WillOnce(InvokeWithoutArgs( |
| 776 this, &PrinterJobHandlerTest::MakeJobFetchReturnNoJobs)); | 774 this, &PrinterJobHandlerTest::MakeJobFetchReturnNoJobs)); |
| 777 | 775 |
| 778 EXPECT_CALL(url_callback_, OnRequestCreate(GURL(TicketURI(1)), _)) | 776 EXPECT_CALL(url_callback_, OnRequestCreate(GURL(TicketURI(1)), _)) |
| 779 .Times(AtLeast(kNumRetriesBeforeAbandonJob)); | 777 .Times(AtLeast(kNumRetriesBeforeAbandonJob)); |
| 780 | 778 |
| 781 BeginTest(70); | 779 BeginTest(70); |
| 782 } | 780 } |
| 783 | 781 |
| 784 } // namespace cloud_print | 782 } // namespace cloud_print |
| OLD | NEW |