| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/debug/leak_annotations.h" | 8 #include "base/debug/leak_annotations.h" |
| 9 #include "base/run_loop.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 11 #include "content/child/web_url_loader_impl.h" | 12 #include "content/child/web_url_loader_impl.h" |
| 12 #include "content/common/frame_messages.h" | 13 #include "content/common/frame_messages.h" |
| 13 #include "content/common/frame_owner_properties.h" | 14 #include "content/common/frame_owner_properties.h" |
| 14 #include "content/common/renderer.mojom.h" | 15 #include "content/common/renderer.mojom.h" |
| 15 #include "content/common/view_messages.h" | 16 #include "content/common/view_messages.h" |
| 16 #include "content/public/common/previews_state.h" | 17 #include "content/public/common/previews_state.h" |
| 17 #include "content/public/renderer/document_state.h" | 18 #include "content/public/renderer/document_state.h" |
| 18 #include "content/public/test/frame_load_waiter.h" | 19 #include "content/public/test/frame_load_waiter.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 TEST_F(RenderFrameImplTest, SaveImageFromDataURL) { | 296 TEST_F(RenderFrameImplTest, SaveImageFromDataURL) { |
| 296 const IPC::Message* msg1 = render_thread_->sink().GetFirstMessageMatching( | 297 const IPC::Message* msg1 = render_thread_->sink().GetFirstMessageMatching( |
| 297 FrameHostMsg_SaveImageFromDataURL::ID); | 298 FrameHostMsg_SaveImageFromDataURL::ID); |
| 298 EXPECT_FALSE(msg1); | 299 EXPECT_FALSE(msg1); |
| 299 render_thread_->sink().ClearMessages(); | 300 render_thread_->sink().ClearMessages(); |
| 300 | 301 |
| 301 const std::string image_data_url = | 302 const std::string image_data_url = |
| 302 "data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="; | 303 "data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="; |
| 303 | 304 |
| 304 frame()->SaveImageFromDataURL(WebString::FromUTF8(image_data_url)); | 305 frame()->SaveImageFromDataURL(WebString::FromUTF8(image_data_url)); |
| 305 ProcessPendingMessages(); | 306 base::RunLoop().RunUntilIdle(); |
| 306 const IPC::Message* msg2 = render_thread_->sink().GetFirstMessageMatching( | 307 const IPC::Message* msg2 = render_thread_->sink().GetFirstMessageMatching( |
| 307 FrameHostMsg_SaveImageFromDataURL::ID); | 308 FrameHostMsg_SaveImageFromDataURL::ID); |
| 308 EXPECT_TRUE(msg2); | 309 EXPECT_TRUE(msg2); |
| 309 | 310 |
| 310 FrameHostMsg_SaveImageFromDataURL::Param param1; | 311 FrameHostMsg_SaveImageFromDataURL::Param param1; |
| 311 FrameHostMsg_SaveImageFromDataURL::Read(msg2, ¶m1); | 312 FrameHostMsg_SaveImageFromDataURL::Read(msg2, ¶m1); |
| 312 EXPECT_EQ(std::get<2>(param1), image_data_url); | 313 EXPECT_EQ(std::get<2>(param1), image_data_url); |
| 313 | 314 |
| 314 ProcessPendingMessages(); | 315 base::RunLoop().RunUntilIdle(); |
| 315 render_thread_->sink().ClearMessages(); | 316 render_thread_->sink().ClearMessages(); |
| 316 | 317 |
| 317 const std::string large_data_url(1024 * 1024 * 20 - 1, 'd'); | 318 const std::string large_data_url(1024 * 1024 * 20 - 1, 'd'); |
| 318 | 319 |
| 319 frame()->SaveImageFromDataURL(WebString::FromUTF8(large_data_url)); | 320 frame()->SaveImageFromDataURL(WebString::FromUTF8(large_data_url)); |
| 320 ProcessPendingMessages(); | 321 base::RunLoop().RunUntilIdle(); |
| 321 const IPC::Message* msg3 = render_thread_->sink().GetFirstMessageMatching( | 322 const IPC::Message* msg3 = render_thread_->sink().GetFirstMessageMatching( |
| 322 FrameHostMsg_SaveImageFromDataURL::ID); | 323 FrameHostMsg_SaveImageFromDataURL::ID); |
| 323 EXPECT_TRUE(msg3); | 324 EXPECT_TRUE(msg3); |
| 324 | 325 |
| 325 FrameHostMsg_SaveImageFromDataURL::Param param2; | 326 FrameHostMsg_SaveImageFromDataURL::Param param2; |
| 326 FrameHostMsg_SaveImageFromDataURL::Read(msg3, ¶m2); | 327 FrameHostMsg_SaveImageFromDataURL::Read(msg3, ¶m2); |
| 327 EXPECT_EQ(std::get<2>(param2), large_data_url); | 328 EXPECT_EQ(std::get<2>(param2), large_data_url); |
| 328 | 329 |
| 329 ProcessPendingMessages(); | 330 base::RunLoop().RunUntilIdle(); |
| 330 render_thread_->sink().ClearMessages(); | 331 render_thread_->sink().ClearMessages(); |
| 331 | 332 |
| 332 const std::string exceeded_data_url(1024 * 1024 * 20 + 1, 'd'); | 333 const std::string exceeded_data_url(1024 * 1024 * 20 + 1, 'd'); |
| 333 | 334 |
| 334 frame()->SaveImageFromDataURL(WebString::FromUTF8(exceeded_data_url)); | 335 frame()->SaveImageFromDataURL(WebString::FromUTF8(exceeded_data_url)); |
| 335 ProcessPendingMessages(); | 336 base::RunLoop().RunUntilIdle(); |
| 336 const IPC::Message* msg4 = render_thread_->sink().GetFirstMessageMatching( | 337 const IPC::Message* msg4 = render_thread_->sink().GetFirstMessageMatching( |
| 337 FrameHostMsg_SaveImageFromDataURL::ID); | 338 FrameHostMsg_SaveImageFromDataURL::ID); |
| 338 EXPECT_FALSE(msg4); | 339 EXPECT_FALSE(msg4); |
| 339 } | 340 } |
| 340 | 341 |
| 341 TEST_F(RenderFrameImplTest, ZoomLimit) { | 342 TEST_F(RenderFrameImplTest, ZoomLimit) { |
| 342 const double kMinZoomLevel = ZoomFactorToZoomLevel(kMinimumZoomFactor); | 343 const double kMinZoomLevel = ZoomFactorToZoomLevel(kMinimumZoomFactor); |
| 343 const double kMaxZoomLevel = ZoomFactorToZoomLevel(kMaximumZoomFactor); | 344 const double kMaxZoomLevel = ZoomFactorToZoomLevel(kMaximumZoomFactor); |
| 344 | 345 |
| 345 // Verifies navigation to a URL with preset zoom level indeed sets the level. | 346 // Verifies navigation to a URL with preset zoom level indeed sets the level. |
| 346 // Regression test for http://crbug.com/139559, where the level was not | 347 // Regression test for http://crbug.com/139559, where the level was not |
| 347 // properly set when it is out of the default zoom limits of WebView. | 348 // properly set when it is out of the default zoom limits of WebView. |
| 348 CommonNavigationParams common_params; | 349 CommonNavigationParams common_params; |
| 349 common_params.url = GURL("data:text/html,min_zoomlimit_test"); | 350 common_params.url = GURL("data:text/html,min_zoomlimit_test"); |
| 350 common_params.navigation_type = FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT; | 351 common_params.navigation_type = FrameMsg_Navigate_Type::DIFFERENT_DOCUMENT; |
| 351 GetMainRenderFrame()->SetHostZoomLevel(common_params.url, kMinZoomLevel); | 352 GetMainRenderFrame()->SetHostZoomLevel(common_params.url, kMinZoomLevel); |
| 352 GetMainRenderFrame()->NavigateInternal( | 353 GetMainRenderFrame()->NavigateInternal( |
| 353 common_params, StartNavigationParams(), RequestNavigationParams(), | 354 common_params, StartNavigationParams(), RequestNavigationParams(), |
| 354 std::unique_ptr<StreamOverrideParameters>()); | 355 std::unique_ptr<StreamOverrideParameters>()); |
| 355 ProcessPendingMessages(); | 356 base::RunLoop().RunUntilIdle(); |
| 356 EXPECT_DOUBLE_EQ(kMinZoomLevel, view_->GetWebView()->ZoomLevel()); | 357 EXPECT_DOUBLE_EQ(kMinZoomLevel, view_->GetWebView()->ZoomLevel()); |
| 357 | 358 |
| 358 // It should work even when the zoom limit is temporarily changed in the page. | 359 // It should work even when the zoom limit is temporarily changed in the page. |
| 359 view_->GetWebView()->ZoomLimitsChanged(ZoomFactorToZoomLevel(1.0), | 360 view_->GetWebView()->ZoomLimitsChanged(ZoomFactorToZoomLevel(1.0), |
| 360 ZoomFactorToZoomLevel(1.0)); | 361 ZoomFactorToZoomLevel(1.0)); |
| 361 common_params.url = GURL("data:text/html,max_zoomlimit_test"); | 362 common_params.url = GURL("data:text/html,max_zoomlimit_test"); |
| 362 GetMainRenderFrame()->SetHostZoomLevel(common_params.url, kMaxZoomLevel); | 363 GetMainRenderFrame()->SetHostZoomLevel(common_params.url, kMaxZoomLevel); |
| 363 GetMainRenderFrame()->NavigateInternal( | 364 GetMainRenderFrame()->NavigateInternal( |
| 364 common_params, StartNavigationParams(), RequestNavigationParams(), | 365 common_params, StartNavigationParams(), RequestNavigationParams(), |
| 365 std::unique_ptr<StreamOverrideParameters>()); | 366 std::unique_ptr<StreamOverrideParameters>()); |
| 366 ProcessPendingMessages(); | 367 base::RunLoop().RunUntilIdle(); |
| 367 EXPECT_DOUBLE_EQ(kMaxZoomLevel, view_->GetWebView()->ZoomLevel()); | 368 EXPECT_DOUBLE_EQ(kMaxZoomLevel, view_->GetWebView()->ZoomLevel()); |
| 368 } | 369 } |
| 369 | 370 |
| 370 // Regression test for crbug.com/692557. It shouldn't crash if we inititate a | 371 // Regression test for crbug.com/692557. It shouldn't crash if we inititate a |
| 371 // text finding, and then delete the frame immediately before the text finding | 372 // text finding, and then delete the frame immediately before the text finding |
| 372 // returns any text match. | 373 // returns any text match. |
| 373 TEST_F(RenderFrameImplTest, NoCrashWhenDeletingFrameDuringFind) { | 374 TEST_F(RenderFrameImplTest, NoCrashWhenDeletingFrameDuringFind) { |
| 374 blink::WebFindOptions options; | 375 blink::WebFindOptions options; |
| 375 options.force = true; | 376 options.force = true; |
| 376 FrameMsg_Find find_message(0, 1, base::ASCIIToUTF16("foo"), options); | 377 FrameMsg_Find find_message(0, 1, base::ASCIIToUTF16("foo"), options); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 393 // The host should receive a request for it sent to the frame. | 394 // The host should receive a request for it sent to the frame. |
| 394 const IPC::Message* msg = render_thread_->sink().GetFirstMessageMatching( | 395 const IPC::Message* msg = render_thread_->sink().GetFirstMessageMatching( |
| 395 FrameHostMsg_RequestOverlayRoutingToken::ID); | 396 FrameHostMsg_RequestOverlayRoutingToken::ID); |
| 396 EXPECT_TRUE(msg); | 397 EXPECT_TRUE(msg); |
| 397 | 398 |
| 398 // Send a token. | 399 // Send a token. |
| 399 base::UnguessableToken token = base::UnguessableToken::Create(); | 400 base::UnguessableToken token = base::UnguessableToken::Create(); |
| 400 FrameMsg_SetOverlayRoutingToken token_message(0, token); | 401 FrameMsg_SetOverlayRoutingToken token_message(0, token); |
| 401 frame()->OnMessageReceived(token_message); | 402 frame()->OnMessageReceived(token_message); |
| 402 | 403 |
| 403 ProcessPendingMessages(); | 404 base::RunLoop().RunUntilIdle(); |
| 404 ASSERT_TRUE(overlay_routing_token_.has_value()); | 405 ASSERT_TRUE(overlay_routing_token_.has_value()); |
| 405 ASSERT_EQ(overlay_routing_token_.value(), token); | 406 ASSERT_EQ(overlay_routing_token_.value(), token); |
| 406 } | 407 } |
| 407 | 408 |
| 408 // Verify that RFI sends tokens if they're already available. | 409 // Verify that RFI sends tokens if they're already available. |
| 409 TEST_F(RenderFrameImplTest, TestOverlayRoutingTokenSendsNow) { | 410 TEST_F(RenderFrameImplTest, TestOverlayRoutingTokenSendsNow) { |
| 410 ASSERT_FALSE(overlay_routing_token_.has_value()); | 411 ASSERT_FALSE(overlay_routing_token_.has_value()); |
| 411 base::UnguessableToken token = base::UnguessableToken::Create(); | 412 base::UnguessableToken token = base::UnguessableToken::Create(); |
| 412 FrameMsg_SetOverlayRoutingToken token_message(0, token); | 413 FrameMsg_SetOverlayRoutingToken token_message(0, token); |
| 413 frame()->OnMessageReceived(token_message); | 414 frame()->OnMessageReceived(token_message); |
| 414 | 415 |
| 415 // The frame now has a token. We don't care if it sends the token before | 416 // The frame now has a token. We don't care if it sends the token before |
| 416 // returning or posts a message. | 417 // returning or posts a message. |
| 417 ProcessPendingMessages(); | 418 base::RunLoop().RunUntilIdle(); |
| 418 frame()->RequestOverlayRoutingToken( | 419 frame()->RequestOverlayRoutingToken( |
| 419 base::Bind(&RenderFrameImplTest::ReceiveOverlayRoutingToken, | 420 base::Bind(&RenderFrameImplTest::ReceiveOverlayRoutingToken, |
| 420 base::Unretained(this))); | 421 base::Unretained(this))); |
| 421 ASSERT_TRUE(overlay_routing_token_.has_value()); | 422 ASSERT_TRUE(overlay_routing_token_.has_value()); |
| 422 ASSERT_EQ(overlay_routing_token_.value(), token); | 423 ASSERT_EQ(overlay_routing_token_.value(), token); |
| 423 | 424 |
| 424 // Since the token already arrived, a request for it shouldn't be sent. | 425 // Since the token already arrived, a request for it shouldn't be sent. |
| 425 const IPC::Message* msg = render_thread_->sink().GetFirstMessageMatching( | 426 const IPC::Message* msg = render_thread_->sink().GetFirstMessageMatching( |
| 426 FrameHostMsg_RequestOverlayRoutingToken::ID); | 427 FrameHostMsg_RequestOverlayRoutingToken::ID); |
| 427 EXPECT_FALSE(msg); | 428 EXPECT_FALSE(msg); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 GURL(test.is_https ? "https://example.com" : "http://example.com")); | 541 GURL(test.is_https ? "https://example.com" : "http://example.com")); |
| 541 request.SetPreviewsState(test.initial_request_previews_state); | 542 request.SetPreviewsState(test.initial_request_previews_state); |
| 542 | 543 |
| 543 EXPECT_EQ(test.expected_should_use_client_lo_fi_for_request, | 544 EXPECT_EQ(test.expected_should_use_client_lo_fi_for_request, |
| 544 frame()->ShouldUseClientLoFiForRequest(request)) | 545 frame()->ShouldUseClientLoFiForRequest(request)) |
| 545 << (&test - tests); | 546 << (&test - tests); |
| 546 } | 547 } |
| 547 } | 548 } |
| 548 | 549 |
| 549 } // namespace content | 550 } // namespace content |
| OLD | NEW |