| 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 30 matching lines...) Expand all Loading... |
| 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 scoped_ptr<base::ListValue> list = |
| 49 ListBuilder() | 49 ListBuilder() |
| 50 .Append(42) | 50 .Append(42) |
| 51 .Append(std::move(ListBuilder().Append(std::move( | 51 .Append(ListBuilder() |
| 52 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 std::move( | 56 ListBuilder() |
| 57 ListBuilder() | 57 .Append(DictionaryBuilder() |
| 58 .Append(std::move(DictionaryBuilder() | 58 .Set("type", "match") |
| 59 .Set("type", "match") | 59 .Set("offset", 1) |
| 60 .Set("offset", 1) | 60 .Set("length", 4) |
| 61 .Set("length", 4))) | 61 .Build()) |
| 62 .Append(std::move(DictionaryBuilder() | 62 .Append(DictionaryBuilder() |
| 63 .Set("type", "dim") | 63 .Set("type", "dim") |
| 64 .Set("offset", 6) | 64 .Set("offset", 6) |
| 65 .Set("length", 3))))))))) | 65 .Set("length", 3) |
| 66 .Build()) |
| 67 .Build()) |
| 68 .Build()) |
| 69 .Build()) |
| 66 .Build(); | 70 .Build(); |
| 67 | 71 |
| 68 ACMatchClassifications styles_expected; | 72 ACMatchClassifications styles_expected; |
| 69 styles_expected.push_back(ACMatchClassification(0, kNone)); | 73 styles_expected.push_back(ACMatchClassification(0, kNone)); |
| 70 styles_expected.push_back(ACMatchClassification(1, kMatch)); | 74 styles_expected.push_back(ACMatchClassification(1, kMatch)); |
| 71 styles_expected.push_back(ACMatchClassification(5, kNone)); | 75 styles_expected.push_back(ACMatchClassification(5, kNone)); |
| 72 styles_expected.push_back(ACMatchClassification(6, kDim)); | 76 styles_expected.push_back(ACMatchClassification(6, kDim)); |
| 73 styles_expected.push_back(ACMatchClassification(9, kNone)); | 77 styles_expected.push_back(ACMatchClassification(9, kNone)); |
| 74 | 78 |
| 75 scoped_ptr<SendSuggestions::Params> params( | 79 scoped_ptr<SendSuggestions::Params> params( |
| 76 SendSuggestions::Params::Create(*list)); | 80 SendSuggestions::Params::Create(*list)); |
| 77 EXPECT_TRUE(params); | 81 EXPECT_TRUE(params); |
| 78 EXPECT_TRUE(params->suggest_results[0].get()); | 82 EXPECT_TRUE(params->suggest_results[0].get()); |
| 79 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 83 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 80 *params->suggest_results[0])); | 84 *params->suggest_results[0])); |
| 81 | 85 |
| 82 // Same input, but swap the order. Ensure it still works. | 86 // Same input, but swap the order. Ensure it still works. |
| 83 scoped_ptr<base::ListValue> swap_list = | 87 scoped_ptr<base::ListValue> swap_list = |
| 84 ListBuilder() | 88 ListBuilder() |
| 85 .Append(42) | 89 .Append(42) |
| 86 .Append(std::move(ListBuilder().Append(std::move( | 90 .Append(ListBuilder() |
| 87 DictionaryBuilder() | 91 .Append(DictionaryBuilder() |
| 88 .Set("content", "content") | 92 .Set("content", "content") |
| 89 .Set("description", "description") | 93 .Set("description", "description") |
| 90 .Set("descriptionStyles", | 94 .Set("descriptionStyles", |
| 91 std::move( | 95 ListBuilder() |
| 92 ListBuilder() | 96 .Append(DictionaryBuilder() |
| 93 .Append(std::move(DictionaryBuilder() | 97 .Set("type", "dim") |
| 94 .Set("type", "dim") | 98 .Set("offset", 6) |
| 95 .Set("offset", 6) | 99 .Set("length", 3) |
| 96 .Set("length", 3))) | 100 .Build()) |
| 97 .Append(std::move(DictionaryBuilder() | 101 .Append(DictionaryBuilder() |
| 98 .Set("type", "match") | 102 .Set("type", "match") |
| 99 .Set("offset", 1) | 103 .Set("offset", 1) |
| 100 .Set("length", 4))))))))) | 104 .Set("length", 4) |
| 105 .Build()) |
| 106 .Build()) |
| 107 .Build()) |
| 108 .Build()) |
| 101 .Build(); | 109 .Build(); |
| 102 | 110 |
| 103 scoped_ptr<SendSuggestions::Params> swapped_params( | 111 scoped_ptr<SendSuggestions::Params> swapped_params( |
| 104 SendSuggestions::Params::Create(*swap_list)); | 112 SendSuggestions::Params::Create(*swap_list)); |
| 105 EXPECT_TRUE(swapped_params); | 113 EXPECT_TRUE(swapped_params); |
| 106 EXPECT_TRUE(swapped_params->suggest_results[0].get()); | 114 EXPECT_TRUE(swapped_params->suggest_results[0].get()); |
| 107 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 115 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 108 *swapped_params->suggest_results[0])); | 116 *swapped_params->suggest_results[0])); |
| 109 } | 117 } |
| 110 | 118 |
| 111 // 0123456789 | 119 // 0123456789 |
| 112 // uuuuu | 120 // uuuuu |
| 113 // + dd | 121 // + dd |
| 114 // + mm | 122 // + mm |
| 115 // + mmmm | 123 // + mmmm |
| 116 // + dd | 124 // + dd |
| 117 // = 3773unnnn66 | 125 // = 3773unnnn66 |
| 118 TEST(ExtensionOmniboxTest, DescriptionStylesCombine) { | 126 TEST(ExtensionOmniboxTest, DescriptionStylesCombine) { |
| 119 scoped_ptr<base::ListValue> list = | 127 scoped_ptr<base::ListValue> list = |
| 120 ListBuilder() | 128 ListBuilder() |
| 121 .Append(42) | 129 .Append(42) |
| 122 .Append(std::move(ListBuilder().Append(std::move( | 130 .Append(ListBuilder() |
| 123 DictionaryBuilder() | 131 .Append(DictionaryBuilder() |
| 124 .Set("content", "content") | 132 .Set("content", "content") |
| 125 .Set("description", "description") | 133 .Set("description", "description") |
| 126 .Set("descriptionStyles", | 134 .Set("descriptionStyles", |
| 127 std::move( | 135 ListBuilder() |
| 128 ListBuilder() | 136 .Append(DictionaryBuilder() |
| 129 .Append(std::move(DictionaryBuilder() | 137 .Set("type", "url") |
| 130 .Set("type", "url") | 138 .Set("offset", 0) |
| 131 .Set("offset", 0) | 139 .Set("length", 5) |
| 132 .Set("length", 5))) | 140 .Build()) |
| 133 .Append(std::move(DictionaryBuilder() | 141 .Append(DictionaryBuilder() |
| 134 .Set("type", "dim") | 142 .Set("type", "dim") |
| 135 .Set("offset", 9) | 143 .Set("offset", 9) |
| 136 .Set("length", 2))) | 144 .Set("length", 2) |
| 137 .Append(std::move(DictionaryBuilder() | 145 .Build()) |
| 138 .Set("type", "match") | 146 .Append(DictionaryBuilder() |
| 139 .Set("offset", 9) | 147 .Set("type", "match") |
| 140 .Set("length", 2))) | 148 .Set("offset", 9) |
| 141 .Append(std::move(DictionaryBuilder() | 149 .Set("length", 2) |
| 142 .Set("type", "match") | 150 .Build()) |
| 143 .Set("offset", 0) | 151 .Append(DictionaryBuilder() |
| 144 .Set("length", 4))) | 152 .Set("type", "match") |
| 145 .Append(std::move(DictionaryBuilder() | 153 .Set("offset", 0) |
| 146 .Set("type", "dim") | 154 .Set("length", 4) |
| 147 .Set("offset", 1) | 155 .Build()) |
| 148 .Set("length", 2))))))))) | 156 .Append(DictionaryBuilder() |
| 157 .Set("type", "dim") |
| 158 .Set("offset", 1) |
| 159 .Set("length", 2) |
| 160 .Build()) |
| 161 .Build()) |
| 162 .Build()) |
| 163 .Build()) |
| 149 .Build(); | 164 .Build(); |
| 150 | 165 |
| 151 ACMatchClassifications styles_expected; | 166 ACMatchClassifications styles_expected; |
| 152 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch)); | 167 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch)); |
| 153 styles_expected.push_back(ACMatchClassification(1, kUrl | kMatch | kDim)); | 168 styles_expected.push_back(ACMatchClassification(1, kUrl | kMatch | kDim)); |
| 154 styles_expected.push_back(ACMatchClassification(3, kUrl | kMatch)); | 169 styles_expected.push_back(ACMatchClassification(3, kUrl | kMatch)); |
| 155 styles_expected.push_back(ACMatchClassification(4, kUrl)); | 170 styles_expected.push_back(ACMatchClassification(4, kUrl)); |
| 156 styles_expected.push_back(ACMatchClassification(5, kNone)); | 171 styles_expected.push_back(ACMatchClassification(5, kNone)); |
| 157 styles_expected.push_back(ACMatchClassification(9, kMatch | kDim)); | 172 styles_expected.push_back(ACMatchClassification(9, kMatch | kDim)); |
| 158 | 173 |
| 159 scoped_ptr<SendSuggestions::Params> params( | 174 scoped_ptr<SendSuggestions::Params> params( |
| 160 SendSuggestions::Params::Create(*list)); | 175 SendSuggestions::Params::Create(*list)); |
| 161 EXPECT_TRUE(params); | 176 EXPECT_TRUE(params); |
| 162 EXPECT_TRUE(params->suggest_results[0].get()); | 177 EXPECT_TRUE(params->suggest_results[0].get()); |
| 163 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 178 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 164 *params->suggest_results[0])); | 179 *params->suggest_results[0])); |
| 165 | 180 |
| 166 // Try moving the "dim/match" style pair at offset 9. Output should be the | 181 // Try moving the "dim/match" style pair at offset 9. Output should be the |
| 167 // same. | 182 // same. |
| 168 scoped_ptr<base::ListValue> moved_list = | 183 scoped_ptr<base::ListValue> moved_list = |
| 169 ListBuilder() | 184 ListBuilder() |
| 170 .Append(42) | 185 .Append(42) |
| 171 .Append(std::move(ListBuilder().Append(std::move( | 186 .Append(ListBuilder() |
| 172 DictionaryBuilder() | 187 .Append(DictionaryBuilder() |
| 173 .Set("content", "content") | 188 .Set("content", "content") |
| 174 .Set("description", "description") | 189 .Set("description", "description") |
| 175 .Set("descriptionStyles", | 190 .Set("descriptionStyles", |
| 176 std::move( | 191 ListBuilder() |
| 177 ListBuilder() | 192 .Append(DictionaryBuilder() |
| 178 .Append(std::move(DictionaryBuilder() | 193 .Set("type", "url") |
| 179 .Set("type", "url") | 194 .Set("offset", 0) |
| 180 .Set("offset", 0) | 195 .Set("length", 5) |
| 181 .Set("length", 5))) | 196 .Build()) |
| 182 .Append(std::move(DictionaryBuilder() | 197 .Append(DictionaryBuilder() |
| 183 .Set("type", "match") | 198 .Set("type", "match") |
| 184 .Set("offset", 0) | 199 .Set("offset", 0) |
| 185 .Set("length", 4))) | 200 .Set("length", 4) |
| 186 .Append(std::move(DictionaryBuilder() | 201 .Build()) |
| 187 .Set("type", "dim") | 202 .Append(DictionaryBuilder() |
| 188 .Set("offset", 9) | 203 .Set("type", "dim") |
| 189 .Set("length", 2))) | 204 .Set("offset", 9) |
| 190 .Append(std::move(DictionaryBuilder() | 205 .Set("length", 2) |
| 191 .Set("type", "match") | 206 .Build()) |
| 192 .Set("offset", 9) | 207 .Append(DictionaryBuilder() |
| 193 .Set("length", 2))) | 208 .Set("type", "match") |
| 194 .Append(std::move(DictionaryBuilder() | 209 .Set("offset", 9) |
| 195 .Set("type", "dim") | 210 .Set("length", 2) |
| 196 .Set("offset", 1) | 211 .Build()) |
| 197 .Set("length", 2))))))))) | 212 .Append(DictionaryBuilder() |
| 213 .Set("type", "dim") |
| 214 .Set("offset", 1) |
| 215 .Set("length", 2) |
| 216 .Build()) |
| 217 .Build()) |
| 218 .Build()) |
| 219 .Build()) |
| 198 .Build(); | 220 .Build(); |
| 199 | 221 |
| 200 scoped_ptr<SendSuggestions::Params> moved_params( | 222 scoped_ptr<SendSuggestions::Params> moved_params( |
| 201 SendSuggestions::Params::Create(*moved_list)); | 223 SendSuggestions::Params::Create(*moved_list)); |
| 202 EXPECT_TRUE(moved_params); | 224 EXPECT_TRUE(moved_params); |
| 203 EXPECT_TRUE(moved_params->suggest_results[0].get()); | 225 EXPECT_TRUE(moved_params->suggest_results[0].get()); |
| 204 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 226 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 205 *moved_params->suggest_results[0])); | 227 *moved_params->suggest_results[0])); |
| 206 } | 228 } |
| 207 | 229 |
| 208 // 0123456789 | 230 // 0123456789 |
| 209 // uuuuu | 231 // uuuuu |
| 210 // + mmmmm | 232 // + mmmmm |
| 211 // + mmm | 233 // + mmm |
| 212 // + ddd | 234 // + ddd |
| 213 // + ddd | 235 // + ddd |
| 214 // = 77777nnnnn | 236 // = 77777nnnnn |
| 215 TEST(ExtensionOmniboxTest, DescriptionStylesCombine2) { | 237 TEST(ExtensionOmniboxTest, DescriptionStylesCombine2) { |
| 216 scoped_ptr<base::ListValue> list = | 238 scoped_ptr<base::ListValue> list = |
| 217 ListBuilder() | 239 ListBuilder() |
| 218 .Append(42) | 240 .Append(42) |
| 219 .Append(std::move(ListBuilder().Append(std::move( | 241 .Append(ListBuilder() |
| 220 DictionaryBuilder() | 242 .Append(DictionaryBuilder() |
| 221 .Set("content", "content") | 243 .Set("content", "content") |
| 222 .Set("description", "description") | 244 .Set("description", "description") |
| 223 .Set("descriptionStyles", | 245 .Set("descriptionStyles", |
| 224 std::move( | 246 ListBuilder() |
| 225 ListBuilder() | 247 .Append(DictionaryBuilder() |
| 226 .Append(std::move(DictionaryBuilder() | 248 .Set("type", "url") |
| 227 .Set("type", "url") | 249 .Set("offset", 0) |
| 228 .Set("offset", 0) | 250 .Set("length", 5) |
| 229 .Set("length", 5))) | 251 .Build()) |
| 230 .Append(std::move(DictionaryBuilder() | 252 .Append(DictionaryBuilder() |
| 231 .Set("type", "match") | 253 .Set("type", "match") |
| 232 .Set("offset", 0) | 254 .Set("offset", 0) |
| 233 .Set("length", 5))) | 255 .Set("length", 5) |
| 234 .Append(std::move(DictionaryBuilder() | 256 .Build()) |
| 235 .Set("type", "match") | 257 .Append(DictionaryBuilder() |
| 236 .Set("offset", 0) | 258 .Set("type", "match") |
| 237 .Set("length", 3))) | 259 .Set("offset", 0) |
| 238 .Append(std::move(DictionaryBuilder() | 260 .Set("length", 3) |
| 239 .Set("type", "dim") | 261 .Build()) |
| 240 .Set("offset", 2) | 262 .Append(DictionaryBuilder() |
| 241 .Set("length", 3))) | 263 .Set("type", "dim") |
| 242 .Append(std::move(DictionaryBuilder() | 264 .Set("offset", 2) |
| 243 .Set("type", "dim") | 265 .Set("length", 3) |
| 244 .Set("offset", 0) | 266 .Build()) |
| 245 .Set("length", 3))))))))) | 267 .Append(DictionaryBuilder() |
| 268 .Set("type", "dim") |
| 269 .Set("offset", 0) |
| 270 .Set("length", 3) |
| 271 .Build()) |
| 272 .Build()) |
| 273 .Build()) |
| 274 .Build()) |
| 246 .Build(); | 275 .Build(); |
| 247 | 276 |
| 248 ACMatchClassifications styles_expected; | 277 ACMatchClassifications styles_expected; |
| 249 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch | kDim)); | 278 styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch | kDim)); |
| 250 styles_expected.push_back(ACMatchClassification(5, kNone)); | 279 styles_expected.push_back(ACMatchClassification(5, kNone)); |
| 251 | 280 |
| 252 scoped_ptr<SendSuggestions::Params> params( | 281 scoped_ptr<SendSuggestions::Params> params( |
| 253 SendSuggestions::Params::Create(*list)); | 282 SendSuggestions::Params::Create(*list)); |
| 254 EXPECT_TRUE(params); | 283 EXPECT_TRUE(params); |
| 255 EXPECT_TRUE(params->suggest_results[0].get()); | 284 EXPECT_TRUE(params->suggest_results[0].get()); |
| 256 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( | 285 CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| 257 *params->suggest_results[0])); | 286 *params->suggest_results[0])); |
| 258 } | 287 } |
| 259 | 288 |
| 260 // 0123456789 | 289 // 0123456789 |
| 261 // uuuuu | 290 // uuuuu |
| 262 // + mmmmm | 291 // + mmmmm |
| 263 // + mmm | 292 // + mmm |
| 264 // + ddd | 293 // + ddd |
| 265 // + ddd | 294 // + ddd |
| 266 // = 77777nnnnn | 295 // = 77777nnnnn |
| 267 TEST(ExtensionOmniboxTest, DefaultSuggestResult) { | 296 TEST(ExtensionOmniboxTest, DefaultSuggestResult) { |
| 268 // Default suggestions should not have a content parameter. | 297 // Default suggestions should not have a content parameter. |
| 269 scoped_ptr<base::ListValue> list = | 298 scoped_ptr<base::ListValue> list = |
| 270 ListBuilder() | 299 ListBuilder() |
| 271 .Append(std::move( | 300 .Append(DictionaryBuilder() |
| 272 DictionaryBuilder() | 301 .Set("description", "description") |
| 273 .Set("description", "description") | 302 .Set("descriptionStyles", |
| 274 .Set( | 303 ListBuilder() |
| 275 "descriptionStyles", | 304 .Append(DictionaryBuilder() |
| 276 std::move( | 305 .Set("type", "url") |
| 277 ListBuilder() | 306 .Set("offset", 0) |
| 278 .Append(std::move( | 307 .Set("length", 5) |
| 279 DictionaryBuilder() | 308 .Build()) |
| 280 .Set("type", "url") | 309 .Append(DictionaryBuilder() |
| 281 .Set("offset", 0) | 310 .Set("type", "match") |
| 282 .Set("length", 5))) | 311 .Set("offset", 0) |
| 283 .Append(std::move(DictionaryBuilder() | 312 .Set("length", 5) |
| 284 .Set("type", "match") | 313 .Build()) |
| 285 .Set("offset", 0) | 314 .Append(DictionaryBuilder() |
| 286 .Set("length", 5))) | 315 .Set("type", "match") |
| 287 .Append(std::move(DictionaryBuilder() | 316 .Set("offset", 0) |
| 288 .Set("type", "match") | 317 .Set("length", 3) |
| 289 .Set("offset", 0) | 318 .Build()) |
| 290 .Set("length", 3))) | 319 .Append(DictionaryBuilder() |
| 291 .Append(std::move(DictionaryBuilder() | 320 .Set("type", "dim") |
| 292 .Set("type", "dim") | 321 .Set("offset", 2) |
| 293 .Set("offset", 2) | 322 .Set("length", 3) |
| 294 .Set("length", 3))) | 323 .Build()) |
| 295 .Append(std::move(DictionaryBuilder() | 324 .Append(DictionaryBuilder() |
| 296 .Set("type", "dim") | 325 .Set("type", "dim") |
| 297 .Set("offset", 0) | 326 .Set("offset", 0) |
| 298 .Set("length", 3))))))) | 327 .Set("length", 3) |
| 328 .Build()) |
| 329 .Build()) |
| 330 .Build()) |
| 299 .Build(); | 331 .Build(); |
| 300 | 332 |
| 301 scoped_ptr<SetDefaultSuggestion::Params> params( | 333 scoped_ptr<SetDefaultSuggestion::Params> params( |
| 302 SetDefaultSuggestion::Params::Create(*list)); | 334 SetDefaultSuggestion::Params::Create(*list)); |
| 303 EXPECT_TRUE(params); | 335 EXPECT_TRUE(params); |
| 304 } | 336 } |
| 305 | 337 |
| 306 } // namespace extensions | 338 } // namespace extensions |
| OLD | NEW |