1// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "chrome/browser/spellchecker/spellcheck_message_filter_mac.h" 6 7#include "base/strings/utf_string_conversions.h" 8#include "chrome/common/spellcheck_messages.h" 9#include "chrome/common/spellcheck_result.h" 10#include "content/public/browser/browser_thread.h" 11#include "ipc/ipc_message.h" 12#include "testing/gtest/include/gtest/gtest.h" 13 14namespace { 15 16TEST(SpellcheckMessageFilterMacTest, CombineResults) { 17 std::vector<SpellCheckResult> local_results; 18 std::vector<SpellCheckResult> remote_results; 19 base::string16 remote_suggestion = base::ASCIIToUTF16("remote"); 20 base::string16 local_suggestion = base::ASCIIToUTF16("local"); 21 22 // Remote-only result - must be flagged as GRAMMAR after combine 23 remote_results.push_back( 24 SpellCheckResult(SpellCheckResult::SPELLING, 0, 5)); 25 26 // Local-only result - must be discarded after combine 27 local_results.push_back( 28 SpellCheckResult(SpellCheckResult::SPELLING, 10, 5)); 29 30 // local & remote result - must be flagged SPELLING, uses remote suggestion. 31 SpellCheckResult result(SpellCheckResult::SPELLING, 20, 5, local_suggestion); 32 local_results.push_back(result); 33 result.replacement = remote_suggestion; 34 remote_results.push_back(result); 35 36 SpellCheckMessageFilterMac::CombineResults(&remote_results, local_results); 37 38 ASSERT_EQ(2U, remote_results.size()); 39 EXPECT_EQ(SpellCheckResult::GRAMMAR, remote_results[0].decoration); 40 EXPECT_EQ(0, remote_results[0].location); 41 EXPECT_EQ(SpellCheckResult::SPELLING, remote_results[1].decoration); 42 EXPECT_EQ(20, remote_results[1].location); 43 EXPECT_EQ(remote_suggestion, remote_results[1].replacement); 44} 45 46TEST(SpellCheckMessageFilterMacTest, TestOverrideThread) { 47 static const uint32 kSpellcheckMessages[] = { 48 SpellCheckHostMsg_RequestTextCheck::ID, 49 }; 50 scoped_refptr<SpellCheckMessageFilterMac> filter( 51 new SpellCheckMessageFilterMac(0)); 52 content::BrowserThread::ID thread; 53 IPC::Message message; 54 for (size_t i = 0; i < arraysize(kSpellcheckMessages); ++i) { 55 message.SetHeaderValues( 56 0, kSpellcheckMessages[i], IPC::Message::PRIORITY_NORMAL); 57 thread = content::BrowserThread::IO; 58 filter->OverrideThreadForMessage(message, &thread); 59 EXPECT_EQ(content::BrowserThread::UI, thread); 60 } 61} 62 63} // namespace 64