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/chrome_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" |
(...skipping 20 matching lines...) Expand all Loading... | |
31 "<body>Hello<script>window.print()</script>World</body>"; | 31 "<body>Hello<script>window.print()</script>World</body>"; |
32 | 32 |
33 // A longer web page. | 33 // A longer web page. |
34 const char kLongPageHTML[] = | 34 const char kLongPageHTML[] = |
35 "<body><img src=\"\" width=10 height=10000 /></body>"; | 35 "<body><img src=\"\" width=10 height=10000 /></body>"; |
36 | 36 |
37 // A web page to simulate the print preview page. | 37 // A web page to simulate the print preview page. |
38 const char kPrintPreviewHTML[] = | 38 const char kPrintPreviewHTML[] = |
39 "<body><p id=\"pdf-viewer\">Hello World!</p></body>"; | 39 "<body><p id=\"pdf-viewer\">Hello World!</p></body>"; |
40 | 40 |
41 // A web page with a @media print listener. The first callback makes | |
42 // body two pages tall; each subsequent callback adds one more page. | |
43 const char kMediaQueryHTML[] = | |
44 "<body>Hello World!<script>var n = 1; var mediaQuery = " | |
45 "window.matchMedia('print'); mediaQuery.addListener(function(e) { " | |
46 "document.body.style.height = (++n * 840) + 'px';});</script></body>"; | |
47 | |
41 void CreatePrintSettingsDictionary(DictionaryValue* dict) { | 48 void CreatePrintSettingsDictionary(DictionaryValue* dict) { |
42 dict->SetBoolean(printing::kSettingLandscape, false); | 49 dict->SetBoolean(printing::kSettingLandscape, false); |
43 dict->SetBoolean(printing::kSettingCollate, false); | 50 dict->SetBoolean(printing::kSettingCollate, false); |
44 dict->SetInteger(printing::kSettingColor, printing::GRAY); | 51 dict->SetInteger(printing::kSettingColor, printing::GRAY); |
45 dict->SetBoolean(printing::kSettingPrintToPDF, true); | 52 dict->SetBoolean(printing::kSettingPrintToPDF, true); |
46 dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX); | 53 dict->SetInteger(printing::kSettingDuplexMode, printing::SIMPLEX); |
47 dict->SetInteger(printing::kSettingCopies, 1); | 54 dict->SetInteger(printing::kSettingCopies, 1); |
48 dict->SetString(printing::kSettingDeviceName, "dummy"); | 55 dict->SetString(printing::kSettingDeviceName, "dummy"); |
49 dict->SetString(printing::kPreviewUIAddr, "0xb33fbeef"); | 56 dict->SetString(printing::kPreviewUIAddr, "0xb33fbeef"); |
50 dict->SetInteger(printing::kPreviewRequestID, 12345); | 57 dict->SetInteger(printing::kPreviewRequestID, 12345); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 | 148 |
142 // Duplicate of OnPrintPagesTest only using javascript to print. | 149 // Duplicate of OnPrintPagesTest only using javascript to print. |
143 TEST_F(PrintWebViewHelperTest, PrintWithJavascript) { | 150 TEST_F(PrintWebViewHelperTest, PrintWithJavascript) { |
144 // HTML contains a call to window.print() | 151 // HTML contains a call to window.print() |
145 LoadHTML(kPrintWithJSHTML); | 152 LoadHTML(kPrintWithJSHTML); |
146 | 153 |
147 VerifyPageCount(1); | 154 VerifyPageCount(1); |
148 VerifyPagesPrinted(true); | 155 VerifyPagesPrinted(true); |
149 } | 156 } |
150 | 157 |
158 // Tests that printing pages calls @media print callbacks once. | |
159 TEST_F(PrintWebViewHelperTest, PrintWithMediaQuery) { | |
160 LoadHTML(kMediaQueryHTML); | |
161 PrintWebViewHelper::Get(view_)->OnPrintPages(); | |
vandebo (ex-Chrome)
2011/10/24 20:53:47
Does this test fail without your changes? I'm not
dominicc (has gone to gerrit)
2011/10/25 04:44:39
It does, at least on my Mac. Should I split this i
vandebo (ex-Chrome)
2011/10/25 17:03:11
That's not necessary, I just wasn't sure if callin
| |
162 | |
163 VerifyPageCount(2); | |
164 } | |
165 | |
151 // Tests that the renderer blocks window.print() calls if they occur too | 166 // Tests that the renderer blocks window.print() calls if they occur too |
152 // frequently. | 167 // frequently. |
153 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { | 168 TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) { |
154 // Pretend user will cancel printing. | 169 // Pretend user will cancel printing. |
155 chrome_render_thread_->set_print_dialog_user_response(false); | 170 chrome_render_thread_->set_print_dialog_user_response(false); |
156 // Try to print with window.print() a few times. | 171 // Try to print with window.print() a few times. |
157 LoadHTML(kPrintWithJSHTML); | 172 LoadHTML(kPrintWithJSHTML); |
158 LoadHTML(kPrintWithJSHTML); | 173 LoadHTML(kPrintWithJSHTML); |
159 LoadHTML(kPrintWithJSHTML); | 174 LoadHTML(kPrintWithJSHTML); |
160 VerifyPagesPrinted(false); | 175 VerifyPagesPrinted(false); |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 // Fill in some dummy values. | 551 // Fill in some dummy values. |
537 DictionaryValue dict; | 552 DictionaryValue dict; |
538 CreatePrintSettingsDictionary(&dict); | 553 CreatePrintSettingsDictionary(&dict); |
539 OnPrintForPrintPreview(dict); | 554 OnPrintForPrintPreview(dict); |
540 | 555 |
541 VerifyPrintFailed(true); | 556 VerifyPrintFailed(true); |
542 VerifyPagesPrinted(false); | 557 VerifyPagesPrinted(false); |
543 } | 558 } |
544 | 559 |
545 #endif // !defined(OS_CHROMEOS) | 560 #endif // !defined(OS_CHROMEOS) |
OLD | NEW |