| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 scoped_ptr<SendSuggestions::Params> params( |
| 80 SendSuggestions::Params::Create(*list)); | 80 SendSuggestions::Params::Create(*list)); |
| 81 EXPECT_TRUE(params); | 81 EXPECT_TRUE(params); |
| 82 EXPECT_TRUE(params->suggest_results[0].get()); | 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 scoped_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 scoped_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 EXPECT_TRUE(swapped_params->suggest_results[0].get()); | 114 ASSERT_FALSE(swapped_params->suggest_results.empty()); |
| 115 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 115 CompareClassification( |
| 116 *swapped_params->suggest_results[0])); | 116 styles_expected, |
| 117 StyleTypesToACMatchClassifications(swapped_params->suggest_results[0])); |
| 117 } | 118 } |
| 118 | 119 |
| 119 // 0123456789 | 120 // 0123456789 |
| 120 // uuuuu | 121 // uuuuu |
| 121 // + dd | 122 // + dd |
| 122 // + mm | 123 // + mm |
| 123 // + mmmm | 124 // + mmmm |
| 124 // + dd | 125 // + dd |
| 125 // = 3773unnnn66 | 126 // = 3773unnnn66 |
| 126 TEST(ExtensionOmniboxTest, DescriptionStylesCombine) { | 127 TEST(ExtensionOmniboxTest, DescriptionStylesCombine) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch)); | 168 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch)); |
| 168 styles_expected.push_back(ACMatchClassification(1, kUrl | kMatch | kDim)); | 169 styles_expected.push_back(ACMatchClassification(1, kUrl | kMatch | kDim)); |
| 169 styles_expected.push_back(ACMatchClassification(3, kUrl | kMatch)); | 170 styles_expected.push_back(ACMatchClassification(3, kUrl | kMatch)); |
| 170 styles_expected.push_back(ACMatchClassification(4, kUrl)); | 171 styles_expected.push_back(ACMatchClassification(4, kUrl)); |
| 171 styles_expected.push_back(ACMatchClassification(5, kNone)); | 172 styles_expected.push_back(ACMatchClassification(5, kNone)); |
| 172 styles_expected.push_back(ACMatchClassification(9, kMatch | kDim)); | 173 styles_expected.push_back(ACMatchClassification(9, kMatch | kDim)); |
| 173 | 174 |
| 174 scoped_ptr<SendSuggestions::Params> params( | 175 scoped_ptr<SendSuggestions::Params> params( |
| 175 SendSuggestions::Params::Create(*list)); | 176 SendSuggestions::Params::Create(*list)); |
| 176 EXPECT_TRUE(params); | 177 EXPECT_TRUE(params); |
| 177 EXPECT_TRUE(params->suggest_results[0].get()); | 178 ASSERT_FALSE(params->suggest_results.empty()); |
| 178 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 179 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 179 *params->suggest_results[0])); | 180 params->suggest_results[0])); |
| 180 | 181 |
| 181 // 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 |
| 182 // same. | 183 // same. |
| 183 scoped_ptr<base::ListValue> moved_list = | 184 scoped_ptr<base::ListValue> moved_list = |
| 184 ListBuilder() | 185 ListBuilder() |
| 185 .Append(42) | 186 .Append(42) |
| 186 .Append(ListBuilder() | 187 .Append(ListBuilder() |
| 187 .Append(DictionaryBuilder() | 188 .Append(DictionaryBuilder() |
| 188 .Set("content", "content") | 189 .Set("content", "content") |
| 189 .Set("description", "description") | 190 .Set("description", "description") |
| (...skipping 25 matching lines...) Expand all Loading... |
| 215 .Set("length", 2) | 216 .Set("length", 2) |
| 216 .Build()) | 217 .Build()) |
| 217 .Build()) | 218 .Build()) |
| 218 .Build()) | 219 .Build()) |
| 219 .Build()) | 220 .Build()) |
| 220 .Build(); | 221 .Build(); |
| 221 | 222 |
| 222 scoped_ptr<SendSuggestions::Params> moved_params( | 223 scoped_ptr<SendSuggestions::Params> moved_params( |
| 223 SendSuggestions::Params::Create(*moved_list)); | 224 SendSuggestions::Params::Create(*moved_list)); |
| 224 EXPECT_TRUE(moved_params); | 225 EXPECT_TRUE(moved_params); |
| 225 EXPECT_TRUE(moved_params->suggest_results[0].get()); | 226 ASSERT_FALSE(moved_params->suggest_results.empty()); |
| 226 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 227 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 227 *moved_params->suggest_results[0])); | 228 moved_params->suggest_results[0])); |
| 228 } | 229 } |
| 229 | 230 |
| 230 // 0123456789 | 231 // 0123456789 |
| 231 // uuuuu | 232 // uuuuu |
| 232 // + mmmmm | 233 // + mmmmm |
| 233 // + mmm | 234 // + mmm |
| 234 // + ddd | 235 // + ddd |
| 235 // + ddd | 236 // + ddd |
| 236 // = 77777nnnnn | 237 // = 77777nnnnn |
| 237 TEST(ExtensionOmniboxTest, DescriptionStylesCombine2) { | 238 TEST(ExtensionOmniboxTest, DescriptionStylesCombine2) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 .Build()) | 275 .Build()) |
| 275 .Build(); | 276 .Build(); |
| 276 | 277 |
| 277 ACMatchClassifications styles_expected; | 278 ACMatchClassifications styles_expected; |
| 278 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch | kDim)); | 279 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch | kDim)); |
| 279 styles_expected.push_back(ACMatchClassification(5, kNone)); | 280 styles_expected.push_back(ACMatchClassification(5, kNone)); |
| 280 | 281 |
| 281 scoped_ptr<SendSuggestions::Params> params( | 282 scoped_ptr<SendSuggestions::Params> params( |
| 282 SendSuggestions::Params::Create(*list)); | 283 SendSuggestions::Params::Create(*list)); |
| 283 EXPECT_TRUE(params); | 284 EXPECT_TRUE(params); |
| 284 EXPECT_TRUE(params->suggest_results[0].get()); | 285 ASSERT_FALSE(params->suggest_results.empty()); |
| 285 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 286 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 286 *params->suggest_results[0])); | 287 params->suggest_results[0])); |
| 287 } | 288 } |
| 288 | 289 |
| 289 // 0123456789 | 290 // 0123456789 |
| 290 // uuuuu | 291 // uuuuu |
| 291 // + mmmmm | 292 // + mmmmm |
| 292 // + mmm | 293 // + mmm |
| 293 // + ddd | 294 // + ddd |
| 294 // + ddd | 295 // + ddd |
| 295 // = 77777nnnnn | 296 // = 77777nnnnn |
| 296 TEST(ExtensionOmniboxTest, DefaultSuggestResult) { | 297 TEST(ExtensionOmniboxTest, DefaultSuggestResult) { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 .Build()) | 330 .Build()) |
| 330 .Build()) | 331 .Build()) |
| 331 .Build(); | 332 .Build(); |
| 332 | 333 |
| 333 scoped_ptr<SetDefaultSuggestion::Params> params( | 334 scoped_ptr<SetDefaultSuggestion::Params> params( |
| 334 SetDefaultSuggestion::Params::Create(*list)); | 335 SetDefaultSuggestion::Params::Create(*list)); |
| 335 EXPECT_TRUE(params); | 336 EXPECT_TRUE(params); |
| 336 } | 337 } |
| 337 | 338 |
| 338 } // namespace extensions | 339 } // namespace extensions |
| OLD | NEW |