This source file includes following definitions.
- CompareClassification
- TEST
- TEST
- TEST
- TEST
#include "base/values.h"
#include "chrome/browser/extensions/api/omnibox/omnibox_api.h"
#include "chrome/common/extensions/api/omnibox.h"
#include "extensions/common/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 SetDefaultSuggestion = omnibox::SetDefaultSuggestion;
namespace {
const int kNone = ACMatchClassification::NONE;
const int kUrl = ACMatchClassification::URL;
const int kMatch = ACMatchClassification::MATCH;
const int kDim = ACMatchClassification::DIM;
void CompareClassification(const ACMatchClassifications& expected,
const ACMatchClassifications& actual) {
EXPECT_EQ(expected.size(), actual.size());
for (size_t i = 0; i < expected.size() && i < actual.size(); ++i) {
EXPECT_EQ(expected[i].offset, actual[i].offset) << "Index:" << i;
EXPECT_EQ(expected[i].style, actual[i].style) << "Index:" << i;
}
}
}
TEST(ExtensionOmniboxTest, DescriptionStylesSimple) {
scoped_ptr<base::ListValue> list = ListBuilder()
.Append(42)
.Append(ListBuilder()
.Append(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();
ACMatchClassifications styles_expected;
styles_expected.push_back(ACMatchClassification(0, kNone));
styles_expected.push_back(ACMatchClassification(1, kMatch));
styles_expected.push_back(ACMatchClassification(5, kNone));
styles_expected.push_back(ACMatchClassification(6, kDim));
styles_expected.push_back(ACMatchClassification(9, kNone));
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]));
scoped_ptr<base::ListValue> swap_list = ListBuilder()
.Append(42)
.Append(ListBuilder()
.Append(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();
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]));
}
TEST(ExtensionOmniboxTest, DescriptionStylesCombine) {
scoped_ptr<base::ListValue> list = ListBuilder()
.Append(42)
.Append(ListBuilder()
.Append(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();
ACMatchClassifications styles_expected;
styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch));
styles_expected.push_back(ACMatchClassification(1, kUrl | kMatch | kDim));
styles_expected.push_back(ACMatchClassification(3, kUrl | kMatch));
styles_expected.push_back(ACMatchClassification(4, kUrl));
styles_expected.push_back(ACMatchClassification(5, kNone));
styles_expected.push_back(ACMatchClassification(9, kMatch | kDim));
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]));
scoped_ptr<base::ListValue> moved_list = ListBuilder()
.Append(42)
.Append(ListBuilder()
.Append(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();
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]));
}
TEST(ExtensionOmniboxTest, DescriptionStylesCombine2) {
scoped_ptr<base::ListValue> list = ListBuilder()
.Append(42)
.Append(ListBuilder()
.Append(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();
ACMatchClassifications styles_expected;
styles_expected.push_back(ACMatchClassification(0, kUrl | kMatch | kDim));
styles_expected.push_back(ACMatchClassification(5, kNone));
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]));
}
TEST(ExtensionOmniboxTest, DefaultSuggestResult) {
scoped_ptr<base::ListValue> list = ListBuilder()
.Append(DictionaryBuilder()
.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();
scoped_ptr<SetDefaultSuggestion::Params> params(
SetDefaultSuggestion::Params::Create(*list));
EXPECT_TRUE(params);
}
}