blob: fe98964d44f1a63b7a747f960298f2d1d624d785 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/message_loop.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/browser/printing/print_job_worker.h"
#include "chrome/common/notification_registrar.h"
#include "chrome/common/notification_service.h"
#include "printing/printed_pages_source.h"
#include "googleurl/src/gurl.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
class TestSource : public printing::PrintedPagesSource {
public:
virtual std::wstring RenderSourceName() {
return L"";
}
virtual GURL RenderSourceUrl() {
return GURL();
}
};
class TestPrintJobWorker : public printing::PrintJobWorker {
public:
explicit TestPrintJobWorker(printing::PrintJobWorkerOwner* owner)
: printing::PrintJobWorker(owner) {
}
friend class TestOwner;
};
class TestOwner : public printing::PrintJobWorkerOwner {
public:
virtual void AddRef() {
EXPECT_FALSE(true);
}
virtual void Release() {
EXPECT_FALSE(true);
}
virtual void GetSettingsDone(const printing::PrintSettings& new_settings,
printing::PrintingContext::Result result) {
EXPECT_FALSE(true);
}
virtual printing::PrintJobWorker* DetachWorker(
printing::PrintJobWorkerOwner* new_owner) {
// We're screwing up here since we're calling worker from the main thread.
// That's fine for testing. It is actually simulating PrinterQuery behavior.
TestPrintJobWorker* worker(new TestPrintJobWorker(new_owner));
EXPECT_TRUE(worker->Start());
worker->printing_context().UseDefaultSettings();
settings_ = worker->printing_context().settings();
return worker;
}
virtual MessageLoop* message_loop() {
EXPECT_FALSE(true);
return NULL;
}
virtual const printing::PrintSettings& settings() const {
return settings_;
}
virtual int cookie() const {
return 42;
}
private:
printing::PrintSettings settings_;
};
class TestPrintJob : public printing::PrintJob {
public:
TestPrintJob(volatile bool* check) : check_(check) {
}
~TestPrintJob() {
*check_ = true;
}
private:
volatile bool* check_;
};
class TestPrintNotifObserv : public NotificationObserver {
public:
// NotificationObserver
virtual void Observe(NotificationType type,
const NotificationSource& source,
const NotificationDetails& details) {
EXPECT_FALSE(true);
}
};
} // namespace
TEST(PrintJobTest, SimplePrint) {
// Test the multithreaded nature of PrintJob to make sure we can use it with
// known livetime.
// This message loop is actually never run.
MessageLoop current;
NotificationRegistrar registrar_;
TestPrintNotifObserv observ;
registrar_.Add(&observ, NotificationType::ALL,
NotificationService::AllSources());
volatile bool check = false;
scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check));
EXPECT_EQ(MessageLoop::current(), job->message_loop());
TestOwner owner;
TestSource source;
job->Initialize(&owner, &source);
job->Stop();
job = NULL;
EXPECT_TRUE(check);
}
TEST(PrintJobTest, SimplePrintLateInit) {
volatile bool check = false;
MessageLoop current;
scoped_refptr<printing::PrintJob> job(new TestPrintJob(&check));
job = NULL;
EXPECT_TRUE(check);
/* TODO(maruel): Test these.
job->Initialize()
job->Observe();
job->GetSettingsDone();
job->DetachWorker();
job->message_loop();
job->settings();
job->cookie();
job->GetSettings(printing::DEFAULTS, printing::ASK_USER, NULL);
job->StartPrinting();
job->Stop();
job->Cancel();
job->RequestMissingPages();
job->FlushJob(timeout_ms);
job->DisconnectSource();
job->is_job_pending();
job->is_print_dialog_box_shown();
job->document();
// Private
job->UpdatePrintedDocument(NULL);
scoped_refptr<printing::JobEventDetails> event_details;
job->OnNotifyPrintJobEvent(event_details);
job->OnDocumentDone();
job->ControlledWorkerShutdown();
*/
}
|