| 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 <tuple> |
| 5 #include <vector> | 6 #include <vector> |
| 6 | 7 |
| 7 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/common/spellcheck_marker.h" | 9 #include "chrome/common/spellcheck_marker.h" |
| 9 #include "chrome/common/spellcheck_messages.h" | 10 #include "chrome/common/spellcheck_messages.h" |
| 10 #include "chrome/common/spellcheck_result.h" | 11 #include "chrome/common/spellcheck_result.h" |
| 11 #include "chrome/renderer/spellchecker/spellcheck_provider_test.h" | 12 #include "chrome/renderer/spellchecker/spellcheck_provider_test.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "third_party/WebKit/public/platform/WebString.h" | 14 #include "third_party/WebKit/public/platform/WebString.h" |
| 14 | 15 |
| 15 namespace { | 16 namespace { |
| 16 | 17 |
| 17 class SpellCheckProviderMacTest : public SpellCheckProviderTest {}; | 18 class SpellCheckProviderMacTest : public SpellCheckProviderTest {}; |
| 18 | 19 |
| 19 void FakeMessageArrival( | 20 void FakeMessageArrival( |
| 20 SpellCheckProvider* provider, | 21 SpellCheckProvider* provider, |
| 21 const SpellCheckHostMsg_RequestTextCheck::Param& parameters) { | 22 const SpellCheckHostMsg_RequestTextCheck::Param& parameters) { |
| 22 std::vector<SpellCheckResult> fake_result; | 23 std::vector<SpellCheckResult> fake_result; |
| 23 bool handled = provider->OnMessageReceived( | 24 bool handled = provider->OnMessageReceived( |
| 24 SpellCheckMsg_RespondTextCheck( | 25 SpellCheckMsg_RespondTextCheck( |
| 25 0, | 26 0, |
| 26 base::get<1>(parameters), | 27 std::get<1>(parameters), |
| 27 base::ASCIIToUTF16("test"), | 28 base::ASCIIToUTF16("test"), |
| 28 fake_result)); | 29 fake_result)); |
| 29 EXPECT_TRUE(handled); | 30 EXPECT_TRUE(handled); |
| 30 } | 31 } |
| 31 | 32 |
| 32 TEST_F(SpellCheckProviderMacTest, SingleRoundtripSuccess) { | 33 TEST_F(SpellCheckProviderMacTest, SingleRoundtripSuccess) { |
| 33 FakeTextCheckingCompletion completion; | 34 FakeTextCheckingCompletion completion; |
| 34 | 35 |
| 35 provider_.RequestTextChecking(blink::WebString("hello "), | 36 provider_.RequestTextChecking(blink::WebString("hello "), |
| 36 &completion, | 37 &completion, |
| 37 std::vector<SpellCheckMarker>()); | 38 std::vector<SpellCheckMarker>()); |
| 38 EXPECT_EQ(completion.completion_count_, 0U); | 39 EXPECT_EQ(completion.completion_count_, 0U); |
| 39 EXPECT_EQ(provider_.messages_.size(), 1U); | 40 EXPECT_EQ(provider_.messages_.size(), 1U); |
| 40 EXPECT_EQ(provider_.pending_text_request_size(), 1U); | 41 EXPECT_EQ(provider_.pending_text_request_size(), 1U); |
| 41 | 42 |
| 42 SpellCheckHostMsg_RequestTextCheck::Param read_parameters1; | 43 SpellCheckHostMsg_RequestTextCheck::Param read_parameters1; |
| 43 bool ok = SpellCheckHostMsg_RequestTextCheck::Read( | 44 bool ok = SpellCheckHostMsg_RequestTextCheck::Read( |
| 44 provider_.messages_[0], &read_parameters1); | 45 provider_.messages_[0], &read_parameters1); |
| 45 EXPECT_TRUE(ok); | 46 EXPECT_TRUE(ok); |
| 46 EXPECT_EQ(base::get<2>(read_parameters1), base::UTF8ToUTF16("hello ")); | 47 EXPECT_EQ(std::get<2>(read_parameters1), base::UTF8ToUTF16("hello ")); |
| 47 | 48 |
| 48 FakeMessageArrival(&provider_, read_parameters1); | 49 FakeMessageArrival(&provider_, read_parameters1); |
| 49 EXPECT_EQ(completion.completion_count_, 1U); | 50 EXPECT_EQ(completion.completion_count_, 1U); |
| 50 EXPECT_EQ(provider_.pending_text_request_size(), 0U); | 51 EXPECT_EQ(provider_.pending_text_request_size(), 0U); |
| 51 } | 52 } |
| 52 | 53 |
| 53 TEST_F(SpellCheckProviderMacTest, TwoRoundtripSuccess) { | 54 TEST_F(SpellCheckProviderMacTest, TwoRoundtripSuccess) { |
| 54 FakeTextCheckingCompletion completion1; | 55 FakeTextCheckingCompletion completion1; |
| 55 provider_.RequestTextChecking(blink::WebString("hello "), | 56 provider_.RequestTextChecking(blink::WebString("hello "), |
| 56 &completion1, | 57 &completion1, |
| 57 std::vector<SpellCheckMarker>()); | 58 std::vector<SpellCheckMarker>()); |
| 58 FakeTextCheckingCompletion completion2; | 59 FakeTextCheckingCompletion completion2; |
| 59 provider_.RequestTextChecking(blink::WebString("bye "), | 60 provider_.RequestTextChecking(blink::WebString("bye "), |
| 60 &completion2, | 61 &completion2, |
| 61 std::vector<SpellCheckMarker>()); | 62 std::vector<SpellCheckMarker>()); |
| 62 | 63 |
| 63 EXPECT_EQ(completion1.completion_count_, 0U); | 64 EXPECT_EQ(completion1.completion_count_, 0U); |
| 64 EXPECT_EQ(completion2.completion_count_, 0U); | 65 EXPECT_EQ(completion2.completion_count_, 0U); |
| 65 EXPECT_EQ(provider_.messages_.size(), 2U); | 66 EXPECT_EQ(provider_.messages_.size(), 2U); |
| 66 EXPECT_EQ(provider_.pending_text_request_size(), 2U); | 67 EXPECT_EQ(provider_.pending_text_request_size(), 2U); |
| 67 | 68 |
| 68 SpellCheckHostMsg_RequestTextCheck::Param read_parameters1; | 69 SpellCheckHostMsg_RequestTextCheck::Param read_parameters1; |
| 69 bool ok = SpellCheckHostMsg_RequestTextCheck::Read( | 70 bool ok = SpellCheckHostMsg_RequestTextCheck::Read( |
| 70 provider_.messages_[0], &read_parameters1); | 71 provider_.messages_[0], &read_parameters1); |
| 71 EXPECT_TRUE(ok); | 72 EXPECT_TRUE(ok); |
| 72 EXPECT_EQ(base::get<2>(read_parameters1), base::UTF8ToUTF16("hello ")); | 73 EXPECT_EQ(std::get<2>(read_parameters1), base::UTF8ToUTF16("hello ")); |
| 73 | 74 |
| 74 SpellCheckHostMsg_RequestTextCheck::Param read_parameters2; | 75 SpellCheckHostMsg_RequestTextCheck::Param read_parameters2; |
| 75 ok = SpellCheckHostMsg_RequestTextCheck::Read( | 76 ok = SpellCheckHostMsg_RequestTextCheck::Read( |
| 76 provider_.messages_[1], &read_parameters2); | 77 provider_.messages_[1], &read_parameters2); |
| 77 EXPECT_TRUE(ok); | 78 EXPECT_TRUE(ok); |
| 78 EXPECT_EQ(base::get<2>(read_parameters2), base::UTF8ToUTF16("bye ")); | 79 EXPECT_EQ(std::get<2>(read_parameters2), base::UTF8ToUTF16("bye ")); |
| 79 | 80 |
| 80 FakeMessageArrival(&provider_, read_parameters1); | 81 FakeMessageArrival(&provider_, read_parameters1); |
| 81 EXPECT_EQ(completion1.completion_count_, 1U); | 82 EXPECT_EQ(completion1.completion_count_, 1U); |
| 82 EXPECT_EQ(completion2.completion_count_, 0U); | 83 EXPECT_EQ(completion2.completion_count_, 0U); |
| 83 EXPECT_EQ(provider_.pending_text_request_size(), 1U); | 84 EXPECT_EQ(provider_.pending_text_request_size(), 1U); |
| 84 | 85 |
| 85 FakeMessageArrival(&provider_, read_parameters2); | 86 FakeMessageArrival(&provider_, read_parameters2); |
| 86 EXPECT_EQ(completion1.completion_count_, 1U); | 87 EXPECT_EQ(completion1.completion_count_, 1U); |
| 87 EXPECT_EQ(completion2.completion_count_, 1U); | 88 EXPECT_EQ(completion2.completion_count_, 1U); |
| 88 EXPECT_EQ(provider_.pending_text_request_size(), 0U); | 89 EXPECT_EQ(provider_.pending_text_request_size(), 0U); |
| 89 } | 90 } |
| 90 | 91 |
| 91 } // namespace | 92 } // namespace |
| OLD | NEW |