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

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

Issue 7747033: Merge 97702, 97820, 97976 (Closed) Base URL: svn://chrome-svn/chrome/branches/835/src/
Patch Set: Created 9 years, 3 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/render_view_test.h" 8 #include "chrome/test/render_view_test.h"
9 #include "printing/print_job_constants.h" 9 #include "printing/print_job_constants.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 11 matching lines...) Expand all
22 22
23 namespace { 23 namespace {
24 24
25 // A simple web page. 25 // A simple web page.
26 const char kHelloWorldHTML[] = "<body><p>Hello World!</p></body>"; 26 const char kHelloWorldHTML[] = "<body><p>Hello World!</p></body>";
27 27
28 // A simple webpage that prints itself. 28 // A simple webpage that prints itself.
29 const char kPrintWithJSHTML[] = 29 const char kPrintWithJSHTML[] =
30 "<body>Hello<script>window.print()</script>World</body>"; 30 "<body>Hello<script>window.print()</script>World</body>";
31 31
32 // A longer web page.
33 const char kLongPageHTML[] =
34 "<body><img src=\"\" width=10 height=10000 /></body>";
35
32 // A web page to simulate the print preview page. 36 // A web page to simulate the print preview page.
33 const char kPrintPreviewHTML[] = 37 const char kPrintPreviewHTML[] =
34 "<body><p id=\"pdf-viewer\">Hello World!</p></body>"; 38 "<body><p id=\"pdf-viewer\">Hello World!</p></body>";
35 39
36 void CreatePrintSettingsDictionary(DictionaryValue* dict) { 40 void CreatePrintSettingsDictionary(DictionaryValue* dict) {
37 dict->SetBoolean(printing::kSettingLandscape, false); 41 dict->SetBoolean(printing::kSettingLandscape, false);
38 dict->SetBoolean(printing::kSettingCollate, false); 42 dict->SetBoolean(printing::kSettingCollate, false);
39 dict->SetBoolean(printing::kSettingColor, false); 43 dict->SetBoolean(printing::kSettingColor, false);
40 dict->SetBoolean(printing::kSettingPrintToPDF, true); 44 dict->SetBoolean(printing::kSettingPrintToPDF, true);
41 dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX); 45 dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX);
42 dict->SetInteger(printing::kSettingCopies, 1); 46 dict->SetInteger(printing::kSettingCopies, 1);
43 dict->SetString(printing::kSettingDeviceName, "dummy"); 47 dict->SetString(printing::kSettingDeviceName, "dummy");
48 dict->SetString(printing::kPreviewUIAddr, "0xb33fbeef");
44 dict->SetInteger(printing::kPreviewRequestID, 12345); 49 dict->SetInteger(printing::kPreviewRequestID, 12345);
45 dict->SetBoolean(printing::kIsFirstRequest, true); 50 dict->SetBoolean(printing::kIsFirstRequest, true);
46 } 51 }
47 52
48 } // namespace 53 } // namespace
49 54
50 class PrintWebViewHelperTestBase : public RenderViewTest { 55 class PrintWebViewHelperTestBase : public RenderViewTest {
51 public: 56 public:
52 PrintWebViewHelperTestBase() {} 57 PrintWebViewHelperTestBase() {}
53 ~PrintWebViewHelperTestBase() {} 58 ~PrintWebViewHelperTestBase() {}
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 302
298 virtual void SetUp() { 303 virtual void SetUp() {
299 // Append the print preview switch before creating the PrintWebViewHelper. 304 // Append the print preview switch before creating the PrintWebViewHelper.
300 CommandLine::ForCurrentProcess()->AppendSwitch( 305 CommandLine::ForCurrentProcess()->AppendSwitch(
301 switches::kEnablePrintPreview); 306 switches::kEnablePrintPreview);
302 307
303 RenderViewTest::SetUp(); 308 RenderViewTest::SetUp();
304 } 309 }
305 310
306 protected: 311 protected:
312 void VerifyPrintPreviewCancelled(bool did_cancel) {
313 bool print_preview_cancelled =
314 (render_thread_.sink().GetUniqueMessageMatching(
315 PrintHostMsg_PrintPreviewCancelled::ID) != NULL);
316 EXPECT_EQ(did_cancel, print_preview_cancelled);
317 }
318
307 void VerifyPrintPreviewFailed(bool did_fail) { 319 void VerifyPrintPreviewFailed(bool did_fail) {
308 bool print_preview_failed = (render_thread_.sink().GetUniqueMessageMatching( 320 bool print_preview_failed = (render_thread_.sink().GetUniqueMessageMatching(
309 PrintHostMsg_PrintPreviewFailed::ID) != NULL); 321 PrintHostMsg_PrintPreviewFailed::ID) != NULL);
310 EXPECT_EQ(did_fail, print_preview_failed); 322 EXPECT_EQ(did_fail, print_preview_failed);
311 } 323 }
312 324
313 void VerifyPrintPreviewGenerated(bool generated_preview) { 325 void VerifyPrintPreviewGenerated(bool generated_preview) {
314 const IPC::Message* preview_msg = 326 const IPC::Message* preview_msg =
315 render_thread_.sink().GetUniqueMessageMatching( 327 render_thread_.sink().GetUniqueMessageMatching(
316 PrintHostMsg_PagesReadyForPreview::ID); 328 PrintHostMsg_PagesReadyForPreview::ID);
(...skipping 21 matching lines...) Expand all
338 // that channel all works. 350 // that channel all works.
339 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { 351 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) {
340 LoadHTML(kHelloWorldHTML); 352 LoadHTML(kHelloWorldHTML);
341 353
342 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); 354 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview();
343 // Fill in some dummy values. 355 // Fill in some dummy values.
344 DictionaryValue dict; 356 DictionaryValue dict;
345 CreatePrintSettingsDictionary(&dict); 357 CreatePrintSettingsDictionary(&dict);
346 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict); 358 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict);
347 359
348 // Need to finish simulating print preview.
349 // Generate the page and finalize it.
350 PrintWebViewHelper::Get(view_)->OnContinuePreview(
351 printing::INVALID_PAGE_INDEX);
352 PrintWebViewHelper::Get(view_)->OnContinuePreview(
353 printing::INVALID_PAGE_INDEX);
354
355 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); 360 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining());
361 VerifyPrintPreviewCancelled(false);
356 VerifyPrintPreviewFailed(false); 362 VerifyPrintPreviewFailed(false);
357 VerifyPrintPreviewGenerated(true); 363 VerifyPrintPreviewGenerated(true);
358 VerifyPagesPrinted(false); 364 VerifyPagesPrinted(false);
359 } 365 }
360 366
361 // Tests that print preview fails and receiving error messages through 367 // Tests that print preview fails and receiving error messages through
362 // that channel all works. 368 // that channel all works.
363 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) { 369 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewFail) {
364 LoadHTML(kHelloWorldHTML); 370 LoadHTML(kHelloWorldHTML);
365 371
366 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); 372 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview();
367 // An empty dictionary should fail. 373 // An empty dictionary should fail.
368 DictionaryValue empty_dict; 374 DictionaryValue empty_dict;
369 PrintWebViewHelper::Get(view_)->OnPrintPreview(empty_dict); 375 PrintWebViewHelper::Get(view_)->OnPrintPreview(empty_dict);
370 376
371 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); 377 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining());
378 VerifyPrintPreviewCancelled(false);
372 VerifyPrintPreviewFailed(true); 379 VerifyPrintPreviewFailed(true);
373 VerifyPrintPreviewGenerated(false); 380 VerifyPrintPreviewGenerated(false);
374 VerifyPagesPrinted(false); 381 VerifyPagesPrinted(false);
375 } 382 }
376 383
384 // Tests that cancelling print preview works.
385 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreviewCancel) {
386 LoadHTML(kLongPageHTML);
387
388 const int kCancelPage = 3;
389 render_thread_.set_print_preview_cancel_page_number(kCancelPage);
390 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview();
391 // Fill in some dummy values.
392 DictionaryValue dict;
393 CreatePrintSettingsDictionary(&dict);
394 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict);
395
396 EXPECT_EQ(kCancelPage, render_thread_.print_preview_pages_remaining());
397 VerifyPrintPreviewCancelled(true);
398 VerifyPrintPreviewFailed(false);
399 VerifyPrintPreviewGenerated(false);
400 VerifyPagesPrinted(false);
401 }
402
377 // Tests that printing from print preview works and sending and receiving 403 // Tests that printing from print preview works and sending and receiving
378 // messages through that channel all works. 404 // messages through that channel all works.
379 TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) { 405 TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreview) {
380 LoadHTML(kPrintPreviewHTML); 406 LoadHTML(kPrintPreviewHTML);
381 407
382 // Fill in some dummy values. 408 // Fill in some dummy values.
383 DictionaryValue dict; 409 DictionaryValue dict;
384 CreatePrintSettingsDictionary(&dict); 410 CreatePrintSettingsDictionary(&dict);
385 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict); 411 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(dict);
386 412
387 VerifyPrintFailed(false); 413 VerifyPrintFailed(false);
388 VerifyPagesPrinted(true); 414 VerifyPagesPrinted(true);
389 } 415 }
390 416
391 // Tests that printing from print preview fails and receiving error messages 417 // Tests that printing from print preview fails and receiving error messages
392 // through that channel all works. 418 // through that channel all works.
393 TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) { 419 TEST_F(PrintWebViewHelperPreviewTest, OnPrintForPrintPreviewFail) {
394 LoadHTML(kPrintPreviewHTML); 420 LoadHTML(kPrintPreviewHTML);
395 421
396 // An empty dictionary should fail. 422 // An empty dictionary should fail.
397 DictionaryValue empty_dict; 423 DictionaryValue empty_dict;
398 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict); 424 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict);
399 425
400 VerifyPrintFailed(true); 426 VerifyPrintFailed(true);
401 VerifyPagesPrinted(false); 427 VerifyPagesPrinted(false);
402 } 428 }
403 #endif // !defined(OS_CHROMEOS) 429 #endif // !defined(OS_CHROMEOS)
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper.cc ('k') | chrome/renderer/print_web_view_helper_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698