summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/render_view_unittest.cc
diff options
context:
space:
mode:
authorsverrir@chromium.org <sverrir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 17:23:58 +0000
committersverrir@chromium.org <sverrir@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-16 17:23:58 +0000
commitaa82249f5670f88c545039f7ae997643c97fd639 (patch)
tree11ea4e90843eb246e77813ddac68b30bf4d907b0 /chrome/renderer/render_view_unittest.cc
parent538173f8209bd078cb82627e32b06ae522766072 (diff)
downloadchromium_src-aa82249f5670f88c545039f7ae997643c97fd639.zip
chromium_src-aa82249f5670f88c545039f7ae997643c97fd639.tar.gz
chromium_src-aa82249f5670f88c545039f7ae997643c97fd639.tar.bz2
Print only the focused frame. This makes more sense than trying to print all frames since most of the time you end up with ugly clipping and scroll bars on the printed page.
This also fixes printing issue with print selection since we don't pick up the currently selected text if's not in the main frame. Also did some refactoring of the printing test in render_view_unittest. Mainly to reuse the new Image class. BUG=http://crbug.com/15250 TEST=Print pages with frames. Print selection when using multiple frames (one example in bug). Review URL: http://codereview.chromium.org/149644 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20876 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/render_view_unittest.cc')
-rw-r--r--chrome/renderer/render_view_unittest.cc50
1 files changed, 42 insertions, 8 deletions
diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc
index 4b4ed60..135c78d 100644
--- a/chrome/renderer/render_view_unittest.cc
+++ b/chrome/renderer/render_view_unittest.cc
@@ -3,10 +3,13 @@
// found in the LICENSE file.
#include "base/file_util.h"
+#include "base/shared_memory.h"
#include "chrome/common/native_web_keyboard_event.h"
#include "chrome/common/render_messages.h"
#include "chrome/test/render_view_test.h"
#include "net/base/net_errors.h"
+#include "printing/image.h"
+#include "printing/native_metafile.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "webkit/api/public/WebURLError.h"
@@ -363,6 +366,45 @@ TEST_F(RenderViewTest, PrintWithJavascript) {
#endif
}
+TEST_F(RenderViewTest, PrintWithIframe) {
+#if defined(OS_WIN)
+ // Document that populates an iframe..
+ const char html[] =
+ "<html><body>Lorem Ipsum:"
+ "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>"
+ " document.write(frames['sub1'].name);"
+ " frames['sub1'].document.write("
+ " '<p>Cras tempus ante eu felis semper luctus!</p>');"
+ "</script></body></html>";
+
+ LoadHTML(html);
+
+ // Find the frame and set it as the focused one. This should mean that that
+ // the printout should only contain the contents of that frame.
+ WebFrame* sub1_frame = view_->webview()->GetFrameWithName(L"sub1");
+ ASSERT_TRUE(sub1_frame);
+ view_->webview()->SetFocusedFrame(sub1_frame);
+ ASSERT_NE(view_->webview()->GetFocusedFrame(),
+ view_->webview()->GetMainFrame());
+
+ // Initiate printing.
+ view_->OnPrintPages();
+
+ // Verify output through MockPrinter.
+ const MockPrinter* printer(render_thread_.printer());
+ ASSERT_EQ(1, printer->GetPrintedPages());
+ const printing::Image& image1(printer->GetPrintedPage(0)->image());
+
+ // TODO(sverrir): Figure out a way to improve this test to actually print
+ // only the content of the iframe. Currently image1 will contain the full
+ // page.
+ EXPECT_NE(0, image1.size().width());
+ EXPECT_NE(0, image1.size().height());
+#else
+ NOTIMPLEMENTED();
+#endif
+}
+
// Tests if we can print a page and verify its results.
// This test prints HTML pages into a pseudo printer and check their outputs,
// i.e. a simplified version of the PrintingLayoutTextTest UI test.
@@ -431,14 +473,6 @@ TEST_F(RenderViewTest, PrintLayoutTest) {
if (kTestPages[i].checksum)
EXPECT_EQ(kTestPages[i].checksum, bitmap_actual);
- // Retrieve the bitmap data from the pseudo printer.
- // TODO(hbono): implement a function which retrieves an expected result
- // from a file and compares it with this bitmap data.
- const void* bitmap_data;
- size_t bitmap_size;
- EXPECT_TRUE(render_thread_.printer()->GetBitmap(0, &bitmap_data,
- &bitmap_size));
-
if (baseline) {
// Save the source data and the bitmap data into temporary files to
// create base-line results.