Commit 087edc74 authored by komatsu@chromium.org's avatar komatsu@chromium.org

Fix the order of the event dispatch.

UpdateTextInputType should be called before SyncSelectionIfRequired.
UpdateTextInputType may send TextInputTypeChanged to notify the focus
was changed, and SyncSelectionIfRequired may send SelectionChanged
to notify the selection was changed.  Focus change should be notified
before selection change.

BUG=310562

Review URL: https://codereview.chromium.org/33323003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@233449 0039d316-1c4b-4281-b951-d872f2087c98
parent 0869caee
......@@ -1958,6 +1958,37 @@ TEST_F(RenderViewImplTest, GetSSLStatusOfFrame) {
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 {
......
......@@ -2603,8 +2603,13 @@ void RenderViewImpl::didChangeSelection(bool is_empty_selection) {
if (is_empty_selection)
selection_text_.clear();
SyncSelectionIfRequired();
// UpdateTextInputType should be called before SyncSelectionIfRequired.
// UpdateTextInputType may send TextInputTypeChanged to notify the focus
// was changed, and SyncSelectionIfRequired may send SelectionChanged
// to notify the selection was changed. Focus change should be notified
// before selection change.
UpdateTextInputType();
SyncSelectionIfRequired();
#if defined(OS_ANDROID)
UpdateTextInputState(false, true);
#endif
......
......@@ -844,6 +844,8 @@ class CONTENT_EXPORT RenderViewImpl
ShouldUpdateSelectionTextFromContextMenuParams);
FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, BasicRenderFrame);
FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest, TextInputTypeWithPepper);
FRIEND_TEST_ALL_PREFIXES(RenderViewImplTest,
MessageOrderInDidChangeSelection);
FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest, Suppresses);
FRIEND_TEST_ALL_PREFIXES(SuppressErrorPageTest, DoesNotSuppress);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment