OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/message_loop.h" |
| 6 #include "chrome/browser/printing/print_job.h" |
| 7 #include "chrome/browser/printing/printed_pages_source.h" |
| 8 #include "googleurl/src/gurl.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace { |
| 12 |
| 13 class TestSource : public printing::PrintedPagesSource { |
| 14 public: |
| 15 virtual void RenderOnePrintedPage(printing::PrintedDocument* document, |
| 16 int page_number) { |
| 17 } |
| 18 virtual std::wstring RenderSourceName() { |
| 19 return L""; |
| 20 } |
| 21 virtual GURL RenderSourceUrl() { |
| 22 return GURL(); |
| 23 } |
| 24 }; |
| 25 |
| 26 class TestPrintJob : public printing::PrintJob { |
| 27 public: |
| 28 TestPrintJob(printing::PrintedPagesSource* source, volatile bool* check) |
| 29 : printing::PrintJob(source), check_(check) { |
| 30 } |
| 31 TestPrintJob(volatile bool* check) : check_(check) { |
| 32 } |
| 33 ~TestPrintJob() { |
| 34 *check_ = true; |
| 35 } |
| 36 private: |
| 37 volatile bool* check_; |
| 38 }; |
| 39 |
| 40 class TestPrintNotifObserv : public NotificationObserver { |
| 41 public: |
| 42 // NotificationObserver |
| 43 virtual void Observe(NotificationType type, |
| 44 const NotificationSource& source, |
| 45 const NotificationDetails& details) { |
| 46 ASSERT_EQ(NOTIFY_PRINT_JOB_EVENT, type); |
| 47 printing::JobEventDetails::Type event_type = |
| 48 Details<printing::JobEventDetails>(details)->type(); |
| 49 EXPECT_NE(printing::JobEventDetails::NEW_DOC, event_type); |
| 50 EXPECT_NE(printing::JobEventDetails::NEW_PAGE, event_type); |
| 51 EXPECT_NE(printing::JobEventDetails::PAGE_DONE, event_type); |
| 52 EXPECT_NE(printing::JobEventDetails::DOC_DONE, event_type); |
| 53 EXPECT_NE(printing::JobEventDetails::JOB_DONE, event_type); |
| 54 EXPECT_NE(printing::JobEventDetails::ALL_PAGES_REQUESTED, event_type); |
| 55 if (event_type == printing::JobEventDetails::USER_INIT_DONE || |
| 56 event_type == printing::JobEventDetails::USER_INIT_CANCELED || |
| 57 event_type == printing::JobEventDetails::DEFAULT_INIT_DONE || |
| 58 event_type == printing::JobEventDetails::FAILED) { |
| 59 MessageLoop::current()->Quit(); |
| 60 return; |
| 61 } |
| 62 } |
| 63 }; |
| 64 |
| 65 } // namespace |
| 66 |
| 67 TEST(PrintJobTest, SimplePrint) { |
| 68 // Test the multithreaded nature of PrintJob to make sure we can use it with |
| 69 // known livetime. |
| 70 TestPrintNotifObserv observ; |
| 71 MessageLoop current; |
| 72 NotificationService::current()->AddObserver( |
| 73 &observ, NOTIFY_ALL, |
| 74 NotificationService::AllSources()); |
| 75 TestSource source; |
| 76 volatile bool check = false; |
| 77 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&source, &check)); |
| 78 job->GetSettings(printing::PrintJob::DEFAULTS, NULL); |
| 79 EXPECT_EQ(MessageLoop::current(), job->message_loop()); |
| 80 current.Run(); |
| 81 job->Stop(); |
| 82 job = NULL; |
| 83 EXPECT_TRUE(check); |
| 84 NotificationService::current()->RemoveObserver( |
| 85 &observ, NOTIFY_ALL, |
| 86 NotificationService::AllSources()); |
| 87 } |
| 88 |
| 89 TEST(PrintJobTest, SimplePrintLateInit) { |
| 90 volatile bool check = false; |
| 91 MessageLoop current; |
| 92 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check)); |
| 93 job = NULL; |
| 94 EXPECT_TRUE(check); |
| 95 /* TODO(maruel): Test these. |
| 96 job->Initialize() |
| 97 job->Observe(); |
| 98 job->GetSettingsDone(); |
| 99 job->DetachWorker(); |
| 100 job->message_loop(); |
| 101 job->settings(); |
| 102 job->cookie(); |
| 103 job->GetSettings(printing::DEFAULTS, printing::ASK_USER, NULL); |
| 104 job->StartPrinting(); |
| 105 job->Stop(); |
| 106 job->Cancel(); |
| 107 job->RequestMissingPages(); |
| 108 job->FlushJob(timeout_ms); |
| 109 job->DisconnectSource(); |
| 110 job->is_job_pending(); |
| 111 job->is_print_dialog_box_shown(); |
| 112 job->document(); |
| 113 // Private |
| 114 job->UpdatePrintedDocument(NULL); |
| 115 scoped_refptr<printing::JobEventDetails> event_details; |
| 116 job->OnNotifyPrintJobEvent(event_details); |
| 117 job->OnDocumentDone(); |
| 118 job->ControlledWorkerShutdown(); |
| 119 */ |
| 120 } |
OLD | NEW |