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