| 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/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/common/spellcheck_messages.h" | 9 #include "chrome/common/spellcheck_messages.h" |
| 10 #include "chrome/renderer/spellchecker/spellcheck_provider.h" | 10 #include "chrome/renderer/spellchecker/spellcheck_provider.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 text_check_completions_.Lookup(identifier); | 51 text_check_completions_.Lookup(identifier); |
| 52 if (!completion) { | 52 if (!completion) { |
| 53 ResetResult(); | 53 ResetResult(); |
| 54 return; | 54 return; |
| 55 } | 55 } |
| 56 offset_ = offset; | 56 offset_ = offset; |
| 57 text_.assign(text); | 57 text_.assign(text); |
| 58 text_check_completions_.Remove(identifier); | 58 text_check_completions_.Remove(identifier); |
| 59 completion->didFinishCheckingText( | 59 completion->didFinishCheckingText( |
| 60 std::vector<WebKit::WebTextCheckingResult>()); | 60 std::vector<WebKit::WebTextCheckingResult>()); |
| 61 last_request_ = text; |
| 61 } | 62 } |
| 62 | 63 |
| 63 void ResetResult() { | 64 void ResetResult() { |
| 64 offset_ = -1; | 65 offset_ = -1; |
| 65 text_.clear(); | 66 text_.clear(); |
| 66 } | 67 } |
| 67 | 68 |
| 68 int offset_; | 69 int offset_; |
| 69 string16 text_; | 70 string16 text_; |
| 70 std::vector<IPC::Message*> messages_; | 71 std::vector<IPC::Message*> messages_; |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 EXPECT_EQ(ASCIIToUTF16("First "), provider_.text_); | 145 EXPECT_EQ(ASCIIToUTF16("First "), provider_.text_); |
| 145 | 146 |
| 146 // Verify that the SpellCheckProvider class spellcheck the first line when we | 147 // Verify that the SpellCheckProvider class spellcheck the first line when we |
| 147 // type a return key, i.e. when we finish typing a line. | 148 // type a return key, i.e. when we finish typing a line. |
| 148 provider_.ResetResult(); | 149 provider_.ResetResult(); |
| 149 provider_.RequestTextChecking(WebKit::WebString("First Second\n"), 0, | 150 provider_.RequestTextChecking(WebKit::WebString("First Second\n"), 0, |
| 150 &completion); | 151 &completion); |
| 151 EXPECT_EQ(0, provider_.offset_); | 152 EXPECT_EQ(0, provider_.offset_); |
| 152 EXPECT_EQ(ASCIIToUTF16("First Second\n"), provider_.text_); | 153 EXPECT_EQ(ASCIIToUTF16("First Second\n"), provider_.text_); |
| 153 | 154 |
| 154 // Verify that the SpellCheckProvider class spellcheck the second line when we | 155 // Verify that the SpellCheckProvider class spellcheck the lines when we |
| 155 // finish typing a word "Third" to the second line. | 156 // finish typing a word "Third" to the second line. |
| 156 provider_.ResetResult(); | 157 provider_.ResetResult(); |
| 157 provider_.RequestTextChecking(WebKit::WebString("First Second\nThird "), 0, | 158 provider_.RequestTextChecking(WebKit::WebString("First Second\nThird "), 0, |
| 158 &completion); | 159 &completion); |
| 159 EXPECT_EQ(13, provider_.offset_); | 160 EXPECT_EQ(0, provider_.offset_); |
| 160 EXPECT_EQ(ASCIIToUTF16("Third "), provider_.text_); | 161 EXPECT_EQ(ASCIIToUTF16("First Second\nThird "), provider_.text_); |
| 161 | 162 |
| 162 // Verify that the SpellCheckProvider class does not send a spellcheck request | 163 // Verify that the SpellCheckProvider class does not send a spellcheck request |
| 163 // when a user inserts whitespace characters. | 164 // when a user inserts whitespace characters. |
| 164 provider_.ResetResult(); | 165 provider_.ResetResult(); |
| 165 provider_.RequestTextChecking(WebKit::WebString("First Second\nThird "), 0, | 166 provider_.RequestTextChecking(WebKit::WebString("First Second\nThird "), 0, |
| 166 &completion); | 167 &completion); |
| 167 EXPECT_EQ(-1, provider_.offset_); | 168 EXPECT_EQ(-1, provider_.offset_); |
| 168 EXPECT_TRUE(provider_.text_.empty()); | 169 EXPECT_TRUE(provider_.text_.empty()); |
| 169 | 170 |
| 170 // Verify that the SpellCheckProvider class spellcheck the second line when we | 171 // Verify that the SpellCheckProvider class spellcheck the lines when we type |
| 171 // type a period. | 172 // a period. |
| 172 provider_.ResetResult(); | 173 provider_.ResetResult(); |
| 173 provider_.RequestTextChecking( | 174 provider_.RequestTextChecking( |
| 174 WebKit::WebString("First Second\nThird Fourth."), 0, &completion); | 175 WebKit::WebString("First Second\nThird Fourth."), 0, &completion); |
| 175 EXPECT_EQ(13, provider_.offset_); | 176 EXPECT_EQ(0, provider_.offset_); |
| 176 EXPECT_EQ(ASCIIToUTF16("Third Fourth."), provider_.text_); | 177 EXPECT_EQ(ASCIIToUTF16("First Second\nThird Fourth."), provider_.text_); |
| 177 } | 178 } |
| 178 | 179 |
| 179 // Tests that the SpellCheckProvider class cancels incoming spellcheck requests | 180 // Tests that the SpellCheckProvider class cancels incoming spellcheck requests |
| 180 // when it does not need to handle them. | 181 // when it does not need to handle them. |
| 181 TEST_F(SpellCheckProviderTest,CancelUnnecessaryRequests) { | 182 TEST_F(SpellCheckProviderTest,CancelUnnecessaryRequests) { |
| 182 int document_tag = 123; | 183 int document_tag = 123; |
| 183 FakeTextCheckingCompletion completion; | 184 FakeTextCheckingCompletion completion; |
| 184 provider_.RequestTextChecking(WebKit::WebString("hello."), | 185 provider_.RequestTextChecking(WebKit::WebString("hello."), |
| 185 document_tag, | 186 document_tag, |
| 186 &completion); | 187 &completion); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 198 // Test that the SpellCheckProvider class cancels an incoming request that | 199 // Test that the SpellCheckProvider class cancels an incoming request that |
| 199 // does not include any words. | 200 // does not include any words. |
| 200 provider_.RequestTextChecking(WebKit::WebString(":-)"), | 201 provider_.RequestTextChecking(WebKit::WebString(":-)"), |
| 201 document_tag, | 202 document_tag, |
| 202 &completion); | 203 &completion); |
| 203 EXPECT_EQ(completion.completion_count_, 3U); | 204 EXPECT_EQ(completion.completion_count_, 3U); |
| 204 EXPECT_EQ(completion.cancellation_count_, 2U); | 205 EXPECT_EQ(completion.cancellation_count_, 2U); |
| 205 } | 206 } |
| 206 | 207 |
| 207 } // namespace | 208 } // namespace |
| OLD | NEW |