| OLD | NEW |
| 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 "chrome/common/gfx/emf.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" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "webkit/api/public/WebURLError.h" | 12 #include "webkit/api/public/WebURLError.h" |
| 12 | 13 |
| 13 using WebKit::WebURLError; | 14 using WebKit::WebURLError; |
| 14 | 15 |
| 15 TEST_F(RenderViewTest, OnLoadAlternateHTMLText) { | 16 TEST_F(RenderViewTest, OnLoadAlternateHTMLText) { |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 ViewHostMsg_DidPrintPage::ID); | 341 ViewHostMsg_DidPrintPage::ID); |
| 341 EXPECT_TRUE(did_print_msg); | 342 EXPECT_TRUE(did_print_msg); |
| 342 ViewHostMsg_DidPrintPage::Param post_did_print_page_param; | 343 ViewHostMsg_DidPrintPage::Param post_did_print_page_param; |
| 343 ViewHostMsg_DidPrintPage::Read(did_print_msg, &post_did_print_page_param); | 344 ViewHostMsg_DidPrintPage::Read(did_print_msg, &post_did_print_page_param); |
| 344 EXPECT_EQ(0, post_did_print_page_param.a.page_number); | 345 EXPECT_EQ(0, post_did_print_page_param.a.page_number); |
| 345 #else | 346 #else |
| 346 NOTIMPLEMENTED(); | 347 NOTIMPLEMENTED(); |
| 347 #endif | 348 #endif |
| 348 } | 349 } |
| 349 | 350 |
| 351 // Test printing an iframe. This tests we only print the currently focused |
| 352 // frame. |
| 353 TEST_F(RenderViewTest, PrintWithIframe) { |
| 354 #if defined(OS_WIN) |
| 355 // Document that populates an iframe.. |
| 356 const char html[] = |
| 357 "<html><body>Lorem Ipsum:" |
| 358 "<iframe name=\"sub1\" id=\"sub1\"></iframe><script>" |
| 359 " document.write(frames['sub1'].name);" |
| 360 " frames['sub1'].document.write(" |
| 361 " '<p>Cras tempus ante eu felis semper luctus!</p>');" |
| 362 "</script></body></html>"; |
| 363 |
| 364 LoadHTML(html); |
| 365 |
| 366 // Find the frame and set it as the focused one. This should mean that that |
| 367 // the printout should only contain the contents of that frame. |
| 368 WebFrame* sub1_frame = view_->webview()->GetFrameWithName(L"sub1"); |
| 369 ASSERT_TRUE(sub1_frame); |
| 370 |
| 371 view_->webview()->SetFocusedFrame(sub1_frame); |
| 372 ASSERT_NE(view_->webview()->GetFocusedFrame(), |
| 373 view_->webview()->GetMainFrame()); |
| 374 |
| 375 // Initiate printing. |
| 376 view_->OnPrintPages(); |
| 377 |
| 378 // The renderer should be done calculating the number of rendered pages |
| 379 // according to the specified settings defined in the mock render thread. |
| 380 // Verify the page count is correct. |
| 381 const IPC::Message* page_cnt_msg = |
| 382 render_thread_.sink().GetUniqueMessageMatching( |
| 383 ViewHostMsg_DidGetPrintedPagesCount::ID); |
| 384 ASSERT_TRUE(page_cnt_msg); |
| 385 ViewHostMsg_DidGetPrintedPagesCount::Param post_page_count_param; |
| 386 ViewHostMsg_DidGetPrintedPagesCount::Read(page_cnt_msg, |
| 387 &post_page_count_param); |
| 388 EXPECT_EQ(1, post_page_count_param.b); |
| 389 |
| 390 // Verify the rendered "printed page". |
| 391 const IPC::Message* did_print_msg = |
| 392 render_thread_.sink().GetUniqueMessageMatching( |
| 393 ViewHostMsg_DidPrintPage::ID); |
| 394 EXPECT_TRUE(did_print_msg); |
| 395 ViewHostMsg_DidPrintPage::Param post_did_print_page_param; |
| 396 ViewHostMsg_DidPrintPage::Read(did_print_msg, &post_did_print_page_param); |
| 397 EXPECT_EQ(0, post_did_print_page_param.a.page_number); |
| 398 |
| 399 #else |
| 400 NOTIMPLEMENTED(); |
| 401 #endif |
| 402 } |
| 403 |
| 350 // Tests if we can print a page and verify its results. | 404 // Tests if we can print a page and verify its results. |
| 351 // This test prints HTML pages into a pseudo printer and check their outputs, | 405 // This test prints HTML pages into a pseudo printer and check their outputs, |
| 352 // i.e. a simplified version of the PrintingLayoutTextTest UI test. | 406 // i.e. a simplified version of the PrintingLayoutTextTest UI test. |
| 353 namespace { | 407 namespace { |
| 354 // Test cases used in this test. | 408 // Test cases used in this test. |
| 355 const struct { | 409 const struct { |
| 356 const char* page; | 410 const char* page; |
| 357 int printed_pages; | 411 int printed_pages; |
| 358 int width; | 412 int width; |
| 359 int height; | 413 int height; |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 error.domain.fromUTF8("test_domain"); | 861 error.domain.fromUTF8("test_domain"); |
| 808 error.reason = net::ERR_ABORTED; | 862 error.reason = net::ERR_ABORTED; |
| 809 error.unreachableURL = GURL("http://foo"); | 863 error.unreachableURL = GURL("http://foo"); |
| 810 WebFrame* web_frame = GetMainFrame(); | 864 WebFrame* web_frame = GetMainFrame(); |
| 811 WebView* web_view = web_frame->GetView(); | 865 WebView* web_view = web_frame->GetView(); |
| 812 // A cancellation occurred. | 866 // A cancellation occurred. |
| 813 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame); | 867 view_->DidFailProvisionalLoadWithError(web_view, error, web_frame); |
| 814 // Frame should stay in view-source mode. | 868 // Frame should stay in view-source mode. |
| 815 EXPECT_TRUE(web_frame->GetInViewSourceMode()); | 869 EXPECT_TRUE(web_frame->GetInViewSourceMode()); |
| 816 } | 870 } |
| OLD | NEW |