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

Side by Side Diff: src/chrome/renderer/render_view_unittest.cc

Issue 196021: Implement PrintPageAsJPEG feature for Print Preview (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/
Patch Set: '' Created 11 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/chrome/renderer/render_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/gfx/jpeg_codec.h"
6 #include "base/shared_memory.h" 7 #include "base/shared_memory.h"
7 #include "chrome/common/native_web_keyboard_event.h" 8 #include "chrome/common/native_web_keyboard_event.h"
8 #include "chrome/common/render_messages.h" 9 #include "chrome/common/render_messages.h"
10 #include "chrome/renderer/print_web_view_helper.h"
9 #include "chrome/test/render_view_test.h" 11 #include "chrome/test/render_view_test.h"
10 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
11 #include "printing/image.h" 13 #include "printing/image.h"
12 #include "printing/native_metafile.h" 14 #include "printing/native_metafile.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 #include "webkit/api/public/WebString.h" 16 #include "webkit/api/public/WebString.h"
15 #include "webkit/api/public/WebURLError.h" 17 #include "webkit/api/public/WebURLError.h"
16 18
17 using WebKit::WebCompositionCommand; 19 using WebKit::WebCompositionCommand;
18 using WebKit::WebFrame; 20 using WebKit::WebFrame;
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 error.domain.fromUTF8("test_domain"); 862 error.domain.fromUTF8("test_domain");
861 error.reason = net::ERR_ABORTED; 863 error.reason = net::ERR_ABORTED;
862 error.unreachableURL = GURL("http://foo"); 864 error.unreachableURL = GURL("http://foo");
863 WebFrame* web_frame = GetMainFrame(); 865 WebFrame* web_frame = GetMainFrame();
864 WebView* web_view = web_frame->view(); 866 WebView* web_view = web_frame->view();
865 // A cancellation occurred. 867 // A cancellation occurred.
866 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame); 868 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame);
867 // Frame should stay in view-source mode. 869 // Frame should stay in view-source mode.
868 EXPECT_TRUE(web_frame->isViewSourceModeEnabled()); 870 EXPECT_TRUE(web_frame->isViewSourceModeEnabled());
869 } 871 }
872
873 // Print page as bitmap test.
874 TEST_F(RenderViewTest, OnPrintPageAsBitmap) {
875 #if defined(OS_WIN)
876 // Lets simulate a print pages with Hello world.
877 LoadHTML("<body><p>Hello world!</p></body>");
878
879 // Grab the printer settings from the printer.
880 ViewMsg_Print_Params print_settings;
881 MockPrinter* printer(render_thread_.printer());
882 printer->GetDefaultPrintSettings(&print_settings);
883 ViewMsg_PrintPage_Params page_params = ViewMsg_PrintPage_Params();
884 page_params.params = print_settings;
885 page_params.page_number = 0;
886
887 // Fetch the image data from the web frame.
888 std::vector<unsigned char> data;
889 view_->print_helper()->PrintPageAsJPEG(page_params,
890 view_->webview()->GetMainFrame(),
891 1.0f,
892 &data);
893 std::vector<unsigned char> decoded;
894 int w, h;
895 EXPECT_TRUE(JPEGCodec::Decode(&data[0], data.size(), JPEGCodec::FORMAT_RGBA,
896 &decoded, &w, &h));
897
898 // Check if its not 100% white.
899 bool is_white = true;
900 for (int y = 0; y < h; y++) {
901 for (int x = 0; x < w; x++) {
902 unsigned char* px = &decoded[(y * w + x) * 4];
903 if (px[0] != 0xFF && px[1] != 0xFF && px[2] != 0xFF) {
904 is_white = false;
905 break;
906 }
907 }
908 }
909 ASSERT_TRUE(!is_white);
910 #else
911 NOTIMPLEMENTED();
912 #endif
913 }
OLDNEW
« no previous file with comments | « src/chrome/renderer/render_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698