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

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

Issue 254002: Fix cmd-up/cmd-down. (Closed)
Patch Set: Fix typo found by suzhe Created 11 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 unified diff | Download patch
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/gfx/jpeg_codec.h"
7 #include "base/shared_memory.h" 7 #include "base/shared_memory.h"
8 #include "chrome/common/native_web_keyboard_event.h" 8 #include "chrome/common/native_web_keyboard_event.h"
9 #include "chrome/common/render_messages.h" 9 #include "chrome/common/render_messages.h"
10 #include "chrome/renderer/print_web_view_helper.h" 10 #include "chrome/renderer/print_web_view_helper.h"
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 FilePath bitmap_path; 489 FilePath bitmap_path;
490 file_util::CreateTemporaryFile(&bitmap_path); 490 file_util::CreateTemporaryFile(&bitmap_path);
491 render_thread_.printer()->SaveBitmap(0, bitmap_path.value()); 491 render_thread_.printer()->SaveBitmap(0, bitmap_path.value());
492 } 492 }
493 } 493 }
494 #else 494 #else
495 NOTIMPLEMENTED(); 495 NOTIMPLEMENTED();
496 #endif 496 #endif
497 } 497 }
498 498
499 // Print page as bitmap test.
500 TEST_F(RenderViewTest, OnPrintPageAsBitmap) {
501 #if defined(OS_WIN)
502 // Lets simulate a print pages with Hello world.
503 LoadHTML("<body><p>Hello world!</p></body>");
504
505 // Grab the printer settings from the printer.
506 ViewMsg_Print_Params print_settings;
507 MockPrinter* printer(render_thread_.printer());
508 printer->GetDefaultPrintSettings(&print_settings);
509 ViewMsg_PrintPage_Params page_params = ViewMsg_PrintPage_Params();
510 page_params.params = print_settings;
511 page_params.page_number = 0;
512
513 // Fetch the image data from the web frame.
514 std::vector<unsigned char> data;
515 view_->print_helper()->PrintPageAsJPEG(page_params,
516 view_->webview()->GetMainFrame(),
517 1.0f,
518 &data);
519 std::vector<unsigned char> decoded;
520 int w, h;
521 EXPECT_TRUE(JPEGCodec::Decode(&data[0], data.size(), JPEGCodec::FORMAT_RGBA,
522 &decoded, &w, &h));
523
524 // Check if its not 100% white.
525 bool is_white = true;
526 for (int y = 0; y < h; y++) {
527 for (int x = 0; x < w; x++) {
528 unsigned char* px = &decoded[(y * w + x) * 4];
529 if (px[0] != 0xFF && px[1] != 0xFF && px[2] != 0xFF) {
530 is_white = false;
531 break;
532 }
533 }
534 }
535 ASSERT_TRUE(!is_white);
536 #else
537 NOTIMPLEMENTED();
538 #endif
539 }
540
499 // Test that we can receive correct DOM events when we send input events 541 // Test that we can receive correct DOM events when we send input events
500 // through the RenderWidget::OnHandleInputEvent() function. 542 // through the RenderWidget::OnHandleInputEvent() function.
501 TEST_F(RenderViewTest, OnHandleKeyboardEvent) { 543 TEST_F(RenderViewTest, OnHandleKeyboardEvent) {
502 #if defined(OS_WIN) 544 #if defined(OS_WIN)
503 // Load an HTML page consisting of one <input> element and three 545 // Load an HTML page consisting of one <input> element and three
504 // contentediable <div> elements. 546 // contentediable <div> elements.
505 // The <input> element is used for sending keyboard events, and the <div> 547 // The <input> element is used for sending keyboard events, and the <div>
506 // elements are used for writing DOM events in the following format: 548 // elements are used for writing DOM events in the following format:
507 // "<keyCode>,<shiftKey>,<controlKey>,<altKey>". 549 // "<keyCode>,<shiftKey>,<controlKey>,<altKey>".
508 // TODO(hbono): <http://crbug.com/2215> Our WebKit port set |ev.metaKey| to 550 // TODO(hbono): <http://crbug.com/2215> Our WebKit port set |ev.metaKey| to
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 WebURLError error; 903 WebURLError error;
862 error.domain.fromUTF8("test_domain"); 904 error.domain.fromUTF8("test_domain");
863 error.reason = net::ERR_ABORTED; 905 error.reason = net::ERR_ABORTED;
864 error.unreachableURL = GURL("http://foo"); 906 error.unreachableURL = GURL("http://foo");
865 WebFrame* web_frame = GetMainFrame(); 907 WebFrame* web_frame = GetMainFrame();
866 // A cancellation occurred. 908 // A cancellation occurred.
867 view_->didFailProvisionalLoad(web_frame, error); 909 view_->didFailProvisionalLoad(web_frame, error);
868 // Frame should stay in view-source mode. 910 // Frame should stay in view-source mode.
869 EXPECT_TRUE(web_frame->isViewSourceModeEnabled()); 911 EXPECT_TRUE(web_frame->isViewSourceModeEnabled());
870 } 912 }
871
872 // Print page as bitmap test.
873 TEST_F(RenderViewTest, OnPrintPageAsBitmap) {
874 #if defined(OS_WIN)
875 // Lets simulate a print pages with Hello world.
876 LoadHTML("<body><p>Hello world!</p></body>");
877
878 // Grab the printer settings from the printer.
879 ViewMsg_Print_Params print_settings;
880 MockPrinter* printer(render_thread_.printer());
881 printer->GetDefaultPrintSettings(&print_settings);
882 ViewMsg_PrintPage_Params page_params = ViewMsg_PrintPage_Params();
883 page_params.params = print_settings;
884 page_params.page_number = 0;
885
886 // Fetch the image data from the web frame.
887 std::vector<unsigned char> data;
888 view_->print_helper()->PrintPageAsJPEG(page_params,
889 view_->webview()->GetMainFrame(),
890 1.0f,
891 &data);
892 std::vector<unsigned char> decoded;
893 int w, h;
894 EXPECT_TRUE(JPEGCodec::Decode(&data[0], data.size(), JPEGCodec::FORMAT_RGBA,
895 &decoded, &w, &h));
896
897 // Check if its not 100% white.
898 bool is_white = true;
899 for (int y = 0; y < h; y++) {
900 for (int x = 0; x < w; x++) {
901 unsigned char* px = &decoded[(y * w + x) * 4];
902 if (px[0] != 0xFF && px[1] != 0xFF && px[2] != 0xFF) {
903 is_white = false;
904 break;
905 }
906 }
907 }
908 ASSERT_TRUE(!is_white);
909 #else
910 NOTIMPLEMENTED();
911 #endif
912 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698