Commit a36c6e4d authored by Siye Liu's avatar Siye Liu Committed by Commit Bot

Reset |new_text_inserted_| after each |RequestLock| call.

We should reset the flag |new_text_inserted_| after each |RequestLock|
call because the flag is used to indicate whether current session has
new text inserted/replaced. We should clear the flag at the end of
current session to prepare the state for next edit session.

Bug: 1013472
Change-Id: I6efd9600d84550857ba4f55a42966753d2a7bdab
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1972752Reviewed-by: default avatarYohei Yukawa <yukawa@chromium.org>
Reviewed-by: default avatarSiye Liu <siliu@microsoft.com>
Commit-Queue: Siye Liu <siliu@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#727469}
parent c8ede4df
......@@ -696,6 +696,9 @@ STDMETHODIMP TSFTextStore::RequestLock(DWORD lock_flags, HRESULT* result) {
StartCompositionOnNewText(new_composition_start, composition_string);
}
// reset the flag since we've already inserted/replaced the text.
new_text_inserted_ = false;
// reset string_buffer_ if composition is no longer active.
if (!text_input_client_->HasCompositionText()) {
string_pending_insertion_.clear();
......@@ -1387,7 +1390,6 @@ void TSFTextStore::StartCompositionOnNewText(
}
if (text_input_client_) {
new_text_inserted_ = false;
text_input_client_->SetCompositionText(composition_text);
// Notify accessibility about this ongoing composition if the string is not
// empty
......
......@@ -194,6 +194,7 @@ class TSFTextStoreTestCallback {
protected:
// Accessors to the internal state of TSFTextStore.
bool* edit_flag() { return &text_store_->edit_flag_; }
bool* new_text_inserted() { return &text_store_->new_text_inserted_; }
base::string16* string_buffer() {
return &text_store_->string_buffer_document_;
}
......@@ -3141,5 +3142,96 @@ TEST_F(TSFTextStoreTest, RegressionTest5) {
EXPECT_EQ(S_OK, result);
}
// regression tests for crbug.com/1013472.
// We should reset |new_text_inserted_| at the end of
// |TSFTextStore::RequestLock| since the text should have been already
// inserted/replaced.
class RegressionTest6Callback : public TSFTextStoreTestCallback {
public:
explicit RegressionTest6Callback(TSFTextStore* text_store)
: TSFTextStoreTestCallback(text_store) {}
HRESULT LockGranted1(DWORD flags) {
EXPECT_EQ(false, *new_text_inserted());
SetTextTest(0, 0, L"a", S_OK);
GetTextTest(0, -1, L"a", 1);
SetSelectionTest(1, 1, S_OK);
text_spans()->clear();
ImeTextSpan text_span_1;
text_span_1.start_offset = 0;
text_span_1.end_offset = 2;
text_span_1.underline_color = SK_ColorBLACK;
text_span_1.thickness = ImeTextSpan::Thickness::kThick;
text_span_1.background_color = SK_ColorTRANSPARENT;
text_spans()->push_back(text_span_1);
*edit_flag() = true;
*composition_start() = 0;
composition_range()->set_start(0);
composition_range()->set_end(2);
text_store_->OnKeyTraceDown(65u, 1966081u);
*has_composition_range() = true;
return S_OK;
}
void SetCompositionText1(const ui::CompositionText& composition) {
EXPECT_EQ(L"a", composition.text);
EXPECT_EQ(1u, composition.selection.start());
EXPECT_EQ(1u, composition.selection.end());
ASSERT_EQ(1u, composition.ime_text_spans.size());
EXPECT_EQ(true, *new_text_inserted());
SetHasCompositionText(true);
}
HRESULT LockGranted2(DWORD flags) {
EXPECT_EQ(false, *new_text_inserted());
GetTextTest(0, -1, L"a", 1);
text_spans()->clear();
*edit_flag() = true;
*composition_start() = 1;
composition_range()->set_start(0);
composition_range()->set_end(0);
*has_composition_range() = false;
text_store_->OnKeyTraceUp(65u, 1966081u);
return S_OK;
}
void InsertText2(const base::string16& text) {
EXPECT_EQ(L"a", text);
SetHasCompositionText(false);
}
private:
DISALLOW_COPY_AND_ASSIGN(RegressionTest6Callback);
};
TEST_F(TSFTextStoreTest, RegressionTest6) {
RegressionTest6Callback callback(text_store_.get());
EXPECT_CALL(text_input_client_, SetCompositionText(_))
.WillOnce(
Invoke(&callback, &RegressionTest6Callback::SetCompositionText1));
EXPECT_CALL(text_input_client_, InsertText(_))
.WillOnce(Invoke(&callback, &RegressionTest6Callback::InsertText2));
EXPECT_CALL(*sink_, OnLockGranted(_))
.WillOnce(Invoke(&callback, &RegressionTest6Callback::LockGranted1))
.WillOnce(Invoke(&callback, &RegressionTest6Callback::LockGranted2));
ON_CALL(text_input_client_, HasCompositionText())
.WillByDefault(
Invoke(&callback, &TSFTextStoreTestCallback::HasCompositionText));
HRESULT result = kInvalidResult;
EXPECT_EQ(S_OK, text_store_->RequestLock(TS_LF_READWRITE, &result));
EXPECT_EQ(S_OK, result);
result = kInvalidResult;
EXPECT_EQ(S_OK, text_store_->RequestLock(TS_LF_READWRITE, &result));
EXPECT_EQ(S_OK, result);
}
} // namespace
} // namespace ui
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