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

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

Issue 149644: Print only the focused frame. This makes more sense than trying to print all... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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
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/shared_memory.h"
6 #include "chrome/common/native_web_keyboard_event.h" 7 #include "chrome/common/native_web_keyboard_event.h"
7 #include "chrome/common/render_messages.h" 8 #include "chrome/common/render_messages.h"
8 #include "chrome/test/render_view_test.h" 9 #include "chrome/test/render_view_test.h"
9 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
11 #include "printing/image.h"
12 #include "printing/native_metafile.h"
10 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
11 #include "webkit/api/public/WebURLError.h" 14 #include "webkit/api/public/WebURLError.h"
12 15
13 using WebKit::WebCompositionCommand; 16 using WebKit::WebCompositionCommand;
14 using WebKit::WebTextDirection; 17 using WebKit::WebTextDirection;
15 using WebKit::WebURLError; 18 using WebKit::WebURLError;
16 19
17 static WebCompositionCommand ToCompositionCommand(int string_type) { 20 static WebCompositionCommand ToCompositionCommand(int string_type) {
18 switch (string_type) { 21 switch (string_type) {
19 default: 22 default:
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 ViewHostMsg_DidPrintPage::ID); 359 ViewHostMsg_DidPrintPage::ID);
357 EXPECT_TRUE(did_print_msg); 360 EXPECT_TRUE(did_print_msg);
358 ViewHostMsg_DidPrintPage::Param post_did_print_page_param; 361 ViewHostMsg_DidPrintPage::Param post_did_print_page_param;
359 ViewHostMsg_DidPrintPage::Read(did_print_msg, &post_did_print_page_param); 362 ViewHostMsg_DidPrintPage::Read(did_print_msg, &post_did_print_page_param);
360 EXPECT_EQ(0, post_did_print_page_param.a.page_number); 363 EXPECT_EQ(0, post_did_print_page_param.a.page_number);
361 #else 364 #else
362 NOTIMPLEMENTED(); 365 NOTIMPLEMENTED();
363 #endif 366 #endif
364 } 367 }
365 368
369 TEST_F(RenderViewTest, PrintWithIframe) {
370 #if defined(OS_WIN)
371 // Document that populates an iframe..
372 const char html[] =
373 "<html><body>Lorem Ipsum:"
374 "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>"
375 " document.write(frames['sub1'].name);"
376 " frames['sub1'].document.write("
377 " '<p>Cras tempus ante eu felis semper luctus!</p>');"
378 "</script></body></html>";
379
380 LoadHTML(html);
381
382 // Find the frame and set it as the focused one. This should mean that that
383 // the printout should only contain the contents of that frame.
384 WebFrame* sub1_frame = view_->webview()->GetFrameWithName(L"sub1");
385 ASSERT_TRUE(sub1_frame);
386 view_->webview()->SetFocusedFrame(sub1_frame);
387 ASSERT_NE(view_->webview()->GetFocusedFrame(),
388 view_->webview()->GetMainFrame());
389
390 // Initiate printing.
391 view_->OnPrintPages();
392
393 // Verify output through MockPrinter.
394 const MockPrinter* printer(render_thread_.printer());
395 ASSERT_EQ(1, printer->GetPrintedPages());
396 const printing::Image& image1(printer->GetPrintedPage(0)->image());
397
398 // TODO(sverrir): Figure out a way to improve this test to actually print
399 // only the content of the iframe. Currently image1 will contain the full
400 // page.
401 EXPECT_NE(0, image1.size().width());
402 EXPECT_NE(0, image1.size().height());
403 #else
404 NOTIMPLEMENTED();
405 #endif
406 }
407
366 // Tests if we can print a page and verify its results. 408 // Tests if we can print a page and verify its results.
367 // This test prints HTML pages into a pseudo printer and check their outputs, 409 // This test prints HTML pages into a pseudo printer and check their outputs,
368 // i.e. a simplified version of the PrintingLayoutTextTest UI test. 410 // i.e. a simplified version of the PrintingLayoutTextTest UI test.
369 namespace { 411 namespace {
370 // Test cases used in this test. 412 // Test cases used in this test.
371 const struct { 413 const struct {
372 const char* page; 414 const char* page;
373 int printed_pages; 415 int printed_pages;
374 int width; 416 int width;
375 int height; 417 int height;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 EXPECT_GT(kTestPages[i].height * (100 + kErrorMargin) / 100, height); 466 EXPECT_GT(kTestPages[i].height * (100 + kErrorMargin) / 100, height);
425 EXPECT_LT(kTestPages[i].height* (100 - kErrorMargin) / 100, height); 467 EXPECT_LT(kTestPages[i].height* (100 - kErrorMargin) / 100, height);
426 468
427 // Retrieve the checksum of the bitmap data from the pseudo printer and 469 // Retrieve the checksum of the bitmap data from the pseudo printer and
428 // compare it with the expected result. 470 // compare it with the expected result.
429 std::string bitmap_actual; 471 std::string bitmap_actual;
430 EXPECT_TRUE(render_thread_.printer()->GetBitmapChecksum(0, &bitmap_actual)); 472 EXPECT_TRUE(render_thread_.printer()->GetBitmapChecksum(0, &bitmap_actual));
431 if (kTestPages[i].checksum) 473 if (kTestPages[i].checksum)
432 EXPECT_EQ(kTestPages[i].checksum, bitmap_actual); 474 EXPECT_EQ(kTestPages[i].checksum, bitmap_actual);
433 475
434 // Retrieve the bitmap data from the pseudo printer.
435 // TODO(hbono): implement a function which retrieves an expected result
436 // from a file and compares it with this bitmap data.
437 const void* bitmap_data;
438 size_t bitmap_size;
439 EXPECT_TRUE(render_thread_.printer()->GetBitmap(0, &bitmap_data,
440 &bitmap_size));
441
442 if (baseline) { 476 if (baseline) {
443 // Save the source data and the bitmap data into temporary files to 477 // Save the source data and the bitmap data into temporary files to
444 // create base-line results. 478 // create base-line results.
445 FilePath source_path; 479 FilePath source_path;
446 file_util::CreateTemporaryFileName(&source_path); 480 file_util::CreateTemporaryFileName(&source_path);
447 render_thread_.printer()->SaveSource(0, source_path.value()); 481 render_thread_.printer()->SaveSource(0, source_path.value());
448 482
449 FilePath bitmap_path; 483 FilePath bitmap_path;
450 file_util::CreateTemporaryFileName(&bitmap_path); 484 file_util::CreateTemporaryFileName(&bitmap_path);
451 render_thread_.printer()->SaveBitmap(0, bitmap_path.value()); 485 render_thread_.printer()->SaveBitmap(0, bitmap_path.value());
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 error.domain.fromUTF8("test_domain"); 857 error.domain.fromUTF8("test_domain");
824 error.reason = net::ERR_ABORTED; 858 error.reason = net::ERR_ABORTED;
825 error.unreachableURL = GURL("http://foo"); 859 error.unreachableURL = GURL("http://foo");
826 WebFrame* web_frame = GetMainFrame(); 860 WebFrame* web_frame = GetMainFrame();
827 WebView* web_view = web_frame->GetView(); 861 WebView* web_view = web_frame->GetView();
828 // A cancellation occurred. 862 // A cancellation occurred.
829 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame); 863 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame);
830 // Frame should stay in view-source mode. 864 // Frame should stay in view-source mode.
831 EXPECT_TRUE(web_frame->GetInViewSourceMode()); 865 EXPECT_TRUE(web_frame->GetInViewSourceMode());
832 } 866 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698