OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" | 9 #include "chrome/browser/spellchecker/spellcheck_platform_mac.h" |
10 #include "chrome/common/spellcheck_result.h" | 10 #include "chrome/common/spellcheck_result.h" |
11 #include "content/public/test/test_utils.h" | 11 #include "content/public/test/test_utils.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 class SpellcheckMacTest: public testing::Test { | 16 class SpellcheckMacTest: public testing::Test { |
17 public: | 17 public: |
18 SpellcheckMacTest() | 18 SpellcheckMacTest() |
19 : callback_(base::Bind(&SpellcheckMacTest::CompletionCallback, | 19 : callback_(base::Bind(&SpellcheckMacTest::CompletionCallback, |
20 base::Unretained(this))), | 20 base::Unretained(this))), |
21 callback_finished_(false), | 21 callback_finished_(false), |
22 message_loop_(MessageLoop::TYPE_UI) {} | 22 message_loop_(base::MessageLoop::TYPE_UI) {} |
23 | 23 |
24 void WaitForCallback() { | 24 void WaitForCallback() { |
25 content::RunMessageLoop(); | 25 content::RunMessageLoop(); |
26 } | 26 } |
27 | 27 |
28 std::vector<SpellCheckResult> results_; | 28 std::vector<SpellCheckResult> results_; |
29 spellcheck_mac::TextCheckCompleteCallback callback_; | 29 spellcheck_mac::TextCheckCompleteCallback callback_; |
30 bool callback_finished_; | 30 bool callback_finished_; |
31 | 31 |
32 private: | 32 private: |
33 void QuitMessageLoop() { | 33 void QuitMessageLoop() { |
34 CHECK(MessageLoop::current() == &message_loop_); | 34 CHECK(base::MessageLoop::current() == &message_loop_); |
35 MessageLoop::current()->Quit(); | 35 base::MessageLoop::current()->Quit(); |
36 } | 36 } |
37 | 37 |
38 void CompletionCallback(const std::vector<SpellCheckResult>& results) { | 38 void CompletionCallback(const std::vector<SpellCheckResult>& results) { |
39 results_ = results; | 39 results_ = results; |
40 callback_finished_ = true; | 40 callback_finished_ = true; |
41 message_loop_.PostTask(FROM_HERE, | 41 message_loop_.PostTask(FROM_HERE, |
42 base::Bind(&SpellcheckMacTest::QuitMessageLoop, | 42 base::Bind(&SpellcheckMacTest::QuitMessageLoop, |
43 base::Unretained(this))); | 43 base::Unretained(this))); |
44 } | 44 } |
45 | 45 |
46 MessageLoop message_loop_; | 46 base::MessageLoop message_loop_; |
47 spellcheck_mac::ScopedEnglishLanguageForTest scoped_language_; | 47 spellcheck_mac::ScopedEnglishLanguageForTest scoped_language_; |
48 }; | 48 }; |
49 | 49 |
50 // Tests that words are properly ignored. Currently only enabled on OS X as it | 50 // Tests that words are properly ignored. Currently only enabled on OS X as it |
51 // is the only platform to support ignoring words. Note that in this test, we | 51 // is the only platform to support ignoring words. Note that in this test, we |
52 // supply a non-zero doc_tag, in order to test that ignored words are matched to | 52 // supply a non-zero doc_tag, in order to test that ignored words are matched to |
53 // the correct document. | 53 // the correct document. |
54 TEST_F(SpellcheckMacTest, IgnoreWords_EN_US) { | 54 TEST_F(SpellcheckMacTest, IgnoreWords_EN_US) { |
55 const char* kTestCases[] = { | 55 const char* kTestCases[] = { |
56 "teh", | 56 "teh", |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // RequestTextCheck results. | 379 // RequestTextCheck results. |
380 TEST_F(SpellcheckMacTest, SpellCheckIgnoresOrthography) { | 380 TEST_F(SpellcheckMacTest, SpellCheckIgnoresOrthography) { |
381 string16 test_string(ASCIIToUTF16("Icland is awesome.")); | 381 string16 test_string(ASCIIToUTF16("Icland is awesome.")); |
382 spellcheck_mac::RequestTextCheck(0, test_string, callback_); | 382 spellcheck_mac::RequestTextCheck(0, test_string, callback_); |
383 WaitForCallback(); | 383 WaitForCallback(); |
384 EXPECT_TRUE(callback_finished_); | 384 EXPECT_TRUE(callback_finished_); |
385 EXPECT_EQ(1U, results_.size()); | 385 EXPECT_EQ(1U, results_.size()); |
386 } | 386 } |
387 | 387 |
388 } // namespace | 388 } // namespace |
OLD | NEW |