Commit b914b6a2 authored by bashi@chromium.org's avatar bashi@chromium.org

Fix assertion failure in range.mm while examining system dictionary popup.

Convert WTF::notFound to NSNotFound.

BUG=83158
TEST=chrome/browser/renderer_host/text_input_client_mac_unittest.mm

Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=86246

Review URL: http://codereview.chromium.org/7039054

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86378 0039d316-1c4b-4281-b951-d872f2087c98
parent 5c420b42
......@@ -7,6 +7,7 @@
#include "base/bind.h"
#include "base/message_loop.h"
#include "base/threading/thread.h"
#include "chrome/browser/renderer_host/text_input_client_message_filter.h"
#include "chrome/common/text_input_client_messages.h"
#include "chrome/test/testing_profile.h"
#include "content/browser/renderer_host/mock_render_process_host.h"
......@@ -18,6 +19,8 @@
namespace {
const int64 kTaskDelayMs = 200;
// This test does not test the WebKit side of the dictionary system (which
// performs the actual data fetching), but rather this just tests that the
// service's signaling system works.
......@@ -37,9 +40,8 @@ class TextInputClientMacTest : public testing::Test {
// Helper method to post a task on the testing thread's MessageLoop after
// a short delay.
void PostTask(const base::Closure& task) {
const int64 kTaskDelayMs = 200;
thread_.message_loop()->PostDelayedTask(FROM_HERE, task, kTaskDelayMs);
void PostTask(const base::Closure& task, const int64 delay = kTaskDelayMs) {
thread_.message_loop()->PostDelayedTask(FROM_HERE, task, delay);
}
RenderWidgetHost* widget() {
......@@ -106,6 +108,41 @@ TEST_F(TextInputClientMacTest, TimeoutCharacterIndex) {
EXPECT_EQ(NSNotFound, index);
}
TEST_F(TextInputClientMacTest, NotFoundCharacterIndex) {
ScopedTestingThread thread(this);
const NSUInteger kPreviousValue = 42;
const size_t kNotFoundValue = static_cast<size_t>(-1);
// Set an arbitrary value to ensure the index is not |NSNotFound|.
PostTask(base::Bind(&TextInputClientMac::SetCharacterIndexAndSignal,
base::Unretained(service()), kPreviousValue));
scoped_refptr<TextInputClientMessageFilter> filter(
new TextInputClientMessageFilter(widget()->process()->id()));
scoped_ptr<IPC::Message> message(
new TextInputClientReplyMsg_GotCharacterIndexForPoint(
widget()->routing_id(), kNotFoundValue));
bool message_ok = true;
// Set |WTF::notFound| to the index |kTaskDelayMs| after the previous
// setting.
PostTask(base::Bind(&TextInputClientMessageFilter::OnMessageReceived,
filter.get(), *message, &message_ok),
kTaskDelayMs * 2);
NSUInteger index = service()->GetCharacterIndexAtPoint(
widget(), gfx::Point(2, 2));
EXPECT_EQ(kPreviousValue, index);
index = service()->GetCharacterIndexAtPoint(widget(), gfx::Point(2, 2));
EXPECT_EQ(NSNotFound, index);
EXPECT_EQ(2U, ipc_sink().message_count());
for (size_t i = 0; i < ipc_sink().message_count(); ++i) {
const IPC::Message* ipc_message = ipc_sink().GetMessageAt(i);
EXPECT_EQ(ipc_message->type(),
TextInputClientMsg_CharacterIndexForPoint::ID);
}
}
TEST_F(TextInputClientMacTest, GetRectForRange) {
ScopedTestingThread thread(this);
const NSRect kSuccessValue = NSMakeRect(42, 43, 44, 45);
......
......@@ -43,6 +43,11 @@ bool TextInputClientMessageFilter::OnMessageReceived(
void TextInputClientMessageFilter::OnGotCharacterIndexForPoint(size_t index) {
TextInputClientMac* service = TextInputClientMac::GetInstance();
// |index| could be WTF::notFound (-1) and it's value is different from
// NSNotFound so we need to convert it.
if (index == static_cast<size_t>(-1)) {
index = NSNotFound;
}
service->SetCharacterIndexAndSignal(index);
}
......
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