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

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

Issue 2458833005: Move printing defines to buildflag system. (Closed)
Patch Set: Merge Created 4 years, 1 month 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
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 "components/printing/renderer/print_web_view_helper.h" 5 #include "components/printing/renderer/print_web_view_helper.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <tuple> 10 #include <tuple>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "build/build_config.h" 16 #include "build/build_config.h"
17 #include "components/printing/common/print_messages.h" 17 #include "components/printing/common/print_messages.h"
18 #include "components/printing/test/mock_printer.h" 18 #include "components/printing/test/mock_printer.h"
19 #include "components/printing/test/print_mock_render_thread.h" 19 #include "components/printing/test/print_mock_render_thread.h"
20 #include "components/printing/test/print_test_content_renderer_client.h" 20 #include "components/printing/test/print_test_content_renderer_client.h"
21 #include "content/public/renderer/render_view.h" 21 #include "content/public/renderer/render_view.h"
22 #include "content/public/test/render_view_test.h" 22 #include "content/public/test/render_view_test.h"
23 #include "ipc/ipc_listener.h" 23 #include "ipc/ipc_listener.h"
24 #include "printing/features/features.h"
24 #include "printing/print_job_constants.h" 25 #include "printing/print_job_constants.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 #include "third_party/WebKit/public/platform/WebString.h" 27 #include "third_party/WebKit/public/platform/WebString.h"
27 #include "third_party/WebKit/public/web/WebLocalFrame.h" 28 #include "third_party/WebKit/public/web/WebLocalFrame.h"
28 #include "third_party/WebKit/public/web/WebRange.h" 29 #include "third_party/WebKit/public/web/WebRange.h"
29 #include "third_party/WebKit/public/web/WebView.h" 30 #include "third_party/WebKit/public/web/WebView.h"
30 31
31 #if defined(OS_WIN) || defined(OS_MACOSX) 32 #if defined(OS_WIN) || defined(OS_MACOSX)
32 #include "base/files/file_util.h" 33 #include "base/files/file_util.h"
33 #include "printing/image.h" 34 #include "printing/image.h"
(...skipping 10 matching lines...) Expand all
44 // A simple web page. 45 // A simple web page.
45 const char kHelloWorldHTML[] = "<body><p>Hello World!</p></body>"; 46 const char kHelloWorldHTML[] = "<body><p>Hello World!</p></body>";
46 47
47 #if !defined(OS_CHROMEOS) 48 #if !defined(OS_CHROMEOS)
48 // A simple webpage with a button to print itself with. 49 // A simple webpage with a button to print itself with.
49 const char kPrintOnUserAction[] = 50 const char kPrintOnUserAction[] =
50 "<body>" 51 "<body>"
51 " <button id=\"print\" onclick=\"window.print();\">Hello World!</button>" 52 " <button id=\"print\" onclick=\"window.print();\">Hello World!</button>"
52 "</body>"; 53 "</body>";
53 54
54 #if defined(ENABLE_PRINT_PREVIEW) 55 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
55 // HTML with 3 pages. 56 // HTML with 3 pages.
56 const char kMultipageHTML[] = 57 const char kMultipageHTML[] =
57 "<html><head><style>" 58 "<html><head><style>"
58 ".break { page-break-after: always; }" 59 ".break { page-break-after: always; }"
59 "</style></head>" 60 "</style></head>"
60 "<body>" 61 "<body>"
61 "<div class='break'>page1</div>" 62 "<div class='break'>page1</div>"
62 "<div class='break'>page2</div>" 63 "<div class='break'>page2</div>"
63 "<div>page3</div>" 64 "<div>page3</div>"
64 "</body></html>"; 65 "</body></html>";
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 dict->SetInteger(kPreviewUIID, 4); 107 dict->SetInteger(kPreviewUIID, 4);
107 dict->SetInteger(kPreviewRequestID, 12345); 108 dict->SetInteger(kPreviewRequestID, 12345);
108 dict->SetBoolean(kIsFirstRequest, true); 109 dict->SetBoolean(kIsFirstRequest, true);
109 dict->SetInteger(kSettingMarginsType, DEFAULT_MARGINS); 110 dict->SetInteger(kSettingMarginsType, DEFAULT_MARGINS);
110 dict->SetBoolean(kSettingPreviewModifiable, false); 111 dict->SetBoolean(kSettingPreviewModifiable, false);
111 dict->SetBoolean(kSettingHeaderFooterEnabled, false); 112 dict->SetBoolean(kSettingHeaderFooterEnabled, false);
112 dict->SetBoolean(kSettingGenerateDraftData, true); 113 dict->SetBoolean(kSettingGenerateDraftData, true);
113 dict->SetBoolean(kSettingShouldPrintBackgrounds, false); 114 dict->SetBoolean(kSettingShouldPrintBackgrounds, false);
114 dict->SetBoolean(kSettingShouldPrintSelectionOnly, false); 115 dict->SetBoolean(kSettingShouldPrintSelectionOnly, false);
115 } 116 }
116 #endif // defined(ENABLE_PRINT_PREVIEW) 117 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
117 #endif // !defined(OS_CHROMEOS) 118 #endif // !defined(OS_CHROMEOS)
118 119
119 #if defined(ENABLE_PRINT_PREVIEW) 120 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
120 class DidPreviewPageListener : public IPC::Listener { 121 class DidPreviewPageListener : public IPC::Listener {
121 public: 122 public:
122 explicit DidPreviewPageListener(base::RunLoop* run_loop) 123 explicit DidPreviewPageListener(base::RunLoop* run_loop)
123 : run_loop_(run_loop) {} 124 : run_loop_(run_loop) {}
124 125
125 bool OnMessageReceived(const IPC::Message& message) override { 126 bool OnMessageReceived(const IPC::Message& message) override {
126 if (message.type() == PrintHostMsg_MetafileReadyForPrinting::ID || 127 if (message.type() == PrintHostMsg_MetafileReadyForPrinting::ID ||
127 message.type() == PrintHostMsg_PrintPreviewFailed::ID || 128 message.type() == PrintHostMsg_PrintPreviewFailed::ID ||
128 message.type() == PrintHostMsg_PrintPreviewCancelled::ID) 129 message.type() == PrintHostMsg_PrintPreviewCancelled::ID)
129 run_loop_->Quit(); 130 run_loop_->Quit();
130 return false; 131 return false;
131 } 132 }
132 133
133 private: 134 private:
134 base::RunLoop* const run_loop_; 135 base::RunLoop* const run_loop_;
135 DISALLOW_COPY_AND_ASSIGN(DidPreviewPageListener); 136 DISALLOW_COPY_AND_ASSIGN(DidPreviewPageListener);
136 }; 137 };
137 #endif // defined(ENABLE_PRINT_PREVIEW) 138 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
138 139
139 } // namespace 140 } // namespace
140 141
141 class PrintWebViewHelperTestBase : public content::RenderViewTest { 142 class PrintWebViewHelperTestBase : public content::RenderViewTest {
142 public: 143 public:
143 PrintWebViewHelperTestBase() : print_render_thread_(nullptr) {} 144 PrintWebViewHelperTestBase() : print_render_thread_(nullptr) {}
144 ~PrintWebViewHelperTestBase() override {} 145 ~PrintWebViewHelperTestBase() override {}
145 146
146 protected: 147 protected:
147 // content::RenderViewTest: 148 // content::RenderViewTest:
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 render_thread_->sink().GetUniqueMessageMatching( 185 render_thread_->sink().GetUniqueMessageMatching(
185 PrintHostMsg_DidGetPrintedPagesCount::ID); 186 PrintHostMsg_DidGetPrintedPagesCount::ID);
186 ASSERT_TRUE(page_cnt_msg); 187 ASSERT_TRUE(page_cnt_msg);
187 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param; 188 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param;
188 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg, 189 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg,
189 &post_page_count_param); 190 &post_page_count_param);
190 EXPECT_EQ(count, std::get<1>(post_page_count_param)); 191 EXPECT_EQ(count, std::get<1>(post_page_count_param));
191 #endif // defined(OS_CHROMEOS) 192 #endif // defined(OS_CHROMEOS)
192 } 193 }
193 194
194 #if defined(ENABLE_PRINT_PREVIEW) 195 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
195 // The renderer should be done calculating the number of rendered pages 196 // The renderer should be done calculating the number of rendered pages
196 // according to the specified settings defined in the mock render thread. 197 // according to the specified settings defined in the mock render thread.
197 // Verify the page count is correct. 198 // Verify the page count is correct.
198 void VerifyPreviewPageCount(int count) { 199 void VerifyPreviewPageCount(int count) {
199 const IPC::Message* page_cnt_msg = 200 const IPC::Message* page_cnt_msg =
200 render_thread_->sink().GetUniqueMessageMatching( 201 render_thread_->sink().GetUniqueMessageMatching(
201 PrintHostMsg_DidGetPreviewPageCount::ID); 202 PrintHostMsg_DidGetPreviewPageCount::ID);
202 ASSERT_TRUE(page_cnt_msg); 203 ASSERT_TRUE(page_cnt_msg);
203 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param; 204 PrintHostMsg_DidGetPreviewPageCount::Param post_page_count_param;
204 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg, 205 PrintHostMsg_DidGetPreviewPageCount::Read(page_cnt_msg,
205 &post_page_count_param); 206 &post_page_count_param);
206 EXPECT_EQ(count, std::get<0>(post_page_count_param).page_count); 207 EXPECT_EQ(count, std::get<0>(post_page_count_param).page_count);
207 } 208 }
208 #endif // defined(ENABLE_PRINT_PREVIEW) 209 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
209 210
210 // Verifies whether the pages printed or not. 211 // Verifies whether the pages printed or not.
211 void VerifyPagesPrinted(bool printed) { 212 void VerifyPagesPrinted(bool printed) {
212 const IPC::Message* print_msg = 213 const IPC::Message* print_msg =
213 render_thread_->sink().GetUniqueMessageMatching( 214 render_thread_->sink().GetUniqueMessageMatching(
214 PrintHostMsg_DidPrintPage::ID); 215 PrintHostMsg_DidPrintPage::ID);
215 bool did_print_msg = !!print_msg; 216 bool did_print_msg = !!print_msg;
216 ASSERT_EQ(printed, did_print_msg); 217 ASSERT_EQ(printed, did_print_msg);
217 if (printed) { 218 if (printed) {
218 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; 219 PrintHostMsg_DidPrintPage::Param post_did_print_page_param;
219 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); 220 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param);
220 EXPECT_EQ(0, std::get<0>(post_did_print_page_param).page_number); 221 EXPECT_EQ(0, std::get<0>(post_did_print_page_param).page_number);
221 } 222 }
222 } 223 }
223 224
224 #if defined(ENABLE_BASIC_PRINTING) 225 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
225 void OnPrintPages() { 226 void OnPrintPages() {
226 PrintWebViewHelper::Get(view_)->OnPrintPages(); 227 PrintWebViewHelper::Get(view_)->OnPrintPages();
227 ProcessPendingMessages(); 228 ProcessPendingMessages();
228 } 229 }
229 #endif // defined(ENABLE_BASIC_PRINTING) 230 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
230 231
231 #if defined(ENABLE_PRINT_PREVIEW) 232 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
232 void VerifyPreviewRequest(bool requested) { 233 void VerifyPreviewRequest(bool requested) {
233 const IPC::Message* print_msg = 234 const IPC::Message* print_msg =
234 render_thread_->sink().GetUniqueMessageMatching( 235 render_thread_->sink().GetUniqueMessageMatching(
235 PrintHostMsg_SetupScriptedPrintPreview::ID); 236 PrintHostMsg_SetupScriptedPrintPreview::ID);
236 bool did_print_msg = !!print_msg; 237 bool did_print_msg = !!print_msg;
237 ASSERT_EQ(requested, did_print_msg); 238 ASSERT_EQ(requested, did_print_msg);
238 } 239 }
239 240
240 void OnPrintPreview(const base::DictionaryValue& dict) { 241 void OnPrintPreview(const base::DictionaryValue& dict) {
241 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_); 242 PrintWebViewHelper* print_web_view_helper = PrintWebViewHelper::Get(view_);
242 print_web_view_helper->OnInitiatePrintPreview(false); 243 print_web_view_helper->OnInitiatePrintPreview(false);
243 base::RunLoop run_loop; 244 base::RunLoop run_loop;
244 DidPreviewPageListener filter(&run_loop); 245 DidPreviewPageListener filter(&run_loop);
245 render_thread_->sink().AddFilter(&filter); 246 render_thread_->sink().AddFilter(&filter);
246 print_web_view_helper->OnPrintPreview(dict); 247 print_web_view_helper->OnPrintPreview(dict);
247 run_loop.Run(); 248 run_loop.Run();
248 render_thread_->sink().RemoveFilter(&filter); 249 render_thread_->sink().RemoveFilter(&filter);
249 } 250 }
250 #endif // defined(ENABLE_PRINT_PREVIEW) 251 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
251 252
252 #if defined(ENABLE_BASIC_PRINTING) 253 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
253 void OnPrintForPrintPreview(const base::DictionaryValue& dict) { 254 void OnPrintForPrintPreview(const base::DictionaryValue& dict) {
254 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict); 255 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict);
255 ProcessPendingMessages(); 256 ProcessPendingMessages();
256 } 257 }
257 #endif // defined(ENABLE_BASIC_PRINTING) 258 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
258 259
259 // Naked pointer as ownership is with content::RenderViewTest::render_thread_. 260 // Naked pointer as ownership is with content::RenderViewTest::render_thread_.
260 PrintMockRenderThread* print_render_thread_; 261 PrintMockRenderThread* print_render_thread_;
261 262
262 private: 263 private:
263 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase); 264 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase);
264 }; 265 };
265 266
266 // RenderViewTest-based tests crash on Android 267 // RenderViewTest-based tests crash on Android
267 // http://crbug.com/187500 268 // http://crbug.com/187500
268 #if defined(OS_ANDROID) 269 #if defined(OS_ANDROID)
269 #define MAYBE_PrintWebViewHelperTest DISABLED_PrintWebViewHelperTest 270 #define MAYBE_PrintWebViewHelperTest DISABLED_PrintWebViewHelperTest
270 #else 271 #else
271 #define MAYBE_PrintWebViewHelperTest PrintWebViewHelperTest 272 #define MAYBE_PrintWebViewHelperTest PrintWebViewHelperTest
272 #endif // defined(OS_ANDROID) 273 #endif // defined(OS_ANDROID)
273 274
274 class MAYBE_PrintWebViewHelperTest : public PrintWebViewHelperTestBase { 275 class MAYBE_PrintWebViewHelperTest : public PrintWebViewHelperTestBase {
275 public: 276 public:
276 MAYBE_PrintWebViewHelperTest() {} 277 MAYBE_PrintWebViewHelperTest() {}
277 ~MAYBE_PrintWebViewHelperTest() override {} 278 ~MAYBE_PrintWebViewHelperTest() override {}
278 279
279 void SetUp() override { PrintWebViewHelperTestBase::SetUp(); } 280 void SetUp() override { PrintWebViewHelperTestBase::SetUp(); }
280 281
281 private: 282 private:
282 DISALLOW_COPY_AND_ASSIGN(MAYBE_PrintWebViewHelperTest); 283 DISALLOW_COPY_AND_ASSIGN(MAYBE_PrintWebViewHelperTest);
283 }; 284 };
284 285
285 // This tests only for platforms without print preview. 286 // This tests only for platforms without print preview.
286 #if !defined(ENABLE_PRINT_PREVIEW) 287 #if !BUILDFLAG(ENABLE_PRINT_PREVIEW)
287 // Tests that the renderer blocks window.print() calls if they occur too 288 // Tests that the renderer blocks window.print() calls if they occur too
288 // frequently. 289 // frequently.
289 TEST_F(MAYBE_PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { 290 TEST_F(MAYBE_PrintWebViewHelperTest, BlockScriptInitiatedPrinting) {
290 // Pretend user will cancel printing. 291 // Pretend user will cancel printing.
291 print_render_thread_->set_print_dialog_user_response(false); 292 print_render_thread_->set_print_dialog_user_response(false);
292 // Try to print with window.print() a few times. 293 // Try to print with window.print() a few times.
293 PrintWithJavaScript(); 294 PrintWithJavaScript();
294 PrintWithJavaScript(); 295 PrintWithJavaScript();
295 PrintWithJavaScript(); 296 PrintWithJavaScript();
296 VerifyPagesPrinted(false); 297 VerifyPagesPrinted(false);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 VerifyPagesPrinted(true); 348 VerifyPagesPrinted(true);
348 } 349 }
349 350
350 // Duplicate of OnPrintPagesTest only using javascript to print. 351 // Duplicate of OnPrintPagesTest only using javascript to print.
351 TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithJavascript) { 352 TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithJavascript) {
352 PrintWithJavaScript(); 353 PrintWithJavaScript();
353 354
354 VerifyPageCount(1); 355 VerifyPageCount(1);
355 VerifyPagesPrinted(true); 356 VerifyPagesPrinted(true);
356 } 357 }
357 #endif // !defined(ENABLE_PRINT_PREVIEW) 358 #endif // !BUILDFLAG(ENABLE_PRINT_PREVIEW)
358 359
359 #if defined(ENABLE_BASIC_PRINTING) 360 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
360 // Tests that printing pages work and sending and receiving messages through 361 // Tests that printing pages work and sending and receiving messages through
361 // that channel all works. 362 // that channel all works.
362 TEST_F(MAYBE_PrintWebViewHelperTest, OnPrintPages) { 363 TEST_F(MAYBE_PrintWebViewHelperTest, OnPrintPages) {
363 LoadHTML(kHelloWorldHTML); 364 LoadHTML(kHelloWorldHTML);
364 OnPrintPages(); 365 OnPrintPages();
365 366
366 VerifyPageCount(1); 367 VerifyPageCount(1);
367 VerifyPagesPrinted(true); 368 VerifyPagesPrinted(true);
368 } 369 }
369 #endif // defined(ENABLE_BASIC_PRINTING) 370 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
370 371
371 #if defined(OS_MACOSX) && defined(ENABLE_BASIC_PRINTING) 372 #if defined(OS_MACOSX) && BUILDFLAG(ENABLE_BASIC_PRINTING)
372 // TODO(estade): I don't think this test is worth porting to Linux. We will have 373 // TODO(estade): I don't think this test is worth porting to Linux. We will have
373 // to rip out and replace most of the IPC code if we ever plan to improve 374 // to rip out and replace most of the IPC code if we ever plan to improve
374 // printing, and the comment below by sverrir suggests that it doesn't do much 375 // printing, and the comment below by sverrir suggests that it doesn't do much
375 // for us anyway. 376 // for us anyway.
376 TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithIframe) { 377 TEST_F(MAYBE_PrintWebViewHelperTest, PrintWithIframe) {
377 // Document that populates an iframe. 378 // Document that populates an iframe.
378 const char html[] = 379 const char html[] =
379 "<html><body>Lorem Ipsum:" 380 "<html><body>Lorem Ipsum:"
380 "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>" 381 "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>"
381 " document.write(frames['sub1'].name);" 382 " document.write(frames['sub1'].name);"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 // Test cases used in this test. 420 // Test cases used in this test.
420 struct TestPageData { 421 struct TestPageData {
421 const char* page; 422 const char* page;
422 size_t printed_pages; 423 size_t printed_pages;
423 int width; 424 int width;
424 int height; 425 int height;
425 const char* checksum; 426 const char* checksum;
426 const wchar_t* file; 427 const wchar_t* file;
427 }; 428 };
428 429
429 #if defined(OS_MACOSX) && defined(ENABLE_BASIC_PRINTING) 430 #if defined(OS_MACOSX) && BUILDFLAG(ENABLE_BASIC_PRINTING)
430 const TestPageData kTestPages[] = { 431 const TestPageData kTestPages[] = {
431 { 432 {
432 "<html>" 433 "<html>"
433 "<head>" 434 "<head>"
434 "<meta" 435 "<meta"
435 " http-equiv=\"Content-Type\"" 436 " http-equiv=\"Content-Type\""
436 " content=\"text/html; charset=utf-8\"/>" 437 " content=\"text/html; charset=utf-8\"/>"
437 "<title>Test 1</title>" 438 "<title>Test 1</title>"
438 "</head>" 439 "</head>"
439 "<body style=\"background-color: white;\">" 440 "<body style=\"background-color: white;\">"
440 "<p style=\"font-family: arial;\">Hello World!</p>" 441 "<p style=\"font-family: arial;\">Hello World!</p>"
441 "</body>", 442 "</body>",
442 1, 443 1,
443 // Mac printing code compensates for the WebKit scale factor while 444 // Mac printing code compensates for the WebKit scale factor while
444 // generating the metafile, so we expect smaller pages. (On non-Mac 445 // generating the metafile, so we expect smaller pages. (On non-Mac
445 // platforms, this would be 675x900). 446 // platforms, this would be 675x900).
446 600, 780, nullptr, nullptr, 447 600, 780, nullptr, nullptr,
447 }, 448 },
448 }; 449 };
449 #endif // defined(OS_MACOSX) && defined(ENABLE_BASIC_PRINTING) 450 #endif // defined(OS_MACOSX) && BUILDFLAG(ENABLE_BASIC_PRINTING)
450 } // namespace 451 } // namespace
451 452
452 // TODO(estade): need to port MockPrinter to get this on Linux. This involves 453 // TODO(estade): need to port MockPrinter to get this on Linux. This involves
453 // hooking up Cairo to read a pdf stream, or accessing the cairo surface in the 454 // hooking up Cairo to read a pdf stream, or accessing the cairo surface in the
454 // metafile directly. 455 // metafile directly.
455 // Same for printing via PDF on Windows. 456 // Same for printing via PDF on Windows.
456 #if defined(OS_MACOSX) && defined(ENABLE_BASIC_PRINTING) 457 #if defined(OS_MACOSX) && BUILDFLAG(ENABLE_BASIC_PRINTING)
457 TEST_F(MAYBE_PrintWebViewHelperTest, PrintLayoutTest) { 458 TEST_F(MAYBE_PrintWebViewHelperTest, PrintLayoutTest) {
458 bool baseline = false; 459 bool baseline = false;
459 460
460 EXPECT_TRUE(print_render_thread_->printer()); 461 EXPECT_TRUE(print_render_thread_->printer());
461 for (size_t i = 0; i < arraysize(kTestPages); ++i) { 462 for (size_t i = 0; i < arraysize(kTestPages); ++i) {
462 // Load an HTML page and print it. 463 // Load an HTML page and print it.
463 LoadHTML(kTestPages[i].page); 464 LoadHTML(kTestPages[i].page);
464 OnPrintPages(); 465 OnPrintPages();
465 VerifyPagesPrinted(true); 466 VerifyPagesPrinted(true);
466 467
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 514
514 // RenderViewTest-based tests crash on Android 515 // RenderViewTest-based tests crash on Android
515 // http://crbug.com/187500 516 // http://crbug.com/187500
516 #if defined(OS_ANDROID) 517 #if defined(OS_ANDROID)
517 #define MAYBE_PrintWebViewHelperPreviewTest \ 518 #define MAYBE_PrintWebViewHelperPreviewTest \
518 DISABLED_PrintWebViewHelperPreviewTest 519 DISABLED_PrintWebViewHelperPreviewTest
519 #else 520 #else
520 #define MAYBE_PrintWebViewHelperPreviewTest PrintWebViewHelperPreviewTest 521 #define MAYBE_PrintWebViewHelperPreviewTest PrintWebViewHelperPreviewTest
521 #endif // defined(OS_ANDROID) 522 #endif // defined(OS_ANDROID)
522 523
523 #if defined(ENABLE_PRINT_PREVIEW) 524 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
524 class MAYBE_PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { 525 class MAYBE_PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase {
525 public: 526 public:
526 MAYBE_PrintWebViewHelperPreviewTest() {} 527 MAYBE_PrintWebViewHelperPreviewTest() {}
527 ~MAYBE_PrintWebViewHelperPreviewTest() override {} 528 ~MAYBE_PrintWebViewHelperPreviewTest() override {}
528 529
529 protected: 530 protected:
530 void VerifyPrintPreviewCancelled(bool did_cancel) { 531 void VerifyPrintPreviewCancelled(bool did_cancel) {
531 bool print_preview_cancelled = 532 bool print_preview_cancelled =
532 !!render_thread_->sink().GetUniqueMessageMatching( 533 !!render_thread_->sink().GetUniqueMessageMatching(
533 PrintHostMsg_PrintPreviewCancelled::ID); 534 PrintHostMsg_PrintPreviewCancelled::ID);
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 CreatePrintSettingsDictionary(&dict); 941 CreatePrintSettingsDictionary(&dict);
941 OnPrintPreview(dict); 942 OnPrintPreview(dict);
942 943
943 EXPECT_EQ(kCancelPage, print_render_thread_->print_preview_pages_remaining()); 944 EXPECT_EQ(kCancelPage, print_render_thread_->print_preview_pages_remaining());
944 VerifyPrintPreviewCancelled(true); 945 VerifyPrintPreviewCancelled(true);
945 VerifyPrintPreviewFailed(false); 946 VerifyPrintPreviewFailed(false);
946 VerifyPrintPreviewGenerated(false); 947 VerifyPrintPreviewGenerated(false);
947 VerifyPagesPrinted(false); 948 VerifyPagesPrinted(false);
948 } 949 }
949 950
950 #if defined(ENABLE_BASIC_PRINTING) 951 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
951 // Tests that printing from print preview works and sending and receiving 952 // Tests that printing from print preview works and sending and receiving
952 // messages through that channel all works. 953 // messages through that channel all works.
953 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) { 954 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) {
954 LoadHTML(kPrintPreviewHTML); 955 LoadHTML(kPrintPreviewHTML);
955 956
956 // Fill in some dummy values. 957 // Fill in some dummy values.
957 base::DictionaryValue dict; 958 base::DictionaryValue dict;
958 CreatePrintSettingsDictionary(&dict); 959 CreatePrintSettingsDictionary(&dict);
959 OnPrintForPrintPreview(dict); 960 OnPrintForPrintPreview(dict);
960 961
961 VerifyPrintFailed(false); 962 VerifyPrintFailed(false);
962 VerifyPagesPrinted(true); 963 VerifyPagesPrinted(true);
963 } 964 }
964 965
965 // Tests that printing from print preview fails and receiving error messages 966 // Tests that printing from print preview fails and receiving error messages
966 // through that channel all works. 967 // through that channel all works.
967 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { 968 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) {
968 LoadHTML(kPrintPreviewHTML); 969 LoadHTML(kPrintPreviewHTML);
969 970
970 // An empty dictionary should fail. 971 // An empty dictionary should fail.
971 base::DictionaryValue empty_dict; 972 base::DictionaryValue empty_dict;
972 OnPrintForPrintPreview(empty_dict); 973 OnPrintForPrintPreview(empty_dict);
973 974
974 VerifyPagesPrinted(false); 975 VerifyPagesPrinted(false);
975 } 976 }
976 #endif // defined(ENABLE_BASIC_PRINTING) 977 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
977 978
978 // Tests that when default printer has invalid printer settings, print preview 979 // Tests that when default printer has invalid printer settings, print preview
979 // receives error message. 980 // receives error message.
980 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, 981 TEST_F(MAYBE_PrintWebViewHelperPreviewTest,
981 OnPrintPreviewUsingInvalidPrinterSettings) { 982 OnPrintPreviewUsingInvalidPrinterSettings) {
982 LoadHTML(kPrintPreviewHTML); 983 LoadHTML(kPrintPreviewHTML);
983 984
984 // Set mock printer to provide invalid settings. 985 // Set mock printer to provide invalid settings.
985 print_render_thread_->printer()->UseInvalidSettings(); 986 print_render_thread_->printer()->UseInvalidSettings();
986 987
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1031 OnPrintPreview(dict); 1032 OnPrintPreview(dict);
1032 1033
1033 VerifyPrintPreviewInvalidPrinterSettings(true); 1034 VerifyPrintPreviewInvalidPrinterSettings(true);
1034 EXPECT_EQ(0, print_render_thread_->print_preview_pages_remaining()); 1035 EXPECT_EQ(0, print_render_thread_->print_preview_pages_remaining());
1035 1036
1036 // It should receive the invalid printer settings message only. 1037 // It should receive the invalid printer settings message only.
1037 VerifyPrintPreviewFailed(false); 1038 VerifyPrintPreviewFailed(false);
1038 VerifyPrintPreviewGenerated(false); 1039 VerifyPrintPreviewGenerated(false);
1039 } 1040 }
1040 1041
1041 #if defined(ENABLE_BASIC_PRINTING) 1042 #if BUILDFLAG(ENABLE_BASIC_PRINTING)
1042 TEST_F(MAYBE_PrintWebViewHelperPreviewTest, 1043 TEST_F(MAYBE_PrintWebViewHelperPreviewTest,
1043 OnPrintForPrintPreviewUsingInvalidPrinterSettings) { 1044 OnPrintForPrintPreviewUsingInvalidPrinterSettings) {
1044 LoadHTML(kPrintPreviewHTML); 1045 LoadHTML(kPrintPreviewHTML);
1045 1046
1046 // Set mock printer to provide invalid settings. 1047 // Set mock printer to provide invalid settings.
1047 print_render_thread_->printer()->UseInvalidSettings(); 1048 print_render_thread_->printer()->UseInvalidSettings();
1048 1049
1049 // Fill in some dummy values. 1050 // Fill in some dummy values.
1050 base::DictionaryValue dict; 1051 base::DictionaryValue dict;
1051 CreatePrintSettingsDictionary(&dict); 1052 CreatePrintSettingsDictionary(&dict);
1052 OnPrintForPrintPreview(dict); 1053 OnPrintForPrintPreview(dict);
1053 1054
1054 VerifyPrintFailed(true); 1055 VerifyPrintFailed(true);
1055 VerifyPagesPrinted(false); 1056 VerifyPagesPrinted(false);
1056 } 1057 }
1057 #endif // defined(ENABLE_BASIC_PRINTING) 1058 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
1058 #endif // defined(ENABLE_PRINT_PREVIEW) 1059 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
1059 1060
1060 #endif // !defined(OS_CHROMEOS) 1061 #endif // !defined(OS_CHROMEOS)
1061 1062
1062 } // namespace printing 1063 } // namespace printing
OLDNEW
« no previous file with comments | « components/printing/test/print_test_content_renderer_client.cc ('k') | components/renderer_context_menu/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698