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

Side by Side Diff: chrome/renderer/spellchecker/spellcheck_provider_mac_unittest.cc

Issue 283623002: Add support for passing an arbitrary parameter to an IPC message handler. The motivation is for Web… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: sync Created 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <vector> 5 #include <vector>
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/common/spellcheck_marker.h" 8 #include "chrome/common/spellcheck_marker.h"
9 #include "chrome/common/spellcheck_messages.h" 9 #include "chrome/common/spellcheck_messages.h"
10 #include "chrome/common/spellcheck_result.h" 10 #include "chrome/common/spellcheck_result.h"
11 #include "chrome/renderer/spellchecker/spellcheck_provider_test.h" 11 #include "chrome/renderer/spellchecker/spellcheck_provider_test.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/platform/WebString.h" 13 #include "third_party/WebKit/public/platform/WebString.h"
14 14
15 namespace { 15 namespace {
16 16
17 class SpellCheckProviderMacTest : public SpellCheckProviderTest {}; 17 class SpellCheckProviderMacTest : public SpellCheckProviderTest {};
18 18
19 struct MessageParameters { 19 void FakeMessageArrival(
20 MessageParameters() 20 SpellCheckProvider* provider,
21 : router_id(0), 21 const SpellCheckHostMsg_RequestTextCheck::Param& parameters) {
22 request_id(0) {}
23
24 int router_id;
25 int request_id;
26 base::string16 text;
27 std::vector<SpellCheckMarker> markers;
28 };
29
30 MessageParameters ReadRequestTextCheck(IPC::Message* message) {
31 MessageParameters parameters;
32 bool ok = SpellCheckHostMsg_RequestTextCheck::Read(
33 message,
34 &parameters.router_id,
35 &parameters.request_id,
36 &parameters.text,
37 &parameters.markers);
38 EXPECT_TRUE(ok);
39 return parameters;
40 }
41
42 void FakeMessageArrival(SpellCheckProvider* provider,
43 const MessageParameters& parameters) {
44 std::vector<SpellCheckResult> fake_result; 22 std::vector<SpellCheckResult> fake_result;
45 bool handled = provider->OnMessageReceived( 23 bool handled = provider->OnMessageReceived(
46 SpellCheckMsg_RespondTextCheck( 24 SpellCheckMsg_RespondTextCheck(
47 0, 25 0,
48 parameters.request_id, 26 parameters.b,
49 fake_result)); 27 fake_result));
50 EXPECT_TRUE(handled); 28 EXPECT_TRUE(handled);
51 } 29 }
52 30
53 TEST_F(SpellCheckProviderMacTest, SingleRoundtripSuccess) { 31 TEST_F(SpellCheckProviderMacTest, SingleRoundtripSuccess) {
54 FakeTextCheckingCompletion completion; 32 FakeTextCheckingCompletion completion;
55 33
56 provider_.RequestTextChecking(blink::WebString("hello "), 34 provider_.RequestTextChecking(blink::WebString("hello "),
57 &completion, 35 &completion,
58 std::vector<SpellCheckMarker>()); 36 std::vector<SpellCheckMarker>());
59 EXPECT_EQ(completion.completion_count_, 0U); 37 EXPECT_EQ(completion.completion_count_, 0U);
60 EXPECT_EQ(provider_.messages_.size(), 1U); 38 EXPECT_EQ(provider_.messages_.size(), 1U);
61 EXPECT_EQ(provider_.pending_text_request_size(), 1U); 39 EXPECT_EQ(provider_.pending_text_request_size(), 1U);
62 40
63 MessageParameters read_parameters = 41 SpellCheckHostMsg_RequestTextCheck::Param read_parameters1;
64 ReadRequestTextCheck(provider_.messages_[0]); 42 bool ok = SpellCheckHostMsg_RequestTextCheck::Read(
65 EXPECT_EQ(read_parameters.text, base::UTF8ToUTF16("hello ")); 43 provider_.messages_[0], &read_parameters1);
44 EXPECT_TRUE(ok);
45 EXPECT_EQ(read_parameters1.c, base::UTF8ToUTF16("hello "));
66 46
67 FakeMessageArrival(&provider_, read_parameters); 47 FakeMessageArrival(&provider_, read_parameters1);
68 EXPECT_EQ(completion.completion_count_, 1U); 48 EXPECT_EQ(completion.completion_count_, 1U);
69 EXPECT_EQ(provider_.pending_text_request_size(), 0U); 49 EXPECT_EQ(provider_.pending_text_request_size(), 0U);
70 } 50 }
71 51
72 TEST_F(SpellCheckProviderMacTest, TwoRoundtripSuccess) { 52 TEST_F(SpellCheckProviderMacTest, TwoRoundtripSuccess) {
73 FakeTextCheckingCompletion completion1; 53 FakeTextCheckingCompletion completion1;
74 provider_.RequestTextChecking(blink::WebString("hello "), 54 provider_.RequestTextChecking(blink::WebString("hello "),
75 &completion1, 55 &completion1,
76 std::vector<SpellCheckMarker>()); 56 std::vector<SpellCheckMarker>());
77 FakeTextCheckingCompletion completion2; 57 FakeTextCheckingCompletion completion2;
78 provider_.RequestTextChecking(blink::WebString("bye "), 58 provider_.RequestTextChecking(blink::WebString("bye "),
79 &completion2, 59 &completion2,
80 std::vector<SpellCheckMarker>()); 60 std::vector<SpellCheckMarker>());
81 61
82 EXPECT_EQ(completion1.completion_count_, 0U); 62 EXPECT_EQ(completion1.completion_count_, 0U);
83 EXPECT_EQ(completion2.completion_count_, 0U); 63 EXPECT_EQ(completion2.completion_count_, 0U);
84 EXPECT_EQ(provider_.messages_.size(), 2U); 64 EXPECT_EQ(provider_.messages_.size(), 2U);
85 EXPECT_EQ(provider_.pending_text_request_size(), 2U); 65 EXPECT_EQ(provider_.pending_text_request_size(), 2U);
86 66
87 MessageParameters read_parameters1 = 67 SpellCheckHostMsg_RequestTextCheck::Param read_parameters1;
88 ReadRequestTextCheck(provider_.messages_[0]); 68 bool ok = SpellCheckHostMsg_RequestTextCheck::Read(
89 EXPECT_EQ(read_parameters1.text, base::UTF8ToUTF16("hello ")); 69 provider_.messages_[0], &read_parameters1);
70 EXPECT_TRUE(ok);
71 EXPECT_EQ(read_parameters1.c, base::UTF8ToUTF16("hello "));
90 72
91 MessageParameters read_parameters2 = 73 SpellCheckHostMsg_RequestTextCheck::Param read_parameters2;
92 ReadRequestTextCheck(provider_.messages_[1]); 74 ok = SpellCheckHostMsg_RequestTextCheck::Read(
93 EXPECT_EQ(read_parameters2.text, base::UTF8ToUTF16("bye ")); 75 provider_.messages_[1], &read_parameters2);
76 EXPECT_TRUE(ok);
77 EXPECT_EQ(read_parameters2.c, base::UTF8ToUTF16("bye "));
94 78
95 FakeMessageArrival(&provider_, read_parameters1); 79 FakeMessageArrival(&provider_, read_parameters1);
96 EXPECT_EQ(completion1.completion_count_, 1U); 80 EXPECT_EQ(completion1.completion_count_, 1U);
97 EXPECT_EQ(completion2.completion_count_, 0U); 81 EXPECT_EQ(completion2.completion_count_, 0U);
98 EXPECT_EQ(provider_.pending_text_request_size(), 1U); 82 EXPECT_EQ(provider_.pending_text_request_size(), 1U);
99 83
100 FakeMessageArrival(&provider_, read_parameters2); 84 FakeMessageArrival(&provider_, read_parameters2);
101 EXPECT_EQ(completion1.completion_count_, 1U); 85 EXPECT_EQ(completion1.completion_count_, 1U);
102 EXPECT_EQ(completion2.completion_count_, 1U); 86 EXPECT_EQ(completion2.completion_count_, 1U);
103 EXPECT_EQ(provider_.pending_text_request_size(), 0U); 87 EXPECT_EQ(provider_.pending_text_request_size(), 0U);
104 } 88 }
105 89
106 } // namespace 90 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698