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

Unified Diff: chrome/renderer/print_web_view_helper_browsertest.cc

Issue 7993005: Reuse PrintContext to excessively triggering matchMedia('print') listeners. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Adds a unit test and updates DPI on change. 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/print_web_view_helper.cc ('k') | webkit/glue/webkit_glue.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/print_web_view_helper_browsertest.cc
diff --git a/chrome/renderer/print_web_view_helper_browsertest.cc b/chrome/renderer/print_web_view_helper_browsertest.cc
index 75a21ecef104de2e8d7cb3989c59a9f70ba88279..52384381b4dac38ab0bfe977dda45a20e9b98c9c 100644
--- a/chrome/renderer/print_web_view_helper_browsertest.cc
+++ b/chrome/renderer/print_web_view_helper_browsertest.cc
@@ -38,6 +38,13 @@ const char kLongPageHTML[] =
const char kPrintPreviewHTML[] =
"<body><p id=\"pdf-viewer\">Hello World!</p></body>";
+// A web page with a @media print listener. The first callback makes
+// body two pages tall; each subsequent callback adds one more page.
+const char kMediaQueryHTML[] =
+ "<body>Hello World!<script>var n = 1; var mediaQuery = "
+ "window.matchMedia('print'); mediaQuery.addListener(function(e) { "
+ "document.body.style.height = (++n * 840) + 'px';});</script></body>";
+
void CreatePrintSettingsDictionary(DictionaryValue* dict) {
dict->SetBoolean(printing::kSettingLandscape, false);
dict->SetBoolean(printing::kSettingCollate, false);
@@ -148,6 +155,14 @@ TEST_F(PrintWebViewHelperTest, PrintWithJavascript) {
VerifyPagesPrinted(true);
}
+// Tests that printing pages calls @media print callbacks once.
+TEST_F(PrintWebViewHelperTest, PrintWithMediaQuery) {
+ LoadHTML(kMediaQueryHTML);
+ 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
+
+ VerifyPageCount(2);
+}
+
// Tests that the renderer blocks window.print() calls if they occur too
// frequently.
TEST_F(PrintWebViewHelperTest, BlockScriptInitiatedPrinting) {
« no previous file with comments | « chrome/renderer/print_web_view_helper.cc ('k') | webkit/glue/webkit_glue.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698