// found in the LICENSE file.
#include "base/basictypes.h"
-
+#include "base/bind.h"
+#include "base/callback.h"
#include "base/memory/shared_memory.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/windows_version.h"
+#include "content/child/request_extra_data.h"
+#include "content/child/service_worker/service_worker_network_provider.h"
+#include "content/common/frame_messages.h"
#include "content/common/ssl_status_serialization.h"
#include "content/common/view_messages.h"
+#include "content/public/browser/browser_context.h"
#include "content/public/browser/native_web_keyboard_event.h"
#include "content/public/browser/web_ui_controller_factory.h"
#include "content/public/common/bindings_policy.h"
#include "content/public/common/page_zoom.h"
#include "content/public/common/url_constants.h"
#include "content/public/common/url_utils.h"
+#include "content/public/renderer/content_renderer_client.h"
#include "content/public/renderer/document_state.h"
-#include "content/public/renderer/history_item_serialization.h"
#include "content/public/renderer/navigation_state.h"
+#include "content/public/test/browser_test_utils.h"
#include "content/public/test/render_view_test.h"
+#include "content/public/test/test_utils.h"
+#include "content/renderer/accessibility/renderer_accessibility.h"
+#include "content/renderer/accessibility/renderer_accessibility_complete.h"
+#include "content/renderer/accessibility/renderer_accessibility_focus_only.h"
+#include "content/renderer/history_controller.h"
+#include "content/renderer/history_serialization.h"
#include "content/renderer/render_view_impl.h"
-#include "content/shell/browser/shell_content_browser_client.h"
-#include "content/shell/common/shell_content_client.h"
+#include "content/shell/browser/shell.h"
+#include "content/shell/browser/shell_browser_context.h"
+#include "content/test/frame_load_waiter.h"
#include "content/test/mock_keyboard.h"
#include "net/base/net_errors.h"
#include "net/cert/cert_status_flags.h"
#include "third_party/WebKit/public/platform/WebData.h"
#include "third_party/WebKit/public/platform/WebHTTPBody.h"
#include "third_party/WebKit/public/platform/WebString.h"
-#include "third_party/WebKit/public/platform/WebURLError.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h"
#include "third_party/WebKit/public/web/WebDataSource.h"
-#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebHistoryItem.h"
+#include "third_party/WebKit/public/web/WebLocalFrame.h"
#include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "third_party/WebKit/public/web/WebWindowFeatures.h"
#include "ui/gfx/codec/jpeg_codec.h"
#include "ui/gfx/range/range.h"
-#if defined(OS_LINUX) && !defined(USE_AURA)
-#include "ui/base/gtk/event_synthesis_gtk.h"
-#endif
-
#if defined(USE_AURA)
#include "ui/events/event.h"
#endif
#include <X11/Xlib.h>
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_code_conversion.h"
-#include "ui/events/x/events_x_utils.h"
+#include "ui/events/test/events_test_utils_x11.h"
+#endif
+
+#if defined(USE_OZONE)
+#include "ui/events/keycodes/keyboard_code_conversion.h"
#endif
-using WebKit::WebFrame;
-using WebKit::WebInputEvent;
-using WebKit::WebMouseEvent;
-using WebKit::WebRuntimeFeatures;
-using WebKit::WebString;
-using WebKit::WebTextDirection;
-using WebKit::WebURLError;
+using blink::WebFrame;
+using blink::WebInputEvent;
+using blink::WebLocalFrame;
+using blink::WebMouseEvent;
+using blink::WebRuntimeFeatures;
+using blink::WebString;
+using blink::WebTextDirection;
+using blink::WebURLError;
-namespace content {
+namespace content {
namespace {
-#if defined(USE_AURA) && defined(USE_X11)
+#if (defined(USE_AURA) && defined(USE_X11)) || defined(USE_OZONE)
// Converts MockKeyboard::Modifiers to ui::EventFlags.
int ConvertMockKeyboardModifier(MockKeyboard::Modifiers modifiers) {
static struct ModifierMap {
}
};
-} // namespace
-
class RenderViewImplTest : public RenderViewTest {
public:
RenderViewImplTest() {
virtual void SetUp() OVERRIDE {
RenderViewTest::SetUp();
- // This test depends on Blink flag InputModeAttribute, which is enabled
- // under only test. Content browser test doesn't enable the feature so we
- // need enable it manually.
- // TODO(yoichio): Remove this if InputMode feature is enabled by default.
- WebRuntimeFeatures::enableInputModeAttribute(true);
+ // Enable Blink's experimental and test only features so that test code
+ // does not have to bother enabling each feature.
+ WebRuntimeFeatures::enableExperimentalFeatures(true);
+ WebRuntimeFeatures::enableTestOnlyFeatures(true);
}
RenderViewImpl* view() {
return static_cast<RenderViewImpl*>(view_);
}
+ RenderFrameImpl* frame() {
+ return static_cast<RenderFrameImpl*>(view()->GetMainRenderFrame());
+ }
+
// Sends IPC messages that emulates a key-press event.
int SendKeyEvent(MockKeyboard::Layout layout,
int key_code,
MockKeyboard::Modifiers modifiers,
- string16* output) {
+ base::string16* output) {
#if defined(OS_WIN)
// Retrieve the Unicode character for the given tuple (keyboard-layout,
// key-code, and modifiers).
CHECK(output);
const int flags = ConvertMockKeyboardModifier(modifiers);
- XEvent xevent1;
- InitXKeyEventForTesting(ui::ET_KEY_PRESSED,
- static_cast<ui::KeyboardCode>(key_code),
- flags,
- &xevent1);
- ui::KeyEvent event1(&xevent1, false);
+ ui::ScopedXI2Event xevent;
+ xevent.InitKeyEvent(ui::ET_KEY_PRESSED,
+ static_cast<ui::KeyboardCode>(key_code),
+ flags);
+ ui::KeyEvent event1(xevent, false);
NativeWebKeyboardEvent keydown_event(&event1);
SendNativeKeyEvent(keydown_event);
- XEvent xevent2;
- InitXKeyEventForTesting(ui::ET_KEY_PRESSED,
- static_cast<ui::KeyboardCode>(key_code),
- flags,
- &xevent2);
- ui::KeyEvent event2(&xevent2, true);
+ xevent.InitKeyEvent(ui::ET_KEY_PRESSED,
+ static_cast<ui::KeyboardCode>(key_code),
+ flags);
+ ui::KeyEvent event2(xevent, true);
NativeWebKeyboardEvent char_event(&event2);
SendNativeKeyEvent(char_event);
- XEvent xevent3;
- InitXKeyEventForTesting(ui::ET_KEY_RELEASED,
- static_cast<ui::KeyboardCode>(key_code),
- flags,
- &xevent3);
- ui::KeyEvent event3(&xevent3, false);
+ xevent.InitKeyEvent(ui::ET_KEY_RELEASED,
+ static_cast<ui::KeyboardCode>(key_code),
+ flags);
+ ui::KeyEvent event3(xevent, false);
NativeWebKeyboardEvent keyup_event(&event3);
SendNativeKeyEvent(keyup_event);
long c = GetCharacterFromKeyCode(static_cast<ui::KeyboardCode>(key_code),
flags);
- output->assign(1, static_cast<char16>(c));
+ output->assign(1, static_cast<base::char16>(c));
return 1;
-#elif defined(TOOLKIT_GTK)
- // We ignore |layout|, which means we are only testing the layout of the
- // current locale. TODO(estade): fix this to respect |layout|.
- std::vector<GdkEvent*> events;
- ui::SynthesizeKeyPressEvents(
- NULL, static_cast<ui::KeyboardCode>(key_code),
- modifiers & (MockKeyboard::LEFT_CONTROL | MockKeyboard::RIGHT_CONTROL),
- modifiers & (MockKeyboard::LEFT_SHIFT | MockKeyboard::RIGHT_SHIFT),
- modifiers & (MockKeyboard::LEFT_ALT | MockKeyboard::RIGHT_ALT),
- &events);
-
- guint32 unicode_key = 0;
- for (size_t i = 0; i < events.size(); ++i) {
- // Only send the up/down events for key press itself (skip the up/down
- // events for the modifier keys).
- if ((i + 1) == (events.size() / 2) || i == (events.size() / 2)) {
- unicode_key = gdk_keyval_to_unicode(events[i]->key.keyval);
- NativeWebKeyboardEvent webkit_event(events[i]);
- SendNativeKeyEvent(webkit_event);
-
- // Need to add a char event after the key down.
- if (webkit_event.type == WebKit::WebInputEvent::RawKeyDown) {
- NativeWebKeyboardEvent char_event = webkit_event;
- char_event.type = WebKit::WebInputEvent::Char;
- char_event.skip_in_browser = true;
- SendNativeKeyEvent(char_event);
- }
- }
- gdk_event_free(events[i]);
- }
+#elif defined(USE_OZONE)
+ const int flags = ConvertMockKeyboardModifier(modifiers);
- output->assign(1, static_cast<char16>(unicode_key));
+ // Ozone's native events are ui::Events. So first create the "native" event,
+ // then create the actual ui::KeyEvent with the native event.
+ ui::KeyEvent keydown_native_event(ui::ET_KEY_PRESSED,
+ static_cast<ui::KeyboardCode>(key_code),
+ flags,
+ true);
+ ui::KeyEvent keydown_event(&keydown_native_event, false);
+ NativeWebKeyboardEvent keydown_web_event(&keydown_event);
+ SendNativeKeyEvent(keydown_web_event);
+
+ ui::KeyEvent char_native_event(ui::ET_KEY_PRESSED,
+ static_cast<ui::KeyboardCode>(key_code),
+ flags,
+ true);
+ ui::KeyEvent char_event(&char_native_event, true);
+ NativeWebKeyboardEvent char_web_event(&char_event);
+ SendNativeKeyEvent(char_web_event);
+
+ ui::KeyEvent keyup_native_event(ui::ET_KEY_RELEASED,
+ static_cast<ui::KeyboardCode>(key_code),
+ flags,
+ true);
+ ui::KeyEvent keyup_event(&keyup_native_event, false);
+ NativeWebKeyboardEvent keyup_web_event(&keyup_event);
+ SendNativeKeyEvent(keyup_web_event);
+
+ long c = GetCharacterFromKeyCode(static_cast<ui::KeyboardCode>(key_code),
+ flags);
+ output->assign(1, static_cast<base::char16>(c));
return 1;
#else
NOTIMPLEMENTED();
scoped_ptr<MockKeyboard> mock_keyboard_;
};
+} // namespace
+
// Test that we get form state change notifications when input fields change.
TEST_F(RenderViewImplTest, DISABLED_OnNavStateChanged) {
// Don't want any delay for form state sync changes. This will still post a
}
TEST_F(RenderViewImplTest, OnNavigationHttpPost) {
- ViewMsg_Navigate_Params nav_params;
+ FrameMsg_Navigate_Params nav_params;
// An http url will trigger a resource load so cannot be used here.
nav_params.url = GURL("data:text/html,<div>Page</div>");
- nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ nav_params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
nav_params.transition = PAGE_TRANSITION_TYPED;
nav_params.page_id = -1;
nav_params.is_post = true;
const std::vector<unsigned char> post_data(raw_data, raw_data + length);
nav_params.browser_initiated_post_data = post_data;
- view()->OnNavigate(nav_params);
+ frame()->OnNavigate(nav_params);
ProcessPendingMessages();
const IPC::Message* frame_navigate_msg =
render_thread_->sink().GetUniqueMessageMatching(
- ViewHostMsg_FrameNavigate::ID);
+ FrameHostMsg_DidCommitProvisionalLoad::ID);
EXPECT_TRUE(frame_navigate_msg);
- ViewHostMsg_FrameNavigate::Param host_nav_params;
- ViewHostMsg_FrameNavigate::Read(frame_navigate_msg, &host_nav_params);
+ FrameHostMsg_DidCommitProvisionalLoad::Param host_nav_params;
+ FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg,
+ &host_nav_params);
EXPECT_TRUE(host_nav_params.a.is_post);
// Check post data sent to browser matches
EXPECT_TRUE(host_nav_params.a.page_state.IsValid());
- const WebKit::WebHistoryItem item = PageStateToHistoryItem(
- host_nav_params.a.page_state);
- WebKit::WebHTTPBody body = item.httpBody();
- WebKit::WebHTTPBody::Element element;
+ scoped_ptr<HistoryEntry> entry =
+ PageStateToHistoryEntry(host_nav_params.a.page_state);
+ blink::WebHTTPBody body = entry->root().httpBody();
+ blink::WebHTTPBody::Element element;
bool successful = body.elementAt(0, element);
EXPECT_TRUE(successful);
- EXPECT_EQ(WebKit::WebHTTPBody::Element::TypeData, element.type);
+ EXPECT_EQ(blink::WebHTTPBody::Element::TypeData, element.type);
EXPECT_EQ(length, element.data.size());
EXPECT_EQ(0, memcmp(raw_data, element.data.data(), length));
}
state.set_navigation_state(NavigationState::CreateContentInitiated());
// Navigations to normal HTTP URLs can be handled locally.
- WebKit::WebURLRequest request(GURL("http://foo.com"));
- WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation(
- GetMainFrame(),
- &state,
- request,
- WebKit::WebNavigationTypeLinkClicked,
- WebKit::WebNavigationPolicyCurrentTab,
- false);
- EXPECT_EQ(WebKit::WebNavigationPolicyCurrentTab, policy);
+ blink::WebURLRequest request(GURL("http://foo.com"));
+ blink::WebNavigationPolicy policy = frame()->decidePolicyForNavigation(
+ GetMainFrame(),
+ &state,
+ request,
+ blink::WebNavigationTypeLinkClicked,
+ blink::WebNavigationPolicyCurrentTab,
+ false);
+ EXPECT_EQ(blink::WebNavigationPolicyCurrentTab, policy);
// Verify that form posts to WebUI URLs will be sent to the browser process.
- WebKit::WebURLRequest form_request(GURL("chrome://foo"));
+ blink::WebURLRequest form_request(GURL("chrome://foo"));
form_request.setHTTPMethod("POST");
- policy = view()->decidePolicyForNavigation(
+ policy = frame()->decidePolicyForNavigation(
GetMainFrame(),
&state,
form_request,
- WebKit::WebNavigationTypeFormSubmitted,
- WebKit::WebNavigationPolicyCurrentTab,
+ blink::WebNavigationTypeFormSubmitted,
+ blink::WebNavigationPolicyCurrentTab,
false);
- EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy);
+ EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy);
// Verify that popup links to WebUI URLs also are sent to browser.
- WebKit::WebURLRequest popup_request(GURL("chrome://foo"));
- policy = view()->decidePolicyForNavigation(
+ blink::WebURLRequest popup_request(GURL("chrome://foo"));
+ policy = frame()->decidePolicyForNavigation(
GetMainFrame(),
&state,
popup_request,
- WebKit::WebNavigationTypeLinkClicked,
- WebKit::WebNavigationPolicyNewForegroundTab,
+ blink::WebNavigationTypeLinkClicked,
+ blink::WebNavigationPolicyNewForegroundTab,
false);
- EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy);
+ EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy);
+}
+
+TEST_F(RenderViewImplTest, DecideNavigationPolicyHandlesAllTopLevel) {
+ DocumentState state;
+ state.set_navigation_state(NavigationState::CreateContentInitiated());
+
+ RendererPreferences prefs = view()->renderer_preferences();
+ prefs.browser_handles_all_top_level_requests = true;
+ view()->OnSetRendererPrefs(prefs);
+
+ const blink::WebNavigationType kNavTypes[] = {
+ blink::WebNavigationTypeLinkClicked,
+ blink::WebNavigationTypeFormSubmitted,
+ blink::WebNavigationTypeBackForward,
+ blink::WebNavigationTypeReload,
+ blink::WebNavigationTypeFormResubmitted,
+ blink::WebNavigationTypeOther,
+ };
+
+ blink::WebURLRequest request(GURL("http://foo.com"));
+ for (size_t i = 0; i < arraysize(kNavTypes); ++i) {
+ blink::WebNavigationPolicy policy = frame()->decidePolicyForNavigation(
+ GetMainFrame(),
+ &state,
+ request,
+ kNavTypes[i],
+ blink::WebNavigationPolicyCurrentTab,
+ false);
+ EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy);
+ }
}
TEST_F(RenderViewImplTest, DecideNavigationPolicyForWebUI) {
state.set_navigation_state(NavigationState::CreateContentInitiated());
// Navigations to normal HTTP URLs will be sent to browser process.
- WebKit::WebURLRequest request(GURL("http://foo.com"));
- WebKit::WebNavigationPolicy policy = view()->decidePolicyForNavigation(
+ blink::WebURLRequest request(GURL("http://foo.com"));
+ blink::WebNavigationPolicy policy = frame()->decidePolicyForNavigation(
GetMainFrame(),
&state,
request,
- WebKit::WebNavigationTypeLinkClicked,
- WebKit::WebNavigationPolicyCurrentTab,
+ blink::WebNavigationTypeLinkClicked,
+ blink::WebNavigationPolicyCurrentTab,
false);
- EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy);
+ EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy);
// Navigations to WebUI URLs will also be sent to browser process.
- WebKit::WebURLRequest webui_request(GURL("chrome://foo"));
- policy = view()->decidePolicyForNavigation(
+ blink::WebURLRequest webui_request(GURL("chrome://foo"));
+ policy = frame()->decidePolicyForNavigation(
GetMainFrame(),
&state,
webui_request,
- WebKit::WebNavigationTypeLinkClicked,
- WebKit::WebNavigationPolicyCurrentTab,
+ blink::WebNavigationTypeLinkClicked,
+ blink::WebNavigationPolicyCurrentTab,
false);
- EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy);
+ EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy);
// Verify that form posts to data URLs will be sent to the browser process.
- WebKit::WebURLRequest data_request(GURL("data:text/html,foo"));
+ blink::WebURLRequest data_request(GURL("data:text/html,foo"));
data_request.setHTTPMethod("POST");
- policy = view()->decidePolicyForNavigation(
+ policy = frame()->decidePolicyForNavigation(
GetMainFrame(),
&state,
data_request,
- WebKit::WebNavigationTypeFormSubmitted,
- WebKit::WebNavigationPolicyCurrentTab,
+ blink::WebNavigationTypeFormSubmitted,
+ blink::WebNavigationPolicyCurrentTab,
false);
- EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy);
+ EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy);
// Verify that a popup that creates a view first and then navigates to a
// normal HTTP URL will be sent to the browser process, even though the
// new view does not have any enabled_bindings_.
- WebKit::WebURLRequest popup_request(GURL("http://foo.com"));
- WebKit::WebView* new_web_view = view()->createView(
- GetMainFrame(), popup_request, WebKit::WebWindowFeatures(), "foo",
- WebKit::WebNavigationPolicyNewForegroundTab);
+ blink::WebURLRequest popup_request(GURL("http://foo.com"));
+ blink::WebView* new_web_view = view()->createView(
+ GetMainFrame(), popup_request, blink::WebWindowFeatures(), "foo",
+ blink::WebNavigationPolicyNewForegroundTab, false);
RenderViewImpl* new_view = RenderViewImpl::FromWebView(new_web_view);
- policy = new_view->decidePolicyForNavigation(
- new_web_view->mainFrame(),
- &state,
- popup_request,
- WebKit::WebNavigationTypeLinkClicked,
- WebKit::WebNavigationPolicyNewForegroundTab,
- false);
- EXPECT_EQ(WebKit::WebNavigationPolicyIgnore, policy);
+ policy = static_cast<RenderFrameImpl*>(new_view->GetMainRenderFrame())->
+ decidePolicyForNavigation(
+ new_web_view->mainFrame()->toWebLocalFrame(),
+ &state,
+ popup_request,
+ blink::WebNavigationTypeLinkClicked,
+ blink::WebNavigationPolicyNewForegroundTab,
+ false);
+ EXPECT_EQ(blink::WebNavigationPolicyIgnore, policy);
// Clean up after the new view so we don't leak it.
new_view->Close();
int initial_page_id = view()->GetPageId();
// Respond to a swap out request.
- view()->OnSwapOut();
+ view()->main_render_frame()->OnSwapOut();
// Ensure the swap out commits synchronously.
EXPECT_NE(initial_page_id, view()->GetPageId());
// Check for a valid OnSwapOutACK.
const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching(
- ViewHostMsg_SwapOut_ACK::ID);
+ FrameHostMsg_SwapOut_ACK::ID);
ASSERT_TRUE(msg);
// It is possible to get another swap out request. Ensure that we send
// an ACK, even if we don't have to do anything else.
render_thread_->sink().ClearMessages();
- view()->OnSwapOut();
+ view()->main_render_frame()->OnSwapOut();
const IPC::Message* msg2 = render_thread_->sink().GetUniqueMessageMatching(
- ViewHostMsg_SwapOut_ACK::ID);
+ FrameHostMsg_SwapOut_ACK::ID);
ASSERT_TRUE(msg2);
// If we navigate back to this RenderView, ensure we don't send a state
// update for the swapped out URL. (http://crbug.com/72235)
- ViewMsg_Navigate_Params nav_params;
+ FrameMsg_Navigate_Params nav_params;
nav_params.url = GURL("data:text/html,<div>Page B</div>");
- nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ nav_params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
nav_params.transition = PAGE_TRANSITION_TYPED;
nav_params.current_history_list_length = 1;
nav_params.current_history_list_offset = 0;
nav_params.pending_history_list_offset = 1;
nav_params.page_id = -1;
- view()->OnNavigate(nav_params);
+ frame()->OnNavigate(nav_params);
ProcessPendingMessages();
const IPC::Message* msg3 = render_thread_->sink().GetUniqueMessageMatching(
ViewHostMsg_UpdateState::ID);
render_thread_->sink().ClearMessages();
// Back to page A (page_id 1) and commit.
- ViewMsg_Navigate_Params params_A;
- params_A.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ FrameMsg_Navigate_Params params_A;
+ params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL;
params_A.transition = PAGE_TRANSITION_FORWARD_BACK;
params_A.current_history_list_length = 2;
params_A.current_history_list_offset = 1;
params_A.pending_history_list_offset = 0;
params_A.page_id = 1;
params_A.page_state = state_A;
- view()->OnNavigate(params_A);
+ frame()->OnNavigate(params_A);
ProcessPendingMessages();
// Respond to a swap out request.
- view()->OnSwapOut();
+ view()->main_render_frame()->OnSwapOut();
// Check for a OnSwapOutACK.
const IPC::Message* msg = render_thread_->sink().GetUniqueMessageMatching(
- ViewHostMsg_SwapOut_ACK::ID);
+ FrameHostMsg_SwapOut_ACK::ID);
ASSERT_TRUE(msg);
render_thread_->sink().ClearMessages();
// params.page_state of the initial page (e.g., if the new page fails the
// provisional load in the renderer process, after we unload the old page).
// Ensure the old page gets reloaded, not swappedout://.
- ViewMsg_Navigate_Params nav_params;
+ FrameMsg_Navigate_Params nav_params;
nav_params.url = GURL("data:text/html,<div>Page A</div>");
- nav_params.navigation_type = ViewMsg_Navigate_Type::RELOAD;
+ nav_params.navigation_type = FrameMsg_Navigate_Type::RELOAD;
nav_params.transition = PAGE_TRANSITION_RELOAD;
nav_params.current_history_list_length = 2;
nav_params.current_history_list_offset = 0;
nav_params.pending_history_list_offset = 0;
nav_params.page_id = 1;
nav_params.page_state = state_A;
- view()->OnNavigate(nav_params);
+ frame()->OnNavigate(nav_params);
ProcessPendingMessages();
// Verify page A committed, not swappedout://.
const IPC::Message* frame_navigate_msg =
render_thread_->sink().GetUniqueMessageMatching(
- ViewHostMsg_FrameNavigate::ID);
+ FrameHostMsg_DidCommitProvisionalLoad::ID);
EXPECT_TRUE(frame_navigate_msg);
// Read URL out of the parent trait of the params object.
- ViewHostMsg_FrameNavigate::Param commit_params;
- ViewHostMsg_FrameNavigate::Read(frame_navigate_msg, &commit_params);
+ FrameHostMsg_DidCommitProvisionalLoad::Param commit_params;
+ FrameHostMsg_DidCommitProvisionalLoad::Read(frame_navigate_msg,
+ &commit_params);
EXPECT_NE(GURL("swappedout://"), commit_params.a.url);
}
render_thread_->sink().ClearMessages();
// Go back to C and commit, preparing for our real test.
- ViewMsg_Navigate_Params params_C;
- params_C.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ FrameMsg_Navigate_Params params_C;
+ params_C.navigation_type = FrameMsg_Navigate_Type::NORMAL;
params_C.transition = PAGE_TRANSITION_FORWARD_BACK;
params_C.current_history_list_length = 4;
params_C.current_history_list_offset = 3;
params_C.pending_history_list_offset = 2;
params_C.page_id = 3;
params_C.page_state = state_C;
- view()->OnNavigate(params_C);
+ frame()->OnNavigate(params_C);
ProcessPendingMessages();
render_thread_->sink().ClearMessages();
// the RenderView's page ID.
// Back to page B (page_id 2), without committing.
- ViewMsg_Navigate_Params params_B;
- params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ FrameMsg_Navigate_Params params_B;
+ params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL;
params_B.transition = PAGE_TRANSITION_FORWARD_BACK;
params_B.current_history_list_length = 4;
params_B.current_history_list_offset = 2;
params_B.pending_history_list_offset = 1;
params_B.page_id = 2;
params_B.page_state = state_B;
- view()->OnNavigate(params_B);
+ frame()->OnNavigate(params_B);
// Back to page A (page_id 1) and commit.
- ViewMsg_Navigate_Params params;
- params.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ FrameMsg_Navigate_Params params;
+ params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
params.transition = PAGE_TRANSITION_FORWARD_BACK;
params_B.current_history_list_length = 4;
params_B.current_history_list_offset = 2;
params_B.pending_history_list_offset = 0;
params.page_id = 1;
params.page_state = state_A;
- view()->OnNavigate(params);
+ frame()->OnNavigate(params);
ProcessPendingMessages();
// Now ensure that the UpdateState message we receive is consistent
render_thread_->sink().ClearMessages();
// Back to page A (page_id 1) and commit.
- ViewMsg_Navigate_Params params_A;
- params_A.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ FrameMsg_Navigate_Params params_A;
+ params_A.navigation_type = FrameMsg_Navigate_Type::NORMAL;
params_A.transition = PAGE_TRANSITION_FORWARD_BACK;
params_A.current_history_list_length = 2;
params_A.current_history_list_offset = 1;
params_A.pending_history_list_offset = 0;
params_A.page_id = 1;
params_A.page_state = state_A;
- view()->OnNavigate(params_A);
+ frame()->OnNavigate(params_A);
ProcessPendingMessages();
// A new navigation commits, clearing the forward history.
EXPECT_EQ(3, view()->history_page_ids_[1]);
// The browser then sends a stale navigation to B, which should be ignored.
- ViewMsg_Navigate_Params params_B;
- params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ FrameMsg_Navigate_Params params_B;
+ params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL;
params_B.transition = PAGE_TRANSITION_FORWARD_BACK;
params_B.current_history_list_length = 2;
params_B.current_history_list_offset = 0;
params_B.pending_history_list_offset = 1;
params_B.page_id = 2;
params_B.page_state = state_A; // Doesn't matter, just has to be present.
- view()->OnNavigate(params_B);
+ frame()->OnNavigate(params_B);
// State should be unchanged.
EXPECT_EQ(2, view()->history_list_length_);
// Suppose the browser has limited the number of NavigationEntries to 2.
// It has now dropped the first entry, but the renderer isn't notified.
// Ensure that going back to page B (page_id 2) at offset 0 is successful.
- ViewMsg_Navigate_Params params_B;
- params_B.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ FrameMsg_Navigate_Params params_B;
+ params_B.navigation_type = FrameMsg_Navigate_Type::NORMAL;
params_B.transition = PAGE_TRANSITION_FORWARD_BACK;
params_B.current_history_list_length = 2;
params_B.current_history_list_offset = 1;
params_B.pending_history_list_offset = 0;
params_B.page_id = 2;
params_B.page_state = state_B;
- view()->OnNavigate(params_B);
+ frame()->OnNavigate(params_B);
ProcessPendingMessages();
EXPECT_EQ(2, view()->history_list_length_);
test_case->input_id);
// Move the input focus to the target <input> element, where we should
// activate IMEs.
- ExecuteJavaScriptAndReturnIntValue(ASCIIToUTF16(javascript), NULL);
+ ExecuteJavaScriptAndReturnIntValue(base::ASCIIToUTF16(javascript), NULL);
ProcessPendingMessages();
render_thread_->sink().ClearMessages();
case IME_SETCOMPOSITION:
view()->OnImeSetComposition(
- WideToUTF16Hack(ime_message->ime_string),
- std::vector<WebKit::WebCompositionUnderline>(),
+ base::WideToUTF16(ime_message->ime_string),
+ std::vector<blink::WebCompositionUnderline>(),
ime_message->selection_start,
ime_message->selection_end);
break;
case IME_CONFIRMCOMPOSITION:
view()->OnImeConfirmComposition(
- WideToUTF16Hack(ime_message->ime_string),
+ base::WideToUTF16(ime_message->ime_string),
gfx::Range::InvalidRange(),
false);
break;
case IME_CANCELCOMPOSITION:
view()->OnImeSetComposition(
- string16(),
- std::vector<WebKit::WebCompositionUnderline>(),
+ base::string16(),
+ std::vector<blink::WebCompositionUnderline>(),
0, 0);
break;
}
// Retrieve the content of this page and compare it with the expected
// result.
const int kMaxOutputCharacters = 128;
- std::wstring output = UTF16ToWideHack(
- GetMainFrame()->contentAsText(kMaxOutputCharacters));
- EXPECT_EQ(output, ime_message->result);
+ base::string16 output =
+ GetMainFrame()->contentAsText(kMaxOutputCharacters);
+ EXPECT_EQ(base::WideToUTF16(ime_message->result), output);
}
}
}
WebTextDirection direction;
const wchar_t* expected_result;
} kTextDirection[] = {
- { WebKit::WebTextDirectionRightToLeft, L"\x000A" L"rtl,rtl" },
- { WebKit::WebTextDirectionLeftToRight, L"\x000A" L"ltr,ltr" },
+ { blink::WebTextDirectionRightToLeft, L"\x000A" L"rtl,rtl" },
+ { blink::WebTextDirectionLeftToRight, L"\x000A" L"ltr,ltr" },
};
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTextDirection); ++i) {
// Set the text direction of the <textarea> element.
// Copy the document content to std::wstring and compare with the
// expected result.
const int kMaxOutputCharacters = 16;
- std::wstring output = UTF16ToWideHack(
- GetMainFrame()->contentAsText(kMaxOutputCharacters));
- EXPECT_EQ(output, kTextDirection[i].expected_result);
+ base::string16 output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
+ EXPECT_EQ(base::WideToUTF16(kTextDirection[i].expected_result), output);
}
}
// driver is installed in a PC and the driver can assign a Unicode
// charcter for the given tuple (key-code and modifiers).
int key_code = kKeyCodes[k];
- string16 char_code;
+ base::string16 char_code;
if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0)
continue;
// text created from a virtual-key code, a character code, and the
// modifier-key status.
const int kMaxOutputCharacters = 1024;
- std::string output = UTF16ToUTF8(
+ std::string output = base::UTF16ToUTF8(
GetMainFrame()->contentAsText(kMaxOutputCharacters));
EXPECT_EQ(expected_result, output);
}
// driver is installed in a PC and the driver can assign a Unicode
// charcter for the given tuple (layout, key-code, and modifiers).
int key_code = kKeyCodes[k];
- string16 char_code;
+ base::string16 char_code;
if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0)
continue;
}
// text created from a virtual-key code, a character code, and the
// modifier-key status.
const int kMaxOutputCharacters = 4096;
- std::wstring output = UTF16ToWideHack(
- GetMainFrame()->contentAsText(kMaxOutputCharacters));
- EXPECT_EQ(kLayouts[i].expected_result, output);
+ base::string16 output = GetMainFrame()->contentAsText(kMaxOutputCharacters);
+ EXPECT_EQ(base::WideToUTF16(kLayouts[i].expected_result), output);
}
#else
NOTIMPLEMENTED();
error.domain = WebString::fromUTF8(net::kErrorDomain);
error.reason = net::ERR_FILE_NOT_FOUND;
error.unreachableURL = GURL("http://foo");
- WebFrame* web_frame = GetMainFrame();
+ WebLocalFrame* web_frame = GetMainFrame();
// Start a load that will reach provisional state synchronously,
// but won't complete synchronously.
- ViewMsg_Navigate_Params params;
+ FrameMsg_Navigate_Params params;
params.page_id = -1;
- params.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
params.url = GURL("data:text/html,test data");
- view()->OnNavigate(params);
+ frame()->OnNavigate(params);
// An error occurred.
- view()->didFailProvisionalLoad(web_frame, error);
+ view()->main_render_frame()->didFailProvisionalLoad(web_frame, error);
// Frame should exit view-source mode.
EXPECT_FALSE(web_frame->isViewSourceModeEnabled());
}
error.domain = WebString::fromUTF8(net::kErrorDomain);
error.reason = net::ERR_ABORTED;
error.unreachableURL = GURL("http://foo");
- WebFrame* web_frame = GetMainFrame();
+ WebLocalFrame* web_frame = GetMainFrame();
// Start a load that will reach provisional state synchronously,
// but won't complete synchronously.
- ViewMsg_Navigate_Params params;
+ FrameMsg_Navigate_Params params;
params.page_id = -1;
- params.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
params.url = GURL("data:text/html,test data");
- view()->OnNavigate(params);
+ frame()->OnNavigate(params);
// A cancellation occurred.
- view()->didFailProvisionalLoad(web_frame, error);
+ view()->main_render_frame()->didFailProvisionalLoad(web_frame, error);
// Frame should stay in view-source mode.
EXPECT_TRUE(web_frame->isViewSourceModeEnabled());
}
// Regression test for http://crbug.com/41562
TEST_F(RenderViewImplTest, UpdateTargetURLWithInvalidURL) {
const GURL invalid_gurl("http://");
- view()->setMouseOverURL(WebKit::WebURL(invalid_gurl));
+ view()->setMouseOverURL(blink::WebURL(invalid_gurl));
EXPECT_EQ(invalid_gurl, view()->target_url_);
}
EXPECT_EQ(-1, view()->history_page_ids_[1]);
ClearHistory();
+ blink::WebHistoryItem item;
+ item.initialize();
+
// No history to merge and a committed page to be kept.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
view()->OnSetHistoryLengthAndPrune(0, expected_page_id);
EXPECT_EQ(1, view()->history_list_length_);
ClearHistory();
// No history to merge and a committed page to be pruned.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
view()->OnSetHistoryLengthAndPrune(0, expected_page_id + 1);
EXPECT_EQ(0, view()->history_list_length_);
ClearHistory();
// No history to merge and a committed page that the browser was unaware of.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
view()->OnSetHistoryLengthAndPrune(0, -1);
EXPECT_EQ(1, view()->history_list_length_);
ClearHistory();
// History to merge and a committed page to be kept.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
view()->OnSetHistoryLengthAndPrune(2, expected_page_id);
EXPECT_EQ(3, view()->history_list_length_);
ClearHistory();
// History to merge and a committed page to be pruned.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
view()->OnSetHistoryLengthAndPrune(2, expected_page_id + 1);
EXPECT_EQ(2, view()->history_list_length_);
ClearHistory();
// History to merge and a committed page that the browser was unaware of.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
view()->OnSetHistoryLengthAndPrune(2, -1);
EXPECT_EQ(3, view()->history_list_length_);
int expected_page_id_2 = -1;
// No history to merge and two committed pages, both to be kept.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id_2 = view()->page_id_;
EXPECT_GT(expected_page_id_2, expected_page_id);
view()->OnSetHistoryLengthAndPrune(0, expected_page_id);
ClearHistory();
// No history to merge and two committed pages, and only the second is kept.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id_2 = view()->page_id_;
EXPECT_GT(expected_page_id_2, expected_page_id);
view()->OnSetHistoryLengthAndPrune(0, expected_page_id_2);
// No history to merge and two committed pages, both of which the browser was
// unaware of.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id_2 = view()->page_id_;
EXPECT_GT(expected_page_id_2, expected_page_id);
view()->OnSetHistoryLengthAndPrune(0, -1);
ClearHistory();
// History to merge and two committed pages, both to be kept.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id_2 = view()->page_id_;
EXPECT_GT(expected_page_id_2, expected_page_id);
view()->OnSetHistoryLengthAndPrune(2, expected_page_id);
ClearHistory();
// History to merge and two committed pages, and only the second is kept.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id_2 = view()->page_id_;
EXPECT_GT(expected_page_id_2, expected_page_id);
view()->OnSetHistoryLengthAndPrune(2, expected_page_id_2);
// History to merge and two committed pages, both of which the browser was
// unaware of.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(),
+ item,
+ blink::WebStandardCommit);
expected_page_id_2 = view()->page_id_;
EXPECT_GT(expected_page_id_2, expected_page_id);
view()->OnSetHistoryLengthAndPrune(2, -1);
SendWebMouseEvent(mouse_event);
EXPECT_TRUE(render_thread_->sink().GetUniqueMessageMatching(
- ViewHostMsg_ContextMenu::ID));
+ FrameHostMsg_ContextMenu::ID));
}
TEST_F(RenderViewImplTest, TestBackForward) {
LoadHTML("<div id=pagename>Page A</div>");
- WebKit::WebHistoryItem page_a_item = GetMainFrame()->currentHistoryItem();
+ PageState page_a_state =
+ HistoryEntryToPageState(view()->history_controller()->GetCurrentEntry());
int was_page_a = -1;
- string16 check_page_a =
- ASCIIToUTF16(
+ base::string16 check_page_a =
+ base::ASCIIToUTF16(
"Number(document.getElementById('pagename').innerHTML == 'Page A')");
EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_a, &was_page_a));
EXPECT_EQ(1, was_page_a);
LoadHTML("<div id=pagename>Page B</div>");
int was_page_b = -1;
- string16 check_page_b =
- ASCIIToUTF16(
+ base::string16 check_page_b =
+ base::ASCIIToUTF16(
"Number(document.getElementById('pagename').innerHTML == 'Page B')");
EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b));
EXPECT_EQ(1, was_page_b);
LoadHTML("<div id=pagename>Page C</div>");
int was_page_c = -1;
- string16 check_page_c =
- ASCIIToUTF16(
+ base::string16 check_page_c =
+ base::ASCIIToUTF16(
"Number(document.getElementById('pagename').innerHTML == 'Page C')");
EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c));
EXPECT_EQ(1, was_page_b);
- WebKit::WebHistoryItem forward_item = GetMainFrame()->currentHistoryItem();
- GoBack(GetMainFrame()->previousHistoryItem());
+ PageState forward_state =
+ HistoryEntryToPageState(view()->history_controller()->GetCurrentEntry());
+ GoBack(HistoryEntryToPageState(
+ view()->history_controller()->GetPreviousEntry()));
EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b));
EXPECT_EQ(1, was_page_b);
- GoForward(forward_item);
+ GoForward(forward_state);
EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_c, &was_page_c));
EXPECT_EQ(1, was_page_c);
- GoBack(GetMainFrame()->previousHistoryItem());
+ GoBack(HistoryEntryToPageState(
+ view()->history_controller()->GetPreviousEntry()));
EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b));
EXPECT_EQ(1, was_page_b);
- forward_item = GetMainFrame()->currentHistoryItem();
- GoBack(page_a_item);
+ forward_state =
+ HistoryEntryToPageState(view()->history_controller()->GetCurrentEntry());
+ GoBack(page_a_state);
EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_a, &was_page_a));
EXPECT_EQ(1, was_page_a);
- GoForward(forward_item);
+ GoForward(forward_state);
EXPECT_TRUE(ExecuteJavaScriptAndReturnIntValue(check_page_b, &was_page_b));
EXPECT_EQ(1, was_page_b);
}
-#if defined(OS_MACOSX) || defined(OS_WIN) || defined(USE_AURA)
+#if defined(OS_MACOSX) || defined(USE_AURA)
TEST_F(RenderViewImplTest, GetCompositionCharacterBoundsTest) {
#if defined(OS_WIN)
LoadHTML("<textarea id=\"test\"></textarea>");
ExecuteJavaScript("document.getElementById('test').focus();");
- const string16 empty_string = UTF8ToUTF16("");
- const std::vector<WebKit::WebCompositionUnderline> empty_underline;
+ const base::string16 empty_string;
+ const std::vector<blink::WebCompositionUnderline> empty_underline;
std::vector<gfx::Rect> bounds;
view()->OnSetFocus(true);
view()->OnSetInputMethodActive(true);
// ASCII composition
- const string16 ascii_composition = UTF8ToUTF16("aiueo");
+ const base::string16 ascii_composition = base::UTF8ToUTF16("aiueo");
view()->OnImeSetComposition(ascii_composition, empty_underline, 0, 0);
view()->GetCompositionCharacterBounds(&bounds);
ASSERT_EQ(ascii_composition.size(), bounds.size());
empty_string, gfx::Range::InvalidRange(), false);
// Non surrogate pair unicode character.
- const string16 unicode_composition = UTF8ToUTF16(
+ const base::string16 unicode_composition = base::UTF8ToUTF16(
"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A");
view()->OnImeSetComposition(unicode_composition, empty_underline, 0, 0);
view()->GetCompositionCharacterBounds(&bounds);
empty_string, gfx::Range::InvalidRange(), false);
// Surrogate pair character.
- const string16 surrogate_pair_char = UTF8ToUTF16("\xF0\xA0\xAE\x9F");
+ const base::string16 surrogate_pair_char =
+ base::UTF8ToUTF16("\xF0\xA0\xAE\x9F");
view()->OnImeSetComposition(surrogate_pair_char,
empty_underline,
0,
empty_string, gfx::Range::InvalidRange(), false);
// Mixed string.
- const string16 surrogate_pair_mixed_composition =
- surrogate_pair_char + UTF8ToUTF16("\xE3\x81\x82") + surrogate_pair_char +
- UTF8ToUTF16("b") + surrogate_pair_char;
+ const base::string16 surrogate_pair_mixed_composition =
+ surrogate_pair_char + base::UTF8ToUTF16("\xE3\x81\x82") +
+ surrogate_pair_char + base::UTF8ToUTF16("b") + surrogate_pair_char;
const size_t utf16_length = 8UL;
const bool is_surrogate_pair_empty_rect[8] = {
false, true, false, false, true, false, false, true };
const double kMinZoomLevel = ZoomFactorToZoomLevel(kMinimumZoomFactor);
const double kMaxZoomLevel = ZoomFactorToZoomLevel(kMaximumZoomFactor);
- ViewMsg_Navigate_Params params;
+ FrameMsg_Navigate_Params params;
params.page_id = -1;
- params.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
// Verifies navigation to a URL with preset zoom level indeed sets the level.
// Regression test for http://crbug.com/139559, where the level was not
// properly set when it is out of the default zoom limits of WebView.
params.url = GURL("data:text/html,min_zoomlimit_test");
view()->OnSetZoomLevelForLoadingURL(params.url, kMinZoomLevel);
- view()->OnNavigate(params);
+ frame()->OnNavigate(params);
ProcessPendingMessages();
EXPECT_DOUBLE_EQ(kMinZoomLevel, view()->GetWebView()->zoomLevel());
ZoomFactorToZoomLevel(1.0));
params.url = GURL("data:text/html,max_zoomlimit_test");
view()->OnSetZoomLevelForLoadingURL(params.url, kMaxZoomLevel);
- view()->OnNavigate(params);
+ frame()->OnNavigate(params);
ProcessPendingMessages();
EXPECT_DOUBLE_EQ(kMaxZoomLevel, view()->GetWebView()->zoomLevel());
}
"</body>"
"</html>");
ExecuteJavaScript("document.getElementById('test1').focus();");
- view()->OnSetEditableSelectionOffsets(4, 8);
- const std::vector<WebKit::WebCompositionUnderline> empty_underline;
- view()->OnSetCompositionFromExistingText(7, 10, empty_underline);
- WebKit::WebTextInputInfo info = view()->webview()->textInputInfo();
+ frame()->OnSetEditableSelectionOffsets(4, 8);
+ const std::vector<blink::WebCompositionUnderline> empty_underline;
+ frame()->OnSetCompositionFromExistingText(7, 10, empty_underline);
+ blink::WebTextInputInfo info = view()->webview()->textInputInfo();
EXPECT_EQ(4, info.selectionStart);
EXPECT_EQ(8, info.selectionEnd);
EXPECT_EQ(7, info.compositionStart);
EXPECT_EQ(10, info.compositionEnd);
- view()->OnUnselect();
+ frame()->OnUnselect();
info = view()->webview()->textInputInfo();
EXPECT_EQ(0, info.selectionStart);
EXPECT_EQ(0, info.selectionEnd);
"</body>"
"</html>");
ExecuteJavaScript("document.getElementById('test1').focus();");
- view()->OnSetEditableSelectionOffsets(10, 10);
- view()->OnExtendSelectionAndDelete(3, 4);
- WebKit::WebTextInputInfo info = view()->webview()->textInputInfo();
+ frame()->OnSetEditableSelectionOffsets(10, 10);
+ frame()->OnExtendSelectionAndDelete(3, 4);
+ blink::WebTextInputInfo info = view()->webview()->textInputInfo();
EXPECT_EQ("abcdefgopqrstuvwxyz", info.value);
EXPECT_EQ(7, info.selectionStart);
EXPECT_EQ(7, info.selectionEnd);
- view()->OnSetEditableSelectionOffsets(4, 8);
- view()->OnExtendSelectionAndDelete(2, 5);
+ frame()->OnSetEditableSelectionOffsets(4, 8);
+ frame()->OnExtendSelectionAndDelete(2, 5);
info = view()->webview()->textInputInfo();
EXPECT_EQ("abuvwxyz", info.value);
EXPECT_EQ(2, info.selectionStart);
LoadHTML("hello <iframe srcdoc='fail' name='frame'></iframe>");
// Navigate the frame only.
- ViewMsg_Navigate_Params nav_params;
+ FrameMsg_Navigate_Params nav_params;
nav_params.url = GURL("data:text/html,world");
- nav_params.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ nav_params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
nav_params.transition = PAGE_TRANSITION_TYPED;
nav_params.current_history_list_length = 1;
nav_params.current_history_list_offset = 0;
nav_params.pending_history_list_offset = 1;
nav_params.page_id = -1;
nav_params.frame_to_navigate = "frame";
- view()->OnNavigate(nav_params);
- ProcessPendingMessages();
+ frame()->OnNavigate(nav_params);
+ FrameLoadWaiter(
+ RenderFrame::FromWebFrame(frame()->GetWebFrame()->firstChild())).Wait();
// Copy the document content to std::wstring and compare with the
// expected result.
const int kMaxOutputCharacters = 256;
- std::wstring output = UTF16ToWideHack(
+ std::string output = base::UTF16ToUTF8(
GetMainFrame()->contentAsText(kMaxOutputCharacters));
- EXPECT_EQ(output, L"hello \n\nworld");
+ EXPECT_EQ(output, "hello \n\nworld");
}
// This test ensures that a RenderFrame object is created for the top level
TEST_F(RenderViewImplTest, GetSSLStatusOfFrame) {
LoadHTML("<!DOCTYPE html><html><body></body></html>");
- WebFrame* frame = GetMainFrame();
+ WebLocalFrame* frame = GetMainFrame();
SSLStatus ssl_status = view()->GetSSLStatusOfFrame(frame);
EXPECT_FALSE(net::IsCertStatusError(ssl_status.cert_status));
- const_cast<WebKit::WebURLResponse&>(frame->dataSource()->response()).
+ const_cast<blink::WebURLResponse&>(frame->dataSource()->response()).
setSecurityInfo(
- SerializeSecurityInfo(0, net::CERT_STATUS_ALL_ERRORS, 0, 0));
+ SerializeSecurityInfo(0, net::CERT_STATUS_ALL_ERRORS, 0, 0,
+ SignedCertificateTimestampIDStatusList()));
ssl_status = view()->GetSSLStatusOfFrame(frame);
EXPECT_TRUE(net::IsCertStatusError(ssl_status.cert_status));
}
+TEST_F(RenderViewImplTest, MessageOrderInDidChangeSelection) {
+ view()->OnSetInputMethodActive(true);
+ view()->set_send_content_state_immediately(true);
+ LoadHTML("<textarea id=\"test\"></textarea>");
+
+ view()->handling_input_event_ = true;
+ ExecuteJavaScript("document.getElementById('test').focus();");
+
+ bool is_input_type_called = false;
+ bool is_selection_called = false;
+ size_t last_input_type = 0;
+ size_t last_selection = 0;
+
+ for (size_t i = 0; i < render_thread_->sink().message_count(); ++i) {
+ const uint32 type = render_thread_->sink().GetMessageAt(i)->type();
+ if (type == ViewHostMsg_TextInputTypeChanged::ID) {
+ is_input_type_called = true;
+ last_input_type = i;
+ } else if (type == ViewHostMsg_SelectionChanged::ID) {
+ is_selection_called = true;
+ last_selection = i;
+ }
+ }
+
+ EXPECT_TRUE(is_input_type_called);
+ EXPECT_TRUE(is_selection_called);
+
+ // InputTypeChange shold be called earlier than SelectionChanged.
+ EXPECT_LT(last_input_type, last_selection);
+}
+
class SuppressErrorPageTest : public RenderViewTest {
public:
- virtual void SetUp() OVERRIDE {
- SetRendererClientForTesting(&client_);
- RenderViewTest::SetUp();
+ virtual ContentRendererClient* CreateContentRendererClient() OVERRIDE {
+ return new TestContentRendererClient;
}
RenderViewImpl* view() {
return static_cast<RenderViewImpl*>(view_);
}
+ RenderFrameImpl* frame() {
+ return static_cast<RenderFrameImpl*>(view()->GetMainRenderFrame());
+ }
+
private:
class TestContentRendererClient : public ContentRendererClient {
public:
- virtual bool ShouldSuppressErrorPage(const GURL& url) OVERRIDE {
+ virtual bool ShouldSuppressErrorPage(RenderFrame* render_frame,
+ const GURL& url) OVERRIDE {
return url == GURL("http://example.com/suppress");
}
virtual void GetNavigationErrorStrings(
- WebKit::WebFrame* frame,
- const WebKit::WebURLRequest& failed_request,
- const WebKit::WebURLError& error,
- const std::string& accept_languages,
+ content::RenderView* render_view,
+ blink::WebFrame* frame,
+ const blink::WebURLRequest& failed_request,
+ const blink::WebURLError& error,
std::string* error_html,
- string16* error_description) OVERRIDE {
+ base::string16* error_description) OVERRIDE {
if (error_html)
*error_html = "A suffusion of yellow.";
}
};
-
- TestContentRendererClient client_;
};
#if defined(OS_ANDROID)
error.domain = WebString::fromUTF8(net::kErrorDomain);
error.reason = net::ERR_FILE_NOT_FOUND;
error.unreachableURL = GURL("http://example.com/suppress");
- WebFrame* web_frame = GetMainFrame();
+ WebLocalFrame* web_frame = GetMainFrame();
// Start a load that will reach provisional state synchronously,
// but won't complete synchronously.
- ViewMsg_Navigate_Params params;
+ FrameMsg_Navigate_Params params;
params.page_id = -1;
- params.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
params.url = GURL("data:text/html,test data");
- view()->OnNavigate(params);
+ frame()->OnNavigate(params);
// An error occurred.
- view()->didFailProvisionalLoad(web_frame, error);
+ view()->main_render_frame()->didFailProvisionalLoad(web_frame, error);
const int kMaxOutputCharacters = 22;
- EXPECT_EQ("", UTF16ToASCII(web_frame->contentAsText(kMaxOutputCharacters)));
+ EXPECT_EQ("",
+ base::UTF16ToASCII(web_frame->contentAsText(kMaxOutputCharacters)));
}
#if defined(OS_ANDROID)
error.domain = WebString::fromUTF8(net::kErrorDomain);
error.reason = net::ERR_FILE_NOT_FOUND;
error.unreachableURL = GURL("http://example.com/dont-suppress");
- WebFrame* web_frame = GetMainFrame();
+ WebLocalFrame* web_frame = GetMainFrame();
// Start a load that will reach provisional state synchronously,
// but won't complete synchronously.
- ViewMsg_Navigate_Params params;
+ FrameMsg_Navigate_Params params;
params.page_id = -1;
- params.navigation_type = ViewMsg_Navigate_Type::NORMAL;
+ params.navigation_type = FrameMsg_Navigate_Type::NORMAL;
params.url = GURL("data:text/html,test data");
- view()->OnNavigate(params);
+ frame()->OnNavigate(params);
// An error occurred.
- view()->didFailProvisionalLoad(web_frame, error);
- ProcessPendingMessages();
+ view()->main_render_frame()->didFailProvisionalLoad(web_frame, error);
+ // The error page itself is loaded asynchronously.
+ FrameLoadWaiter(frame()).Wait();
const int kMaxOutputCharacters = 22;
EXPECT_EQ("A suffusion of yellow.",
- UTF16ToASCII(web_frame->contentAsText(kMaxOutputCharacters)));
+ base::UTF16ToASCII(web_frame->contentAsText(kMaxOutputCharacters)));
+}
+
+// Tests if IME API's candidatewindow* events sent from browser are handled
+// in renderer.
+TEST_F(RenderViewImplTest, SendCandidateWindowEvents) {
+ // Sends an HTML with an <input> element and scripts to the renderer.
+ // The script handles all 3 of candidatewindow* events for an
+ // InputMethodContext object and once it received 'show', 'update', 'hide'
+ // should appear in the result div.
+ LoadHTML("<input id='test'>"
+ "<div id='result'>Result: </div>"
+ "<script>"
+ "window.onload = function() {"
+ " var result = document.getElementById('result');"
+ " var test = document.getElementById('test');"
+ " test.focus();"
+ " var context = test.inputMethodContext;"
+ " if (context) {"
+ " context.oncandidatewindowshow = function() {"
+ " result.innerText += 'show'; };"
+ " context.oncandidatewindowupdate = function(){"
+ " result.innerText += 'update'; };"
+ " context.oncandidatewindowhide = function(){"
+ " result.innerText += 'hide'; };"
+ " }"
+ "};"
+ "</script>");
+
+ // Fire candidatewindow events.
+ view()->OnCandidateWindowShown();
+ view()->OnCandidateWindowUpdated();
+ view()->OnCandidateWindowHidden();
+
+ // Retrieve the content and check if it is expected.
+ const int kMaxOutputCharacters = 50;
+ std::string output = base::UTF16ToUTF8(
+ GetMainFrame()->contentAsText(kMaxOutputCharacters));
+ EXPECT_EQ(output, "\nResult:showupdatehide");
+}
+
+// Ensure the render view sends favicon url update events correctly.
+TEST_F(RenderViewImplTest, SendFaviconURLUpdateEvent) {
+ // An event should be sent when a favicon url exists.
+ LoadHTML("<html>"
+ "<head>"
+ "<link rel='icon' href='http://www.google.com/favicon.ico'>"
+ "</head>"
+ "</html>");
+ EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
+ ViewHostMsg_UpdateFaviconURL::ID));
+ render_thread_->sink().ClearMessages();
+
+ // An event should not be sent if no favicon url exists. This is an assumption
+ // made by some of Chrome's favicon handling.
+ LoadHTML("<html>"
+ "<head>"
+ "</head>"
+ "</html>");
+ EXPECT_FALSE(render_thread_->sink().GetFirstMessageMatching(
+ ViewHostMsg_UpdateFaviconURL::ID));
+}
+
+// Test progress tracker messages.
+TEST_F(RenderViewImplTest, SendProgressCompletionUpdates) {
+ std::string data_url_string = "data:text/html,<body>placeholder</body>";
+ GURL url(data_url_string);
+ GetMainFrame()->loadRequest(blink::WebURLRequest(url));
+
+ EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
+ FrameHostMsg_DidStartLoading::ID));
+
+ // The load started, we should receive a start notification and a progress
+ // update with the minimum progress.
+ const IPC::Message* message = render_thread_->sink().GetFirstMessageMatching(
+ ViewHostMsg_DidChangeLoadProgress::ID);
+ EXPECT_TRUE(message);
+ Tuple1<double> progress_value;
+ ViewHostMsg_DidChangeLoadProgress::Read(message, &progress_value);
+ EXPECT_EQ(0.1, progress_value.a);
+ render_thread_->sink().ClearMessages();
+
+ FrameLoadWaiter(frame()).Wait();
+
+ // The data url has loaded, so we should see a progress change to 1.0 (done)
+ // and a stop notification.
+ message = render_thread_->sink().GetFirstMessageMatching(
+ ViewHostMsg_DidChangeLoadProgress::ID);
+ EXPECT_TRUE(message);
+ ViewHostMsg_DidChangeLoadProgress::Read(message, &progress_value);
+ EXPECT_EQ(1.0, progress_value.a);
+
+ EXPECT_TRUE(render_thread_->sink().GetFirstMessageMatching(
+ FrameHostMsg_DidStopLoading::ID));
+ render_thread_->sink().ClearMessages();
+}
+
+TEST_F(RenderViewImplTest, FocusElementCallsFocusedNodeChanged) {
+ LoadHTML("<input id='test1' value='hello1'></input>"
+ "<input id='test2' value='hello2'></input>");
+
+ ExecuteJavaScript("document.getElementById('test1').focus();");
+ const IPC::Message* msg1 = render_thread_->sink().GetFirstMessageMatching(
+ ViewHostMsg_FocusedNodeChanged::ID);
+ EXPECT_TRUE(msg1);
+
+ ViewHostMsg_FocusedNodeChanged::Param params;
+ ViewHostMsg_FocusedNodeChanged::Read(msg1, ¶ms);
+ EXPECT_TRUE(params.a);
+ render_thread_->sink().ClearMessages();
+
+ ExecuteJavaScript("document.getElementById('test2').focus();");
+ const IPC::Message* msg2 = render_thread_->sink().GetFirstMessageMatching(
+ ViewHostMsg_FocusedNodeChanged::ID);
+ EXPECT_TRUE(msg2);
+ ViewHostMsg_FocusedNodeChanged::Read(msg2, ¶ms);
+ EXPECT_TRUE(params.a);
+ render_thread_->sink().ClearMessages();
+
+ view()->webview()->clearFocusedElement();
+ const IPC::Message* msg3 = render_thread_->sink().GetFirstMessageMatching(
+ ViewHostMsg_FocusedNodeChanged::ID);
+ EXPECT_TRUE(msg3);
+ ViewHostMsg_FocusedNodeChanged::Read(msg3, ¶ms);
+ EXPECT_FALSE(params.a);
+ render_thread_->sink().ClearMessages();
+}
+
+TEST_F(RenderViewImplTest, ServiceWorkerNetworkProviderSetup) {
+ ServiceWorkerNetworkProvider* provider = NULL;
+ RequestExtraData* extra_data = NULL;
+
+ // Make sure each new document has a new provider and
+ // that the main request is tagged with the provider's id.
+ LoadHTML("<b>A Document</b>");
+ ASSERT_TRUE(GetMainFrame()->dataSource());
+ provider = ServiceWorkerNetworkProvider::FromDocumentState(
+ DocumentState::FromDataSource(GetMainFrame()->dataSource()));
+ ASSERT_TRUE(provider);
+ extra_data = static_cast<RequestExtraData*>(
+ GetMainFrame()->dataSource()->request().extraData());
+ ASSERT_TRUE(extra_data);
+ EXPECT_EQ(extra_data->service_worker_provider_id(),
+ provider->provider_id());
+ int provider1_id = provider->provider_id();
+
+ LoadHTML("<b>New Document B Goes Here</b>");
+ ASSERT_TRUE(GetMainFrame()->dataSource());
+ provider = ServiceWorkerNetworkProvider::FromDocumentState(
+ DocumentState::FromDataSource(GetMainFrame()->dataSource()));
+ ASSERT_TRUE(provider);
+ EXPECT_NE(provider1_id, provider->provider_id());
+ extra_data = static_cast<RequestExtraData*>(
+ GetMainFrame()->dataSource()->request().extraData());
+ ASSERT_TRUE(extra_data);
+ EXPECT_EQ(extra_data->service_worker_provider_id(),
+ provider->provider_id());
+
+ // See that subresource requests are also tagged with the provider's id.
+ EXPECT_EQ(frame(), RenderFrameImpl::FromWebFrame(GetMainFrame()));
+ blink::WebURLRequest request(GURL("http://foo.com"));
+ request.setTargetType(blink::WebURLRequest::TargetIsSubresource);
+ blink::WebURLResponse redirect_response;
+ frame()->willSendRequest(GetMainFrame(), 0, request, redirect_response);
+ extra_data = static_cast<RequestExtraData*>(request.extraData());
+ ASSERT_TRUE(extra_data);
+ EXPECT_EQ(extra_data->service_worker_provider_id(),
+ provider->provider_id());
+}
+
+TEST_F(RenderViewImplTest, OnSetAccessibilityMode) {
+ ASSERT_EQ(AccessibilityModeOff, view()->accessibility_mode());
+ ASSERT_EQ((RendererAccessibility*) NULL, view()->renderer_accessibility());
+
+ view()->OnSetAccessibilityMode(AccessibilityModeTreeOnly);
+ ASSERT_EQ(AccessibilityModeTreeOnly, view()->accessibility_mode());
+ ASSERT_NE((RendererAccessibility*) NULL, view()->renderer_accessibility());
+ ASSERT_EQ(RendererAccessibilityTypeComplete,
+ view()->renderer_accessibility()->GetType());
+
+ view()->OnSetAccessibilityMode(AccessibilityModeOff);
+ ASSERT_EQ(AccessibilityModeOff, view()->accessibility_mode());
+ ASSERT_EQ((RendererAccessibility*) NULL, view()->renderer_accessibility());
+
+ view()->OnSetAccessibilityMode(AccessibilityModeComplete);
+ ASSERT_EQ(AccessibilityModeComplete, view()->accessibility_mode());
+ ASSERT_NE((RendererAccessibility*) NULL, view()->renderer_accessibility());
+ ASSERT_EQ(RendererAccessibilityTypeComplete,
+ view()->renderer_accessibility()->GetType());
+
+ view()->OnSetAccessibilityMode(AccessibilityModeEditableTextOnly);
+ ASSERT_EQ(AccessibilityModeEditableTextOnly, view()->accessibility_mode());
+ ASSERT_NE((RendererAccessibility*) NULL, view()->renderer_accessibility());
+ ASSERT_EQ(RendererAccessibilityTypeFocusOnly,
+ view()->renderer_accessibility()->GetType());
}
} // namespace content