Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Unified Diff: components/omnibox/suggestion_answer_unittest.cc

Issue 669573005: Add a class to parse answer json. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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());
+}
« components/omnibox/suggestion_answer.h ('K') | « components/omnibox/suggestion_answer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698