OLD | NEW |
---|---|
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/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 18 matching lines...) Expand all Loading... | |
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. | 32 // A longer web page. |
33 const char kLongPageHTML[] = | 33 const char kLongPageHTML[] = |
34 "<body><img src=\"\" width=10 height=10000 /></body>"; | 34 "<body><img src=\"\" width=10 height=10000 /></body>"; |
35 | 35 |
36 // A web page to simulate the print preview page. | 36 // A web page to simulate the print preview page. |
37 const char kPrintPreviewHTML[] = | 37 const char kPrintPreviewHTML[] = |
38 "<body><p id=\"pdf-viewer\">Hello World!</p></body>"; | 38 "<body><p id=\"pdf-viewer\">Hello World!</p></body>"; |
39 | 39 |
vandebo (ex-Chrome)
2011/09/02 18:12:50
Probably should add a test for the new code you ad
kmadhusu
2011/09/03 00:34:00
I have added a js test.
| |
40 void CreatePrintSettingsDictionary(DictionaryValue* dict) { | 40 void CreatePrintSettingsDictionary(DictionaryValue* dict) { |
41 DictionaryValue* duplex_info = new DictionaryValue(); | |
42 duplex_info->SetInteger(printing::kPrinterDefaultDuplexValue, | |
43 printing::ONE_SIDED); | |
44 duplex_info->SetInteger(printing::kUserSelectedDuplexValue, | |
45 printing::SIMPLEX); | |
46 | |
41 dict->SetBoolean(printing::kSettingLandscape, false); | 47 dict->SetBoolean(printing::kSettingLandscape, false); |
42 dict->SetBoolean(printing::kSettingCollate, false); | 48 dict->SetBoolean(printing::kSettingCollate, false); |
43 dict->SetBoolean(printing::kSettingColor, false); | 49 dict->SetBoolean(printing::kSettingColor, false); |
44 dict->SetBoolean(printing::kSettingPrintToPDF, true); | 50 dict->SetBoolean(printing::kSettingPrintToPDF, true); |
45 dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX); | 51 dict->Set(printing::kSettingDuplexModeInfo, duplex_info); |
46 dict->SetInteger(printing::kSettingCopies, 1); | 52 dict->SetInteger(printing::kSettingCopies, 1); |
47 dict->SetString(printing::kSettingDeviceName, "dummy"); | 53 dict->SetString(printing::kSettingDeviceName, "dummy"); |
48 dict->SetString(printing::kPreviewUIAddr, "0xb33fbeef"); | 54 dict->SetString(printing::kPreviewUIAddr, "0xb33fbeef"); |
49 dict->SetInteger(printing::kPreviewRequestID, 12345); | 55 dict->SetInteger(printing::kPreviewRequestID, 12345); |
50 dict->SetBoolean(printing::kIsFirstRequest, true); | 56 dict->SetBoolean(printing::kIsFirstRequest, true); |
51 dict->SetBoolean(printing::kSettingDefaultMarginsSelected, true); | 57 dict->SetBoolean(printing::kSettingDefaultMarginsSelected, true); |
52 dict->SetBoolean(printing::kSettingHeaderFooterEnabled, false); | 58 dict->SetBoolean(printing::kSettingHeaderFooterEnabled, false); |
53 dict->SetBoolean(printing::kSettingGenerateDraftData, true); | 59 dict->SetBoolean(printing::kSettingGenerateDraftData, true); |
54 } | 60 } |
55 | 61 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
373 | 379 |
374 // Tests that print preview work and sending and receiving messages through | 380 // Tests that print preview work and sending and receiving messages through |
375 // that channel all works. | 381 // that channel all works. |
376 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { | 382 TEST_F(PrintWebViewHelperPreviewTest, OnPrintPreview) { |
377 LoadHTML(kHelloWorldHTML); | 383 LoadHTML(kHelloWorldHTML); |
378 | 384 |
379 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); | 385 PrintWebViewHelper::Get(view_)->OnInitiatePrintPreview(); |
380 // Fill in some dummy values. | 386 // Fill in some dummy values. |
381 DictionaryValue dict; | 387 DictionaryValue dict; |
382 CreatePrintSettingsDictionary(&dict); | 388 CreatePrintSettingsDictionary(&dict); |
389 | |
383 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict); | 390 PrintWebViewHelper::Get(view_)->OnPrintPreview(dict); |
384 | 391 |
385 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); | 392 EXPECT_EQ(0, render_thread_.print_preview_pages_remaining()); |
386 VerifyPrintPreviewCancelled(false); | 393 VerifyPrintPreviewCancelled(false); |
387 VerifyPrintPreviewFailed(false); | 394 VerifyPrintPreviewFailed(false); |
388 VerifyPrintPreviewGenerated(true); | 395 VerifyPrintPreviewGenerated(true); |
389 VerifyPagesPrinted(false); | 396 VerifyPagesPrinted(false); |
390 } | 397 } |
391 | 398 |
392 // Test to verify that complete metafile is generated for a subset of pages | 399 // Test to verify that complete metafile is generated for a subset of pages |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 LoadHTML(kPrintPreviewHTML); | 486 LoadHTML(kPrintPreviewHTML); |
480 | 487 |
481 // An empty dictionary should fail. | 488 // An empty dictionary should fail. |
482 DictionaryValue empty_dict; | 489 DictionaryValue empty_dict; |
483 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict); | 490 PrintWebViewHelper::Get(view_)->OnPrintForPrintPreview(empty_dict); |
484 | 491 |
485 VerifyPrintFailed(true); | 492 VerifyPrintFailed(true); |
486 VerifyPagesPrinted(false); | 493 VerifyPagesPrinted(false); |
487 } | 494 } |
488 #endif // !defined(OS_CHROMEOS) | 495 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |