| Index: components/omnibox/suggestion_answer_unittest.cc
|
| diff --git a/components/omnibox/suggestion_answer_unittest.cc b/components/omnibox/suggestion_answer_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..83fb9f5d17f120a76aa390e81dbfa73e17849298
|
| --- /dev/null
|
| +++ b/components/omnibox/suggestion_answer_unittest.cc
|
| @@ -0,0 +1,61 @@
|
| +// Copyright 2014 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/omnibox/suggestion_answer.h"
|
| +
|
| +#include "base/strings/string16.h"
|
| +#include "base/strings/utf_string_conversions.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +TEST(SuggestionAnswerTest, CopiesAreEqual) {
|
| + SuggestionAnswer answer1;
|
| + SuggestionAnswer answer2(answer1);
|
| + EXPECT_EQ(answer1, answer2);
|
| +}
|
| +
|
| +TEST(SuggestionAnswerTest, EmptyAnswerIsInvalid) {
|
| + SuggestionAnswer answer;
|
| + EXPECT_FALSE(answer.is_valid());
|
| +}
|
| +
|
| +TEST(SuggestionAnswerTest, EmptyJsonIsInvalid) {
|
| + std::string json = "";
|
| + SuggestionAnswer answer;
|
| + EXPECT_FALSE(SuggestionAnswer::ParseAnswer(json, &answer));
|
| + EXPECT_FALSE(answer.is_valid());
|
| +}
|
| +
|
| +TEST(SuggestionAnswerTest, MalformedJsonIsInvalid) {
|
| + std::string json = "} malformed json {";
|
| + SuggestionAnswer answer;
|
| + EXPECT_FALSE(SuggestionAnswer::ParseAnswer(json, &answer));
|
| + EXPECT_FALSE(answer.is_valid());
|
| +}
|
| +
|
| +TEST(SuggestionAnswerTest, ExactlyTwoLinesRequired) {
|
| + std::string json =
|
| + "{ 'l': ["
|
| + " { 'il': { 't': [{ 't': 'text', 'tt': 8 }] } }, "
|
| + "] }";
|
| + SuggestionAnswer answer;
|
| + EXPECT_FALSE(SuggestionAnswer::ParseAnswer(json, &answer));
|
| + EXPECT_FALSE(answer.is_valid());
|
| +
|
| + json =
|
| + "{ 'l': ["
|
| + " { 'il': { 't': [{ 't': 'text', 'tt': 8 }] } }, "
|
| + " { 'il': { 't': [{ 't': 'other text', 'tt': 5 }] } }"
|
| + "] }";
|
| + EXPECT_FALSE(SuggestionAnswer::ParseAnswer(json, &answer));
|
| + EXPECT_FALSE(answer.is_valid());
|
| +
|
| + json =
|
| + "{ 'l': ["
|
| + " { 'il': { 't': [{ 't': 'text', 'tt': 8 }] } }, "
|
| + " { 'il': { 't': [{ 't': 'other text', 'tt': 5 }] } }"
|
| + " { 'il': { 't': [{ 't': 'yet more text', 'tt': 13 }] } }"
|
| + "] }";
|
| + EXPECT_FALSE(SuggestionAnswer::ParseAnswer(json, &answer));
|
| + EXPECT_FALSE(answer.is_valid());
|
| +}
|
|
|