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

Side by Side Diff: chrome/renderer/print_web_view_helper_browsertest.cc

Issue 8230034: Split most of RenderViewTest and associated classes into content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Mac build breaks. Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/common/chrome_switches.h" 5 #include "chrome/common/chrome_switches.h"
6 #include "chrome/common/print_messages.h" 6 #include "chrome/common/print_messages.h"
7 #include "chrome/renderer/print_web_view_helper.h" 7 #include "chrome/renderer/print_web_view_helper.h"
8 #include "chrome/test/base/render_view_test.h" 8 #include "chrome/test/base/chrome_render_view_test.h"
9 #include "content/public/renderer/render_view.h" 9 #include "content/public/renderer/render_view.h"
10 #include "printing/print_job_constants.h" 10 #include "printing/print_job_constants.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h" 13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
15 15
16 #if defined(OS_WIN) || defined(OS_MACOSX) 16 #if defined(OS_WIN) || defined(OS_MACOSX)
17 #include "base/file_util.h" 17 #include "base/file_util.h"
18 #include "printing/image.h" 18 #include "printing/image.h"
(...skipping 30 matching lines...) Expand all
49 dict->SetString(printing::kPreviewUIAddr, "0xb33fbeef"); 49 dict->SetString(printing::kPreviewUIAddr, "0xb33fbeef");
50 dict->SetInteger(printing::kPreviewRequestID, 12345); 50 dict->SetInteger(printing::kPreviewRequestID, 12345);
51 dict->SetBoolean(printing::kIsFirstRequest, true); 51 dict->SetBoolean(printing::kIsFirstRequest, true);
52 dict->SetInteger(printing::kSettingMarginsType, printing::DEFAULT_MARGINS); 52 dict->SetInteger(printing::kSettingMarginsType, printing::DEFAULT_MARGINS);
53 dict->SetBoolean(printing::kSettingHeaderFooterEnabled, false); 53 dict->SetBoolean(printing::kSettingHeaderFooterEnabled, false);
54 dict->SetBoolean(printing::kSettingGenerateDraftData, true); 54 dict->SetBoolean(printing::kSettingGenerateDraftData, true);
55 } 55 }
56 56
57 } // namespace 57 } // namespace
58 58
59 class PrintWebViewHelperTestBase : public RenderViewTest { 59 class PrintWebViewHelperTestBase : public ChromeRenderViewTest {
60 public: 60 public:
61 PrintWebViewHelperTestBase() {} 61 PrintWebViewHelperTestBase() {}
62 ~PrintWebViewHelperTestBase() {} 62 ~PrintWebViewHelperTestBase() {}
63 63
64 protected: 64 protected:
65 // The renderer should be done calculating the number of rendered pages 65 // The renderer should be done calculating the number of rendered pages
66 // according to the specified settings defined in the mock render thread. 66 // according to the specified settings defined in the mock render thread.
67 // Verify the page count is correct. 67 // Verify the page count is correct.
68 void VerifyPageCount(int count) { 68 void VerifyPageCount(int count) {
69 #if defined(OS_CHROMEOS) 69 #if defined(OS_CHROMEOS)
70 // The DidGetPrintedPagesCount message isn't sent on ChromeOS. Right now we 70 // The DidGetPrintedPagesCount message isn't sent on ChromeOS. Right now we
71 // always print all pages, and there are checks to that effect built into 71 // always print all pages, and there are checks to that effect built into
72 // the print code. 72 // the print code.
73 #else 73 #else
74 const IPC::Message* page_cnt_msg = 74 const IPC::Message* page_cnt_msg =
75 render_thread_.sink().GetUniqueMessageMatching( 75 render_thread_->sink().GetUniqueMessageMatching(
76 PrintHostMsg_DidGetPrintedPagesCount::ID); 76 PrintHostMsg_DidGetPrintedPagesCount::ID);
77 ASSERT_TRUE(page_cnt_msg); 77 ASSERT_TRUE(page_cnt_msg);
78 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param; 78 PrintHostMsg_DidGetPrintedPagesCount::Param post_page_count_param;
79 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg, 79 PrintHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg,
80 &post_page_count_param); 80 &post_page_count_param);
81 EXPECT_EQ(count, post_page_count_param.b); 81 EXPECT_EQ(count, post_page_count_param.b);
82 #endif // defined(OS_CHROMEOS) 82 #endif // defined(OS_CHROMEOS)
83 } 83 }
84 84
85 // Verifies whether the pages printed or not. 85 // Verifies whether the pages printed or not.
86 void VerifyPagesPrinted(bool printed) { 86 void VerifyPagesPrinted(bool printed) {
87 #if defined(OS_CHROMEOS) 87 #if defined(OS_CHROMEOS)
88 bool did_print_msg = (render_thread_.sink().GetUniqueMessageMatching( 88 bool did_print_msg = (render_thread_->sink().GetUniqueMessageMatching(
89 PrintHostMsg_TempFileForPrintingWritten::ID) != NULL); 89 PrintHostMsg_TempFileForPrintingWritten::ID) != NULL);
90 ASSERT_EQ(printed, did_print_msg); 90 ASSERT_EQ(printed, did_print_msg);
91 #else 91 #else
92 const IPC::Message* print_msg = 92 const IPC::Message* print_msg =
93 render_thread_.sink().GetUniqueMessageMatching( 93 render_thread_->sink().GetUniqueMessageMatching(
94 PrintHostMsg_DidPrintPage::ID); 94 PrintHostMsg_DidPrintPage::ID);
95 bool did_print_msg = (NULL != print_msg); 95 bool did_print_msg = (NULL != print_msg);
96 ASSERT_EQ(printed, did_print_msg); 96 ASSERT_EQ(printed, did_print_msg);
97 if (printed) { 97 if (printed) {
98 PrintHostMsg_DidPrintPage::Param post_did_print_page_param; 98 PrintHostMsg_DidPrintPage::Param post_did_print_page_param;
99 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param); 99 PrintHostMsg_DidPrintPage::Read(print_msg, &post_did_print_page_param);
100 EXPECT_EQ(0, post_did_print_page_param.a.page_number); 100 EXPECT_EQ(0, post_did_print_page_param.a.page_number);
101 } 101 }
102 #endif // defined(OS_CHROMEOS) 102 #endif // defined(OS_CHROMEOS)
103 } 103 }
(...skipping 10 matching lines...) Expand all
114 114
115 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase); 115 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTestBase);
116 }; 116 };
117 117
118 class PrintWebViewHelperTest : public PrintWebViewHelperTestBase { 118 class PrintWebViewHelperTest : public PrintWebViewHelperTestBase {
119 public: 119 public:
120 PrintWebViewHelperTest() {} 120 PrintWebViewHelperTest() {}
121 virtual ~PrintWebViewHelperTest() {} 121 virtual ~PrintWebViewHelperTest() {}
122 122
123 virtual void SetUp() { 123 virtual void SetUp() {
124 RenderViewTest::SetUp(); 124 ChromeRenderViewTest::SetUp();
125 } 125 }
126 126
127 protected: 127 protected:
128 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest); 128 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperTest);
129 }; 129 };
130 130
131 // Tests that printing pages work and sending and receiving messages through 131 // Tests that printing pages work and sending and receiving messages through
132 // that channel all works. 132 // that channel all works.
133 TEST_F(PrintWebViewHelperTest, OnPrintPages) { 133 TEST_F(PrintWebViewHelperTest, OnPrintPages) {
134 LoadHTML(kHelloWorldHTML); 134 LoadHTML(kHelloWorldHTML);
135 PrintWebViewHelper::Get(view_)->OnPrintPages(); 135 PrintWebViewHelper::Get(view_)->OnPrintPages();
136 136
137 VerifyPageCount(1); 137 VerifyPageCount(1);
138 VerifyPagesPrinted(true); 138 VerifyPagesPrinted(true);
139 } 139 }
140 140
141 // Duplicate of OnPrintPagesTest only using javascript to print. 141 // Duplicate of OnPrintPagesTest only using javascript to print.
142 TEST_F(PrintWebViewHelperTest, PrintWithJavascript) { 142 TEST_F(PrintWebViewHelperTest, PrintWithJavascript) {
143 // HTML contains a call to window.print() 143 // HTML contains a call to window.print()
144 LoadHTML(kPrintWithJSHTML); 144 LoadHTML(kPrintWithJSHTML);
145 145
146 VerifyPageCount(1); 146 VerifyPageCount(1);
147 VerifyPagesPrinted(true); 147 VerifyPagesPrinted(true);
148 } 148 }
149 149
150 // Tests that the renderer blocks window.print() calls if they occur too 150 // Tests that the renderer blocks window.print() calls if they occur too
151 // frequently. 151 // frequently.
152 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { 152 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) {
153 // Pretend user will cancel printing. 153 // Pretend user will cancel printing.
154 render_thread_.set_print_dialog_user_response(false); 154 chrome_render_thread_->set_print_dialog_user_response(false);
155 // Try to print with window.print() a few times. 155 // Try to print with window.print() a few times.
156 LoadHTML(kPrintWithJSHTML); 156 LoadHTML(kPrintWithJSHTML);
157 LoadHTML(kPrintWithJSHTML); 157 LoadHTML(kPrintWithJSHTML);
158 LoadHTML(kPrintWithJSHTML); 158 LoadHTML(kPrintWithJSHTML);
159 VerifyPagesPrinted(false); 159 VerifyPagesPrinted(false);
160 160
161 // Pretend user will print. (but printing is blocked.) 161 // Pretend user will print. (but printing is blocked.)
162 render_thread_.set_print_dialog_user_response(true); 162 chrome_render_thread_->set_print_dialog_user_response(true);
163 LoadHTML(kPrintWithJSHTML); 163 LoadHTML(kPrintWithJSHTML);
164 VerifyPagesPrinted(false); 164 VerifyPagesPrinted(false);
165 165
166 // Unblock script initiated printing and verify printing works. 166 // Unblock script initiated printing and verify printing works.
167 PrintWebViewHelper::Get(view_)->ResetScriptedPrintCount(); 167 PrintWebViewHelper::Get(view_)->ResetScriptedPrintCount();
168 render_thread_.printer()->ResetPrinter(); 168 chrome_render_thread_->printer()->ResetPrinter();
169 LoadHTML(kPrintWithJSHTML); 169 LoadHTML(kPrintWithJSHTML);
170 VerifyPageCount(1); 170 VerifyPageCount(1);
171 VerifyPagesPrinted(true); 171 VerifyPagesPrinted(true);
172 } 172 }
173 173
174 #if defined(OS_WIN) || defined(OS_MACOSX) 174 #if defined(OS_WIN) || defined(OS_MACOSX)
175 // TODO(estade): I don't think this test is worth porting to Linux. We will have 175 // TODO(estade): I don't think this test is worth porting to Linux. We will have
176 // to rip out and replace most of the IPC code if we ever plan to improve 176 // to rip out and replace most of the IPC code if we ever plan to improve
177 // printing, and the comment below by sverrir suggests that it doesn't do much 177 // printing, and the comment below by sverrir suggests that it doesn't do much
178 // for us anyway. 178 // for us anyway.
(...skipping 15 matching lines...) Expand all
194 view_->GetWebView()->findFrameByName(WebString::fromUTF8("sub1")); 194 view_->GetWebView()->findFrameByName(WebString::fromUTF8("sub1"));
195 ASSERT_TRUE(sub1_frame); 195 ASSERT_TRUE(sub1_frame);
196 view_->GetWebView()->setFocusedFrame(sub1_frame); 196 view_->GetWebView()->setFocusedFrame(sub1_frame);
197 ASSERT_NE(view_->GetWebView()->focusedFrame(), 197 ASSERT_NE(view_->GetWebView()->focusedFrame(),
198 view_->GetWebView()->mainFrame()); 198 view_->GetWebView()->mainFrame());
199 199
200 // Initiate printing. 200 // Initiate printing.
201 PrintWebViewHelper::Get(view_)->OnPrintPages(); 201 PrintWebViewHelper::Get(view_)->OnPrintPages();
202 202
203 // Verify output through MockPrinter. 203 // Verify output through MockPrinter.
204 const MockPrinter* printer(render_thread_.printer()); 204 const MockPrinter* printer(chrome_render_thread_->printer());
205 ASSERT_EQ(1, printer->GetPrintedPages()); 205 ASSERT_EQ(1, printer->GetPrintedPages());
206 const printing::Image& image1(printer->GetPrintedPage(0)->image()); 206 const printing::Image& image1(printer->GetPrintedPage(0)->image());
207 207
208 // TODO(sverrir): Figure out a way to improve this test to actually print 208 // TODO(sverrir): Figure out a way to improve this test to actually print
209 // only the content of the iframe. Currently image1 will contain the full 209 // only the content of the iframe. Currently image1 will contain the full
210 // page. 210 // page.
211 EXPECT_NE(0, image1.size().width()); 211 EXPECT_NE(0, image1.size().width());
212 EXPECT_NE(0, image1.size().height()); 212 EXPECT_NE(0, image1.size().height());
213 } 213 }
214 #endif 214 #endif
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 }; 251 };
252 } // namespace 252 } // namespace
253 253
254 // TODO(estade): need to port MockPrinter to get this on Linux. This involves 254 // TODO(estade): need to port MockPrinter to get this on Linux. This involves
255 // hooking up Cairo to read a pdf stream, or accessing the cairo surface in the 255 // hooking up Cairo to read a pdf stream, or accessing the cairo surface in the
256 // metafile directly. 256 // metafile directly.
257 #if defined(OS_WIN) || defined(OS_MACOSX) 257 #if defined(OS_WIN) || defined(OS_MACOSX)
258 TEST_F(PrintWebViewHelperTest, PrintLayoutTest) { 258 TEST_F(PrintWebViewHelperTest, PrintLayoutTest) {
259 bool baseline = false; 259 bool baseline = false;
260 260
261 EXPECT_TRUE(render_thread_.printer() != NULL); 261 EXPECT_TRUE(chrome_render_thread_->printer() != NULL);
262 for (size_t i = 0; i < arraysize(kTestPages); ++i) { 262 for (size_t i = 0; i < arraysize(kTestPages); ++i) {
263 // Load an HTML page and print it. 263 // Load an HTML page and print it.
264 LoadHTML(kTestPages[i].page); 264 LoadHTML(kTestPages[i].page);
265 PrintWebViewHelper::Get(view_)->OnPrintPages(); 265 PrintWebViewHelper::Get(view_)->OnPrintPages();
266 266
267 // MockRenderThread::Send() just calls MockRenderThread::OnMsgReceived(). 267 // MockRenderThread::Send() just calls MockRenderThread::OnMsgReceived().
268 // So, all IPC messages sent in the above RenderView::OnPrintPages() call 268 // So, all IPC messages sent in the above RenderView::OnPrintPages() call
269 // has been handled by the MockPrinter object, i.e. this printing job 269 // has been handled by the MockPrinter object, i.e. this printing job
270 // has been already finished. 270 // has been already finished.
271 // So, we can start checking the output pages of this printing job. 271 // So, we can start checking the output pages of this printing job.
272 // Retrieve the number of pages actually printed. 272 // Retrieve the number of pages actually printed.
273 size_t pages = render_thread_.printer()->GetPrintedPages(); 273 size_t pages = chrome_render_thread_->printer()->GetPrintedPages();
274 EXPECT_EQ(kTestPages[i].printed_pages, pages); 274 EXPECT_EQ(kTestPages[i].printed_pages, pages);
275 275
276 // Retrieve the width and height of the output page. 276 // Retrieve the width and height of the output page.
277 int width = render_thread_.printer()->GetWidth(0); 277 int width = chrome_render_thread_->printer()->GetWidth(0);
278 int height = render_thread_.printer()->GetHeight(0); 278 int height = chrome_render_thread_->printer()->GetHeight(0);
279 279
280 // Check with margin for error. This has been failing with a one pixel 280 // Check with margin for error. This has been failing with a one pixel
281 // offset on our buildbot. 281 // offset on our buildbot.
282 const int kErrorMargin = 5; // 5% 282 const int kErrorMargin = 5; // 5%
283 EXPECT_GT(kTestPages[i].width * (100 + kErrorMargin) / 100, width); 283 EXPECT_GT(kTestPages[i].width * (100 + kErrorMargin) / 100, width);
284 EXPECT_LT(kTestPages[i].width * (100 - kErrorMargin) / 100, width); 284 EXPECT_LT(kTestPages[i].width * (100 - kErrorMargin) / 100, width);
285 EXPECT_GT(kTestPages[i].height * (100 + kErrorMargin) / 100, height); 285 EXPECT_GT(kTestPages[i].height * (100 + kErrorMargin) / 100, height);
286 EXPECT_LT(kTestPages[i].height* (100 - kErrorMargin) / 100, height); 286 EXPECT_LT(kTestPages[i].height* (100 - kErrorMargin) / 100, height);
287 287
288 // Retrieve the checksum of the bitmap data from the pseudo printer and 288 // Retrieve the checksum of the bitmap data from the pseudo printer and
289 // compare it with the expected result. 289 // compare it with the expected result.
290 std::string bitmap_actual; 290 std::string bitmap_actual;
291 EXPECT_TRUE(render_thread_.printer()->GetBitmapChecksum(0, &bitmap_actual)); 291 EXPECT_TRUE(
292 chrome_render_thread_->printer()->GetBitmapChecksum(0, &bitmap_actual));
292 if (kTestPages[i].checksum) 293 if (kTestPages[i].checksum)
293 EXPECT_EQ(kTestPages[i].checksum, bitmap_actual); 294 EXPECT_EQ(kTestPages[i].checksum, bitmap_actual);
294 295
295 if (baseline) { 296 if (baseline) {
296 // Save the source data and the bitmap data into temporary files to 297 // Save the source data and the bitmap data into temporary files to
297 // create base-line results. 298 // create base-line results.
298 FilePath source_path; 299 FilePath source_path;
299 file_util::CreateTemporaryFile(&source_path); 300 file_util::CreateTemporaryFile(&source_path);
300 render_thread_.printer()->SaveSource(0, source_path); 301 chrome_render_thread_->printer()->SaveSource(0, source_path);
301 302
302 FilePath bitmap_path; 303 FilePath bitmap_path;
303 file_util::CreateTemporaryFile(&bitmap_path); 304 file_util::CreateTemporaryFile(&bitmap_path);
304 render_thread_.printer()->SaveBitmap(0, bitmap_path); 305 chrome_render_thread_->printer()->SaveBitmap(0, bitmap_path);
305 } 306 }
306 } 307 }
307 } 308 }
308 #endif 309 #endif
309 310
310 // These print preview tests do not work on Chrome OS yet. 311 // These print preview tests do not work on Chrome OS yet.
311 #if !defined(OS_CHROMEOS) 312 #if !defined(OS_CHROMEOS)
312 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase { 313 class PrintWebViewHelperPreviewTest : public PrintWebViewHelperTestBase {
313 public: 314 public:
314 PrintWebViewHelperPreviewTest() {} 315 PrintWebViewHelperPreviewTest() {}
315 virtual ~PrintWebViewHelperPreviewTest() {} 316 virtual ~PrintWebViewHelperPreviewTest() {}
316 317
317 virtual void SetUp() { 318 virtual void SetUp() {
318 // Append the print preview switch before creating the PrintWebViewHelper. 319 // Append the print preview switch before creating the PrintWebViewHelper.
319 CommandLine::ForCurrentProcess()->AppendSwitch( 320 CommandLine::ForCurrentProcess()->AppendSwitch(
320 switches::kEnablePrintPreview); 321 switches::kEnablePrintPreview);
321 322
322 RenderViewTest::SetUp(); 323 ChromeRenderViewTest::SetUp();
323 } 324 }
324 325
325 protected: 326 protected:
326 void VerifyPrintPreviewCancelled(bool did_cancel) { 327 void VerifyPrintPreviewCancelled(bool did_cancel) {
327 bool print_preview_cancelled = 328 bool print_preview_cancelled =
328 (render_thread_.sink().GetUniqueMessageMatching( 329 (render_thread_->sink().GetUniqueMessageMatching(
329 PrintHostMsg_PrintPreviewCancelled::ID) != NULL); 330 PrintHostMsg_PrintPreviewCancelled::ID) != NULL);
330 EXPECT_EQ(did_cancel, print_preview_cancelled); 331 EXPECT_EQ(did_cancel, print_preview_cancelled);
331 } 332 }
332 333
333 void VerifyPrintPreviewFailed(bool did_fail) { 334 void VerifyPrintPreviewFailed(bool did_fail) {
334 bool print_preview_failed = (render_thread_.sink().GetUniqueMessageMatching( 335 bool print_preview_failed =
335 PrintHostMsg_PrintPreviewFailed::ID) != NULL); 336 (render_thread_->sink().GetUniqueMessageMatching(
337 PrintHostMsg_PrintPreviewFailed::ID) != NULL);
336 EXPECT_EQ(did_fail, print_preview_failed); 338 EXPECT_EQ(did_fail, print_preview_failed);
337 } 339 }
338 340
339 void VerifyPrintPreviewGenerated(bool generated_preview) { 341 void VerifyPrintPreviewGenerated(bool generated_preview) {
340 const IPC::Message* preview_msg = 342 const IPC::Message* preview_msg =
341 render_thread_.sink().GetUniqueMessageMatching( 343 render_thread_->sink().GetUniqueMessageMatching(
342 PrintHostMsg_MetafileReadyForPrinting::ID); 344 PrintHostMsg_MetafileReadyForPrinting::ID);
343 bool did_get_preview_msg = (NULL != preview_msg); 345 bool did_get_preview_msg = (NULL != preview_msg);
344 ASSERT_EQ(generated_preview, did_get_preview_msg); 346 ASSERT_EQ(generated_preview, did_get_preview_msg);
345 if (did_get_preview_msg) { 347 if (did_get_preview_msg) {
346 PrintHostMsg_MetafileReadyForPrinting::Param preview_param; 348 PrintHostMsg_MetafileReadyForPrinting::Param preview_param;
347 PrintHostMsg_MetafileReadyForPrinting::Read(preview_msg, &preview_param); 349 PrintHostMsg_MetafileReadyForPrinting::Read(preview_msg, &preview_param);
348 EXPECT_NE(0, preview_param.a.document_cookie); 350 EXPECT_NE(0, preview_param.a.document_cookie);
349 EXPECT_NE(0, preview_param.a.expected_pages_count); 351 EXPECT_NE(0, preview_param.a.expected_pages_count);
350 EXPECT_NE(0U, preview_param.a.data_size); 352 EXPECT_NE(0U, preview_param.a.data_size);
351 } 353 }
352 } 354 }
353 355
354 void VerifyPrintFailed(bool did_fail) { 356 void VerifyPrintFailed(bool did_fail) {
355 bool print_failed = (render_thread_.sink().GetUniqueMessageMatching( 357 bool print_failed = (render_thread_->sink().GetUniqueMessageMatching(
356 PrintHostMsg_PrintingFailed::ID) != NULL); 358 PrintHostMsg_PrintingFailed::ID) != NULL);
357 EXPECT_EQ(did_fail, print_failed); 359 EXPECT_EQ(did_fail, print_failed);
358 } 360 }
359 361
360 void VerifyPrintPreviewInvalidPrinterSettings(bool settings_invalid) { 362 void VerifyPrintPreviewInvalidPrinterSettings(bool settings_invalid) {
361 bool print_preview_invalid_printer_settings = 363 bool print_preview_invalid_printer_settings =
362 (render_thread_.sink().GetUniqueMessageMatching( 364 (render_thread_->sink().GetUniqueMessageMatching(
363 PrintHostMsg_PrintPreviewInvalidPrinterSettings::ID) != NULL); 365 PrintHostMsg_PrintPreviewInvalidPrinterSettings::ID) != NULL);
364 EXPECT_EQ(settings_invalid, print_preview_invalid_printer_settings); 366 EXPECT_EQ(settings_invalid, print_preview_invalid_printer_settings);
365 } 367 }
366 368
367 // |page_number| is 0-based. 369 // |page_number| is 0-based.
368 void VerifyDidPreviewPage(bool generate_draft_pages, int page_number) { 370 void VerifyDidPreviewPage(bool generate_draft_pages, int page_number) {
369 bool msg_found = false; 371 bool msg_found = false;
370 size_t msg_count = render_thread_.sink().message_count(); 372 size_t msg_count = render_thread_->sink().message_count();
371 for (size_t i = 0; i < msg_count; ++i) { 373 for (size_t i = 0; i < msg_count; ++i) {
372 const IPC::Message* msg = render_thread_.sink().GetMessageAt(i); 374 const IPC::Message* msg = render_thread_->sink().GetMessageAt(i);
373 if (msg->type() == PrintHostMsg_DidPreviewPage::ID) { 375 if (msg->type() == PrintHostMsg_DidPreviewPage::ID) {
374 PrintHostMsg_DidPreviewPage::Param page_param; 376 PrintHostMsg_DidPreviewPage::Param page_param;
375 PrintHostMsg_DidPreviewPage::Read(msg, &page_param); 377 PrintHostMsg_DidPreviewPage::Read(msg, &page_param);
376 if (page_param.a.page_number == page_number) { 378 if (page_param.a.page_number == page_number) {
377 msg_found = true; 379 msg_found = true;
378 if (generate_draft_pages) 380 if (generate_draft_pages)
379 EXPECT_NE(0U, page_param.a.data_size); 381 EXPECT_NE(0U, page_param.a.data_size);
380 else 382 else
381 EXPECT_EQ(0U, page_param.a.data_size); 383 EXPECT_EQ(0U, page_param.a.data_size);
382 break; 384 break;
383 } 385 }
384 } 386 }
385 } 387 }
386 ASSERT_EQ(generate_draft_pages, msg_found); 388 ASSERT_EQ(generate_draft_pages, msg_found);
387 } 389 }
388 390
389 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest); 391 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelperPreviewTest);
390 }; 392 };
391 393
392 // Tests that print preview work and sending and receiving messages through 394 // Tests that print preview work and sending and receiving messages through
393 // that channel all works. 395 // that channel all works.
394 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { 396 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) {
395 LoadHTML(kHelloWorldHTML); 397 LoadHTML(kHelloWorldHTML);
396 398
397 // Fill in some dummy values. 399 // Fill in some dummy values.
398 DictionaryValue dict; 400 DictionaryValue dict;
399 CreatePrintSettingsDictionary(&dict); 401 CreatePrintSettingsDictionary(&dict);
400 OnPrintPreview(dict); 402 OnPrintPreview(dict);
401 403
402 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); 404 EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining());
403 VerifyPrintPreviewCancelled(false); 405 VerifyPrintPreviewCancelled(false);
404 VerifyPrintPreviewFailed(false); 406 VerifyPrintPreviewFailed(false);
405 VerifyPrintPreviewGenerated(true); 407 VerifyPrintPreviewGenerated(true);
406 VerifyPagesPrinted(false); 408 VerifyPagesPrinted(false);
407 } 409 }
408 410
409 // Test to verify that complete metafile is generated for a subset of pages 411 // Test to verify that complete metafile is generated for a subset of pages
410 // without creating draft pages. 412 // without creating draft pages.
411 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) { 413 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewForSelectedPages) {
412 LoadHTML(kHelloWorldHTML); 414 LoadHTML(kHelloWorldHTML);
(...skipping 28 matching lines...) Expand all
441 443
442 // Tests that print preview fails and receiving error messages through 444 // Tests that print preview fails and receiving error messages through
443 // that channel all works. 445 // that channel all works.
444 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { 446 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) {
445 LoadHTML(kHelloWorldHTML); 447 LoadHTML(kHelloWorldHTML);
446 448
447 // An empty dictionary should fail. 449 // An empty dictionary should fail.
448 DictionaryValue empty_dict; 450 DictionaryValue empty_dict;
449 OnPrintPreview(empty_dict); 451 OnPrintPreview(empty_dict);
450 452
451 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); 453 EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining());
452 VerifyPrintPreviewCancelled(false); 454 VerifyPrintPreviewCancelled(false);
453 VerifyPrintPreviewFailed(true); 455 VerifyPrintPreviewFailed(true);
454 VerifyPrintPreviewGenerated(false); 456 VerifyPrintPreviewGenerated(false);
455 VerifyPagesPrinted(false); 457 VerifyPagesPrinted(false);
456 } 458 }
457 459
458 // Tests that cancelling print preview works. 460 // Tests that cancelling print preview works.
459 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewCancel) { 461 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewCancel) {
460 LoadHTML(kLongPageHTML); 462 LoadHTML(kLongPageHTML);
461 463
462 const int kCancelPage = 3; 464 const int kCancelPage = 3;
463 render_thread_.set_print_preview_cancel_page_number(kCancelPage); 465 chrome_render_thread_->set_print_preview_cancel_page_number(kCancelPage);
464 // Fill in some dummy values. 466 // Fill in some dummy values.
465 DictionaryValue dict; 467 DictionaryValue dict;
466 CreatePrintSettingsDictionary(&dict); 468 CreatePrintSettingsDictionary(&dict);
467 OnPrintPreview(dict); 469 OnPrintPreview(dict);
468 470
469 EXPECT_EQ(kCancelPage, render_thread_.print_preview_pages_remaining()); 471 EXPECT_EQ(kCancelPage,
472 chrome_render_thread_->print_preview_pages_remaining());
470 VerifyPrintPreviewCancelled(true); 473 VerifyPrintPreviewCancelled(true);
471 VerifyPrintPreviewFailed(false); 474 VerifyPrintPreviewFailed(false);
472 VerifyPrintPreviewGenerated(false); 475 VerifyPrintPreviewGenerated(false);
473 VerifyPagesPrinted(false); 476 VerifyPagesPrinted(false);
474 } 477 }
475 478
476 // Tests that printing from print preview works and sending and receiving 479 // Tests that printing from print preview works and sending and receiving
477 // messages through that channel all works. 480 // messages through that channel all works.
478 TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) { 481 TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) {
479 LoadHTML(kPrintPreviewHTML); 482 LoadHTML(kPrintPreviewHTML);
(...skipping 19 matching lines...) Expand all
499 VerifyPagesPrinted(false); 502 VerifyPagesPrinted(false);
500 } 503 }
501 504
502 // Tests that when default printer has invalid printer settings, print preview 505 // Tests that when default printer has invalid printer settings, print preview
503 // receives error message. 506 // receives error message.
504 TEST_F(PrintWebViewHelperPreviewTest, 507 TEST_F(PrintWebViewHelperPreviewTest,
505 OnPrintPreviewUsingInvalidPrinterSettings) { 508 OnPrintPreviewUsingInvalidPrinterSettings) {
506 LoadHTML(kPrintPreviewHTML); 509 LoadHTML(kPrintPreviewHTML);
507 510
508 // Set mock printer to provide invalid settings. 511 // Set mock printer to provide invalid settings.
509 render_thread_.printer()->UseInvalidSettings(); 512 chrome_render_thread_->printer()->UseInvalidSettings();
510 513
511 // Fill in some dummy values. 514 // Fill in some dummy values.
512 DictionaryValue dict; 515 DictionaryValue dict;
513 CreatePrintSettingsDictionary(&dict); 516 CreatePrintSettingsDictionary(&dict);
514 OnPrintPreview(dict); 517 OnPrintPreview(dict);
515 518
516 // We should have received invalid printer settings from |printer_|. 519 // We should have received invalid printer settings from |printer_|.
517 VerifyPrintPreviewInvalidPrinterSettings(true); 520 VerifyPrintPreviewInvalidPrinterSettings(true);
518 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); 521 EXPECT_EQ(0, chrome_render_thread_->print_preview_pages_remaining());
519 522
520 // It should receive the invalid printer settings message only. 523 // It should receive the invalid printer settings message only.
521 VerifyPrintPreviewFailed(false); 524 VerifyPrintPreviewFailed(false);
522 VerifyPrintPreviewGenerated(false); 525 VerifyPrintPreviewGenerated(false);
523 } 526 }
524 527
525 TEST_F(PrintWebViewHelperPreviewTest, 528 TEST_F(PrintWebViewHelperPreviewTest,
526 OnPrintForPrintPreviewUsingInvalidPrinterSettings) { 529 OnPrintForPrintPreviewUsingInvalidPrinterSettings) {
527 LoadHTML(kPrintPreviewHTML); 530 LoadHTML(kPrintPreviewHTML);
528 531
529 // Set mock printer to provide invalid settings. 532 // Set mock printer to provide invalid settings.
530 render_thread_.printer()->UseInvalidSettings(); 533 chrome_render_thread_->printer()->UseInvalidSettings();
531 534
532 // Fill in some dummy values. 535 // Fill in some dummy values.
533 DictionaryValue dict; 536 DictionaryValue dict;
534 CreatePrintSettingsDictionary(&dict); 537 CreatePrintSettingsDictionary(&dict);
535 OnPrintForPrintPreview(dict); 538 OnPrintForPrintPreview(dict);
536 539
537 VerifyPrintFailed(true); 540 VerifyPrintFailed(true);
538 VerifyPagesPrinted(false); 541 VerifyPagesPrinted(false);
539 } 542 }
540 543
541 #endif // !defined(OS_CHROMEOS) 544 #endif // !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/renderer/page_click_tracker_browsertest.cc ('k') | chrome/renderer/safe_browsing/malware_dom_details_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698