| 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/stl_util.h" | 7 #include "base/stl_util.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "components/spellcheck/common/spellcheck_marker.h" | 9 #include "components/spellcheck/common/spellcheck_marker.h" |
| 10 #include "components/spellcheck/renderer/spellcheck_provider_test.h" | 10 #include "components/spellcheck/renderer/spellcheck_provider_test.h" |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 // only a line being edited by the user. | 32 // only a line being edited by the user. |
| 33 TEST_F(SpellCheckProviderTest, MultiLineText) { | 33 TEST_F(SpellCheckProviderTest, MultiLineText) { |
| 34 FakeTextCheckingCompletion completion; | 34 FakeTextCheckingCompletion completion; |
| 35 | 35 |
| 36 // Verify that the SpellCheckProvider class does not spellcheck empty text. | 36 // Verify that the SpellCheckProvider class does not spellcheck empty text. |
| 37 provider_.ResetResult(); | 37 provider_.ResetResult(); |
| 38 provider_.RequestTextChecking(base::string16(), &completion, | 38 provider_.RequestTextChecking(base::string16(), &completion, |
| 39 std::vector<SpellCheckMarker>()); | 39 std::vector<SpellCheckMarker>()); |
| 40 EXPECT_TRUE(provider_.text_.empty()); | 40 EXPECT_TRUE(provider_.text_.empty()); |
| 41 | 41 |
| 42 // Verify that the SpellCheckProvider class does not spellcheck text while we | |
| 43 // are typing a word. | |
| 44 provider_.ResetResult(); | |
| 45 provider_.RequestTextChecking(ASCIIToUTF16("First"), &completion, | |
| 46 std::vector<SpellCheckMarker>()); | |
| 47 EXPECT_TRUE(provider_.text_.empty()); | |
| 48 | |
| 49 // Verify that the SpellCheckProvider class spellcheck the first word when we | 42 // Verify that the SpellCheckProvider class spellcheck the first word when we |
| 50 // type a space key, i.e. when we finish typing a word. | 43 // stop typing after finishing the first word. |
| 51 provider_.ResetResult(); | 44 provider_.ResetResult(); |
| 52 provider_.RequestTextChecking(ASCIIToUTF16("First "), &completion, | 45 provider_.RequestTextChecking(ASCIIToUTF16("First"), &completion, |
| 53 std::vector<SpellCheckMarker>()); | 46 std::vector<SpellCheckMarker>()); |
| 54 EXPECT_EQ(ASCIIToUTF16("First "), provider_.text_); | 47 EXPECT_EQ(ASCIIToUTF16("First"), provider_.text_); |
| 55 | 48 |
| 56 // Verify that the SpellCheckProvider class spellcheck the first line when we | 49 // Verify that the SpellCheckProvider class spellcheck the first line when we |
| 57 // type a return key, i.e. when we finish typing a line. | 50 // type a return key, i.e. when we finish typing a line. |
| 58 provider_.ResetResult(); | 51 provider_.ResetResult(); |
| 59 provider_.RequestTextChecking(ASCIIToUTF16("First Second\n"), &completion, | 52 provider_.RequestTextChecking(ASCIIToUTF16("First Second\n"), &completion, |
| 60 std::vector<SpellCheckMarker>()); | 53 std::vector<SpellCheckMarker>()); |
| 61 EXPECT_EQ(ASCIIToUTF16("First Second\n"), provider_.text_); | 54 EXPECT_EQ(ASCIIToUTF16("First Second\n"), provider_.text_); |
| 62 | 55 |
| 63 // Verify that the SpellCheckProvider class spellcheck the lines when we | 56 // Verify that the SpellCheckProvider class spellcheck the lines when we |
| 64 // finish typing a word "Third" to the second line. | 57 // finish typing a word "Third" to the second line. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 std::vector<SpellCheckMarker>()); | 128 std::vector<SpellCheckMarker>()); |
| 136 EXPECT_EQ(0U, completion.cancellation_count_) << "Should finish checking \"" | 129 EXPECT_EQ(0U, completion.cancellation_count_) << "Should finish checking \"" |
| 137 << substring << "\""; | 130 << substring << "\""; |
| 138 | 131 |
| 139 provider_.RequestTextChecking(text, &completion, | 132 provider_.RequestTextChecking(text, &completion, |
| 140 std::vector<SpellCheckMarker>()); | 133 std::vector<SpellCheckMarker>()); |
| 141 EXPECT_EQ(0U, completion.cancellation_count_) << "Should finish checking \"" | 134 EXPECT_EQ(0U, completion.cancellation_count_) << "Should finish checking \"" |
| 142 << text << "\""; | 135 << text << "\""; |
| 143 } | 136 } |
| 144 | 137 |
| 145 // Tests that the SpellCheckProvider cancels spelling requests in the middle of | |
| 146 // a word. | |
| 147 TEST_F(SpellCheckProviderTest, CancelMidWordRequests) { | |
| 148 FakeTextCheckingCompletion completion; | |
| 149 provider_.RequestTextChecking(ASCIIToUTF16("hello "), &completion, | |
| 150 std::vector<SpellCheckMarker>()); | |
| 151 EXPECT_EQ(completion.completion_count_, 1U); | |
| 152 EXPECT_EQ(completion.cancellation_count_, 0U); | |
| 153 EXPECT_EQ(provider_.spelling_service_call_count_, 1U); | |
| 154 | |
| 155 provider_.RequestTextChecking(ASCIIToUTF16("hello world"), &completion, | |
| 156 std::vector<SpellCheckMarker>()); | |
| 157 EXPECT_EQ(completion.completion_count_, 2U); | |
| 158 EXPECT_EQ(completion.cancellation_count_, 1U); | |
| 159 EXPECT_EQ(provider_.spelling_service_call_count_, 1U); | |
| 160 | |
| 161 provider_.RequestTextChecking(ASCIIToUTF16("hello world."), &completion, | |
| 162 std::vector<SpellCheckMarker>()); | |
| 163 EXPECT_EQ(completion.completion_count_, 3U); | |
| 164 EXPECT_EQ(completion.cancellation_count_, 1U); | |
| 165 EXPECT_EQ(provider_.spelling_service_call_count_, 2U); | |
| 166 } | |
| 167 | |
| 168 } // namespace | 138 } // namespace |
| OLD | NEW |