| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/common/notification_registrar.h" | 10 #include "content/common/notification_registrar.h" |
| 10 #include "content/common/notification_service.h" | 11 #include "content/common/notification_service.h" |
| 11 #include "googleurl/src/gurl.h" | 12 #include "googleurl/src/gurl.h" |
| 12 #include "printing/printed_pages_source.h" | 13 #include "printing/printed_pages_source.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 class TestSource : public printing::PrintedPagesSource { | 18 class TestSource : public printing::PrintedPagesSource { |
| 18 public: | 19 public: |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 private: | 70 private: |
| 70 ~TestPrintJob() { | 71 ~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 NotificationObserver { | 77 class TestPrintNotifObserv : public NotificationObserver { |
| 77 public: | 78 public: |
| 78 // NotificationObserver | 79 // NotificationObserver |
| 79 virtual void Observe(NotificationType type, | 80 virtual void Observe(int type, |
| 80 const NotificationSource& source, | 81 const NotificationSource& source, |
| 81 const NotificationDetails& details) { | 82 const NotificationDetails& details) { |
| 82 EXPECT_FALSE(true); | 83 EXPECT_FALSE(true); |
| 83 } | 84 } |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 } // namespace | 87 } // namespace |
| 87 | 88 |
| 88 TEST(PrintJobTest, SimplePrint) { | 89 TEST(PrintJobTest, SimplePrint) { |
| 89 // 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 |
| 90 // known lifetime. | 91 // known lifetime. |
| 91 | 92 |
| 92 // This message loop is actually never run. | 93 // This message loop is actually never run. |
| 93 MessageLoop current; | 94 MessageLoop current; |
| 94 | 95 |
| 95 NotificationRegistrar registrar_; | 96 NotificationRegistrar registrar_; |
| 96 TestPrintNotifObserv observ; | 97 TestPrintNotifObserv observ; |
| 97 registrar_.Add(&observ, NotificationType::ALL, | 98 registrar_.Add(&observ, content::NOTIFICATION_ALL, |
| 98 NotificationService::AllSources()); | 99 NotificationService::AllSources()); |
| 99 volatile bool check = false; | 100 volatile bool check = false; |
| 100 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check)); | 101 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check)); |
| 101 EXPECT_EQ(MessageLoop::current(), job->message_loop()); | 102 EXPECT_EQ(MessageLoop::current(), job->message_loop()); |
| 102 scoped_refptr<TestOwner> owner(new TestOwner); | 103 scoped_refptr<TestOwner> owner(new TestOwner); |
| 103 TestSource source; | 104 TestSource source; |
| 104 job->Initialize(owner, &source, 1); | 105 job->Initialize(owner, &source, 1); |
| 105 job->Stop(); | 106 job->Stop(); |
| 106 job = NULL; | 107 job = NULL; |
| 107 EXPECT_TRUE(check); | 108 EXPECT_TRUE(check); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 131 job->is_job_pending(); | 132 job->is_job_pending(); |
| 132 job->document(); | 133 job->document(); |
| 133 // Private | 134 // Private |
| 134 job->UpdatePrintedDocument(NULL); | 135 job->UpdatePrintedDocument(NULL); |
| 135 scoped_refptr<printing::JobEventDetails> event_details; | 136 scoped_refptr<printing::JobEventDetails> event_details; |
| 136 job->OnNotifyPrintJobEvent(event_details); | 137 job->OnNotifyPrintJobEvent(event_details); |
| 137 job->OnDocumentDone(); | 138 job->OnDocumentDone(); |
| 138 job->ControlledWorkerShutdown(); | 139 job->ControlledWorkerShutdown(); |
| 139 */ | 140 */ |
| 140 } | 141 } |
| OLD | NEW |