| OLD | NEW |
| 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 void FakeMessageArrival( | 19 void FakeMessageArrival( |
| 20 SpellCheckProvider* provider, | 20 SpellCheckProvider* provider, |
| 21 const SpellCheckHostMsg_RequestTextCheck::Param& parameters) { | 21 const SpellCheckHostMsg_RequestTextCheck::Param& parameters) { |
| 22 std::vector<SpellCheckResult> fake_result; | 22 std::vector<SpellCheckResult> fake_result; |
| 23 bool handled = provider->OnMessageReceived( | 23 bool handled = provider->OnMessageReceived( |
| 24 SpellCheckMsg_RespondTextCheck( | 24 SpellCheckMsg_RespondTextCheck( |
| 25 0, | 25 0, |
| 26 parameters.b, | 26 get<1>(parameters), |
| 27 fake_result)); | 27 fake_result)); |
| 28 EXPECT_TRUE(handled); | 28 EXPECT_TRUE(handled); |
| 29 } | 29 } |
| 30 | 30 |
| 31 TEST_F(SpellCheckProviderMacTest, SingleRoundtripSuccess) { | 31 TEST_F(SpellCheckProviderMacTest, SingleRoundtripSuccess) { |
| 32 FakeTextCheckingCompletion completion; | 32 FakeTextCheckingCompletion completion; |
| 33 | 33 |
| 34 provider_.RequestTextChecking(blink::WebString("hello "), | 34 provider_.RequestTextChecking(blink::WebString("hello "), |
| 35 &completion, | 35 &completion, |
| 36 std::vector<SpellCheckMarker>()); | 36 std::vector<SpellCheckMarker>()); |
| 37 EXPECT_EQ(completion.completion_count_, 0U); | 37 EXPECT_EQ(completion.completion_count_, 0U); |
| 38 EXPECT_EQ(provider_.messages_.size(), 1U); | 38 EXPECT_EQ(provider_.messages_.size(), 1U); |
| 39 EXPECT_EQ(provider_.pending_text_request_size(), 1U); | 39 EXPECT_EQ(provider_.pending_text_request_size(), 1U); |
| 40 | 40 |
| 41 SpellCheckHostMsg_RequestTextCheck::Param read_parameters1; | 41 SpellCheckHostMsg_RequestTextCheck::Param read_parameters1; |
| 42 bool ok = SpellCheckHostMsg_RequestTextCheck::Read( | 42 bool ok = SpellCheckHostMsg_RequestTextCheck::Read( |
| 43 provider_.messages_[0], &read_parameters1); | 43 provider_.messages_[0], &read_parameters1); |
| 44 EXPECT_TRUE(ok); | 44 EXPECT_TRUE(ok); |
| 45 EXPECT_EQ(read_parameters1.c, base::UTF8ToUTF16("hello ")); | 45 EXPECT_EQ(get<2>(read_parameters1), base::UTF8ToUTF16("hello ")); |
| 46 | 46 |
| 47 FakeMessageArrival(&provider_, read_parameters1); | 47 FakeMessageArrival(&provider_, read_parameters1); |
| 48 EXPECT_EQ(completion.completion_count_, 1U); | 48 EXPECT_EQ(completion.completion_count_, 1U); |
| 49 EXPECT_EQ(provider_.pending_text_request_size(), 0U); | 49 EXPECT_EQ(provider_.pending_text_request_size(), 0U); |
| 50 } | 50 } |
| 51 | 51 |
| 52 TEST_F(SpellCheckProviderMacTest, TwoRoundtripSuccess) { | 52 TEST_F(SpellCheckProviderMacTest, TwoRoundtripSuccess) { |
| 53 FakeTextCheckingCompletion completion1; | 53 FakeTextCheckingCompletion completion1; |
| 54 provider_.RequestTextChecking(blink::WebString("hello "), | 54 provider_.RequestTextChecking(blink::WebString("hello "), |
| 55 &completion1, | 55 &completion1, |
| 56 std::vector<SpellCheckMarker>()); | 56 std::vector<SpellCheckMarker>()); |
| 57 FakeTextCheckingCompletion completion2; | 57 FakeTextCheckingCompletion completion2; |
| 58 provider_.RequestTextChecking(blink::WebString("bye "), | 58 provider_.RequestTextChecking(blink::WebString("bye "), |
| 59 &completion2, | 59 &completion2, |
| 60 std::vector<SpellCheckMarker>()); | 60 std::vector<SpellCheckMarker>()); |
| 61 | 61 |
| 62 EXPECT_EQ(completion1.completion_count_, 0U); | 62 EXPECT_EQ(completion1.completion_count_, 0U); |
| 63 EXPECT_EQ(completion2.completion_count_, 0U); | 63 EXPECT_EQ(completion2.completion_count_, 0U); |
| 64 EXPECT_EQ(provider_.messages_.size(), 2U); | 64 EXPECT_EQ(provider_.messages_.size(), 2U); |
| 65 EXPECT_EQ(provider_.pending_text_request_size(), 2U); | 65 EXPECT_EQ(provider_.pending_text_request_size(), 2U); |
| 66 | 66 |
| 67 SpellCheckHostMsg_RequestTextCheck::Param read_parameters1; | 67 SpellCheckHostMsg_RequestTextCheck::Param read_parameters1; |
| 68 bool ok = SpellCheckHostMsg_RequestTextCheck::Read( | 68 bool ok = SpellCheckHostMsg_RequestTextCheck::Read( |
| 69 provider_.messages_[0], &read_parameters1); | 69 provider_.messages_[0], &read_parameters1); |
| 70 EXPECT_TRUE(ok); | 70 EXPECT_TRUE(ok); |
| 71 EXPECT_EQ(read_parameters1.c, base::UTF8ToUTF16("hello ")); | 71 EXPECT_EQ(get<2>(read_parameters1), base::UTF8ToUTF16("hello ")); |
| 72 | 72 |
| 73 SpellCheckHostMsg_RequestTextCheck::Param read_parameters2; | 73 SpellCheckHostMsg_RequestTextCheck::Param read_parameters2; |
| 74 ok = SpellCheckHostMsg_RequestTextCheck::Read( | 74 ok = SpellCheckHostMsg_RequestTextCheck::Read( |
| 75 provider_.messages_[1], &read_parameters2); | 75 provider_.messages_[1], &read_parameters2); |
| 76 EXPECT_TRUE(ok); | 76 EXPECT_TRUE(ok); |
| 77 EXPECT_EQ(read_parameters2.c, base::UTF8ToUTF16("bye ")); | 77 EXPECT_EQ(get<2>(read_parameters2), base::UTF8ToUTF16("bye ")); |
| 78 | 78 |
| 79 FakeMessageArrival(&provider_, read_parameters1); | 79 FakeMessageArrival(&provider_, read_parameters1); |
| 80 EXPECT_EQ(completion1.completion_count_, 1U); | 80 EXPECT_EQ(completion1.completion_count_, 1U); |
| 81 EXPECT_EQ(completion2.completion_count_, 0U); | 81 EXPECT_EQ(completion2.completion_count_, 0U); |
| 82 EXPECT_EQ(provider_.pending_text_request_size(), 1U); | 82 EXPECT_EQ(provider_.pending_text_request_size(), 1U); |
| 83 | 83 |
| 84 FakeMessageArrival(&provider_, read_parameters2); | 84 FakeMessageArrival(&provider_, read_parameters2); |
| 85 EXPECT_EQ(completion1.completion_count_, 1U); | 85 EXPECT_EQ(completion1.completion_count_, 1U); |
| 86 EXPECT_EQ(completion2.completion_count_, 1U); | 86 EXPECT_EQ(completion2.completion_count_, 1U); |
| 87 EXPECT_EQ(provider_.pending_text_request_size(), 0U); | 87 EXPECT_EQ(provider_.pending_text_request_size(), 0U); |
| 88 } | 88 } |
| 89 | 89 |
| 90 } // namespace | 90 } // namespace |
| OLD | NEW |