| 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 virtual base::string16 RenderSourceName() override { |
| 23 return base::string16(); | 23 return base::string16(); |
| 24 } | 24 } |
| 25 }; | 25 }; |
| 26 | 26 |
| 27 class TestPrintJobWorker : public printing::PrintJobWorker { | 27 class TestPrintJobWorker : public printing::PrintJobWorker { |
| 28 public: | 28 public: |
| 29 explicit TestPrintJobWorker(printing::PrintJobWorkerOwner* owner) | 29 explicit TestPrintJobWorker(printing::PrintJobWorkerOwner* owner) |
| 30 : printing::PrintJobWorker(content::ChildProcessHost::kInvalidUniqueID, | 30 : printing::PrintJobWorker(content::ChildProcessHost::kInvalidUniqueID, |
| 31 content::ChildProcessHost::kInvalidUniqueID, | 31 content::ChildProcessHost::kInvalidUniqueID, |
| 32 owner) {} | 32 owner) {} |
| 33 friend class TestOwner; | 33 friend class TestOwner; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 class TestOwner : public printing::PrintJobWorkerOwner { | 36 class TestOwner : public printing::PrintJobWorkerOwner { |
| 37 public: | 37 public: |
| 38 virtual void GetSettingsDone( | 38 virtual void GetSettingsDone( |
| 39 const printing::PrintSettings& new_settings, | 39 const printing::PrintSettings& new_settings, |
| 40 printing::PrintingContext::Result result) OVERRIDE { | 40 printing::PrintingContext::Result result) override { |
| 41 EXPECT_FALSE(true); | 41 EXPECT_FALSE(true); |
| 42 } | 42 } |
| 43 virtual printing::PrintJobWorker* DetachWorker( | 43 virtual printing::PrintJobWorker* DetachWorker( |
| 44 printing::PrintJobWorkerOwner* new_owner) OVERRIDE { | 44 printing::PrintJobWorkerOwner* new_owner) override { |
| 45 // We're screwing up here since we're calling worker from the main thread. | 45 // 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. | 46 // That's fine for testing. It is actually simulating PrinterQuery behavior. |
| 47 TestPrintJobWorker* worker(new TestPrintJobWorker(new_owner)); | 47 TestPrintJobWorker* worker(new TestPrintJobWorker(new_owner)); |
| 48 EXPECT_TRUE(worker->Start()); | 48 EXPECT_TRUE(worker->Start()); |
| 49 worker->printing_context()->UseDefaultSettings(); | 49 worker->printing_context()->UseDefaultSettings(); |
| 50 settings_ = worker->printing_context()->settings(); | 50 settings_ = worker->printing_context()->settings(); |
| 51 return worker; | 51 return worker; |
| 52 } | 52 } |
| 53 virtual const printing::PrintSettings& settings() const OVERRIDE { | 53 virtual const printing::PrintSettings& settings() const override { |
| 54 return settings_; | 54 return settings_; |
| 55 } | 55 } |
| 56 virtual int cookie() const OVERRIDE { | 56 virtual int cookie() const override { |
| 57 return 42; | 57 return 42; |
| 58 } | 58 } |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 virtual ~TestOwner() {} | 61 virtual ~TestOwner() {} |
| 62 | 62 |
| 63 printing::PrintSettings settings_; | 63 printing::PrintSettings settings_; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 class TestPrintJob : public printing::PrintJob { | 66 class TestPrintJob : public printing::PrintJob { |
| 67 public: | 67 public: |
| 68 explicit TestPrintJob(volatile bool* check) : check_(check) { | 68 explicit TestPrintJob(volatile bool* check) : check_(check) { |
| 69 } | 69 } |
| 70 private: | 70 private: |
| 71 virtual ~TestPrintJob() { | 71 virtual ~TestPrintJob() { |
| 72 *check_ = true; | 72 *check_ = true; |
| 73 } | 73 } |
| 74 volatile bool* check_; | 74 volatile bool* check_; |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 class TestPrintNotifObserv : public content::NotificationObserver { | 77 class TestPrintNotifObserv : public content::NotificationObserver { |
| 78 public: | 78 public: |
| 79 // content::NotificationObserver | 79 // content::NotificationObserver |
| 80 virtual void Observe(int type, | 80 virtual void Observe(int type, |
| 81 const content::NotificationSource& source, | 81 const content::NotificationSource& source, |
| 82 const content::NotificationDetails& details) OVERRIDE { | 82 const content::NotificationDetails& details) override { |
| 83 ADD_FAILURE(); | 83 ADD_FAILURE(); |
| 84 } | 84 } |
| 85 }; | 85 }; |
| 86 | 86 |
| 87 } // namespace | 87 } // namespace |
| 88 | 88 |
| 89 TEST(PrintJobTest, SimplePrint) { | 89 TEST(PrintJobTest, SimplePrint) { |
| 90 // Test the multi-threaded nature of PrintJob to make sure we can use it with | 90 // Test the multi-threaded nature of PrintJob to make sure we can use it with |
| 91 // known lifetime. | 91 // known lifetime. |
| 92 | 92 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 job->is_job_pending(); | 138 job->is_job_pending(); |
| 139 job->document(); | 139 job->document(); |
| 140 // Private | 140 // Private |
| 141 job->UpdatePrintedDocument(NULL); | 141 job->UpdatePrintedDocument(NULL); |
| 142 scoped_refptr<printing::JobEventDetails> event_details; | 142 scoped_refptr<printing::JobEventDetails> event_details; |
| 143 job->OnNotifyPrintJobEvent(event_details); | 143 job->OnNotifyPrintJobEvent(event_details); |
| 144 job->OnDocumentDone(); | 144 job->OnDocumentDone(); |
| 145 job->ControlledWorkerShutdown(); | 145 job->ControlledWorkerShutdown(); |
| 146 */ | 146 */ |
| 147 } | 147 } |
| OLD | NEW |