Chromium Code Reviews| Index: chrome/browser/extensions/api/omnibox/omnibox_unittest.cc |
| diff --git a/chrome/browser/extensions/api/omnibox/omnibox_unittest.cc b/chrome/browser/extensions/api/omnibox/omnibox_unittest.cc |
| index b75bc620482b7aa77aaf99a9adcdf9cfcae1a12f..55fdc9ff995404f39ea07409a146b8ed5b87778c 100644 |
| --- a/chrome/browser/extensions/api/omnibox/omnibox_unittest.cc |
| +++ b/chrome/browser/extensions/api/omnibox/omnibox_unittest.cc |
| @@ -4,11 +4,16 @@ |
| #include "base/values.h" |
| #include "chrome/browser/extensions/api/omnibox/omnibox_api.h" |
| +#include "chrome/common/extensions/api/omnibox.h" |
| +#include "chrome/common/extensions/value_builder.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| #include "testing/platform_test.h" |
| namespace extensions { |
| +namespace omnibox = api::omnibox; |
| +namespace SendSuggestions = omnibox::SendSuggestions; |
| + |
| namespace { |
| const int kNone = ACMatchClassification::NONE; |
| @@ -16,16 +21,6 @@ const int kUrl = ACMatchClassification::URL; |
| const int kMatch = ACMatchClassification::MATCH; |
| const int kDim = ACMatchClassification::DIM; |
| -void AppendStyle(const std::string& type, |
| - int offset, int length, |
| - ListValue* styles) { |
| - DictionaryValue* style = new DictionaryValue; |
| - style->SetString("type", type); |
| - style->SetInteger("offset", offset); |
| - style->SetInteger("length", length); |
| - styles->Append(style); |
| -} |
| - |
| void CompareClassification(const ACMatchClassifications& expected, |
| const ACMatchClassifications& actual) { |
| EXPECT_EQ(expected.size(), actual.size()); |
| @@ -45,9 +40,18 @@ void CompareClassification(const ACMatchClassifications& expected, |
| // + ddd |
| // = nmmmmndddn |
| TEST(ExtensionOmniboxTest, DescriptionStylesSimple) { |
| - ListValue styles_value; |
| - AppendStyle("match", 1, 4, &styles_value); |
| - AppendStyle("dim", 6, 3, &styles_value); |
| + ListValue* list = ListBuilder().Append(42).Append(ListBuilder().Append( |
|
not at google - send to devlin
2013/03/22 17:33:30
looks like a memory leak? you're releasing this (a
Aaron Jacobs
2013/03/22 19:54:15
Done.
|
| + DictionaryBuilder().Set("content", "content") |
| + .Set("description", "description") |
| + .Set("descriptionStyles", ListBuilder() |
| + .Append(DictionaryBuilder() |
| + .Set("type", "match") |
| + .Set("offset", 1) |
| + .Set("length", 4)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "dim") |
| + .Set("offset", 6) |
| + .Set("length", 3))))).Build().release(); |
|
not at google - send to devlin
2013/03/22 17:33:30
using some indentation here would be nice to make
Aaron Jacobs
2013/03/22 19:54:15
Done.
|
| ACMatchClassifications styles_expected; |
| styles_expected.push_back(ACMatchClassification(0, kNone)); |
| @@ -56,17 +60,33 @@ TEST(ExtensionOmniboxTest, DescriptionStylesSimple) { |
| styles_expected.push_back(ACMatchClassification(6, kDim)); |
| styles_expected.push_back(ACMatchClassification(9, kNone)); |
| - ExtensionOmniboxSuggestion suggestions; |
| - suggestions.description.resize(10); |
| - EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value)); |
| - CompareClassification(styles_expected, suggestions.description_styles); |
| + scoped_ptr<SendSuggestions::Params> params( |
| + SendSuggestions::Params::Create(*list)); |
| + EXPECT_TRUE(params); |
| + EXPECT_TRUE(params->suggest_results[0].get()); |
| + CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| + *params->suggest_results[0])); |
| // Same input, but swap the order. Ensure it still works. |
| - styles_value.Clear(); |
| - AppendStyle("dim", 6, 3, &styles_value); |
| - AppendStyle("match", 1, 4, &styles_value); |
| - EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value)); |
| - CompareClassification(styles_expected, suggestions.description_styles); |
| + ListValue* swap_list = ListBuilder().Append(42).Append(ListBuilder().Append( |
|
not at google - send to devlin
2013/03/22 17:33:30
same comments
Aaron Jacobs
2013/03/22 19:54:15
Done.
|
| + DictionaryBuilder().Set("content", "content") |
| + .Set("description", "description") |
| + .Set("descriptionStyles", ListBuilder() |
| + .Append(DictionaryBuilder() |
| + .Set("type", "dim") |
| + .Set("offset", 6) |
| + .Set("length", 3)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "match") |
| + .Set("offset", 1) |
| + .Set("length", 4))))).Build().release(); |
| + |
| + scoped_ptr<SendSuggestions::Params> swapped_params( |
| + SendSuggestions::Params::Create(*swap_list)); |
| + EXPECT_TRUE(swapped_params); |
| + EXPECT_TRUE(swapped_params->suggest_results[0].get()); |
| + CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| + *swapped_params->suggest_results[0])); |
| } |
| // 0123456789 |
| @@ -77,12 +97,30 @@ TEST(ExtensionOmniboxTest, DescriptionStylesSimple) { |
| // + dd |
| // = 3773unnnn66 |
| TEST(ExtensionOmniboxTest, DescriptionStylesCombine) { |
| - ListValue styles_value; |
| - AppendStyle("url", 0, 5, &styles_value); |
| - AppendStyle("dim", 9, 2, &styles_value); |
| - AppendStyle("match", 9, 2, &styles_value); |
| - AppendStyle("match", 0, 4, &styles_value); |
| - AppendStyle("dim", 1, 2, &styles_value); |
| + ListValue* list = ListBuilder().Append(42).Append(ListBuilder().Append( |
|
not at google - send to devlin
2013/03/22 17:33:30
same comments
Aaron Jacobs
2013/03/22 19:54:15
Done.
|
| + DictionaryBuilder().Set("content", "content") |
| + .Set("description", "description") |
| + .Set("descriptionStyles", ListBuilder() |
| + .Append(DictionaryBuilder() |
| + .Set("type", "url") |
| + .Set("offset", 0) |
| + .Set("length", 5)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "dim") |
| + .Set("offset", 9) |
| + .Set("length", 2)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "match") |
| + .Set("offset", 9) |
| + .Set("length", 2)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "match") |
| + .Set("offset", 0) |
| + .Set("length", 4)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "dim") |
| + .Set("offset", 1) |
| + .Set("length", 2))))).Build().release(); |
| ACMatchClassifications styles_expected; |
| styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch)); |
| @@ -92,21 +130,46 @@ TEST(ExtensionOmniboxTest, DescriptionStylesCombine) { |
| styles_expected.push_back(ACMatchClassification(5, kNone)); |
| styles_expected.push_back(ACMatchClassification(9, kMatch | kDim)); |
| - ExtensionOmniboxSuggestion suggestions; |
| - suggestions.description.resize(10); |
| - EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value)); |
| - CompareClassification(styles_expected, suggestions.description_styles); |
| + scoped_ptr<SendSuggestions::Params> params( |
| + SendSuggestions::Params::Create(*list)); |
| + EXPECT_TRUE(params); |
| + EXPECT_TRUE(params->suggest_results[0].get()); |
| + CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| + *params->suggest_results[0])); |
| // Try moving the "dim/match" style pair at offset 9. Output should be the |
| // same. |
| - styles_value.Clear(); |
| - AppendStyle("url", 0, 5, &styles_value); |
| - AppendStyle("match", 0, 4, &styles_value); |
| - AppendStyle("dim", 9, 2, &styles_value); |
| - AppendStyle("match", 9, 2, &styles_value); |
| - AppendStyle("dim", 1, 2, &styles_value); |
| - EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value)); |
| - CompareClassification(styles_expected, suggestions.description_styles); |
| + ListValue* moved_list = ListBuilder().Append(42).Append(ListBuilder().Append( |
|
not at google - send to devlin
2013/03/22 17:33:30
same comments
Aaron Jacobs
2013/03/22 19:54:15
Done.
|
| + DictionaryBuilder().Set("content", "content") |
| + .Set("description", "description") |
| + .Set("descriptionStyles", ListBuilder() |
| + .Append(DictionaryBuilder() |
| + .Set("type", "url") |
| + .Set("offset", 0) |
| + .Set("length", 5)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "match") |
| + .Set("offset", 0) |
| + .Set("length", 4)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "dim") |
| + .Set("offset", 9) |
| + .Set("length", 2)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "match") |
| + .Set("offset", 9) |
| + .Set("length", 2)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "dim") |
| + .Set("offset", 1) |
| + .Set("length", 2))))).Build().release(); |
| + |
| + scoped_ptr<SendSuggestions::Params> moved_params( |
| + SendSuggestions::Params::Create(*moved_list)); |
| + EXPECT_TRUE(moved_params); |
| + EXPECT_TRUE(moved_params->suggest_results[0].get()); |
| + CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| + *moved_params->suggest_results[0])); |
| } |
| // 0123456789 |
| @@ -117,21 +180,41 @@ TEST(ExtensionOmniboxTest, DescriptionStylesCombine) { |
| // + ddd |
| // = 77777nnnnn |
| TEST(ExtensionOmniboxTest, DescriptionStylesCombine2) { |
| - ListValue styles_value; |
| - AppendStyle("url", 0, 5, &styles_value); |
| - AppendStyle("match", 0, 5, &styles_value); |
| - AppendStyle("match", 0, 3, &styles_value); |
| - AppendStyle("dim", 2, 3, &styles_value); |
| - AppendStyle("dim", 0, 3, &styles_value); |
| + ListValue* list = ListBuilder().Append(42).Append(ListBuilder().Append( |
|
not at google - send to devlin
2013/03/22 17:33:30
same comments
Aaron Jacobs
2013/03/22 19:54:15
Done.
|
| + DictionaryBuilder().Set("content", "content") |
| + .Set("description", "description") |
| + .Set("descriptionStyles", ListBuilder() |
| + .Append(DictionaryBuilder() |
| + .Set("type", "url") |
| + .Set("offset", 0) |
| + .Set("length", 5)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "match") |
| + .Set("offset", 0) |
| + .Set("length", 5)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "match") |
| + .Set("offset", 0) |
| + .Set("length", 3)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "dim") |
| + .Set("offset", 2) |
| + .Set("length", 3)) |
| + .Append(DictionaryBuilder() |
| + .Set("type", "dim") |
| + .Set("offset", 0) |
| + .Set("length", 3))))).Build().release(); |
| ACMatchClassifications styles_expected; |
| styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch | kDim)); |
| styles_expected.push_back(ACMatchClassification(5, kNone)); |
| - ExtensionOmniboxSuggestion suggestions; |
| - suggestions.description.resize(10); |
| - EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value)); |
| - CompareClassification(styles_expected, suggestions.description_styles); |
| + scoped_ptr<SendSuggestions::Params> params( |
| + SendSuggestions::Params::Create(*list)); |
| + EXPECT_TRUE(params); |
| + EXPECT_TRUE(params->suggest_results[0].get()); |
| + CompareClassification(styles_expected, StyleTypesToACMatchClassifications( |
| + *params->suggest_results[0])); |
| } |
| } // namespace extensions |