element is used by the EditorClientImpl class to insert
// characters received through the RenderWidget::OnHandleInputEvent()
// function.
view_->set_send_content_state_immediately(true);
LoadHTML(""
""
"
"
""
""
"
"
"
"
""
"");
ExecuteJavaScript("document.getElementById('test').focus();");
render_thread_.sink().ClearMessages();
// For each key code, we send three keyboard events.
// * Pressing only the key;
// * Pressing the key and a left-shift key, and;
// * Pressing the key and a right-alt (AltGr) key.
static const MockKeyboard::Modifiers kModifiers[] = {
MockKeyboard::NONE,
MockKeyboard::LEFT_SHIFT,
#if defined(OS_WIN)
MockKeyboard::RIGHT_ALT,
#endif
};
MockKeyboard::Layout layout = kLayouts[i].layout;
for (size_t j = 0; j < ARRAYSIZE_UNSAFE(kModifiers); ++j) {
// Virtual key codes used for this test.
static const int kKeyCodes[] = {
'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z',
ui::VKEY_OEM_1,
ui::VKEY_OEM_PLUS,
ui::VKEY_OEM_COMMA,
ui::VKEY_OEM_MINUS,
ui::VKEY_OEM_PERIOD,
ui::VKEY_OEM_2,
ui::VKEY_OEM_3,
ui::VKEY_OEM_4,
ui::VKEY_OEM_5,
ui::VKEY_OEM_6,
ui::VKEY_OEM_7,
#if defined(OS_WIN)
// Unclear how to handle this on Linux.
ui::VKEY_OEM_8,
#endif
};
MockKeyboard::Modifiers modifiers = kModifiers[j];
for (size_t k = 0; k < ARRAYSIZE_UNSAFE(kKeyCodes); ++k) {
// Send a keyboard event to the RenderView object.
// We should test a keyboard event only when the given keyboard-layout
// 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];
std::wstring char_code;
if (SendKeyEvent(layout, key_code, modifiers, &char_code) < 0)
continue;
}
}
// Retrieve the text in the test page and compare it with the expected
// 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);
}
#else
NOTIMPLEMENTED();
#endif
}
// Crashy, http://crbug.com/53247.
TEST_F(RenderViewTest, DISABLED_DidFailProvisionalLoadWithErrorForError) {
GetMainFrame()->enableViewSourceMode(true);
WebURLError error;
error.domain.fromUTF8("test_domain");
error.reason = net::ERR_FILE_NOT_FOUND;
error.unreachableURL = GURL("http://foo");
WebFrame* web_frame = GetMainFrame();
// An error occurred.
view_->didFailProvisionalLoad(web_frame, error);
// Frame should exit view-source mode.
EXPECT_FALSE(web_frame->isViewSourceModeEnabled());
}
TEST_F(RenderViewTest, DidFailProvisionalLoadWithErrorForCancellation) {
GetMainFrame()->enableViewSourceMode(true);
WebURLError error;
error.domain.fromUTF8("test_domain");
error.reason = net::ERR_ABORTED;
error.unreachableURL = GURL("http://foo");
WebFrame* web_frame = GetMainFrame();
// A cancellation occurred.
view_->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(RenderViewTest, UpdateTargetURLWithInvalidURL) {
const GURL invalid_gurl("http://");
view_->setMouseOverURL(WebKit::WebURL(invalid_gurl));
EXPECT_EQ(invalid_gurl, view_->target_url_);
}
TEST_F(RenderViewTest, SetHistoryLengthAndPrune) {
int expected_page_id = -1;
// No history to merge and no committed pages.
view_->OnSetHistoryLengthAndPrune(0, -1);
EXPECT_EQ(0, view_->history_list_length_);
EXPECT_EQ(-1, view_->history_list_offset_);
// History to merge and no committed pages.
view_->OnSetHistoryLengthAndPrune(2, -1);
EXPECT_EQ(2, view_->history_list_length_);
EXPECT_EQ(1, view_->history_list_offset_);
EXPECT_EQ(-1, view_->history_page_ids_[0]);
EXPECT_EQ(-1, view_->history_page_ids_[1]);
ClearHistory();
// No history to merge and a committed page to be kept.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->OnSetHistoryLengthAndPrune(0, expected_page_id);
EXPECT_EQ(1, view_->history_list_length_);
EXPECT_EQ(0, view_->history_list_offset_);
EXPECT_EQ(expected_page_id, view_->history_page_ids_[0]);
ClearHistory();
// No history to merge and a committed page to be pruned.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->OnSetHistoryLengthAndPrune(0, expected_page_id + 1);
EXPECT_EQ(0, view_->history_list_length_);
EXPECT_EQ(-1, view_->history_list_offset_);
ClearHistory();
// No history to merge and a committed page that the browser was unaware of.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->OnSetHistoryLengthAndPrune(0, -1);
EXPECT_EQ(1, view_->history_list_length_);
EXPECT_EQ(0, view_->history_list_offset_);
EXPECT_EQ(expected_page_id, view_->history_page_ids_[0]);
ClearHistory();
// History to merge and a committed page to be kept.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->OnSetHistoryLengthAndPrune(2, expected_page_id);
EXPECT_EQ(3, view_->history_list_length_);
EXPECT_EQ(2, view_->history_list_offset_);
EXPECT_EQ(-1, view_->history_page_ids_[0]);
EXPECT_EQ(-1, view_->history_page_ids_[1]);
EXPECT_EQ(expected_page_id, view_->history_page_ids_[2]);
ClearHistory();
// History to merge and a committed page to be pruned.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->OnSetHistoryLengthAndPrune(2, expected_page_id + 1);
EXPECT_EQ(2, view_->history_list_length_);
EXPECT_EQ(1, view_->history_list_offset_);
EXPECT_EQ(-1, view_->history_page_ids_[0]);
EXPECT_EQ(-1, view_->history_page_ids_[1]);
ClearHistory();
// History to merge and a committed page that the browser was unaware of.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->OnSetHistoryLengthAndPrune(2, -1);
EXPECT_EQ(3, view_->history_list_length_);
EXPECT_EQ(2, view_->history_list_offset_);
EXPECT_EQ(-1, view_->history_page_ids_[0]);
EXPECT_EQ(-1, view_->history_page_ids_[1]);
EXPECT_EQ(expected_page_id, view_->history_page_ids_[2]);
ClearHistory();
int expected_page_id_2 = -1;
// No history to merge and two committed pages, both to be kept.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->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);
EXPECT_EQ(2, view_->history_list_length_);
EXPECT_EQ(1, view_->history_list_offset_);
EXPECT_EQ(expected_page_id, view_->history_page_ids_[0]);
EXPECT_EQ(expected_page_id_2, view_->history_page_ids_[1]);
ClearHistory();
// No history to merge and two committed pages, and only the second is kept.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->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);
EXPECT_EQ(1, view_->history_list_length_);
EXPECT_EQ(0, view_->history_list_offset_);
EXPECT_EQ(expected_page_id_2, view_->history_page_ids_[0]);
ClearHistory();
// No history to merge and two committed pages, both of which the browser was
// unaware of.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id_2 = view_->page_id_;
EXPECT_GT(expected_page_id_2, expected_page_id);
view_->OnSetHistoryLengthAndPrune(0, -1);
EXPECT_EQ(2, view_->history_list_length_);
EXPECT_EQ(1, view_->history_list_offset_);
EXPECT_EQ(expected_page_id, view_->history_page_ids_[0]);
EXPECT_EQ(expected_page_id_2, view_->history_page_ids_[1]);
ClearHistory();
// History to merge and two committed pages, both to be kept.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->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);
EXPECT_EQ(4, view_->history_list_length_);
EXPECT_EQ(3, view_->history_list_offset_);
EXPECT_EQ(-1, view_->history_page_ids_[0]);
EXPECT_EQ(-1, view_->history_page_ids_[1]);
EXPECT_EQ(expected_page_id, view_->history_page_ids_[2]);
EXPECT_EQ(expected_page_id_2, view_->history_page_ids_[3]);
ClearHistory();
// History to merge and two committed pages, and only the second is kept.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->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);
EXPECT_EQ(3, view_->history_list_length_);
EXPECT_EQ(2, view_->history_list_offset_);
EXPECT_EQ(-1, view_->history_page_ids_[0]);
EXPECT_EQ(-1, view_->history_page_ids_[1]);
EXPECT_EQ(expected_page_id_2, view_->history_page_ids_[2]);
ClearHistory();
// History to merge and two committed pages, both of which the browser was
// unaware of.
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id = view_->page_id_;
view_->didCommitProvisionalLoad(GetMainFrame(), true);
expected_page_id_2 = view_->page_id_;
EXPECT_GT(expected_page_id_2, expected_page_id);
view_->OnSetHistoryLengthAndPrune(2, -1);
EXPECT_EQ(4, view_->history_list_length_);
EXPECT_EQ(3, view_->history_list_offset_);
EXPECT_EQ(-1, view_->history_page_ids_[0]);
EXPECT_EQ(-1, view_->history_page_ids_[1]);
EXPECT_EQ(expected_page_id, view_->history_page_ids_[2]);
EXPECT_EQ(expected_page_id_2, view_->history_page_ids_[3]);
}