Cast: Stop logging kVideoFrameSentToEncoder and rename a couple events.
[chromium-blink-merge.git] / chrome / renderer / spellchecker / spellcheck_provider_mac_unittest.cc
blobbab1107d5fca982ca65fa0478fae710474335e03
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.
5 #include <vector>
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"
15 namespace {
17 class SpellCheckProviderMacTest : public SpellCheckProviderTest {};
19 struct MessageParameters {
20 MessageParameters()
21 : router_id(0),
22 request_id(0) {}
24 int router_id;
25 int request_id;
26 base::string16 text;
27 std::vector<SpellCheckMarker> markers;
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;
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,
49 fake_result));
50 EXPECT_TRUE(handled);
53 TEST_F(SpellCheckProviderMacTest, SingleRoundtripSuccess) {
54 FakeTextCheckingCompletion completion;
56 provider_.RequestTextChecking(blink::WebString("hello "),
57 &completion,
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 "),
75 &completion1,
76 std::vector<SpellCheckMarker>());
77 FakeTextCheckingCompletion completion2;
78 provider_.RequestTextChecking(blink::WebString("bye "),
79 &completion2,
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);
106 } // namespace