Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Side by Side Diff: chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc

Issue 10155006: Cancel unnecessary spellcheck requests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 string16 text_; 69 string16 text_;
70 std::vector<IPC::Message*> messages_; 70 std::vector<IPC::Message*> messages_;
71 }; 71 };
72 72
73 namespace { 73 namespace {
74 74
75 // A fake completion object for verification. 75 // A fake completion object for verification.
76 class FakeTextCheckingCompletion : public WebKit::WebTextCheckingCompletion { 76 class FakeTextCheckingCompletion : public WebKit::WebTextCheckingCompletion {
77 public: 77 public:
78 FakeTextCheckingCompletion() 78 FakeTextCheckingCompletion()
79 : completion_count_(0) { 79 : completion_count_(0),
80 cancellation_count_(0) {
80 } 81 }
81 82
82 virtual void didFinishCheckingText( 83 virtual void didFinishCheckingText(
83 const WebKit::WebVector<WebKit::WebTextCheckingResult>& results) 84 const WebKit::WebVector<WebKit::WebTextCheckingResult>& results)
84 OVERRIDE { 85 OVERRIDE {
85 ++completion_count_; 86 ++completion_count_;
86 last_results_ = results; 87 last_results_ = results;
87 } 88 }
88 89
90 virtual void didCancelCheckingText() OVERRIDE {
91 ++completion_count_;
92 ++cancellation_count_;
93 }
94
89 size_t completion_count_; 95 size_t completion_count_;
96 size_t cancellation_count_;
90 WebKit::WebVector<WebKit::WebTextCheckingResult> last_results_; 97 WebKit::WebVector<WebKit::WebTextCheckingResult> last_results_;
91 }; 98 };
92 99
93 class SpellCheckProviderTest : public testing::Test { 100 class SpellCheckProviderTest : public testing::Test {
94 public: 101 public:
95 SpellCheckProviderTest() { } 102 SpellCheckProviderTest() { }
96 virtual ~SpellCheckProviderTest() { } 103 virtual ~SpellCheckProviderTest() { }
97 104
98 protected: 105 protected:
99 TestingSpellCheckProvider provider_; 106 TestingSpellCheckProvider provider_;
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 169
163 // Verify that the SpellCheckProvider class spellcheck the second line when we 170 // Verify that the SpellCheckProvider class spellcheck the second line when we
164 // type a period. 171 // type a period.
165 provider_.ResetResult(); 172 provider_.ResetResult();
166 provider_.RequestTextChecking( 173 provider_.RequestTextChecking(
167 WebKit::WebString("First Second\nThird Fourth."), 0, &completion); 174 WebKit::WebString("First Second\nThird Fourth."), 0, &completion);
168 EXPECT_EQ(13, provider_.offset_); 175 EXPECT_EQ(13, provider_.offset_);
169 EXPECT_EQ(ASCIIToUTF16("Third Fourth."), provider_.text_); 176 EXPECT_EQ(ASCIIToUTF16("Third Fourth."), provider_.text_);
170 } 177 }
171 178
179 // Tests that the SpellCheckProvider class cancels incoming spellcheck requests
180 // when it does not need to handle them.
181 TEST_F(SpellCheckProviderTest,CancelUnnecessaryRequests) {
182 int document_tag = 123;
183 FakeTextCheckingCompletion completion;
184 provider_.RequestTextChecking(WebKit::WebString("hello."),
185 document_tag,
186 &completion);
187 EXPECT_EQ(completion.completion_count_, 1U);
188 EXPECT_EQ(completion.cancellation_count_, 0U);
189
190 // Test that the SpellCheckProvider class cancels an incoming request with the
191 // text same as above.
192 provider_.RequestTextChecking(WebKit::WebString("hello."),
193 document_tag,
194 &completion);
195 EXPECT_EQ(completion.completion_count_, 2U);
196 EXPECT_EQ(completion.cancellation_count_, 1U);
197
198 // Test that the SpellCheckProvider class cancels an incoming request that
199 // does not include any words.
200 provider_.RequestTextChecking(WebKit::WebString(":-)"),
201 document_tag,
202 &completion);
203 EXPECT_EQ(completion.completion_count_, 3U);
204 EXPECT_EQ(completion.cancellation_count_, 2U);
205 }
206
172 } // namespace 207 } // namespace
OLDNEW
« no previous file with comments | « chrome/renderer/spellchecker/spellcheck_provider.cc ('k') | chrome/renderer/spellchecker/spellcheck_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698