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

Side by Side Diff: chrome/browser/extensions/api/omnibox/omnibox_unittest.cc

Issue 12314164: Modified Omnibox extension api to use JSON Schema Compiler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: kalman's requests Created 7 years, 9 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/values.h" 5 #include "base/values.h"
6 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" 6 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
7 #include "chrome/common/extensions/api/omnibox.h"
7 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
8 #include "testing/platform_test.h" 9 #include "testing/platform_test.h"
9 10
10 namespace extensions { 11 namespace extensions {
11 12
12 namespace { 13 namespace {
13 14
14 const int kNone = ACMatchClassification::NONE; 15 const int kNone = ACMatchClassification::NONE;
15 const int kUrl = ACMatchClassification::URL; 16 const int kUrl = ACMatchClassification::URL;
16 const int kMatch = ACMatchClassification::MATCH; 17 const int kMatch = ACMatchClassification::MATCH;
(...skipping 21 matching lines...) Expand all
38 } // namespace 39 } // namespace
39 40
40 // Test output key: n = character with no styling, d = dim, m = match, u = url 41 // Test output key: n = character with no styling, d = dim, m = match, u = url
41 // u = 1, m = 2, d = 4. u+d = 5, etc. 42 // u = 1, m = 2, d = 4. u+d = 5, etc.
42 43
43 // 0123456789 44 // 0123456789
44 // mmmm 45 // mmmm
45 // + ddd 46 // + ddd
46 // = nmmmmndddn 47 // = nmmmmndddn
47 TEST(ExtensionOmniboxTest, DescriptionStylesSimple) { 48 TEST(ExtensionOmniboxTest, DescriptionStylesSimple) {
48 ListValue styles_value; 49 scoped_ptr<ListValue> styles_value(new ListValue);
49 AppendStyle("match", 1, 4, &styles_value); 50 AppendStyle("match", 1, 4, styles_value.get());
50 AppendStyle("dim", 6, 3, &styles_value); 51 AppendStyle("dim", 6, 3, styles_value.get());
52
53 scoped_ptr<DictionaryValue> dict(new DictionaryValue);
54 dict->SetStringWithoutPathExpansion("content", "content");
55 dict->SetStringWithoutPathExpansion("description", "dscription");
56 dict->SetWithoutPathExpansion("descriptionStyles", styles_value.release());
not at google - send to devlin 2013/03/16 00:04:25 you'll probably find chrome/common/extensions/valu
Aaron Jacobs 2013/03/21 21:59:55 Done.
57
58 scoped_ptr<ListValue> dict_list(new ListValue);
59 dict_list->Set(0, dict.release());
60
61 ListValue list;
62 // Set the request_id
63 list.Set(0, new base::FundamentalValue(42));
64 list.Set(1, dict_list.release());
51 65
52 ACMatchClassifications styles_expected; 66 ACMatchClassifications styles_expected;
53 styles_expected.push_back(ACMatchClassification(0, kNone)); 67 styles_expected.push_back(ACMatchClassification(0, kNone));
54 styles_expected.push_back(ACMatchClassification(1, kMatch)); 68 styles_expected.push_back(ACMatchClassification(1, kMatch));
55 styles_expected.push_back(ACMatchClassification(5, kNone)); 69 styles_expected.push_back(ACMatchClassification(5, kNone));
56 styles_expected.push_back(ACMatchClassification(6, kDim)); 70 styles_expected.push_back(ACMatchClassification(6, kDim));
57 styles_expected.push_back(ACMatchClassification(9, kNone)); 71 styles_expected.push_back(ACMatchClassification(9, kNone));
58 72
59 ExtensionOmniboxSuggestion suggestions; 73 scoped_ptr<api::omnibox::SendSuggestions::Params> params(
60 suggestions.description.resize(10); 74 api::omnibox::SendSuggestions::Params::Create(list));
not at google - send to devlin 2013/03/16 00:04:25 for consistency, use same typedefs in the api file
Aaron Jacobs 2013/03/21 21:59:55 Done.
61 EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value)); 75 EXPECT_TRUE(params);
62 CompareClassification(styles_expected, suggestions.description_styles); 76 EXPECT_TRUE(params->suggest_results[0].get());
not at google - send to devlin 2013/03/16 00:04:25 .get() unnecessary
Aaron Jacobs 2013/03/21 21:59:55 I can't remove it (it's a linked_ptr, not a scoped
77 CompareClassification(styles_expected, StyleTypesToACMatchClassifications(
78 *params->suggest_results[0]));
63 79
64 // Same input, but swap the order. Ensure it still works. 80 // Same input, but swap the order. Ensure it still works.
65 styles_value.Clear(); 81 scoped_ptr<ListValue> swapped_styles_value(new ListValue);
66 AppendStyle("dim", 6, 3, &styles_value); 82 AppendStyle("dim", 6, 3, swapped_styles_value.get());
67 AppendStyle("match", 1, 4, &styles_value); 83 AppendStyle("match", 1, 4, swapped_styles_value.get());
68 EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value)); 84
69 CompareClassification(styles_expected, suggestions.description_styles); 85 scoped_ptr<DictionaryValue> swapped_dict(new DictionaryValue);
86 swapped_dict->SetStringWithoutPathExpansion("content", "content");
87 swapped_dict->SetStringWithoutPathExpansion("description", "dscription");
88 swapped_dict->SetWithoutPathExpansion("descriptionStyles",
89 swapped_styles_value.release());
90
91 scoped_ptr<ListValue> swapped_dict_list(new ListValue);
92 swapped_dict_list->Set(0, swapped_dict.release());
93
94 ListValue swapped_list;
95 // Set the request_id
96 swapped_list.Set(0, new base::FundamentalValue(42));
97 swapped_list.Set(1, swapped_dict_list.release());
98
99 scoped_ptr<api::omnibox::SendSuggestions::Params> swapped_params(
100 api::omnibox::SendSuggestions::Params::Create(swapped_list));
101 EXPECT_TRUE(swapped_params);
102 EXPECT_TRUE(swapped_params->suggest_results[0].get());
103 CompareClassification(styles_expected, StyleTypesToACMatchClassifications(
104 *swapped_params->suggest_results[0]));
70 } 105 }
71 106
72 // 0123456789 107 // 0123456789
73 // uuuuu 108 // uuuuu
74 // + dd 109 // + dd
75 // + mm 110 // + mm
76 // + mmmm 111 // + mmmm
77 // + dd 112 // + dd
78 // = 3773unnnn66 113 // = 3773unnnn66
79 TEST(ExtensionOmniboxTest, DescriptionStylesCombine) { 114 TEST(ExtensionOmniboxTest, DescriptionStylesCombine) {
80 ListValue styles_value; 115 scoped_ptr<ListValue> styles_value(new ListValue);
81 AppendStyle("url", 0, 5, &styles_value); 116 AppendStyle("url", 0, 5, styles_value.get());
82 AppendStyle("dim", 9, 2, &styles_value); 117 AppendStyle("dim", 9, 2, styles_value.get());
83 AppendStyle("match", 9, 2, &styles_value); 118 AppendStyle("match", 9, 2, styles_value.get());
84 AppendStyle("match", 0, 4, &styles_value); 119 AppendStyle("match", 0, 4, styles_value.get());
85 AppendStyle("dim", 1, 2, &styles_value); 120 AppendStyle("dim", 1, 2, styles_value.get());
121
122 scoped_ptr<DictionaryValue> dict(new DictionaryValue);
123 dict->SetStringWithoutPathExpansion("content", "content");
124 dict->SetStringWithoutPathExpansion("description", "dscription");
125 dict->SetWithoutPathExpansion("descriptionStyles", styles_value.release());
126
127 scoped_ptr<ListValue> dict_list(new ListValue);
128 dict_list->Set(0, dict.release());
129
130 ListValue list;
131 // Set the request_id
132 list.Set(0, new base::FundamentalValue(42));
133 list.Set(1, dict_list.release());
86 134
87 ACMatchClassifications styles_expected; 135 ACMatchClassifications styles_expected;
88 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch)); 136 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch));
89 styles_expected.push_back(ACMatchClassification(1, kUrl | kMatch | kDim)); 137 styles_expected.push_back(ACMatchClassification(1, kUrl | kMatch | kDim));
90 styles_expected.push_back(ACMatchClassification(3, kUrl | kMatch)); 138 styles_expected.push_back(ACMatchClassification(3, kUrl | kMatch));
91 styles_expected.push_back(ACMatchClassification(4, kUrl)); 139 styles_expected.push_back(ACMatchClassification(4, kUrl));
92 styles_expected.push_back(ACMatchClassification(5, kNone)); 140 styles_expected.push_back(ACMatchClassification(5, kNone));
93 styles_expected.push_back(ACMatchClassification(9, kMatch | kDim)); 141 styles_expected.push_back(ACMatchClassification(9, kMatch | kDim));
94 142
95 ExtensionOmniboxSuggestion suggestions; 143 scoped_ptr<api::omnibox::SendSuggestions::Params> params(
96 suggestions.description.resize(10); 144 api::omnibox::SendSuggestions::Params::Create(list));
97 EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value)); 145 EXPECT_TRUE(params);
98 CompareClassification(styles_expected, suggestions.description_styles); 146 EXPECT_TRUE(params->suggest_results[0].get());
147 CompareClassification(styles_expected, StyleTypesToACMatchClassifications(
148 *params->suggest_results[0]));
99 149
100 // Try moving the "dim/match" style pair at offset 9. Output should be the 150 // Try moving the "dim/match" style pair at offset 9. Output should be the
101 // same. 151 // same.
102 styles_value.Clear(); 152 scoped_ptr<ListValue> moved_styles_value(new ListValue);
103 AppendStyle("url", 0, 5, &styles_value); 153 AppendStyle("url", 0, 5, moved_styles_value.get());
104 AppendStyle("match", 0, 4, &styles_value); 154 AppendStyle("match", 0, 4, moved_styles_value.get());
105 AppendStyle("dim", 9, 2, &styles_value); 155 AppendStyle("dim", 9, 2, moved_styles_value.get());
106 AppendStyle("match", 9, 2, &styles_value); 156 AppendStyle("match", 9, 2, moved_styles_value.get());
107 AppendStyle("dim", 1, 2, &styles_value); 157 AppendStyle("dim", 1, 2, moved_styles_value.get());
108 EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value)); 158
109 CompareClassification(styles_expected, suggestions.description_styles); 159 scoped_ptr<DictionaryValue> moved_dict(new DictionaryValue);
160 moved_dict->SetStringWithoutPathExpansion("content", "content");
161 moved_dict->SetStringWithoutPathExpansion("description", "dscription");
162 moved_dict->SetWithoutPathExpansion("descriptionStyles",
163 moved_styles_value.release());
164
165 scoped_ptr<ListValue> moved_dict_list(new ListValue);
166 moved_dict_list->Set(0, moved_dict.release());
167
168 ListValue moved_list;
169 // Set the request_id
170 moved_list.Set(0, new base::FundamentalValue(42));
171 moved_list.Set(1, moved_dict_list.release());
172
173 scoped_ptr<api::omnibox::SendSuggestions::Params> moved_params(
174 api::omnibox::SendSuggestions::Params::Create(moved_list));
175 EXPECT_TRUE(moved_params);
176 EXPECT_TRUE(moved_params->suggest_results[0].get());
177 CompareClassification(styles_expected, StyleTypesToACMatchClassifications(
178 *moved_params->suggest_results[0]));
110 } 179 }
111 180
112 // 0123456789 181 // 0123456789
113 // uuuuu 182 // uuuuu
114 // + mmmmm 183 // + mmmmm
115 // + mmm 184 // + mmm
116 // + ddd 185 // + ddd
117 // + ddd 186 // + ddd
118 // = 77777nnnnn 187 // = 77777nnnnn
119 TEST(ExtensionOmniboxTest, DescriptionStylesCombine2) { 188 TEST(ExtensionOmniboxTest, DescriptionStylesCombine2) {
120 ListValue styles_value; 189 scoped_ptr<ListValue> styles_value(new ListValue);
121 AppendStyle("url", 0, 5, &styles_value); 190 AppendStyle("url", 0, 5, styles_value.get());
122 AppendStyle("match", 0, 5, &styles_value); 191 AppendStyle("match", 0, 5, styles_value.get());
123 AppendStyle("match", 0, 3, &styles_value); 192 AppendStyle("match", 0, 3, styles_value.get());
124 AppendStyle("dim", 2, 3, &styles_value); 193 AppendStyle("dim", 2, 3, styles_value.get());
125 AppendStyle("dim", 0, 3, &styles_value); 194 AppendStyle("dim", 0, 3, styles_value.get());
195
196 scoped_ptr<DictionaryValue> dict(new DictionaryValue);
197 dict->SetStringWithoutPathExpansion("content", "content");
198 dict->SetStringWithoutPathExpansion("description", "dscription");
199 dict->SetWithoutPathExpansion("descriptionStyles", styles_value.release());
200
201 scoped_ptr<ListValue> dict_list(new ListValue);
202 dict_list->Set(0, dict.release());
203
204 ListValue list;
205 // Set the request_id
206 list.Set(0, new base::FundamentalValue(42));
207 list.Set(1, dict_list.release());
126 208
127 ACMatchClassifications styles_expected; 209 ACMatchClassifications styles_expected;
128 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch | kDim)); 210 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch | kDim));
129 styles_expected.push_back(ACMatchClassification(5, kNone)); 211 styles_expected.push_back(ACMatchClassification(5, kNone));
130 212
131 ExtensionOmniboxSuggestion suggestions; 213 scoped_ptr<api::omnibox::SendSuggestions::Params> params(
132 suggestions.description.resize(10); 214 api::omnibox::SendSuggestions::Params::Create(list));
133 EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value)); 215 EXPECT_TRUE(params);
134 CompareClassification(styles_expected, suggestions.description_styles); 216 EXPECT_TRUE(params->suggest_results[0].get());
217 CompareClassification(styles_expected, StyleTypesToACMatchClassifications(
218 *params->suggest_results[0]));
135 } 219 }
136 220
137 } // namespace extensions 221 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698