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

Unified 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 side-by-side diff with in-line comments
Download patch
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..455505c98c3a04df0cc00374a9470960da4157e5 100644
--- a/chrome/browser/extensions/api/omnibox/omnibox_unittest.cc
+++ b/chrome/browser/extensions/api/omnibox/omnibox_unittest.cc
@@ -4,6 +4,7 @@
#include "base/values.h"
#include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
+#include "chrome/common/extensions/api/omnibox.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
@@ -45,9 +46,22 @@ 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);
+ scoped_ptr<ListValue> styles_value(new ListValue);
+ AppendStyle("match", 1, 4, styles_value.get());
+ AppendStyle("dim", 6, 3, styles_value.get());
+
+ scoped_ptr<DictionaryValue> dict(new DictionaryValue);
+ dict->SetStringWithoutPathExpansion("content", "content");
+ dict->SetStringWithoutPathExpansion("description", "dscription");
+ 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.
+
+ scoped_ptr<ListValue> dict_list(new ListValue);
+ dict_list->Set(0, dict.release());
+
+ ListValue list;
+ // Set the request_id
+ list.Set(0, new base::FundamentalValue(42));
+ list.Set(1, dict_list.release());
ACMatchClassifications styles_expected;
styles_expected.push_back(ACMatchClassification(0, kNone));
@@ -56,17 +70,38 @@ 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<api::omnibox::SendSuggestions::Params> params(
+ 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.
+ EXPECT_TRUE(params);
+ 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
+ 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);
+ scoped_ptr<ListValue> swapped_styles_value(new ListValue);
+ AppendStyle("dim", 6, 3, swapped_styles_value.get());
+ AppendStyle("match", 1, 4, swapped_styles_value.get());
+
+ scoped_ptr<DictionaryValue> swapped_dict(new DictionaryValue);
+ swapped_dict->SetStringWithoutPathExpansion("content", "content");
+ swapped_dict->SetStringWithoutPathExpansion("description", "dscription");
+ swapped_dict->SetWithoutPathExpansion("descriptionStyles",
+ swapped_styles_value.release());
+
+ scoped_ptr<ListValue> swapped_dict_list(new ListValue);
+ swapped_dict_list->Set(0, swapped_dict.release());
+
+ ListValue swapped_list;
+ // Set the request_id
+ swapped_list.Set(0, new base::FundamentalValue(42));
+ swapped_list.Set(1, swapped_dict_list.release());
+
+ scoped_ptr<api::omnibox::SendSuggestions::Params> swapped_params(
+ api::omnibox::SendSuggestions::Params::Create(swapped_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 +112,25 @@ 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);
+ scoped_ptr<ListValue> styles_value(new ListValue);
+ AppendStyle("url", 0, 5, styles_value.get());
+ AppendStyle("dim", 9, 2, styles_value.get());
+ AppendStyle("match", 9, 2, styles_value.get());
+ AppendStyle("match", 0, 4, styles_value.get());
+ AppendStyle("dim", 1, 2, styles_value.get());
+
+ scoped_ptr<DictionaryValue> dict(new DictionaryValue);
+ dict->SetStringWithoutPathExpansion("content", "content");
+ dict->SetStringWithoutPathExpansion("description", "dscription");
+ dict->SetWithoutPathExpansion("descriptionStyles", styles_value.release());
+
+ scoped_ptr<ListValue> dict_list(new ListValue);
+ dict_list->Set(0, dict.release());
+
+ ListValue list;
+ // Set the request_id
+ list.Set(0, new base::FundamentalValue(42));
+ list.Set(1, dict_list.release());
ACMatchClassifications styles_expected;
styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch));
@@ -92,21 +140,42 @@ 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<api::omnibox::SendSuggestions::Params> params(
+ api::omnibox::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);
+ scoped_ptr<ListValue> moved_styles_value(new ListValue);
+ AppendStyle("url", 0, 5, moved_styles_value.get());
+ AppendStyle("match", 0, 4, moved_styles_value.get());
+ AppendStyle("dim", 9, 2, moved_styles_value.get());
+ AppendStyle("match", 9, 2, moved_styles_value.get());
+ AppendStyle("dim", 1, 2, moved_styles_value.get());
+
+ scoped_ptr<DictionaryValue> moved_dict(new DictionaryValue);
+ moved_dict->SetStringWithoutPathExpansion("content", "content");
+ moved_dict->SetStringWithoutPathExpansion("description", "dscription");
+ moved_dict->SetWithoutPathExpansion("descriptionStyles",
+ moved_styles_value.release());
+
+ scoped_ptr<ListValue> moved_dict_list(new ListValue);
+ moved_dict_list->Set(0, moved_dict.release());
+
+ ListValue moved_list;
+ // Set the request_id
+ moved_list.Set(0, new base::FundamentalValue(42));
+ moved_list.Set(1, moved_dict_list.release());
+
+ scoped_ptr<api::omnibox::SendSuggestions::Params> moved_params(
+ api::omnibox::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 +186,36 @@ 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);
+ scoped_ptr<ListValue> styles_value(new ListValue);
+ AppendStyle("url", 0, 5, styles_value.get());
+ AppendStyle("match", 0, 5, styles_value.get());
+ AppendStyle("match", 0, 3, styles_value.get());
+ AppendStyle("dim", 2, 3, styles_value.get());
+ AppendStyle("dim", 0, 3, styles_value.get());
+
+ scoped_ptr<DictionaryValue> dict(new DictionaryValue);
+ dict->SetStringWithoutPathExpansion("content", "content");
+ dict->SetStringWithoutPathExpansion("description", "dscription");
+ dict->SetWithoutPathExpansion("descriptionStyles", styles_value.release());
+
+ scoped_ptr<ListValue> dict_list(new ListValue);
+ dict_list->Set(0, dict.release());
+
+ ListValue list;
+ // Set the request_id
+ list.Set(0, new base::FundamentalValue(42));
+ list.Set(1, dict_list.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<api::omnibox::SendSuggestions::Params> params(
+ api::omnibox::SendSuggestions::Params::Create(list));
+ EXPECT_TRUE(params);
+ EXPECT_TRUE(params->suggest_results[0].get());
+ CompareClassification(styles_expected, StyleTypesToACMatchClassifications(
+ *params->suggest_results[0]));
}
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698