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 "build/build_config.h" | 9 #include "build/build_config.h" |
10 #include "content/common/frame_messages.h" | 10 #include "content/common/frame_messages.h" |
11 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
12 #include "content/public/renderer/document_state.h" | 12 #include "content/public/renderer/document_state.h" |
13 #include "content/public/test/frame_load_waiter.h" | 13 #include "content/public/test/frame_load_waiter.h" |
14 #include "content/public/test/render_view_test.h" | 14 #include "content/public/test/render_view_test.h" |
15 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
16 #include "content/renderer/navigation_state_impl.h" | 16 #include "content/renderer/navigation_state_impl.h" |
17 #include "content/renderer/render_frame_impl.h" | 17 #include "content/renderer/render_frame_impl.h" |
18 #include "content/renderer/render_view_impl.h" | 18 #include "content/renderer/render_view_impl.h" |
19 #include "content/test/fake_compositor_dependencies.h" | 19 #include "content/test/fake_compositor_dependencies.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 #include "third_party/WebKit/public/platform/WebEffectiveConnectionType.h" | 21 #include "third_party/WebKit/public/platform/WebEffectiveConnectionType.h" |
| 22 #include "third_party/WebKit/public/platform/WebString.h" |
22 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 23 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
23 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" | 24 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" |
24 #include "third_party/WebKit/public/web/WebHistoryItem.h" | 25 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
25 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 26 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
26 | 27 |
| 28 using blink::WebString; |
| 29 |
27 namespace { | 30 namespace { |
28 const int32_t kSubframeRouteId = 20; | 31 const int32_t kSubframeRouteId = 20; |
29 const int32_t kSubframeWidgetRouteId = 21; | 32 const int32_t kSubframeWidgetRouteId = 21; |
30 const int32_t kFrameProxyRouteId = 22; | 33 const int32_t kFrameProxyRouteId = 22; |
31 } // namespace | 34 } // namespace |
32 | 35 |
33 namespace content { | 36 namespace content { |
34 | 37 |
35 // RenderFrameImplTest creates a RenderFrameImpl that is a child of the | 38 // RenderFrameImplTest creates a RenderFrameImpl that is a child of the |
36 // main frame, and has its own RenderWidget. This behaves like an out | 39 // main frame, and has its own RenderWidget. This behaves like an out |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 GetMainRenderFrame()->GetWebFrame(), item, blink::WebStandardCommit); | 290 GetMainRenderFrame()->GetWebFrame(), item, blink::WebStandardCommit); |
288 EXPECT_EQ(blink::WebEffectiveConnectionType::TypeUnknown, | 291 EXPECT_EQ(blink::WebEffectiveConnectionType::TypeUnknown, |
289 GetMainRenderFrame()->getEffectiveConnectionType()); | 292 GetMainRenderFrame()->getEffectiveConnectionType()); |
290 | 293 |
291 // The subframe would be deleted here after a cross-document navigation. | 294 // The subframe would be deleted here after a cross-document navigation. |
292 // It happens to be left around in this test because this does not simulate | 295 // It happens to be left around in this test because this does not simulate |
293 // the frame detach. | 296 // the frame detach. |
294 } | 297 } |
295 } | 298 } |
296 | 299 |
| 300 TEST_F(RenderFrameImplTest, SaveImageFromDataURL) { |
| 301 const IPC::Message* msg1 = render_thread_->sink().GetFirstMessageMatching( |
| 302 FrameHostMsg_SaveImageFromDataURL::ID); |
| 303 EXPECT_FALSE(msg1); |
| 304 render_thread_->sink().ClearMessages(); |
| 305 |
| 306 const std::string image_data_url = |
| 307 "data:image/gif;base64,R0lGODlhAQABAIAAAAUEBAAAACwAAAAAAQABAAACAkQBADs="; |
| 308 |
| 309 frame()->saveImageFromDataURL(WebString::fromUTF8(image_data_url)); |
| 310 ProcessPendingMessages(); |
| 311 const IPC::Message* msg2 = render_thread_->sink().GetFirstMessageMatching( |
| 312 FrameHostMsg_SaveImageFromDataURL::ID); |
| 313 EXPECT_TRUE(msg2); |
| 314 |
| 315 FrameHostMsg_SaveImageFromDataURL::Param param1; |
| 316 FrameHostMsg_SaveImageFromDataURL::Read(msg2, ¶m1); |
| 317 EXPECT_EQ(std::get<2>(param1), image_data_url); |
| 318 |
| 319 ProcessPendingMessages(); |
| 320 render_thread_->sink().ClearMessages(); |
| 321 |
| 322 const std::string large_data_url(1024 * 1024 * 20 - 1, 'd'); |
| 323 |
| 324 frame()->saveImageFromDataURL(WebString::fromUTF8(large_data_url)); |
| 325 ProcessPendingMessages(); |
| 326 const IPC::Message* msg3 = render_thread_->sink().GetFirstMessageMatching( |
| 327 FrameHostMsg_SaveImageFromDataURL::ID); |
| 328 EXPECT_TRUE(msg3); |
| 329 |
| 330 FrameHostMsg_SaveImageFromDataURL::Param param2; |
| 331 FrameHostMsg_SaveImageFromDataURL::Read(msg3, ¶m2); |
| 332 EXPECT_EQ(std::get<2>(param2), large_data_url); |
| 333 |
| 334 ProcessPendingMessages(); |
| 335 render_thread_->sink().ClearMessages(); |
| 336 |
| 337 const std::string exceeded_data_url(1024 * 1024 * 20 + 1, 'd'); |
| 338 |
| 339 frame()->saveImageFromDataURL(WebString::fromUTF8(exceeded_data_url)); |
| 340 ProcessPendingMessages(); |
| 341 const IPC::Message* msg4 = render_thread_->sink().GetFirstMessageMatching( |
| 342 FrameHostMsg_SaveImageFromDataURL::ID); |
| 343 EXPECT_FALSE(msg4); |
| 344 } |
| 345 |
297 } // namespace | 346 } // namespace |
OLD | NEW |