| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 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 // Unit tests for |Misspelling| object. | 5 // Unit tests for |Misspelling| object. |
| 6 | 6 |
| 7 #include "chrome/browser/spellchecker/misspelling.h" | 7 #include "chrome/browser/spellchecker/misspelling.h" |
| 8 | 8 |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 | 13 |
| 14 TEST(MisspellingTest, SerializeTest) { | 14 TEST(MisspellingTest, SerializeTest) { |
| 15 Misspelling misspelling; | 15 Misspelling misspelling; |
| 16 misspelling.context = ASCIIToUTF16("How doe sit know"); | 16 misspelling.context = base::ASCIIToUTF16("How doe sit know"); |
| 17 misspelling.location = 4; | 17 misspelling.location = 4; |
| 18 misspelling.length = 7; | 18 misspelling.length = 7; |
| 19 misspelling.timestamp = base::Time::FromJsTime(42); | 19 misspelling.timestamp = base::Time::FromJsTime(42); |
| 20 misspelling.hash = 9001; | 20 misspelling.hash = 9001; |
| 21 misspelling.suggestions.push_back(ASCIIToUTF16("does it")); | 21 misspelling.suggestions.push_back(base::ASCIIToUTF16("does it")); |
| 22 | 22 |
| 23 scoped_ptr<base::Value> expected(base::JSONReader::Read( | 23 scoped_ptr<base::Value> expected(base::JSONReader::Read( |
| 24 "{\"originalText\": \"How doe sit know\"," | 24 "{\"originalText\": \"How doe sit know\"," |
| 25 "\"misspelledStart\": 4," | 25 "\"misspelledStart\": 4," |
| 26 "\"misspelledLength\": 7," | 26 "\"misspelledLength\": 7," |
| 27 "\"timestamp\": \"42\"," | 27 "\"timestamp\": \"42\"," |
| 28 "\"suggestionId\":\"9001\"," | 28 "\"suggestionId\":\"9001\"," |
| 29 "\"suggestions\": [\"does it\"]," | 29 "\"suggestions\": [\"does it\"]," |
| 30 "\"userActions\": [{\"actionType\": \"PENDING\"}]}")); | 30 "\"userActions\": [{\"actionType\": \"PENDING\"}]}")); |
| 31 | 31 |
| 32 scoped_ptr<base::DictionaryValue> serialized(misspelling.Serialize()); | 32 scoped_ptr<base::DictionaryValue> serialized(misspelling.Serialize()); |
| 33 EXPECT_TRUE(serialized->Equals(expected.get())); | 33 EXPECT_TRUE(serialized->Equals(expected.get())); |
| 34 } | 34 } |
| 35 | 35 |
| 36 TEST(MisspellingTest, GetMisspelledStringTest) { | 36 TEST(MisspellingTest, GetMisspelledStringTest) { |
| 37 Misspelling misspelling; | 37 Misspelling misspelling; |
| 38 misspelling.context = ASCIIToUTF16("How doe sit know"); | 38 misspelling.context = base::ASCIIToUTF16("How doe sit know"); |
| 39 misspelling.location = 4; | 39 misspelling.location = 4; |
| 40 misspelling.length = 7; | 40 misspelling.length = 7; |
| 41 EXPECT_EQ(ASCIIToUTF16("doe sit"), misspelling.GetMisspelledString()); | 41 EXPECT_EQ(base::ASCIIToUTF16("doe sit"), misspelling.GetMisspelledString()); |
| 42 | 42 |
| 43 misspelling.length = 0; | 43 misspelling.length = 0; |
| 44 EXPECT_EQ(base::string16(), misspelling.GetMisspelledString()); | 44 EXPECT_EQ(base::string16(), misspelling.GetMisspelledString()); |
| 45 | 45 |
| 46 misspelling.location = misspelling.context.length(); | 46 misspelling.location = misspelling.context.length(); |
| 47 misspelling.length = 7; | 47 misspelling.length = 7; |
| 48 EXPECT_EQ(base::string16(), misspelling.GetMisspelledString()); | 48 EXPECT_EQ(base::string16(), misspelling.GetMisspelledString()); |
| 49 | 49 |
| 50 misspelling.location = misspelling.context.length() + 1; | 50 misspelling.location = misspelling.context.length() + 1; |
| 51 EXPECT_EQ(base::string16(), misspelling.GetMisspelledString()); | 51 EXPECT_EQ(base::string16(), misspelling.GetMisspelledString()); |
| 52 } | 52 } |
| OLD | NEW |