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