Chromium Code Reviews

Side by Side Diff: chrome/browser/printing/print_job_unittest.cc

Issue 11534: Add superficial unit test for PrintJob. That's a start.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 12 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | | Annotate | Revision Log
« no previous file with comments | « chrome/browser/printing/print_job.cc ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(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 }
85
86 TEST(PrintJobTest, SimplePrintLateInit) {
87 volatile bool check = false;
88 MessageLoop current;
89 scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check));
90 job = NULL;
91 EXPECT_TRUE(check);
92 /* TODO(maruel): Test these.
93 job->Initialize()
94 job->Observe();
95 job->GetSettingsDone();
96 job->DetachWorker();
97 job->message_loop();
98 job->settings();
99 job->cookie();
100 job->GetSettings(printing::DEFAULTS, printing::ASK_USER, NULL);
101 job->StartPrinting();
102 job->Stop();
103 job->Cancel();
104 job->RequestMissingPages();
105 job->FlushJob(timeout_ms);
106 job->DisconnectSource();
107 job->is_job_pending();
108 job->is_print_dialog_box_shown();
109 job->document();
110 // Private
111 job->UpdatePrintedDocument(NULL);
112 scoped_refptr<printing::JobEventDetails> event_details;
113 job->OnNotifyPrintJobEvent(event_details);
114 job->OnDocumentDone();
115 job->ControlledWorkerShutdown();
116 */
117 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/print_job.cc ('k') | chrome/renderer/render_view.cc » ('j') | no next file with comments »

Powered by Google App Engine