Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Side by Side Diff: components/printing/test/print_web_view_helper_browsertest.cc

Issue 1556463003: Mark printing code as basic printing and/or print preview code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/printing/test/print_mock_render_thread.cc ('k') | printing/print_job_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 29 matching lines...) Expand all
40 40
41 // A simple web page. 41 // A simple web page.
42 const char kHelloWorldHTML[] = "<body><p>Hello World!</p></body>"; 42 const char kHelloWorldHTML[] = "<body><p>Hello World!</p></body>";
43 43
44 // A simple webpage with a button to print itself with. 44 // A simple webpage with a button to print itself with.
45 const char kPrintOnUserAction[] = 45 const char kPrintOnUserAction[] =
46 "<body>" 46 "<body>"
47 " <button id=\"print\" onclick=\"window.print();\">Hello World!</button>" 47 " <button id=\"print\" onclick=\"window.print();\">Hello World!</button>"
48 "</body>"; 48 "</body>";
49 49
50 #if defined(ENABLE_PRINT_PREVIEW)
50 // HTML with 3 pages. 51 // HTML with 3 pages.
51 const char kMultipageHTML[] = 52 const char kMultipageHTML[] =
52 "<html><head><style>" 53 "<html><head><style>"
53 ".break { page-break-after: always; }" 54 ".break { page-break-after: always; }"
54 "</style></head>" 55 "</style></head>"
55 "<body>" 56 "<body>"
56 "<div class='break'>page1</div>" 57 "<div class='break'>page1</div>"
57 "<div class='break'>page2</div>" 58 "<div class='break'>page2</div>"
58 "<div>page3</div>" 59 "<div>page3</div>"
59 "</body></html>"; 60 "</body></html>";
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 dict->SetInteger(kPreviewUIID, 4); 102 dict->SetInteger(kPreviewUIID, 4);
102 dict->SetInteger(kPreviewRequestID, 12345); 103 dict->SetInteger(kPreviewRequestID, 12345);
103 dict->SetBoolean(kIsFirstRequest, true); 104 dict->SetBoolean(kIsFirstRequest, true);
104 dict->SetInteger(kSettingMarginsType, DEFAULT_MARGINS); 105 dict->SetInteger(kSettingMarginsType, DEFAULT_MARGINS);
105 dict->SetBoolean(kSettingPreviewModifiable, false); 106 dict->SetBoolean(kSettingPreviewModifiable, false);
106 dict->SetBoolean(kSettingHeaderFooterEnabled, false); 107 dict->SetBoolean(kSettingHeaderFooterEnabled, false);
107 dict->SetBoolean(kSettingGenerateDraftData, true); 108 dict->SetBoolean(kSettingGenerateDraftData, true);
108 dict->SetBoolean(kSettingShouldPrintBackgrounds, false); 109 dict->SetBoolean(kSettingShouldPrintBackgrounds, false);
109 dict->SetBoolean(kSettingShouldPrintSelectionOnly, false); 110 dict->SetBoolean(kSettingShouldPrintSelectionOnly, false);
110 } 111 }
112 #endif // defined(ENABLE_PRINT_PREVIEW)
111 #endif // !defined(OS_CHROMEOS) 113 #endif // !defined(OS_CHROMEOS)
112 114
115 #if defined(ENABLE_PRINT_PREVIEW)
113 class DidPreviewPageListener : public IPC::Listener { 116 class DidPreviewPageListener : public IPC::Listener {
114 public: 117 public:
115 explicit DidPreviewPageListener(base::RunLoop* run_loop) 118 explicit DidPreviewPageListener(base::RunLoop* run_loop)
116 : run_loop_(run_loop) {} 119 : run_loop_(run_loop) {}
117 120
118 bool OnMessageReceived(const IPC::Message& message) override { 121 bool OnMessageReceived(const IPC::Message& message) override {
119 if (message.type() == PrintHostMsg_MetafileReadyForPrinting::ID || 122 if (message.type() == PrintHostMsg_MetafileReadyForPrinting::ID ||
120 message.type() == PrintHostMsg_PrintPreviewFailed::ID || 123 message.type() == PrintHostMsg_PrintPreviewFailed::ID ||
121 message.type() == PrintHostMsg_PrintPreviewCancelled::ID) 124 message.type() == PrintHostMsg_PrintPreviewCancelled::ID)
122 run_loop_->Quit(); 125 run_loop_->Quit();
123 return false; 126 return false;
124 } 127 }
125 128
126 private: 129 private:
127 base::RunLoop* const run_loop_; 130 base::RunLoop* const run_loop_;
128 DISALLOW_COPY_AND_ASSIGN(DidPreviewPageListener); 131 DISALLOW_COPY_AND_ASSIGN(DidPreviewPageListener);
129 }; 132 };
133 #endif // defined(ENABLE_PRINT_PREVIEW)
130 134
131 } // namespace 135 } // namespace
132 136
133 class PrintWebViewHelperTestBase : public content::RenderViewTest { 137 class PrintWebViewHelperTestBase : public content::RenderViewTest {
134 public: 138 public:
135 PrintWebViewHelperTestBase() : print_render_thread_(NULL) {} 139 PrintWebViewHelperTestBase() : print_render_thread_(NULL) {}
136 ~PrintWebViewHelperTestBase() override {} 140 ~PrintWebViewHelperTestBase() override {}
137 141
138 protected: 142 protected:
139 void SetUp() override { 143 void SetUp() override {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 render_thread_->sink().GetUniqueMessageMatching( 177 render_thread_->sink().GetUniqueMessageMatching(
174 PrintHostMsg_DidGetPrintedPagesCount::ID); 178 PrintHostMsg_DidGetPrintedPagesCount::ID);
175 ASSERT_TRUE(page_cnt_msg); 179 ASSERT_TRUE(page_cnt_msg);
176 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param; 180 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param;
177 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg, 181 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg,
178 &post_page_count_param); 182 &post_page_count_param);
179 EXPECT_EQ(count, base::get<1>(post_page_count_param)); 183 EXPECT_EQ(count, base::get<1>(post_page_count_param));
180 #endif // defined(OS_CHROMEOS) 184 #endif // defined(OS_CHROMEOS)
181 } 185 }
182 186
187 #if defined(ENABLE_PRINT_PREVIEW)
183 // The renderer should be done calculating the number of rendered pages 188 // The renderer should be done calculating the number of rendered pages
184 // according to the specified settings defined in the mock render thread. 189 // according to the specified settings defined in the mock render thread.
185 // Verify the page count is correct. 190 // Verify the page count is correct.
186 void VerifyPreviewPageCount(int count) { 191 void VerifyPreviewPageCount(int count) {
187 const IPC::Message* page_cnt_msg = 192 const IPC::Message* page_cnt_msg =
188 render_thread_->sink().GetUniqueMessageMatching( 193 render_thread_->sink().GetUniqueMessageMatching(
189 PrintHostMsg_DidGetPreviewPageCount::ID); 194 PrintHostMsg_DidGetPreviewPageCount::ID);
190 ASSERT_TRUE(page_cnt_msg); 195 ASSERT_TRUE(page_cnt_msg);
191 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param; 196 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param;
192 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg, 197 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg,
193 &post_page_count_param); 198 &post_page_count_param);
194 EXPECT_EQ(count, base::get<0>(post_page_count_param).page_count); 199 EXPECT_EQ(count, base::get<0>(post_page_count_param).page_count);
195 } 200 }
201 #endif // defined(ENABLE_PRINT_PREVIEW)
196 202
197 // Verifies whether the pages printed or not. 203 // Verifies whether the pages printed or not.
198 void VerifyPagesPrinted(bool printed) { 204 void VerifyPagesPrinted(bool printed) {
199 const IPC::Message* print_msg = 205 const IPC::Message* print_msg =
200 render_thread_->sink().GetUniqueMessageMatching( 206 render_thread_->sink().GetUniqueMessageMatching(
201 PrintHostMsg_DidPrintPage::ID); 207 PrintHostMsg_DidPrintPage::ID);
202 bool did_print_msg = (NULL != print_msg); 208 bool did_print_msg = (NULL != print_msg);
203 ASSERT_EQ(printed, did_print_msg); 209 ASSERT_EQ(printed, did_print_msg);
204 if (printed) { 210 if (printed) {
205 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; 211 PrintHostMsg_DidPrintPage::Param post_did_print_page_param;
206 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); 212 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param);
207 EXPECT_EQ(0, base::get<0>(post_did_print_page_param).page_number); 213 EXPECT_EQ(0, base::get<0>(post_did_print_page_param).page_number);
208 } 214 }
209 } 215 }
210 216
211 #if defined(ENABLE_BASIC_PRINTING) 217 #if defined(ENABLE_BASIC_PRINTING)
212 void OnPrintPages() { 218 void OnPrintPages() {
213 PrintWebViewHelper::Get(view_)->OnPrintPages(); 219 PrintWebViewHelper::Get(view_)->OnPrintPages();
214 ProcessPendingMessages(); 220 ProcessPendingMessages();
215 } 221 }
216 #endif // ENABLE_BASIC_PRINTING 222 #endif // defined(ENABLE_BASIC_PRINTING)
217 223
224 #if defined(ENABLE_PRINT_PREVIEW)
218 void VerifyPreviewRequest(bool requested) { 225 void VerifyPreviewRequest(bool requested) {
219 const IPC::Message* print_msg = 226 const IPC::Message* print_msg =
220 render_thread_->sink().GetUniqueMessageMatching( 227 render_thread_->sink().GetUniqueMessageMatching(
221 PrintHostMsg_SetupScriptedPrintPreview::ID); 228 PrintHostMsg_SetupScriptedPrintPreview::ID);
222 bool did_print_msg = (NULL != print_msg); 229 bool did_print_msg = (NULL != print_msg);
223 ASSERT_EQ(requested, did_print_msg); 230 ASSERT_EQ(requested, did_print_msg);
224 } 231 }
225 232
226 void OnPrintPreview(const base::DictionaryValue& dict) { 233 void OnPrintPreview(const base::DictionaryValue& dict) {
227 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); 234 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_);
228 print_web_view_helper->OnInitiatePrintPreview(false); 235 print_web_view_helper->OnInitiatePrintPreview(false);
229 base::RunLoop run_loop; 236 base::RunLoop run_loop;
230 DidPreviewPageListener filter(&run_loop); 237 DidPreviewPageListener filter(&run_loop);
231 render_thread_->sink().AddFilter(&filter); 238 render_thread_->sink().AddFilter(&filter);
232 print_web_view_helper->OnPrintPreview(dict); 239 print_web_view_helper->OnPrintPreview(dict);
233 run_loop.Run(); 240 run_loop.Run();
234 render_thread_->sink().RemoveFilter(&filter); 241 render_thread_->sink().RemoveFilter(&filter);
235 } 242 }
243 #endif // defined(ENABLE_PRINT_PREVIEW)
236 244
245 #if defined(ENABLE_BASIC_PRINTING)
237 void OnPrintForPrintPreview(const base::DictionaryValue& dict) { 246 void OnPrintForPrintPreview(const base::DictionaryValue& dict) {
238 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict); 247 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict);
239 ProcessPendingMessages(); 248 ProcessPendingMessages();
240 } 249 }
250 #endif // defined(ENABLE_BASIC_PRINTING)
241 251
242 // Naked pointer as ownership is with content::RenderViewTest::render_thread_. 252 // Naked pointer as ownership is with content::RenderViewTest::render_thread_.
243 PrintMockRenderThread* print_render_thread_; 253 PrintMockRenderThread* print_render_thread_;
244 254
255 private:
245 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase); 256 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase);
246 }; 257 };
247 258
248 // RenderViewTest-based tests crash on Android 259 // RenderViewTest-based tests crash on Android
249 // http://crbug.com/187500 260 // http://crbug.com/187500
250 #if defined(OS_ANDROID) 261 #if defined(OS_ANDROID)
251 #define MAYBE_PrintWebViewHelperTest DISABLED_PrintWebViewHelperTest 262 #define MAYBE_PrintWebViewHelperTest DISABLED_PrintWebViewHelperTest
252 #else 263 #else
253 #define MAYBE_PrintWebViewHelperTest PrintWebViewHelperTest 264 #define MAYBE_PrintWebViewHelperTest PrintWebViewHelperTest
254 #endif // defined(OS_ANDROID) 265 #endif // defined(OS_ANDROID)
255 266
256 class MAYBE_PrintWebViewHelperTest : public PrintWebViewHelperTestBase { 267 class MAYBE_PrintWebViewHelperTest : public PrintWebViewHelperTestBase {
257 public: 268 public:
258 MAYBE_PrintWebViewHelperTest() {} 269 MAYBE_PrintWebViewHelperTest() {}
259 ~MAYBE_PrintWebViewHelperTest() override {} 270 ~MAYBE_PrintWebViewHelperTest() override {}
260 271
261 void SetUp() override { PrintWebViewHelperTestBase::SetUp(); } 272 void SetUp() override { PrintWebViewHelperTestBase::SetUp(); }
262 273
263 protected: 274 private:
264 DISALLOW_COPY_AND_ASSIGN(MAYBE_PrintWebViewHelperTest); 275 DISALLOW_COPY_AND_ASSIGN(MAYBE_PrintWebViewHelperTest);
265 }; 276 };
266 277
267 // This tests only for platforms without print preview. 278 // This tests only for platforms without print preview.
268 #if !defined(ENABLE_PRINT_PREVIEW) 279 #if !defined(ENABLE_PRINT_PREVIEW)
269 // Tests that the renderer blocks window.print() calls if they occur too 280 // Tests that the renderer blocks window.print() calls if they occur too
270 // frequently. 281 // frequently.
271 TEST_F(MAYBE_PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { 282 TEST_F(MAYBE_PrintWebViewHelperTest, BlockScriptInitiatedPrinting) {
272 // Pretend user will cancel printing. 283 // Pretend user will cancel printing.
273 print_render_thread_->set_print_dialog_user_response(false); 284 print_render_thread_->set_print_dialog_user_response(false);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 VerifyPagesPrinted(true); 340 VerifyPagesPrinted(true);
330 } 341 }
331 342
332 // Duplicate of OnPrintPagesTest only using javascript to print. 343 // Duplicate of OnPrintPagesTest only using javascript to print.
333 TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithJavascript) { 344 TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithJavascript) {
334 PrintWithJavaScript(); 345 PrintWithJavaScript();
335 346
336 VerifyPageCount(1); 347 VerifyPageCount(1);
337 VerifyPagesPrinted(true); 348 VerifyPagesPrinted(true);
338 } 349 }
339 #endif // !ENABLE_PRINT_PREVIEW 350 #endif // !defined(ENABLE_PRINT_PREVIEW)
340 351
341 #if defined(ENABLE_BASIC_PRINTING) 352 #if defined(ENABLE_BASIC_PRINTING)
342 // Tests that printing pages work and sending and receiving messages through 353 // Tests that printing pages work and sending and receiving messages through
343 // that channel all works. 354 // that channel all works.
344 TEST_F(MAYBE_PrintWebViewHelperTest, OnPrintPages) { 355 TEST_F(MAYBE_PrintWebViewHelperTest, OnPrintPages) {
345 LoadHTML(kHelloWorldHTML); 356 LoadHTML(kHelloWorldHTML);
346 OnPrintPages(); 357 OnPrintPages();
347 358
348 VerifyPageCount(1); 359 VerifyPageCount(1);
349 VerifyPagesPrinted(true); 360 VerifyPagesPrinted(true);
350 } 361 }
351 #endif // ENABLE_BASIC_PRINTING 362 #endif // defined(ENABLE_BASIC_PRINTING)
352 363
353 #if defined(OS_MACOSX) && defined(ENABLE_BASIC_PRINTING) 364 #if defined(OS_MACOSX) && defined(ENABLE_BASIC_PRINTING)
354 // TODO(estade): I don't think this test is worth porting to Linux. We will have 365 // TODO(estade): I don't think this test is worth porting to Linux. We will have
355 // to rip out and replace most of the IPC code if we ever plan to improve 366 // to rip out and replace most of the IPC code if we ever plan to improve
356 // printing, and the comment below by sverrir suggests that it doesn't do much 367 // printing, and the comment below by sverrir suggests that it doesn't do much
357 // for us anyway. 368 // for us anyway.
358 TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithIframe) { 369 TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithIframe) {
359 // Document that populates an iframe. 370 // Document that populates an iframe.
360 const char html[] = 371 const char html[] =
361 "<html><body>Lorem Ipsum:" 372 "<html><body>Lorem Ipsum:"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 509
499 // RenderViewTest-based tests crash on Android 510 // RenderViewTest-based tests crash on Android
500 // http://crbug.com/187500 511 // http://crbug.com/187500
501 #if defined(OS_ANDROID) 512 #if defined(OS_ANDROID)
502 #define MAYBE_PrintWebViewHelperPreviewTest \ 513 #define MAYBE_PrintWebViewHelperPreviewTest \
503 DISABLED_PrintWebViewHelperPreviewTest 514 DISABLED_PrintWebViewHelperPreviewTest
504 #else 515 #else
505 #define MAYBE_PrintWebViewHelperPreviewTest PrintWebViewHelperPreviewTest 516 #define MAYBE_PrintWebViewHelperPreviewTest PrintWebViewHelperPreviewTest
506 #endif // defined(OS_ANDROID) 517 #endif // defined(OS_ANDROID)
507 518
519 #if defined(ENABLE_PRINT_PREVIEW)
508 class MAYBE_PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { 520 class MAYBE_PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase {
509 public: 521 public:
510 MAYBE_PrintWebViewHelperPreviewTest() {} 522 MAYBE_PrintWebViewHelperPreviewTest() {}
511 ~MAYBE_PrintWebViewHelperPreviewTest() override {} 523 ~MAYBE_PrintWebViewHelperPreviewTest() override {}
512 524
513 protected: 525 protected:
514 void VerifyPrintPreviewCancelled(bool did_cancel) { 526 void VerifyPrintPreviewCancelled(bool did_cancel) {
515 bool print_preview_cancelled = 527 bool print_preview_cancelled =
516 (render_thread_->sink().GetUniqueMessageMatching( 528 (render_thread_->sink().GetUniqueMessageMatching(
517 PrintHostMsg_PrintPreviewCancelled::ID) != NULL); 529 PrintHostMsg_PrintPreviewCancelled::ID) != NULL);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 EXPECT_EQ(content_width, base::get<0>(param).content_width); 605 EXPECT_EQ(content_width, base::get<0>(param).content_width);
594 EXPECT_EQ(content_height, base::get<0>(param).content_height); 606 EXPECT_EQ(content_height, base::get<0>(param).content_height);
595 EXPECT_EQ(margin_top, base::get<0>(param).margin_top); 607 EXPECT_EQ(margin_top, base::get<0>(param).margin_top);
596 EXPECT_EQ(margin_right, base::get<0>(param).margin_right); 608 EXPECT_EQ(margin_right, base::get<0>(param).margin_right);
597 EXPECT_EQ(margin_left, base::get<0>(param).margin_left); 609 EXPECT_EQ(margin_left, base::get<0>(param).margin_left);
598 EXPECT_EQ(margin_bottom, base::get<0>(param).margin_bottom); 610 EXPECT_EQ(margin_bottom, base::get<0>(param).margin_bottom);
599 EXPECT_EQ(page_has_print_css, base::get<2>(param)); 611 EXPECT_EQ(page_has_print_css, base::get<2>(param));
600 } 612 }
601 } 613 }
602 614
615 private:
603 DISALLOW_COPY_AND_ASSIGN(MAYBE_PrintWebViewHelperPreviewTest); 616 DISALLOW_COPY_AND_ASSIGN(MAYBE_PrintWebViewHelperPreviewTest);
604 }; 617 };
605 618
606 #if defined(ENABLE_PRINT_PREVIEW)
607 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting) { 619 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, BlockScriptInitiatedPrinting) {
608 LoadHTML(kHelloWorldHTML); 620 LoadHTML(kHelloWorldHTML);
609 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); 621 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_);
610 print_web_view_helper->SetScriptedPrintBlocked(true); 622 print_web_view_helper->SetScriptedPrintBlocked(true);
611 PrintWithJavaScript(); 623 PrintWithJavaScript();
612 VerifyPreviewRequest(false); 624 VerifyPreviewRequest(false);
613 625
614 print_web_view_helper->SetScriptedPrintBlocked(false); 626 print_web_view_helper->SetScriptedPrintBlocked(false);
615 PrintWithJavaScript(); 627 PrintWithJavaScript();
616 VerifyPreviewRequest(true); 628 VerifyPreviewRequest(true);
(...skipping 11 matching lines...) Expand all
628 mouse_event.button = blink::WebMouseEvent::ButtonLeft; 640 mouse_event.button = blink::WebMouseEvent::ButtonLeft;
629 mouse_event.x = bounds.CenterPoint().x(); 641 mouse_event.x = bounds.CenterPoint().x();
630 mouse_event.y = bounds.CenterPoint().y(); 642 mouse_event.y = bounds.CenterPoint().y();
631 mouse_event.clickCount = 1; 643 mouse_event.clickCount = 1;
632 SendWebMouseEvent(mouse_event); 644 SendWebMouseEvent(mouse_event);
633 mouse_event.type = blink::WebInputEvent::MouseUp; 645 mouse_event.type = blink::WebInputEvent::MouseUp;
634 SendWebMouseEvent(mouse_event); 646 SendWebMouseEvent(mouse_event);
635 647
636 VerifyPreviewRequest(true); 648 VerifyPreviewRequest(true);
637 } 649 }
638 #endif // ENABLE_PRINT_PREVIEW
639 650
640 // Tests that print preview work and sending and receiving messages through 651 // Tests that print preview work and sending and receiving messages through
641 // that channel all works. 652 // that channel all works.
642 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintPreview) { 653 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintPreview) {
643 LoadHTML(kHelloWorldHTML); 654 LoadHTML(kHelloWorldHTML);
644 655
645 // Fill in some dummy values. 656 // Fill in some dummy values.
646 base::DictionaryValue dict; 657 base::DictionaryValue dict;
647 CreatePrintSettingsDictionary(&dict); 658 CreatePrintSettingsDictionary(&dict);
648 OnPrintPreview(dict); 659 OnPrintPreview(dict);
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 CreatePrintSettingsDictionary(&dict); 936 CreatePrintSettingsDictionary(&dict);
926 OnPrintPreview(dict); 937 OnPrintPreview(dict);
927 938
928 EXPECT_EQ(kCancelPage, print_render_thread_->print_preview_pages_remaining()); 939 EXPECT_EQ(kCancelPage, print_render_thread_->print_preview_pages_remaining());
929 VerifyPrintPreviewCancelled(true); 940 VerifyPrintPreviewCancelled(true);
930 VerifyPrintPreviewFailed(false); 941 VerifyPrintPreviewFailed(false);
931 VerifyPrintPreviewGenerated(false); 942 VerifyPrintPreviewGenerated(false);
932 VerifyPagesPrinted(false); 943 VerifyPagesPrinted(false);
933 } 944 }
934 945
946 #if defined(ENABLE_BASIC_PRINTING)
935 // Tests that printing from print preview works and sending and receiving 947 // Tests that printing from print preview works and sending and receiving
936 // messages through that channel all works. 948 // messages through that channel all works.
937 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) { 949 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) {
938 LoadHTML(kPrintPreviewHTML); 950 LoadHTML(kPrintPreviewHTML);
939 951
940 // Fill in some dummy values. 952 // Fill in some dummy values.
941 base::DictionaryValue dict; 953 base::DictionaryValue dict;
942 CreatePrintSettingsDictionary(&dict); 954 CreatePrintSettingsDictionary(&dict);
943 OnPrintForPrintPreview(dict); 955 OnPrintForPrintPreview(dict);
944 956
945 VerifyPrintFailed(false); 957 VerifyPrintFailed(false);
946 VerifyPagesPrinted(true); 958 VerifyPagesPrinted(true);
947 } 959 }
948 960
949 // Tests that printing from print preview fails and receiving error messages 961 // Tests that printing from print preview fails and receiving error messages
950 // through that channel all works. 962 // through that channel all works.
951 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { 963 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) {
952 LoadHTML(kPrintPreviewHTML); 964 LoadHTML(kPrintPreviewHTML);
953 965
954 // An empty dictionary should fail. 966 // An empty dictionary should fail.
955 base::DictionaryValue empty_dict; 967 base::DictionaryValue empty_dict;
956 OnPrintForPrintPreview(empty_dict); 968 OnPrintForPrintPreview(empty_dict);
957 969
958 VerifyPagesPrinted(false); 970 VerifyPagesPrinted(false);
959 } 971 }
972 #endif // defined(ENABLE_BASIC_PRINTING)
960 973
961 // Tests that when default printer has invalid printer settings, print preview 974 // Tests that when default printer has invalid printer settings, print preview
962 // receives error message. 975 // receives error message.
963 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, 976 TEST_F(MAYBE_PrintWebViewHelperPreviewTest,
964 OnPrintPreviewUsingInvalidPrinterSettings) { 977 OnPrintPreviewUsingInvalidPrinterSettings) {
965 LoadHTML(kPrintPreviewHTML); 978 LoadHTML(kPrintPreviewHTML);
966 979
967 // Set mock printer to provide invalid settings. 980 // Set mock printer to provide invalid settings.
968 print_render_thread_->printer()->UseInvalidSettings(); 981 print_render_thread_->printer()->UseInvalidSettings();
969 982
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 OnPrintPreview(dict); 1027 OnPrintPreview(dict);
1015 1028
1016 VerifyPrintPreviewInvalidPrinterSettings(true); 1029 VerifyPrintPreviewInvalidPrinterSettings(true);
1017 EXPECT_EQ(0, print_render_thread_->print_preview_pages_remaining()); 1030 EXPECT_EQ(0, print_render_thread_->print_preview_pages_remaining());
1018 1031
1019 // It should receive the invalid printer settings message only. 1032 // It should receive the invalid printer settings message only.
1020 VerifyPrintPreviewFailed(false); 1033 VerifyPrintPreviewFailed(false);
1021 VerifyPrintPreviewGenerated(false); 1034 VerifyPrintPreviewGenerated(false);
1022 } 1035 }
1023 1036
1037 #if defined(ENABLE_BASIC_PRINTING)
1024 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, 1038 TEST_F(MAYBE_PrintWebViewHelperPreviewTest,
1025 OnPrintForPrintPreviewUsingInvalidPrinterSettings) { 1039 OnPrintForPrintPreviewUsingInvalidPrinterSettings) {
1026 LoadHTML(kPrintPreviewHTML); 1040 LoadHTML(kPrintPreviewHTML);
1027 1041
1028 // Set mock printer to provide invalid settings. 1042 // Set mock printer to provide invalid settings.
1029 print_render_thread_->printer()->UseInvalidSettings(); 1043 print_render_thread_->printer()->UseInvalidSettings();
1030 1044
1031 // Fill in some dummy values. 1045 // Fill in some dummy values.
1032 base::DictionaryValue dict; 1046 base::DictionaryValue dict;
1033 CreatePrintSettingsDictionary(&dict); 1047 CreatePrintSettingsDictionary(&dict);
1034 OnPrintForPrintPreview(dict); 1048 OnPrintForPrintPreview(dict);
1035 1049
1036 VerifyPrintFailed(true); 1050 VerifyPrintFailed(true);
1037 VerifyPagesPrinted(false); 1051 VerifyPagesPrinted(false);
1038 } 1052 }
1053 #endif // defined(ENABLE_BASIC_PRINTING)
1054 #endif // defined(ENABLE_PRINT_PREVIEW)
1039 1055
1040 #endif // !defined(OS_CHROMEOS) 1056 #endif // !defined(OS_CHROMEOS)
1041 1057
1042 } // namespace printing 1058 } // namespace printing
OLDNEW
« no previous file with comments | « components/printing/test/print_mock_render_thread.cc ('k') | printing/print_job_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698