OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 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/file_path.h" | |
6 #include "base/md5.h" | |
7 #include "base/memory/ref_counted.h" | |
8 #include "base/message_loop.h" | |
9 #include "base/message_loop_proxy.h" | |
10 #include "base/stringprintf.h" | |
11 #include "chrome/common/cloud_print/cloud_print_constants.h" | |
12 #include "chrome/service/cloud_print/cloud_print_helpers.h" | |
13 #include "chrome/service/cloud_print/cloud_print_token_store.h" | |
14 #include "chrome/service/cloud_print/print_system.h" | |
15 #include "chrome/service/cloud_print/printer_job_handler.h" | |
16 #include "net/http/http_response_headers.h" | |
17 #include "net/url_request/test_url_fetcher_factory.h" | |
18 #include "net/url_request/url_request_test_util.h" | |
19 #include "printing/backend/print_backend.h" | |
20 #include "testing/gmock/include/gmock/gmock.h" | |
21 #include "testing/gtest/include/gtest/gtest.h" | |
22 | |
23 using ::testing::AtLeast; | |
24 using ::testing::Exactly; | |
25 using ::testing::Sequence; | |
26 using ::testing::Return; | |
27 using ::testing::SaveArg; | |
28 using ::testing::DoAll; | |
29 using ::testing::_; | |
30 using ::testing::NiceMock; | |
31 using ::testing::StrictMock; | |
32 using ::testing::Invoke; | |
33 using ::testing::SetArgPointee; | |
34 using ::testing::InvokeWithoutArgs; | |
35 | |
36 namespace cloud_print { | |
37 | |
38 const char kExampleJobListResponse[] = "{" | |
39 " \"success\": true," | |
40 " \"jobs\": [" | |
41 " {" | |
42 " \"tags\": [" | |
43 " \"^own\"" | |
44 " ]," | |
45 " \"printerName\": \"Example Printer\"," | |
46 " \"status\": \"QUEUED\"," | |
47 " \"ownerId\": \"sampleuser@gmail.com\"," | |
48 " \"ticketUrl\": \"https://www.google.com/cloudprint/ticket?exampleURI1\"," | |
49 " \"printerid\": \"__example_printer_id\"," | |
50 " \"printerType\": \"GOOGLE\"," | |
51 " \"contentType\": \"text/html\"," | |
52 " \"fileUrl\": \"https://www.google.com/cloudprint/download?exampleURI1\"," | |
53 " \"id\": \"__example_job_id1\"," | |
54 " \"message\": \"\"," | |
55 " \"title\": \"Example Job 1\"," | |
56 " \"errorCode\": \"\"," | |
57 " \"numberOfPages\": 3" | |
58 " }" | |
59 " ]," | |
60 " \"xsrf_token\": \"AIp06DjUd3AV6BO0aujB9NvM2a9ZbogxOQ:1360021066932\"," | |
61 " \"request\": {" | |
62 " \"time\": \"0\"," | |
63 " \"users\": [" | |
64 " \"sampleuser@gmail.com\"" | |
65 " ]," | |
66 " \"params\": {" | |
67 " \"printerid\": [" | |
68 " \"__example_printer_id\"" | |
69 " ]" | |
70 " }," | |
71 " \"user\": \"sampleuser@gmail.com\"" | |
72 " }" | |
73 "}"; | |
74 | |
75 const char kExampleJobListResponseEmpty[] = "{" | |
76 " \"success\": true," | |
77 " \"jobs\": [" | |
78 " ]," | |
79 " \"xsrf_token\": \"AIp06DjUd3AV6BO0aujB9NvM2a9ZbogxOQ:1360021066932\"," | |
80 " \"request\": {" | |
81 " \"time\": \"0\"," | |
82 " \"users\": [" | |
83 " \"sampleuser@gmail.com\"" | |
84 " ]," | |
85 " \"params\": {" | |
86 " \"printerid\": [" | |
87 " \"__example_printer_id\"" | |
88 " ]" | |
89 " }," | |
90 " \"user\": \"sampleuser@gmail.com\"" | |
91 " }" | |
92 "}"; | |
93 | |
94 | |
95 | |
96 const char kExampleJobID[] = "__example_job_id1"; | |
97 | |
98 const char kExampleCloudPrintServerURL[] = "https://www.google.com/cloudprint/"; | |
99 | |
100 const char kExamplePrintTicket[] = "{\"MediaType\":\"plain\"," | |
101 "\"Resolution\":\"300x300dpi\",\"PageRegion\":\"Letter\"," | |
102 "\"InputSlot\":\"auto\",\"PageSize\":\"Letter\",\"EconoMode\":\"off\"}"; | |
103 | |
104 const char kExamplePrintTicketURI[] = | |
105 "https://www.google.com/cloudprint/ticket?exampleURI1"; | |
106 | |
107 const char kExamplePrintDownloadURI[] = | |
108 "https://www.google.com/cloudprint/download?exampleURI1"; | |
109 | |
110 // Use StringPrintf to construct | |
111 const char kExamplePrinterJobListURI[] = | |
112 "https://www.google.com/cloudprint/fetch" | |
113 "?printerid=__example_printer_id&deb=%s"; | |
114 | |
115 // Use StringPrintf to construct | |
116 const char kExamplePrinterJobControlURI[] = | |
117 "https://www.google.com/cloudprint/control" | |
118 "?jobid=__example_printer_id&status=%s"; | |
119 | |
120 | |
121 // Use StringPrintf to construct | |
122 const char kExampleControlResponse[] = "{" | |
123 " \"success\": true," | |
124 " \"message\": \"Print job updated successfully.\"," | |
125 " \"xsrf_token\": \"AIp06DjKgbfGalbqzj23V1bU6i-vtR2B4w:1360023068789\"," | |
126 " \"request\": {" | |
127 " \"time\": \"0\"," | |
128 " \"users\": [" | |
129 " \"sampleuser@gmail.com\"" | |
130 " ]," | |
131 " \"params\": {" | |
132 " \"xsrf\": [" | |
133 " \"AIp06DgeGIETs42Cj28QWmxGPWVDiaXwVQ:1360023041852\"" | |
134 " ]," | |
135 " \"status\": [" | |
136 " \"%s\"" | |
137 " ]," | |
138 " \"jobid\": [" | |
139 " \"__example_job_id1\"" | |
140 " ]" | |
141 " }," | |
142 " \"user\": \"sampleuser@gmail.com\"" | |
143 " }," | |
144 " \"job\": {" | |
145 " \"tags\": [" | |
146 " \"^own\"" | |
147 " ]," | |
148 " \"printerName\": \"Example Printer\"," | |
149 " \"status\": \"%s\"," | |
150 " \"ownerId\": \"sampleuser@gmail.com\"," | |
151 " \"ticketUrl\": \"https://www.google.com/cloudprint/ticket?exampleURI1\"," | |
152 " \"printerid\": \"__example_printer_id\"," | |
153 " \"contentType\": \"text/html\"," | |
154 " \"fileUrl\": \"https://www.google.com/cloudprint/download?exampleURI1\"," | |
155 " \"id\": \"__example_job_id1\"," | |
156 " \"message\": \"\"," | |
157 " \"title\": \"Example Job\"," | |
158 " \"errorCode\": \"\"," | |
159 " \"numberOfPages\": 3" | |
160 " }" | |
161 "}"; | |
162 | |
163 const char kExamplePrinterID[] = "__example_printer_id"; | |
164 | |
165 const char kExamplePrinterCapabilities[] = ""; | |
166 | |
167 const char kExampleCapsMimeType[] = ""; | |
168 | |
169 // These can stay empty | |
170 const char kExampleDefaults[] = ""; | |
171 | |
172 const char kExampleDefaultMimeType[] = ""; | |
173 | |
174 // Since we're not connecting to the server, this can be any non-empty string. | |
175 const char kExampleCloudPrintOAuthToken[] = "__SAMPLE_TOKEN"; | |
176 | |
177 | |
178 // Not actually printing, no need for real PDF. | |
179 const char kExamplePrintData[] = "__EXAMPLE_PRINT_DATA"; | |
180 | |
181 const char kExampleJobDownloadResponseHeaders[] = | |
182 "Content-Type: Application/PDF\n"; | |
183 | |
184 const char kExampleUpdateDoneURL[] = | |
185 "https://www.google.com/cloudprint/control?jobid=__example_job_id1" | |
186 "&status=DONE&code=0&message=&numpages=0&pagesprinted=0"; | |
187 | |
188 const char kExamplePrinterName[] = "Example Printer"; | |
189 | |
190 const char kExamplePrinterDescription[] = "Example Description"; | |
191 | |
192 class CloudPrintURLFetcherNoServiceProcess | |
193 : public CloudPrintURLFetcher { | |
194 protected: | |
195 virtual net::URLRequestContextGetter* GetRequestContextGetter() { | |
196 return new net::TestURLRequestContextGetter( | |
197 base::MessageLoopProxy::current()); | |
198 } | |
199 }; | |
200 | |
201 | |
202 class CloudPrintURLFetcherNoServiceProcessFactory | |
203 : public CloudPrintURLFetcherFactory { | |
Vitaly Buka (NO REVIEWS)
2013/02/12 23:53:26
http://www.corp.google.com/eng/doc/cppguide.xml?sh
Noam Samuel (WRONG ACCOUNT)
2013/02/13 01:11:45
1. Will submit interface fix as separate CL
2. Ad
| |
204 public: | |
205 virtual CloudPrintURLFetcher* CreateCloudPrintURLFetcher() { | |
206 return new CloudPrintURLFetcherNoServiceProcess; | |
207 } | |
208 }; | |
209 | |
210 | |
211 // This class handles the callback from FakeURLFetcher | |
212 // It is a separate class because callback methods must be | |
213 // on RefCounted classes | |
214 | |
215 class TestURLFetcherCallback { | |
216 public: | |
217 net::FakeURLFetcher* CreateURLFetcher(const GURL& url, | |
218 net::URLFetcherDelegate* d, | |
219 const std::string& response_data, | |
220 bool success) { | |
221 net::FakeURLFetcher* fetcher = | |
222 new net::FakeURLFetcher(url, d, response_data, success); | |
223 OnRequestCreate(url, fetcher); | |
224 return fetcher; | |
225 } | |
226 MOCK_METHOD2(OnRequestCreate, | |
227 void(const GURL&, net::FakeURLFetcher*)); | |
228 }; | |
229 | |
230 | |
231 class MockPrinterJobHandlerDelegate | |
232 : public PrinterJobHandler::Delegate { | |
233 public: | |
234 MOCK_METHOD0(OnAuthError, void()); | |
235 MOCK_METHOD1(OnPrinterDeleted, void(const std::string& str)); | |
236 }; | |
237 | |
238 | |
239 class MockPrintServerWatcher | |
240 : public PrintSystem::PrintServerWatcher { | |
241 public: | |
242 MOCK_METHOD1(StartWatching, | |
243 bool(PrintSystem::PrintServerWatcher::Delegate* d)); | |
244 MOCK_METHOD0(StopWatching, bool()); | |
245 | |
Vitaly Buka (NO REVIEWS)
2013/02/12 23:53:26
Usually I add virtual destructors even if just bas
Noam Samuel (WRONG ACCOUNT)
2013/02/13 01:11:45
Done.
| |
246 MockPrintServerWatcher(); | |
247 PrintSystem::PrintServerWatcher::Delegate* Delegate() { | |
248 return delegate_; | |
249 } | |
250 | |
251 private: | |
252 PrintSystem::PrintServerWatcher::Delegate* delegate_; | |
253 | |
254 bool SetDelegate(PrintSystem::PrintServerWatcher::Delegate* d) { | |
Vitaly Buka (NO REVIEWS)
2013/02/12 23:53:26
This should be void set_delegate()?
http://www.cor
Noam Samuel (WRONG ACCOUNT)
2013/02/13 01:11:45
Turns out this setter was unnecessary. Removed it.
| |
255 delegate_ = d; | |
256 return true; | |
257 } | |
258 }; | |
259 | |
260 class MockPrinterWatcher : public PrintSystem::PrinterWatcher { | |
261 public: | |
262 MOCK_METHOD1(StartWatching, bool(PrintSystem::PrinterWatcher::Delegate* d)); | |
263 MOCK_METHOD0(StopWatching, bool()); | |
264 MOCK_METHOD1(GetCurrentPrinterInfo, | |
265 bool(printing::PrinterBasicInfo* printer_info)); | |
266 | |
267 MockPrinterWatcher(); | |
268 PrintSystem::PrinterWatcher::Delegate* Delegate() { return delegate_; } | |
269 | |
270 private: | |
271 PrintSystem::PrinterWatcher::Delegate* delegate_; | |
272 | |
273 bool SetDelegate(PrintSystem::PrinterWatcher::Delegate* d) { | |
274 delegate_ = d; | |
Vitaly Buka (NO REVIEWS)
2013/02/12 23:53:26
Same
Noam Samuel (WRONG ACCOUNT)
2013/02/13 01:11:45
Ditto.
On 2013/02/12 23:53:26, Vitaly Buka wrote:
| |
275 return true; | |
276 } | |
277 }; | |
278 | |
279 | |
280 class MockJobSpooler : public PrintSystem::JobSpooler { | |
281 public: | |
282 MOCK_METHOD7(Spool, bool( | |
283 const std::string& print_ticket, | |
284 const FilePath& print_data_file_path, | |
285 const std::string& print_data_mime_type, | |
286 const std::string& printer_name, | |
287 const std::string& job_title, | |
288 const std::vector<std::string>& tags, | |
289 PrintSystem::JobSpooler::Delegate* delegate)); | |
290 | |
291 MockJobSpooler(); | |
292 PrintSystem::JobSpooler::Delegate* Delegate() { return delegate_; } | |
Vitaly Buka (NO REVIEWS)
2013/02/12 23:53:26
this should be delegate() const
Noam Samuel (WRONG ACCOUNT)
2013/02/13 01:11:45
Done.
| |
293 | |
294 private: | |
295 PrintSystem::JobSpooler::Delegate* delegate_; | |
296 }; | |
297 | |
298 | |
299 | |
300 class MockPrintSystem : public PrintSystem { | |
301 public: | |
302 MockPrintSystem(); | |
303 PrintSystem::PrintSystemResult succeed() { | |
304 return PrintSystem::PrintSystemResult(true, "success"); | |
305 } | |
306 | |
307 PrintSystem::PrintSystemResult fail() { | |
308 return PrintSystem::PrintSystemResult(false, "failure"); | |
309 } | |
310 | |
311 MockJobSpooler& JobSpooler() { | |
312 return *job_spooler_; | |
313 } | |
314 | |
315 MockPrinterWatcher& PrinterWatcher() { | |
316 return *printer_watcher_; | |
317 } | |
318 | |
319 MockPrintServerWatcher& PrintServerWatcher() { | |
320 return *print_server_watcher_; | |
321 } | |
322 | |
323 MOCK_METHOD0(Init, PrintSystem::PrintSystemResult()); | |
324 MOCK_METHOD1(EnumeratePrinters, PrintSystem::PrintSystemResult( | |
325 printing::PrinterList* printer_list)); | |
326 | |
327 MOCK_METHOD2( | |
328 GetPrinterCapsAndDefaults, | |
329 void(const std::string& printer_name, | |
330 const PrintSystem::PrinterCapsAndDefaultsCallback& callback)); | |
331 | |
332 MOCK_METHOD1(IsValidPrinter, bool(const std::string& printer_name)); | |
333 | |
334 MOCK_METHOD2(ValidatePrintTicket, bool(const std::string& printer_name, | |
335 const std::string& print_ticket_data)); | |
336 | |
337 MOCK_METHOD3(GetJobDetails, bool(const std::string& printer_name, | |
338 PlatformJobId job_id, | |
339 PrintJobDetails* job_details)); | |
340 | |
341 MOCK_METHOD0(CreatePrintServerWatcher, PrintSystem::PrintServerWatcher*()); | |
342 MOCK_METHOD1(CreatePrinterWatcher, | |
343 PrintSystem::PrinterWatcher*(const std::string& printer_name)); | |
344 MOCK_METHOD0(CreateJobSpooler, PrintSystem::JobSpooler*()); | |
345 | |
346 MOCK_METHOD0(GetSupportedMimeTypes, std::string()); | |
347 | |
348 private: | |
349 scoped_refptr<MockJobSpooler> job_spooler_; | |
350 scoped_refptr<MockPrinterWatcher> printer_watcher_; | |
351 scoped_refptr<MockPrintServerWatcher> print_server_watcher_; | |
352 | |
353 }; | |
354 | |
355 | |
356 class PrinterJobHandlerTest : public ::testing::Test { | |
357 public: | |
358 PrinterJobHandlerTest(); | |
359 void SetUp(); | |
360 void TearDown(); | |
Vitaly Buka (NO REVIEWS)
2013/02/12 23:53:26
Use OVERRIDE for all virtual overrides
virtual vo
Noam Samuel (WRONG ACCOUNT)
2013/02/13 01:11:45
Done.
| |
361 void IdleOut(); | |
362 bool GetPrinterInfo(printing::PrinterBasicInfo* info); | |
363 void SendCapsAndDefaults( | |
364 const std::string& printer_name, | |
365 const PrintSystem::PrinterCapsAndDefaultsCallback& callback); | |
366 void AddMimeHeader(const GURL& url, net::FakeURLFetcher* fetcher); | |
367 bool PostSpoolSuccess(); | |
368 | |
369 static void MessageLoopQuitNowHelper(MessageLoop* message_loop); | |
370 static void MessageLoopQuitSoonHelper(MessageLoop* message_loop); | |
371 | |
372 MessageLoopForIO loop_; | |
373 TestURLFetcherCallback url_callback_; | |
374 MockPrinterJobHandlerDelegate jobhandler_delegate_; | |
375 CloudPrintTokenStore token_store_; | |
376 CloudPrintURLFetcherNoServiceProcessFactory cloud_print_factory_; | |
377 scoped_refptr<PrinterJobHandler> job_handler_; | |
378 scoped_refptr<NiceMock<MockPrintSystem> > print_system_; | |
379 net::FakeURLFetcherFactory factory_; | |
380 printing::PrinterBasicInfo basic_info_; | |
381 printing::PrinterCapsAndDefaults caps_and_defaults_; | |
382 PrinterJobHandler::PrinterInfoFromCloud info_from_cloud_; | |
383 }; | |
384 | |
385 | |
386 void PrinterJobHandlerTest::SetUp() { | |
387 basic_info_.printer_name = kExamplePrinterName; | |
388 basic_info_.printer_description = kExamplePrinterDescription; | |
389 basic_info_.is_default = 0; | |
390 | |
391 info_from_cloud_.printer_id = kExamplePrinterID; | |
392 info_from_cloud_.tags_hash = GetHashOfPrinterInfo(basic_info_); | |
393 | |
394 info_from_cloud_.caps_hash = base::MD5String(kExamplePrinterCapabilities); | |
395 | |
396 caps_and_defaults_.printer_capabilities = kExamplePrinterCapabilities; | |
397 caps_and_defaults_.caps_mime_type = kExampleCapsMimeType; | |
398 caps_and_defaults_.printer_defaults = kExampleDefaults; | |
399 caps_and_defaults_.defaults_mime_type = kExampleDefaultMimeType; | |
400 | |
401 print_system_ = new NiceMock<MockPrintSystem>(); | |
402 | |
403 token_store_.SetToken(kExampleCloudPrintOAuthToken); | |
404 | |
405 ON_CALL(print_system_->PrinterWatcher(), GetCurrentPrinterInfo(_)) | |
406 .WillByDefault(Invoke(this, &PrinterJobHandlerTest::GetPrinterInfo)); | |
407 | |
408 ON_CALL(*print_system_, GetPrinterCapsAndDefaults(_, _)) | |
409 .WillByDefault(Invoke(this, &PrinterJobHandlerTest::SendCapsAndDefaults)); | |
410 | |
411 CloudPrintURLFetcher::set_factory(&cloud_print_factory_); | |
412 } | |
413 | |
414 void PrinterJobHandlerTest::MessageLoopQuitNowHelper( | |
415 MessageLoop* message_loop) { | |
416 message_loop->QuitWhenIdle(); | |
417 } | |
418 | |
419 void PrinterJobHandlerTest::MessageLoopQuitSoonHelper( | |
420 MessageLoop* message_loop) { | |
421 message_loop->message_loop_proxy()->PostTask( | |
422 FROM_HERE, | |
423 base::Bind(&MessageLoopQuitNowHelper, message_loop)); | |
424 } | |
425 | |
426 PrinterJobHandlerTest::PrinterJobHandlerTest() | |
427 : factory_(base::Bind(&TestURLFetcherCallback::CreateURLFetcher, | |
428 base::Unretained(&url_callback_)), NULL) { | |
429 } | |
430 | |
431 bool PrinterJobHandlerTest::PostSpoolSuccess() { | |
432 MessageLoop::current()->PostTask( | |
433 FROM_HERE, | |
434 base::Bind( | |
435 &PrinterJobHandler::OnJobSpoolSucceeded, | |
436 job_handler_, 0)); | |
437 | |
438 // Everything that would be posted on the printer thread queue | |
439 // has been posted, we can tell the main message loop to quit when idle | |
440 // and not worry about it idling while the print thread does work | |
441 MessageLoop::current()->PostTask(FROM_HERE, | |
442 base::Bind(&MessageLoopQuitSoonHelper, &loop_)); | |
443 return true; | |
444 } | |
445 | |
446 void PrinterJobHandlerTest::AddMimeHeader(const GURL& url, | |
447 net::FakeURLFetcher* fetcher) { | |
448 scoped_refptr<net::HttpResponseHeaders> download_headers = | |
449 new net::HttpResponseHeaders(kExampleJobDownloadResponseHeaders); | |
450 fetcher->set_response_headers(download_headers); | |
451 } | |
452 | |
453 | |
454 void PrinterJobHandlerTest::SendCapsAndDefaults( | |
455 const std::string& printer_name, | |
456 const PrintSystem::PrinterCapsAndDefaultsCallback& callback) { | |
457 callback.Run(true, printer_name, caps_and_defaults_); | |
458 } | |
459 | |
460 bool PrinterJobHandlerTest::GetPrinterInfo(printing::PrinterBasicInfo* info) { | |
461 *info = basic_info_; | |
462 return true; | |
463 } | |
464 | |
465 void PrinterJobHandlerTest::TearDown() { | |
466 IdleOut(); | |
467 CloudPrintURLFetcher::set_factory(NULL); | |
468 } | |
469 | |
470 void PrinterJobHandlerTest::IdleOut() { | |
471 MessageLoop::current()->RunUntilIdle(); | |
472 } | |
473 | |
474 MockPrintServerWatcher::MockPrintServerWatcher() : delegate_(NULL) { | |
475 ON_CALL(*this, StartWatching(_)) | |
476 .WillByDefault(Invoke(this, &MockPrintServerWatcher::SetDelegate)); | |
477 ON_CALL(*this, StopWatching()).WillByDefault(Return(true)); | |
478 } | |
479 | |
480 | |
481 MockPrinterWatcher::MockPrinterWatcher() : delegate_(NULL) { | |
482 ON_CALL(*this, StartWatching(_)) | |
483 .WillByDefault(Invoke(this, &MockPrinterWatcher::SetDelegate)); | |
484 ON_CALL(*this, StopWatching()).WillByDefault(Return(true)); | |
485 } | |
486 | |
487 MockJobSpooler::MockJobSpooler() : delegate_(NULL) { | |
488 ON_CALL(*this, Spool(_, _, _, _, _, _, _)) | |
489 .WillByDefault(DoAll(SaveArg<6>(&delegate_), Return(true))); | |
490 } | |
491 | |
492 | |
493 MockPrintSystem::MockPrintSystem() | |
494 : job_spooler_(new NiceMock<MockJobSpooler>()), | |
495 printer_watcher_(new NiceMock<MockPrinterWatcher>()), | |
496 print_server_watcher_(new NiceMock<MockPrintServerWatcher>()) { | |
497 ON_CALL(*this, CreateJobSpooler()) | |
498 .WillByDefault(Return(job_spooler_)); | |
499 | |
500 ON_CALL(*this, CreatePrinterWatcher(_)) | |
501 .WillByDefault(Return(printer_watcher_)); | |
502 | |
503 ON_CALL(*this, CreatePrintServerWatcher()) | |
504 .WillByDefault(Return(print_server_watcher_)); | |
505 | |
506 ON_CALL(*this, IsValidPrinter(_)). | |
507 WillByDefault(Return(true)); | |
508 | |
509 ON_CALL(*this, ValidatePrintTicket(_, _)). | |
510 WillByDefault(Return(true)); | |
511 }; | |
512 | |
513 // This test simulates an end-to-end printing of a document | |
514 // but tests only non-failure cases. | |
515 TEST_F(PrinterJobHandlerTest, HappyPathTest) { | |
516 GURL InProgressURL = | |
517 GetUrlForJobStatusUpdate(GURL(kExampleCloudPrintServerURL), | |
518 kExampleJobID, | |
519 PRINT_JOB_STATUS_IN_PROGRESS); | |
520 | |
521 factory_.SetFakeResponse(kExamplePrintTicketURI, kExamplePrintTicket, true); | |
522 factory_.SetFakeResponse(kExamplePrintDownloadURI, kExamplePrintData, true); | |
523 factory_.SetFakeResponse( | |
524 StringPrintf(kExamplePrinterJobListURI, kJobFetchReasonStartup), | |
525 kExampleJobListResponse, true); | |
526 | |
527 | |
528 factory_.SetFakeResponse( | |
529 base::StringPrintf(kExamplePrinterJobListURI, kJobFetchReasonQueryMore), | |
530 kExampleJobListResponseEmpty, true); | |
531 | |
532 factory_.SetFakeResponse( | |
533 kExampleUpdateDoneURL, | |
534 base::StringPrintf(kExampleControlResponse, "DONE", "DONE"), true); | |
535 | |
536 factory_.SetFakeResponse( | |
537 InProgressURL.spec(), | |
538 base::StringPrintf(kExampleControlResponse, | |
539 "IN_PROGRESS", "IN_PROGRESS"), | |
540 true); | |
541 | |
542 | |
543 job_handler_ = new PrinterJobHandler(basic_info_, info_from_cloud_, | |
544 GURL(kExampleCloudPrintServerURL), | |
545 print_system_, &jobhandler_delegate_); | |
546 | |
547 EXPECT_CALL(url_callback_, OnRequestCreate( | |
548 GURL(base::StringPrintf(kExamplePrinterJobListURI, "startup")), _)) | |
549 .Times(Exactly(1)); | |
550 | |
551 EXPECT_CALL(url_callback_, OnRequestCreate( | |
552 GURL(base::StringPrintf(kExamplePrinterJobListURI, "querymore")), _)) | |
553 .Times(Exactly(1)); | |
554 | |
555 EXPECT_CALL(url_callback_, OnRequestCreate(GURL(kExamplePrintTicketURI), _)) | |
556 .Times(Exactly(1)); | |
557 | |
558 EXPECT_CALL(url_callback_, OnRequestCreate( | |
559 GURL(kExamplePrintDownloadURI), _)) | |
560 .Times(Exactly(1)) | |
561 .WillOnce(Invoke(this, &PrinterJobHandlerTest::AddMimeHeader)); | |
562 | |
563 EXPECT_CALL(url_callback_, OnRequestCreate(InProgressURL, _)) | |
564 .Times(Exactly(1)); | |
565 | |
566 EXPECT_CALL(url_callback_, OnRequestCreate(GURL(kExampleUpdateDoneURL), _)) | |
567 .Times(Exactly(1)); | |
568 | |
569 EXPECT_CALL(print_system_->JobSpooler(), | |
570 Spool(kExamplePrintTicket, _, _, _, _, _, _)) | |
571 .Times(Exactly(1)) | |
572 .WillOnce(InvokeWithoutArgs(this, | |
573 &PrinterJobHandlerTest::PostSpoolSuccess)); | |
574 | |
575 | |
576 job_handler_->Initialize(); | |
577 | |
578 MessageLoop::current()->PostDelayedTask( | |
579 FROM_HERE, | |
580 base::Bind(&PrinterJobHandlerTest::MessageLoopQuitSoonHelper, | |
581 MessageLoop::current()), | |
582 base::TimeDelta::FromSeconds(1)); | |
583 | |
584 MessageLoop::current()->Run(); | |
585 } | |
586 | |
587 } // namespace cloud_print | |
588 | |
OLD | NEW |