// 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/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/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/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/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"
}
};
-} // namespace
-
class RenderViewImplTest : public RenderViewTest {
public:
RenderViewImplTest() {
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
// 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.
// 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_);
// 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()->main_render_frame()->didFailProvisionalLoad(web_frame, error);
// 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()->main_render_frame()->didFailProvisionalLoad(web_frame, error);
ClearHistory();
// No history to merge and a committed page to be kept.
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(), true);
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(), true);
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(), true);
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(), true);
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(), true);
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(), true);
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(), true);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(), true);
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(), true);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(), true);
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(), true);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(), true);
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(), true);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(), true);
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(), true);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(), true);
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(), true);
expected_page_id = view()->page_id_;
- view()->didCommitProvisionalLoad(GetMainFrame(), true);
+ frame()->didCommitProvisionalLoad(GetMainFrame(), true);
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) {
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());
}
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);
+ frame()->OnNavigate(nav_params);
ProcessPendingMessages();
// Copy the document content to std::wstring and compare with the
return static_cast<RenderViewImpl*>(view_);
}
+ RenderFrameImpl* frame() {
+ return static_cast<RenderFrameImpl*>(view()->GetMainRenderFrame());
+ }
+
private:
class TestContentRendererClient : public ContentRendererClient {
public:
// 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()->main_render_frame()->didFailProvisionalLoad(web_frame, error);
// 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()->main_render_frame()->didFailProvisionalLoad(web_frame, error);