12a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Copyright (c) 2013 The Chromium Authors. All rights reserved. 22a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 32a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// found in the LICENSE file. 42a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "base/strings/utf_string_conversions.h" 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "chrome/renderer/spellchecker/custom_dictionary_engine.h" 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 82a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 92a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST(CustomDictionaryTest, HandlesEmptyWordWithInvalidSubstring) { 102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CustomDictionaryEngine engine; 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::set<std::string> custom_words; 122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) engine.Init(custom_words); 13a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) EXPECT_FALSE(engine.SpellCheckWord(base::string16().c_str(), 15, 23)); 142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TEST(CustomDictionaryTest, Basic) { 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) CustomDictionaryEngine engine; 185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(engine.SpellCheckWord(base::ASCIIToUTF16("helllo").c_str(), 195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 0, 6)); 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::set<std::string> custom_words; 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) custom_words.insert("helllo"); 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) engine.Init(custom_words); 235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(engine.SpellCheckWord(base::ASCIIToUTF16("helllo").c_str(), 245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 0, 6)); 2590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 267dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 277dbb3d5cf0c15f500944d211057644d6a2f37371Ben MurdochTEST(CustomDictionaryTest, HandlesNullCharacters) { 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::char16 data[4] = {'a', 0, 'b', 'c'}; 297dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch EXPECT_FALSE(CustomDictionaryEngine().SpellCheckWord(data, 1, 1)); 307dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch} 31