| OLD | NEW |
| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/values.h" | 9 #include "base/values.h" |
| 10 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" | 10 #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 // Test output key: n = character with no styling, d = dim, m = match, u = url | 40 // 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. | 41 // u = 1, m = 2, d = 4. u+d = 5, etc. |
| 42 | 42 |
| 43 // 0123456789 | 43 // 0123456789 |
| 44 // mmmm | 44 // mmmm |
| 45 // + ddd | 45 // + ddd |
| 46 // = nmmmmndddn | 46 // = nmmmmndddn |
| 47 TEST(ExtensionOmniboxTest, DescriptionStylesSimple) { | 47 TEST(ExtensionOmniboxTest, DescriptionStylesSimple) { |
| 48 scoped_ptr<base::ListValue> list = | 48 std::unique_ptr<base::ListValue> list = |
| 49 ListBuilder() | 49 ListBuilder() |
| 50 .Append(42) | 50 .Append(42) |
| 51 .Append(ListBuilder() | 51 .Append(ListBuilder() |
| 52 .Append(DictionaryBuilder() | 52 .Append(DictionaryBuilder() |
| 53 .Set("content", "content") | 53 .Set("content", "content") |
| 54 .Set("description", "description") | 54 .Set("description", "description") |
| 55 .Set("descriptionStyles", | 55 .Set("descriptionStyles", |
| 56 ListBuilder() | 56 ListBuilder() |
| 57 .Append(DictionaryBuilder() | 57 .Append(DictionaryBuilder() |
| 58 .Set("type", "match") | 58 .Set("type", "match") |
| (...skipping 10 matching lines...) Expand all Loading... |
| 69 .Build()) | 69 .Build()) |
| 70 .Build(); | 70 .Build(); |
| 71 | 71 |
| 72 ACMatchClassifications styles_expected; | 72 ACMatchClassifications styles_expected; |
| 73 styles_expected.push_back(ACMatchClassification(0, kNone)); | 73 styles_expected.push_back(ACMatchClassification(0, kNone)); |
| 74 styles_expected.push_back(ACMatchClassification(1, kMatch)); | 74 styles_expected.push_back(ACMatchClassification(1, kMatch)); |
| 75 styles_expected.push_back(ACMatchClassification(5, kNone)); | 75 styles_expected.push_back(ACMatchClassification(5, kNone)); |
| 76 styles_expected.push_back(ACMatchClassification(6, kDim)); | 76 styles_expected.push_back(ACMatchClassification(6, kDim)); |
| 77 styles_expected.push_back(ACMatchClassification(9, kNone)); | 77 styles_expected.push_back(ACMatchClassification(9, kNone)); |
| 78 | 78 |
| 79 scoped_ptr<SendSuggestions::Params> params( | 79 std::unique_ptr<SendSuggestions::Params> params( |
| 80 SendSuggestions::Params::Create(*list)); | 80 SendSuggestions::Params::Create(*list)); |
| 81 EXPECT_TRUE(params); | 81 EXPECT_TRUE(params); |
| 82 ASSERT_FALSE(params->suggest_results.empty()); | 82 ASSERT_FALSE(params->suggest_results.empty()); |
| 83 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 83 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 84 params->suggest_results[0])); | 84 params->suggest_results[0])); |
| 85 | 85 |
| 86 // Same input, but swap the order. Ensure it still works. | 86 // Same input, but swap the order. Ensure it still works. |
| 87 scoped_ptr<base::ListValue> swap_list = | 87 std::unique_ptr<base::ListValue> swap_list = |
| 88 ListBuilder() | 88 ListBuilder() |
| 89 .Append(42) | 89 .Append(42) |
| 90 .Append(ListBuilder() | 90 .Append(ListBuilder() |
| 91 .Append(DictionaryBuilder() | 91 .Append(DictionaryBuilder() |
| 92 .Set("content", "content") | 92 .Set("content", "content") |
| 93 .Set("description", "description") | 93 .Set("description", "description") |
| 94 .Set("descriptionStyles", | 94 .Set("descriptionStyles", |
| 95 ListBuilder() | 95 ListBuilder() |
| 96 .Append(DictionaryBuilder() | 96 .Append(DictionaryBuilder() |
| 97 .Set("type", "dim") | 97 .Set("type", "dim") |
| 98 .Set("offset", 6) | 98 .Set("offset", 6) |
| 99 .Set("length", 3) | 99 .Set("length", 3) |
| 100 .Build()) | 100 .Build()) |
| 101 .Append(DictionaryBuilder() | 101 .Append(DictionaryBuilder() |
| 102 .Set("type", "match") | 102 .Set("type", "match") |
| 103 .Set("offset", 1) | 103 .Set("offset", 1) |
| 104 .Set("length", 4) | 104 .Set("length", 4) |
| 105 .Build()) | 105 .Build()) |
| 106 .Build()) | 106 .Build()) |
| 107 .Build()) | 107 .Build()) |
| 108 .Build()) | 108 .Build()) |
| 109 .Build(); | 109 .Build(); |
| 110 | 110 |
| 111 scoped_ptr<SendSuggestions::Params> swapped_params( | 111 std::unique_ptr<SendSuggestions::Params> swapped_params( |
| 112 SendSuggestions::Params::Create(*swap_list)); | 112 SendSuggestions::Params::Create(*swap_list)); |
| 113 EXPECT_TRUE(swapped_params); | 113 EXPECT_TRUE(swapped_params); |
| 114 ASSERT_FALSE(swapped_params->suggest_results.empty()); | 114 ASSERT_FALSE(swapped_params->suggest_results.empty()); |
| 115 CompareClassification( | 115 CompareClassification( |
| 116 styles_expected, | 116 styles_expected, |
| 117 StyleTypesToACMatchClassifications(swapped_params->suggest_results[0])); | 117 StyleTypesToACMatchClassifications(swapped_params->suggest_results[0])); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // 0123456789 | 120 // 0123456789 |
| 121 // uuuuu | 121 // uuuuu |
| 122 // + dd | 122 // + dd |
| 123 // + mm | 123 // + mm |
| 124 // + mmmm | 124 // + mmmm |
| 125 // + dd | 125 // + dd |
| 126 // = 3773unnnn66 | 126 // = 3773unnnn66 |
| 127 TEST(ExtensionOmniboxTest, DescriptionStylesCombine) { | 127 TEST(ExtensionOmniboxTest, DescriptionStylesCombine) { |
| 128 scoped_ptr<base::ListValue> list = | 128 std::unique_ptr<base::ListValue> list = |
| 129 ListBuilder() | 129 ListBuilder() |
| 130 .Append(42) | 130 .Append(42) |
| 131 .Append(ListBuilder() | 131 .Append(ListBuilder() |
| 132 .Append(DictionaryBuilder() | 132 .Append(DictionaryBuilder() |
| 133 .Set("content", "content") | 133 .Set("content", "content") |
| 134 .Set("description", "description") | 134 .Set("description", "description") |
| 135 .Set("descriptionStyles", | 135 .Set("descriptionStyles", |
| 136 ListBuilder() | 136 ListBuilder() |
| 137 .Append(DictionaryBuilder() | 137 .Append(DictionaryBuilder() |
| 138 .Set("type", "url") | 138 .Set("type", "url") |
| (...skipping 26 matching lines...) Expand all Loading... |
| 165 .Build(); | 165 .Build(); |
| 166 | 166 |
| 167 ACMatchClassifications styles_expected; | 167 ACMatchClassifications styles_expected; |
| 168 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch)); | 168 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch)); |
| 169 styles_expected.push_back(ACMatchClassification(1, kUrl | kMatch | kDim)); | 169 styles_expected.push_back(ACMatchClassification(1, kUrl | kMatch | kDim)); |
| 170 styles_expected.push_back(ACMatchClassification(3, kUrl | kMatch)); | 170 styles_expected.push_back(ACMatchClassification(3, kUrl | kMatch)); |
| 171 styles_expected.push_back(ACMatchClassification(4, kUrl)); | 171 styles_expected.push_back(ACMatchClassification(4, kUrl)); |
| 172 styles_expected.push_back(ACMatchClassification(5, kNone)); | 172 styles_expected.push_back(ACMatchClassification(5, kNone)); |
| 173 styles_expected.push_back(ACMatchClassification(9, kMatch | kDim)); | 173 styles_expected.push_back(ACMatchClassification(9, kMatch | kDim)); |
| 174 | 174 |
| 175 scoped_ptr<SendSuggestions::Params> params( | 175 std::unique_ptr<SendSuggestions::Params> params( |
| 176 SendSuggestions::Params::Create(*list)); | 176 SendSuggestions::Params::Create(*list)); |
| 177 EXPECT_TRUE(params); | 177 EXPECT_TRUE(params); |
| 178 ASSERT_FALSE(params->suggest_results.empty()); | 178 ASSERT_FALSE(params->suggest_results.empty()); |
| 179 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 179 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 180 params->suggest_results[0])); | 180 params->suggest_results[0])); |
| 181 | 181 |
| 182 // Try moving the "dim/match" style pair at offset 9. Output should be the | 182 // Try moving the "dim/match" style pair at offset 9. Output should be the |
| 183 // same. | 183 // same. |
| 184 scoped_ptr<base::ListValue> moved_list = | 184 std::unique_ptr<base::ListValue> moved_list = |
| 185 ListBuilder() | 185 ListBuilder() |
| 186 .Append(42) | 186 .Append(42) |
| 187 .Append(ListBuilder() | 187 .Append(ListBuilder() |
| 188 .Append(DictionaryBuilder() | 188 .Append(DictionaryBuilder() |
| 189 .Set("content", "content") | 189 .Set("content", "content") |
| 190 .Set("description", "description") | 190 .Set("description", "description") |
| 191 .Set("descriptionStyles", | 191 .Set("descriptionStyles", |
| 192 ListBuilder() | 192 ListBuilder() |
| 193 .Append(DictionaryBuilder() | 193 .Append(DictionaryBuilder() |
| 194 .Set("type", "url") | 194 .Set("type", "url") |
| (...skipping 18 matching lines...) Expand all Loading... |
| 213 .Append(DictionaryBuilder() | 213 .Append(DictionaryBuilder() |
| 214 .Set("type", "dim") | 214 .Set("type", "dim") |
| 215 .Set("offset", 1) | 215 .Set("offset", 1) |
| 216 .Set("length", 2) | 216 .Set("length", 2) |
| 217 .Build()) | 217 .Build()) |
| 218 .Build()) | 218 .Build()) |
| 219 .Build()) | 219 .Build()) |
| 220 .Build()) | 220 .Build()) |
| 221 .Build(); | 221 .Build(); |
| 222 | 222 |
| 223 scoped_ptr<SendSuggestions::Params> moved_params( | 223 std::unique_ptr<SendSuggestions::Params> moved_params( |
| 224 SendSuggestions::Params::Create(*moved_list)); | 224 SendSuggestions::Params::Create(*moved_list)); |
| 225 EXPECT_TRUE(moved_params); | 225 EXPECT_TRUE(moved_params); |
| 226 ASSERT_FALSE(moved_params->suggest_results.empty()); | 226 ASSERT_FALSE(moved_params->suggest_results.empty()); |
| 227 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 227 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 228 moved_params->suggest_results[0])); | 228 moved_params->suggest_results[0])); |
| 229 } | 229 } |
| 230 | 230 |
| 231 // 0123456789 | 231 // 0123456789 |
| 232 // uuuuu | 232 // uuuuu |
| 233 // + mmmmm | 233 // + mmmmm |
| 234 // + mmm | 234 // + mmm |
| 235 // + ddd | 235 // + ddd |
| 236 // + ddd | 236 // + ddd |
| 237 // = 77777nnnnn | 237 // = 77777nnnnn |
| 238 TEST(ExtensionOmniboxTest, DescriptionStylesCombine2) { | 238 TEST(ExtensionOmniboxTest, DescriptionStylesCombine2) { |
| 239 scoped_ptr<base::ListValue> list = | 239 std::unique_ptr<base::ListValue> list = |
| 240 ListBuilder() | 240 ListBuilder() |
| 241 .Append(42) | 241 .Append(42) |
| 242 .Append(ListBuilder() | 242 .Append(ListBuilder() |
| 243 .Append(DictionaryBuilder() | 243 .Append(DictionaryBuilder() |
| 244 .Set("content", "content") | 244 .Set("content", "content") |
| 245 .Set("description", "description") | 245 .Set("description", "description") |
| 246 .Set("descriptionStyles", | 246 .Set("descriptionStyles", |
| 247 ListBuilder() | 247 ListBuilder() |
| 248 .Append(DictionaryBuilder() | 248 .Append(DictionaryBuilder() |
| 249 .Set("type", "url") | 249 .Set("type", "url") |
| (...skipping 22 matching lines...) Expand all Loading... |
| 272 .Build()) | 272 .Build()) |
| 273 .Build()) | 273 .Build()) |
| 274 .Build()) | 274 .Build()) |
| 275 .Build()) | 275 .Build()) |
| 276 .Build(); | 276 .Build(); |
| 277 | 277 |
| 278 ACMatchClassifications styles_expected; | 278 ACMatchClassifications styles_expected; |
| 279 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch | kDim)); | 279 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch | kDim)); |
| 280 styles_expected.push_back(ACMatchClassification(5, kNone)); | 280 styles_expected.push_back(ACMatchClassification(5, kNone)); |
| 281 | 281 |
| 282 scoped_ptr<SendSuggestions::Params> params( | 282 std::unique_ptr<SendSuggestions::Params> params( |
| 283 SendSuggestions::Params::Create(*list)); | 283 SendSuggestions::Params::Create(*list)); |
| 284 EXPECT_TRUE(params); | 284 EXPECT_TRUE(params); |
| 285 ASSERT_FALSE(params->suggest_results.empty()); | 285 ASSERT_FALSE(params->suggest_results.empty()); |
| 286 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 286 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 287 params->suggest_results[0])); | 287 params->suggest_results[0])); |
| 288 } | 288 } |
| 289 | 289 |
| 290 // 0123456789 | 290 // 0123456789 |
| 291 // uuuuu | 291 // uuuuu |
| 292 // + mmmmm | 292 // + mmmmm |
| 293 // + mmm | 293 // + mmm |
| 294 // + ddd | 294 // + ddd |
| 295 // + ddd | 295 // + ddd |
| 296 // = 77777nnnnn | 296 // = 77777nnnnn |
| 297 TEST(ExtensionOmniboxTest, DefaultSuggestResult) { | 297 TEST(ExtensionOmniboxTest, DefaultSuggestResult) { |
| 298 // Default suggestions should not have a content parameter. | 298 // Default suggestions should not have a content parameter. |
| 299 scoped_ptr<base::ListValue> list = | 299 std::unique_ptr<base::ListValue> list = |
| 300 ListBuilder() | 300 ListBuilder() |
| 301 .Append(DictionaryBuilder() | 301 .Append(DictionaryBuilder() |
| 302 .Set("description", "description") | 302 .Set("description", "description") |
| 303 .Set("descriptionStyles", | 303 .Set("descriptionStyles", |
| 304 ListBuilder() | 304 ListBuilder() |
| 305 .Append(DictionaryBuilder() | 305 .Append(DictionaryBuilder() |
| 306 .Set("type", "url") | 306 .Set("type", "url") |
| 307 .Set("offset", 0) | 307 .Set("offset", 0) |
| 308 .Set("length", 5) | 308 .Set("length", 5) |
| 309 .Build()) | 309 .Build()) |
| (...skipping 14 matching lines...) Expand all Loading... |
| 324 .Build()) | 324 .Build()) |
| 325 .Append(DictionaryBuilder() | 325 .Append(DictionaryBuilder() |
| 326 .Set("type", "dim") | 326 .Set("type", "dim") |
| 327 .Set("offset", 0) | 327 .Set("offset", 0) |
| 328 .Set("length", 3) | 328 .Set("length", 3) |
| 329 .Build()) | 329 .Build()) |
| 330 .Build()) | 330 .Build()) |
| 331 .Build()) | 331 .Build()) |
| 332 .Build(); | 332 .Build(); |
| 333 | 333 |
| 334 scoped_ptr<SetDefaultSuggestion::Params> params( | 334 std::unique_ptr<SetDefaultSuggestion::Params> params( |
| 335 SetDefaultSuggestion::Params::Create(*list)); | 335 SetDefaultSuggestion::Params::Create(*list)); |
| 336 EXPECT_TRUE(params); | 336 EXPECT_TRUE(params); |
| 337 } | 337 } |
| 338 | 338 |
| 339 } // namespace extensions | 339 } // namespace extensions |
| OLD | NEW |