OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 | 6 |
7 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "content/common/intents_messages.h" | 10 #include "content/common/intents_messages.h" |
11 #include "content/common/view_messages.h" | 11 #include "content/common/view_messages.h" |
12 #include "content/public/browser/native_web_keyboard_event.h" | 12 #include "content/public/browser/native_web_keyboard_event.h" |
13 #include "content/public/browser/web_ui_controller_factory.h" | 13 #include "content/public/browser/web_ui_controller_factory.h" |
14 #include "content/public/common/bindings_policy.h" | 14 #include "content/public/common/bindings_policy.h" |
15 #include "content/public/common/url_constants.h" | 15 #include "content/public/common/url_constants.h" |
16 #include "content/public/test/render_view_test.h" | 16 #include "content/public/test/render_view_test.h" |
17 #include "content/renderer/render_view_impl.h" | 17 #include "content/renderer/render_view_impl.h" |
18 #include "content/shell/shell_content_client.h" | 18 #include "content/shell/shell_content_client.h" |
19 #include "content/shell/shell_content_browser_client.h" | 19 #include "content/shell/shell_content_browser_client.h" |
20 #include "content/shell/shell_main_delegate.h" | 20 #include "content/shell/shell_main_delegate.h" |
21 #include "content/test/mock_keyboard.h" | 21 #include "content/test/mock_keyboard.h" |
22 #include "net/base/net_errors.h" | 22 #include "net/base/net_errors.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebData.h" |
| 25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebHTTPBody.
h" |
24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h" |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.
h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURLError.
h" |
| 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebHistoryItem.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.
h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntentServiceInfo.
h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" | 31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebWindowFeatures.h" |
29 #include "ui/base/keycodes/keyboard_codes.h" | 32 #include "ui/base/keycodes/keyboard_codes.h" |
30 #include "ui/base/range/range.h" | 33 #include "ui/base/range/range.h" |
31 #include "ui/gfx/codec/jpeg_codec.h" | 34 #include "ui/gfx/codec/jpeg_codec.h" |
| 35 #include "webkit/glue/glue_serialize.h" |
32 #include "webkit/glue/web_io_operators.h" | 36 #include "webkit/glue/web_io_operators.h" |
33 | 37 |
34 #if defined(OS_LINUX) && !defined(USE_AURA) | 38 #if defined(OS_LINUX) && !defined(USE_AURA) |
35 #include "ui/base/gtk/event_synthesis_gtk.h" | 39 #include "ui/base/gtk/event_synthesis_gtk.h" |
36 #endif | 40 #endif |
37 | 41 |
38 #if defined(USE_AURA) | 42 #if defined(USE_AURA) |
39 #include "ui/aura/event.h" | 43 #include "ui/aura/event.h" |
40 #endif | 44 #endif |
41 | 45 |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 render_thread_->sink().ClearMessages(); | 297 render_thread_->sink().ClearMessages(); |
294 | 298 |
295 // Change the value of the input. We should have gotten an update state | 299 // Change the value of the input. We should have gotten an update state |
296 // notification. We need to spin the message loop to catch this update. | 300 // notification. We need to spin the message loop to catch this update. |
297 ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';"); | 301 ExecuteJavaScript("document.getElementById('elt_text').value = 'foo';"); |
298 ProcessPendingMessages(); | 302 ProcessPendingMessages(); |
299 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( | 303 EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching( |
300 ViewHostMsg_UpdateState::ID)); | 304 ViewHostMsg_UpdateState::ID)); |
301 } | 305 } |
302 | 306 |
| 307 TEST_F(RenderViewImplTest, OnNavigationHttpPost) { |
| 308 ViewMsg_Navigate_Params nav_params; |
| 309 |
| 310 // An http url will trigger a resource load so cannot be used here. |
| 311 nav_params.url = GURL("data:text/html,<div>Page</div>"); |
| 312 nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL; |
| 313 nav_params.transition = content::PAGE_TRANSITION_TYPED; |
| 314 nav_params.page_id = -1; |
| 315 nav_params.is_post = true; |
| 316 |
| 317 // Set up post data. |
| 318 const unsigned char* raw_data = reinterpret_cast<const unsigned char*>( |
| 319 "post \0\ndata"); |
| 320 const int length = 11; |
| 321 const std::vector<unsigned char> post_data(raw_data, raw_data + length); |
| 322 nav_params.browser_initiated_post_data = post_data; |
| 323 |
| 324 view()->OnNavigate(nav_params); |
| 325 ProcessPendingMessages(); |
| 326 |
| 327 const IPC::Message* frame_navigate_msg = |
| 328 render_thread_->sink().GetUniqueMessageMatching( |
| 329 ViewHostMsg_FrameNavigate::ID); |
| 330 EXPECT_TRUE(frame_navigate_msg); |
| 331 |
| 332 ViewHostMsg_FrameNavigate::Param host_nav_params; |
| 333 ViewHostMsg_FrameNavigate::Read(frame_navigate_msg, &host_nav_params); |
| 334 EXPECT_TRUE(host_nav_params.a.is_post); |
| 335 |
| 336 // Check post data sent to browser matches |
| 337 EXPECT_FALSE(host_nav_params.a.content_state.empty()); |
| 338 const WebKit::WebHistoryItem item = webkit_glue::HistoryItemFromString( |
| 339 host_nav_params.a.content_state); |
| 340 WebKit::WebHTTPBody body = item.httpBody(); |
| 341 WebKit::WebHTTPBody::Element element; |
| 342 bool successful = body.elementAt(0, element); |
| 343 EXPECT_TRUE(successful); |
| 344 EXPECT_EQ(WebKit::WebHTTPBody::Element::TypeData, element.type); |
| 345 EXPECT_EQ(0, memcmp(raw_data, element.data.data(), length)); |
| 346 } |
| 347 |
303 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { | 348 TEST_F(RenderViewImplTest, DecideNavigationPolicy) { |
304 WebUITestClient client; | 349 WebUITestClient client; |
305 WebUITestBrowserClient browser_client; | 350 WebUITestBrowserClient browser_client; |
306 content::ContentClient* old_client = content::GetContentClient(); | 351 content::ContentClient* old_client = content::GetContentClient(); |
307 content::ContentBrowserClient* old_browser_client = | 352 content::ContentBrowserClient* old_browser_client = |
308 content::GetContentClient()->browser(); | 353 content::GetContentClient()->browser(); |
309 | 354 |
310 content::SetContentClient(&client); | 355 content::SetContentClient(&client); |
311 content::GetContentClient()->set_browser_for_testing(&browser_client); | 356 content::GetContentClient()->set_browser_for_testing(&browser_client); |
312 client.set_renderer_for_testing(old_client->renderer()); | 357 client.set_renderer_for_testing(old_client->renderer()); |
(...skipping 1332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1645 ASSERT_EQ(utf16_length, bounds.size()); | 1690 ASSERT_EQ(utf16_length, bounds.size()); |
1646 for (size_t i = 0; i < utf16_length; ++i) { | 1691 for (size_t i = 0; i < utf16_length; ++i) { |
1647 if (is_surrogate_pair_empty_rect[i]) { | 1692 if (is_surrogate_pair_empty_rect[i]) { |
1648 EXPECT_EQ(0, bounds[i].width()); | 1693 EXPECT_EQ(0, bounds[i].width()); |
1649 } else { | 1694 } else { |
1650 EXPECT_LT(0, bounds[i].width()); | 1695 EXPECT_LT(0, bounds[i].width()); |
1651 } | 1696 } |
1652 } | 1697 } |
1653 view()->OnImeConfirmComposition(empty_string, ui::Range::InvalidRange()); | 1698 view()->OnImeConfirmComposition(empty_string, ui::Range::InvalidRange()); |
1654 } | 1699 } |
OLD | NEW |