| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/printing/print_job.h" | 5 #include "chrome/browser/printing/print_job.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/printing/print_job_worker.h" | 10 #include "chrome/browser/printing/print_job_worker.h" |
| 11 #include "content/public/browser/notification_registrar.h" | 11 #include "content/public/browser/notification_registrar.h" |
| 12 #include "content/public/browser/notification_service.h" | 12 #include "content/public/browser/notification_service.h" |
| 13 #include "content/public/common/child_process_host.h" | 13 #include "content/public/common/child_process_host.h" |
| 14 #include "content/public/test/test_browser_thread_bundle.h" | 14 #include "content/public/test/test_browser_thread_bundle.h" |
| 15 #include "printing/printed_pages_source.h" | 15 #include "printing/printed_pages_source.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class TestSource : public printing::PrintedPagesSource { | 20 class TestSource : public printing::PrintedPagesSource { |
| 21 public: | 21 public: |
| 22 virtual base::string16 RenderSourceName() override { | 22 base::string16 RenderSourceName() override { return base::string16(); } |
| 23 return base::string16(); | |
| 24 } | |
| 25 }; | 23 }; |
| 26 | 24 |
| 27 class TestPrintJobWorker : public printing::PrintJobWorker { | 25 class TestPrintJobWorker : public printing::PrintJobWorker { |
| 28 public: | 26 public: |
| 29 explicit TestPrintJobWorker(printing::PrintJobWorkerOwner* owner) | 27 explicit TestPrintJobWorker(printing::PrintJobWorkerOwner* owner) |
| 30 : printing::PrintJobWorker(content::ChildProcessHost::kInvalidUniqueID, | 28 : printing::PrintJobWorker(content::ChildProcessHost::kInvalidUniqueID, |
| 31 content::ChildProcessHost::kInvalidUniqueID, | 29 content::ChildProcessHost::kInvalidUniqueID, |
| 32 owner) {} | 30 owner) {} |
| 33 friend class TestOwner; | 31 friend class TestOwner; |
| 34 }; | 32 }; |
| 35 | 33 |
| 36 class TestOwner : public printing::PrintJobWorkerOwner { | 34 class TestOwner : public printing::PrintJobWorkerOwner { |
| 37 public: | 35 public: |
| 38 virtual void GetSettingsDone( | 36 void GetSettingsDone(const printing::PrintSettings& new_settings, |
| 39 const printing::PrintSettings& new_settings, | 37 printing::PrintingContext::Result result) override { |
| 40 printing::PrintingContext::Result result) override { | |
| 41 EXPECT_FALSE(true); | 38 EXPECT_FALSE(true); |
| 42 } | 39 } |
| 43 virtual printing::PrintJobWorker* DetachWorker( | 40 printing::PrintJobWorker* DetachWorker( |
| 44 printing::PrintJobWorkerOwner* new_owner) override { | 41 printing::PrintJobWorkerOwner* new_owner) override { |
| 45 // We're screwing up here since we're calling worker from the main thread. | 42 // We're screwing up here since we're calling worker from the main thread. |
| 46 // That's fine for testing. It is actually simulating PrinterQuery behavior. | 43 // That's fine for testing. It is actually simulating PrinterQuery behavior. |
| 47 TestPrintJobWorker* worker(new TestPrintJobWorker(new_owner)); | 44 TestPrintJobWorker* worker(new TestPrintJobWorker(new_owner)); |
| 48 EXPECT_TRUE(worker->Start()); | 45 EXPECT_TRUE(worker->Start()); |
| 49 worker->printing_context()->UseDefaultSettings(); | 46 worker->printing_context()->UseDefaultSettings(); |
| 50 settings_ = worker->printing_context()->settings(); | 47 settings_ = worker->printing_context()->settings(); |
| 51 return worker; | 48 return worker; |
| 52 } | 49 } |
| 53 virtual const printing::PrintSettings& settings() const override { | 50 const printing::PrintSettings& settings() const override { return settings_; } |
| 54 return settings_; | 51 int cookie() const override { return 42; } |
| 55 } | |
| 56 virtual int cookie() const override { | |
| 57 return 42; | |
| 58 } | |
| 59 | 52 |
| 60 private: | 53 private: |
| 61 virtual ~TestOwner() {} | 54 ~TestOwner() override {} |
| 62 | 55 |
| 63 printing::PrintSettings settings_; | 56 printing::PrintSettings settings_; |
| 64 }; | 57 }; |
| 65 | 58 |
| 66 class TestPrintJob : public printing::PrintJob { | 59 class TestPrintJob : public printing::PrintJob { |
| 67 public: | 60 public: |
| 68 explicit TestPrintJob(volatile bool* check) : check_(check) { | 61 explicit TestPrintJob(volatile bool* check) : check_(check) { |
| 69 } | 62 } |
| 70 private: | 63 private: |
| 71 virtual ~TestPrintJob() { | 64 ~TestPrintJob() override { *check_ = true; } |
| 72 *check_ = true; | |
| 73 } | |
| 74 volatile bool* check_; | 65 volatile bool* check_; |
| 75 }; | 66 }; |
| 76 | 67 |
| 77 class TestPrintNotifObserv : public content::NotificationObserver { | 68 class TestPrintNotifObserv : public content::NotificationObserver { |
| 78 public: | 69 public: |
| 79 // content::NotificationObserver | 70 // content::NotificationObserver |
| 80 virtual void Observe(int type, | 71 void Observe(int type, |
| 81 const content::NotificationSource& source, | 72 const content::NotificationSource& source, |
| 82 const content::NotificationDetails& details) override { | 73 const content::NotificationDetails& details) override { |
| 83 ADD_FAILURE(); | 74 ADD_FAILURE(); |
| 84 } | 75 } |
| 85 }; | 76 }; |
| 86 | 77 |
| 87 } // namespace | 78 } // namespace |
| 88 | 79 |
| 89 TEST(PrintJobTest, SimplePrint) { | 80 TEST(PrintJobTest, SimplePrint) { |
| 90 // Test the multi-threaded nature of PrintJob to make sure we can use it with | 81 // Test the multi-threaded nature of PrintJob to make sure we can use it with |
| 91 // known lifetime. | 82 // known lifetime. |
| 92 | 83 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 job->is_job_pending(); | 129 job->is_job_pending(); |
| 139 job->document(); | 130 job->document(); |
| 140 // Private | 131 // Private |
| 141 job->UpdatePrintedDocument(NULL); | 132 job->UpdatePrintedDocument(NULL); |
| 142 scoped_refptr<printing::JobEventDetails> event_details; | 133 scoped_refptr<printing::JobEventDetails> event_details; |
| 143 job->OnNotifyPrintJobEvent(event_details); | 134 job->OnNotifyPrintJobEvent(event_details); |
| 144 job->OnDocumentDone(); | 135 job->OnDocumentDone(); |
| 145 job->ControlledWorkerShutdown(); | 136 job->ControlledWorkerShutdown(); |
| 146 */ | 137 */ |
| 147 } | 138 } |
| OLD | NEW |