summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/render_view_unittest.cc
diff options
context:
space:
mode:
authormhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-04 12:22:45 +0000
committermhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-04 12:22:45 +0000
commit1f6079539a1ffb2a17579f22280f476895d2414c (patch)
tree53a928f2167e28750be8b50fbdae58f9c2aae9dd /chrome/renderer/render_view_unittest.cc
parent1156a8e6ba080e8890e2a9695bd75c34800d0808 (diff)
downloadchromium_src-1f6079539a1ffb2a17579f22280f476895d2414c.zip
chromium_src-1f6079539a1ffb2a17579f22280f476895d2414c.tar.gz
chromium_src-1f6079539a1ffb2a17579f22280f476895d2414c.tar.bz2
Implement PrintPageAsJPEG feature for Print Preview.In order to show the tab contents to the print tab, the renderer should print the page as a JPEG image so it could be rendered in the DOMUI. A unit test case has been created to make sure the image contains something from deciding whether its not 100% white.MockPrinter has been altered to remove the const parameter, since its useful to retrieve the DefaultSettings not via IPC.BUG=173 (http://crbug.com/173)TEST=created a unit test and ran it.
Review URL: http://codereview.chromium.org/196021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25445 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/render_view_unittest.cc')
-rw-r--r--chrome/renderer/render_view_unittest.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/chrome/renderer/render_view_unittest.cc b/chrome/renderer/render_view_unittest.cc
index 96bcc8f..6f3d51b 100644
--- a/chrome/renderer/render_view_unittest.cc
+++ b/chrome/renderer/render_view_unittest.cc
@@ -3,9 +3,11 @@
// found in the LICENSE file.
#include "base/file_util.h"
+#include "base/gfx/jpeg_codec.h"
#include "base/shared_memory.h"
#include "chrome/common/native_web_keyboard_event.h"
#include "chrome/common/render_messages.h"
+#include "chrome/renderer/print_web_view_helper.h"
#include "chrome/test/render_view_test.h"
#include "net/base/net_errors.h"
#include "printing/image.h"
@@ -867,3 +869,45 @@ TEST_F(RenderViewTest, DidFailProvisionalLoadWithErrorForCancellation) {
// Frame should stay in view-source mode.
EXPECT_TRUE(web_frame->isViewSourceModeEnabled());
}
+
+// Print page as bitmap test.
+TEST_F(RenderViewTest, OnPrintPageAsBitmap) {
+#if defined(OS_WIN)
+ // Lets simulate a print pages with Hello world.
+ LoadHTML("<body><p>Hello world!</p></body>");
+
+ // Grab the printer settings from the printer.
+ ViewMsg_Print_Params print_settings;
+ MockPrinter* printer(render_thread_.printer());
+ printer->GetDefaultPrintSettings(&print_settings);
+ ViewMsg_PrintPage_Params page_params = ViewMsg_PrintPage_Params();
+ page_params.params = print_settings;
+ page_params.page_number = 0;
+
+ // Fetch the image data from the web frame.
+ std::vector<unsigned char> data;
+ view_->print_helper()->PrintPageAsJPEG(page_params,
+ view_->webview()->GetMainFrame(),
+ 1.0f,
+ &data);
+ std::vector<unsigned char> decoded;
+ int w, h;
+ EXPECT_TRUE(JPEGCodec::Decode(&data[0], data.size(), JPEGCodec::FORMAT_RGBA,
+ &decoded, &w, &h));
+
+ // Check if its not 100% white.
+ bool is_white = true;
+ for (int y = 0; y < h; y++) {
+ for (int x = 0; x < w; x++) {
+ unsigned char* px = &decoded[(y * w + x) * 4];
+ if (px[0] != 0xFF && px[1] != 0xFF && px[2] != 0xFF) {
+ is_white = false;
+ break;
+ }
+ }
+ }
+ ASSERT_TRUE(!is_white);
+#else
+ NOTIMPLEMENTED();
+#endif
+}