1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/common/spellcheck_marker.h"
9 #include "chrome/common/spellcheck_messages.h"
10 #include "chrome/common/spellcheck_result.h"
11 #include "chrome/renderer/spellchecker/spellcheck_provider_test.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/platform/WebString.h"
17 class SpellCheckProviderMacTest
: public SpellCheckProviderTest
{};
19 struct MessageParameters
{
27 std::vector
<SpellCheckMarker
> markers
;
30 MessageParameters
ReadRequestTextCheck(IPC::Message
* message
) {
31 MessageParameters parameters
;
32 bool ok
= SpellCheckHostMsg_RequestTextCheck::Read(
34 ¶meters
.router_id
,
35 ¶meters
.request_id
,
42 void FakeMessageArrival(SpellCheckProvider
* provider
,
43 const MessageParameters
& parameters
) {
44 std::vector
<SpellCheckResult
> fake_result
;
45 bool handled
= provider
->OnMessageReceived(
46 SpellCheckMsg_RespondTextCheck(
48 parameters
.request_id
,
53 TEST_F(SpellCheckProviderMacTest
, SingleRoundtripSuccess
) {
54 FakeTextCheckingCompletion completion
;
56 provider_
.RequestTextChecking(blink::WebString("hello "),
58 std::vector
<SpellCheckMarker
>());
59 EXPECT_EQ(completion
.completion_count_
, 0U);
60 EXPECT_EQ(provider_
.messages_
.size(), 1U);
61 EXPECT_EQ(provider_
.pending_text_request_size(), 1U);
63 MessageParameters read_parameters
=
64 ReadRequestTextCheck(provider_
.messages_
[0]);
65 EXPECT_EQ(read_parameters
.text
, base::UTF8ToUTF16("hello "));
67 FakeMessageArrival(&provider_
, read_parameters
);
68 EXPECT_EQ(completion
.completion_count_
, 1U);
69 EXPECT_EQ(provider_
.pending_text_request_size(), 0U);
72 TEST_F(SpellCheckProviderMacTest
, TwoRoundtripSuccess
) {
73 FakeTextCheckingCompletion completion1
;
74 provider_
.RequestTextChecking(blink::WebString("hello "),
76 std::vector
<SpellCheckMarker
>());
77 FakeTextCheckingCompletion completion2
;
78 provider_
.RequestTextChecking(blink::WebString("bye "),
80 std::vector
<SpellCheckMarker
>());
82 EXPECT_EQ(completion1
.completion_count_
, 0U);
83 EXPECT_EQ(completion2
.completion_count_
, 0U);
84 EXPECT_EQ(provider_
.messages_
.size(), 2U);
85 EXPECT_EQ(provider_
.pending_text_request_size(), 2U);
87 MessageParameters read_parameters1
=
88 ReadRequestTextCheck(provider_
.messages_
[0]);
89 EXPECT_EQ(read_parameters1
.text
, base::UTF8ToUTF16("hello "));
91 MessageParameters read_parameters2
=
92 ReadRequestTextCheck(provider_
.messages_
[1]);
93 EXPECT_EQ(read_parameters2
.text
, base::UTF8ToUTF16("bye "));
95 FakeMessageArrival(&provider_
, read_parameters1
);
96 EXPECT_EQ(completion1
.completion_count_
, 1U);
97 EXPECT_EQ(completion2
.completion_count_
, 0U);
98 EXPECT_EQ(provider_
.pending_text_request_size(), 1U);
100 FakeMessageArrival(&provider_
, read_parameters2
);
101 EXPECT_EQ(completion1
.completion_count_
, 1U);
102 EXPECT_EQ(completion2
.completion_count_
, 1U);
103 EXPECT_EQ(provider_
.pending_text_request_size(), 0U);