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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc
===================================================================
--- chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc (revision 133081)
+++ chrome/renderer/spellchecker/spellcheck_provider_hunspell_unittest.cc (working copy)
@@ -76,7 +76,8 @@
class FakeTextCheckingCompletion : public WebKit::WebTextCheckingCompletion {
public:
FakeTextCheckingCompletion()
- : completion_count_(0) {
+ : completion_count_(0),
+ cancellation_count_(0) {
}
virtual void didFinishCheckingText(
@@ -86,7 +87,13 @@
last_results_ = results;
}
+ virtual void didCancelCheckingText() OVERRIDE {
+ ++completion_count_;
+ ++cancellation_count_;
+ }
+
size_t completion_count_;
+ size_t cancellation_count_;
WebKit::WebVector<WebKit::WebTextCheckingResult> last_results_;
};
@@ -169,4 +176,32 @@
EXPECT_EQ(ASCIIToUTF16("Third Fourth."), provider_.text_);
}
+// Tests that the SpellCheckProvider class cancels incoming spellcheck requests
+// when it does not need to handle them.
+TEST_F(SpellCheckProviderTest,CancelUnnecessaryRequests) {
+ int document_tag = 123;
+ FakeTextCheckingCompletion completion;
+ provider_.RequestTextChecking(WebKit::WebString("hello."),
+ document_tag,
+ &completion);
+ EXPECT_EQ(completion.completion_count_, 1U);
+ EXPECT_EQ(completion.cancellation_count_, 0U);
+
+ // Test that the SpellCheckProvider class cancels an incoming request with the
+ // text same as above.
+ provider_.RequestTextChecking(WebKit::WebString("hello."),
+ document_tag,
+ &completion);
+ EXPECT_EQ(completion.completion_count_, 2U);
+ EXPECT_EQ(completion.cancellation_count_, 1U);
+
+ // Test that the SpellCheckProvider class cancels an incoming request that
+ // does not include any words.
+ provider_.RequestTextChecking(WebKit::WebString(":-)"),
+ document_tag,
+ &completion);
+ EXPECT_EQ(completion.completion_count_, 3U);
+ EXPECT_EQ(completion.cancellation_count_, 2U);
+}
+
} // namespace
« 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