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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 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 "components/omnibox/suggestion_answer.h"
6
7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 TEST(SuggestionAnswerTest, CopiesAreEqual) {
12 SuggestionAnswer answer1;
13 SuggestionAnswer answer2(answer1);
14 EXPECT_EQ(answer1, answer2);
15 }
16
17 TEST(SuggestionAnswerTest, EmptyAnswerIsInvalid) {
18 SuggestionAnswer answer;
19 EXPECT_FALSE(answer.is_valid());
20 }
21
22 TEST(SuggestionAnswerTest, EmptyJsonIsInvalid) {
23 std::string json = "";
24 SuggestionAnswer answer;
25 EXPECT_FALSE(SuggestionAnswer::ParseAnswer(json, &answer));
26 EXPECT_FALSE(answer.is_valid());
27 }
28
29 TEST(SuggestionAnswerTest, MalformedJsonIsInvalid) {
30 std::string json = "} malformed json {";
31 SuggestionAnswer answer;
32 EXPECT_FALSE(SuggestionAnswer::ParseAnswer(json, &answer));
33 EXPECT_FALSE(answer.is_valid());
34 }
35
36 TEST(SuggestionAnswerTest, ExactlyTwoLinesRequired) {
37 std::string json =
38 "{ 'l': ["
39 " { 'il': { 't': [{ 't': 'text', 'tt': 8 }] } }, "
40 "] }";
41 SuggestionAnswer answer;
42 EXPECT_FALSE(SuggestionAnswer::ParseAnswer(json, &answer));
43 EXPECT_FALSE(answer.is_valid());
44
45 json =
46 "{ 'l': ["
47 " { 'il': { 't': [{ 't': 'text', 'tt': 8 }] } }, "
48 " { 'il': { 't': [{ 't': 'other text', 'tt': 5 }] } }"
49 "] }";
50 EXPECT_FALSE(SuggestionAnswer::ParseAnswer(json, &answer));
51 EXPECT_FALSE(answer.is_valid());
52
53 json =
54 "{ 'l': ["
55 " { 'il': { 't': [{ 't': 'text', 'tt': 8 }] } }, "
56 " { 'il': { 't': [{ 't': 'other text', 'tt': 5 }] } }"
57 " { 'il': { 't': [{ 't': 'yet more text', 'tt': 13 }] } }"
58 "] }";
59 EXPECT_FALSE(SuggestionAnswer::ParseAnswer(json, &answer));
60 EXPECT_FALSE(answer.is_valid());
61 }
OLDNEW
« 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