| 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 "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h" | 10 #include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h" |
| 11 #include "chrome/common/spellcheck_messages.h" | 11 #include "chrome/common/spellcheck_messages.h" |
| 12 #include "chrome/common/spellcheck_result.h" | 12 #include "chrome/common/spellcheck_result.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 13 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/ui_test_utils.h" | 14 #include "chrome/test/base/ui_test_utils.h" |
| 15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 | 16 |
| 17 // Fake filter for testing, which stores sent messages and | 17 // Fake filter for testing, which stores sent messages and |
| 18 // allows verification by the test case. | 18 // allows verification by the test case. |
| 19 class TestingSpellCheckMessageFilter : public SpellCheckMessageFilterMac { | 19 class TestingSpellCheckMessageFilter : public SpellCheckMessageFilterMac { |
| 20 public: | 20 public: |
| 21 explicit TestingSpellCheckMessageFilter(base::MessageLoopForUI* loop) | 21 explicit TestingSpellCheckMessageFilter(base::MessageLoopForUI* loop) |
| 22 : SpellCheckMessageFilterMac(0), | 22 : SpellCheckMessageFilterMac(0), |
| 23 loop_(loop) { } | 23 loop_(loop) { } |
| 24 | 24 |
| 25 virtual bool Send(IPC::Message* message) override { | 25 bool Send(IPC::Message* message) override { |
| 26 sent_messages_.push_back(message); | 26 sent_messages_.push_back(message); |
| 27 loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 27 loop_->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); |
| 28 return true; | 28 return true; |
| 29 } | 29 } |
| 30 | 30 |
| 31 ScopedVector<IPC::Message> sent_messages_; | 31 ScopedVector<IPC::Message> sent_messages_; |
| 32 base::MessageLoopForUI* loop_; | 32 base::MessageLoopForUI* loop_; |
| 33 | 33 |
| 34 private: | 34 private: |
| 35 virtual ~TestingSpellCheckMessageFilter() {} | 35 ~TestingSpellCheckMessageFilter() override {} |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 typedef InProcessBrowserTest SpellCheckMessageFilterMacBrowserTest; | 38 typedef InProcessBrowserTest SpellCheckMessageFilterMacBrowserTest; |
| 39 | 39 |
| 40 // Uses browsertest to setup chrome threads. | 40 // Uses browsertest to setup chrome threads. |
| 41 IN_PROC_BROWSER_TEST_F(SpellCheckMessageFilterMacBrowserTest, | 41 IN_PROC_BROWSER_TEST_F(SpellCheckMessageFilterMacBrowserTest, |
| 42 SpellCheckReturnMessage) { | 42 SpellCheckReturnMessage) { |
| 43 scoped_refptr<TestingSpellCheckMessageFilter> target( | 43 scoped_refptr<TestingSpellCheckMessageFilter> target( |
| 44 new TestingSpellCheckMessageFilter(base::MessageLoopForUI::current())); | 44 new TestingSpellCheckMessageFilter(base::MessageLoopForUI::current())); |
| 45 | 45 |
| 46 SpellCheckHostMsg_RequestTextCheck to_be_received( | 46 SpellCheckHostMsg_RequestTextCheck to_be_received( |
| 47 123, 456, base::UTF8ToUTF16("zz."), std::vector<SpellCheckMarker>()); | 47 123, 456, base::UTF8ToUTF16("zz."), std::vector<SpellCheckMarker>()); |
| 48 target->OnMessageReceived(to_be_received); | 48 target->OnMessageReceived(to_be_received); |
| 49 | 49 |
| 50 base::MessageLoopForUI::current()->Run(); | 50 base::MessageLoopForUI::current()->Run(); |
| 51 EXPECT_EQ(1U, target->sent_messages_.size()); | 51 EXPECT_EQ(1U, target->sent_messages_.size()); |
| 52 | 52 |
| 53 SpellCheckMsg_RespondTextCheck::Param params; | 53 SpellCheckMsg_RespondTextCheck::Param params; |
| 54 bool ok = SpellCheckMsg_RespondTextCheck::Read( | 54 bool ok = SpellCheckMsg_RespondTextCheck::Read( |
| 55 target->sent_messages_[0], ¶ms); | 55 target->sent_messages_[0], ¶ms); |
| 56 std::vector<SpellCheckResult> sent_results = params.b; | 56 std::vector<SpellCheckResult> sent_results = params.b; |
| 57 | 57 |
| 58 EXPECT_TRUE(ok); | 58 EXPECT_TRUE(ok); |
| 59 EXPECT_EQ(1U, sent_results.size()); | 59 EXPECT_EQ(1U, sent_results.size()); |
| 60 EXPECT_EQ(sent_results[0].location, 0); | 60 EXPECT_EQ(sent_results[0].location, 0); |
| 61 EXPECT_EQ(sent_results[0].length, 2); | 61 EXPECT_EQ(sent_results[0].length, 2); |
| 62 EXPECT_EQ(sent_results[0].decoration, | 62 EXPECT_EQ(sent_results[0].decoration, |
| 63 SpellCheckResult::SPELLING); | 63 SpellCheckResult::SPELLING); |
| 64 } | 64 } |
| OLD | NEW |