Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(817)

Unified Diff: chrome/browser/renderer_host/text_input_client_mac_unittest.mm

Issue 7039054: Fix assertion failure in range.mm while examining system dictionary popup. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Addressed bot failure. Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/renderer_host/text_input_client_message_filter.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/renderer_host/text_input_client_mac_unittest.mm
diff --git a/chrome/browser/renderer_host/text_input_client_mac_unittest.mm b/chrome/browser/renderer_host/text_input_client_mac_unittest.mm
index 6870064e81360133b829b80ae52a0d8db039a655..54ef3411f0449d8827b3516aef55d9c20a5ec355 100644
--- a/chrome/browser/renderer_host/text_input_client_mac_unittest.mm
+++ b/chrome/browser/renderer_host/text_input_client_mac_unittest.mm
@@ -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 + kTaskDelayMs);
Robert Sesek 2011/05/23 12:31:39 Use *2?
bashi 2011/05/24 00:44:17 Done.
+
+ 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 (unsigned i = 0; i < ipc_sink().message_count(); ++i) {
Robert Sesek 2011/05/23 12:31:39 Chromium prefers size_t to unsigned.
bashi 2011/05/24 00:44:17 Done.
+ 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);
« no previous file with comments | « no previous file | chrome/browser/renderer_host/text_input_client_message_filter.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698