summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_omnibox_unittest.cc
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 22:35:56 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-11 22:35:56 +0000
commit098ca94b1a0da99230fcdbb7653f738e286a21a7 (patch)
treea6a1659e7c729d6f90797d67936de6a6e815fa1a /chrome/browser/extensions/extension_omnibox_unittest.cc
parentb4e9c1a0aba8ccb23afb461e99e90090845b0a3e (diff)
downloadchromium_src-098ca94b1a0da99230fcdbb7653f738e286a21a7.zip
chromium_src-098ca94b1a0da99230fcdbb7653f738e286a21a7.tar.gz
chromium_src-098ca94b1a0da99230fcdbb7653f738e286a21a7.tar.bz2
Revise the omnibox extension API so that specifying descriptionStyles is easier.
Now each style has a range that it applies to. The styles can also overlap and be listed out of order. BUG=62385 TEST=covered by unit/browser tests Review URL: http://codereview.chromium.org/4660008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@65869 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_omnibox_unittest.cc')
-rw-r--r--chrome/browser/extensions/extension_omnibox_unittest.cc144
1 files changed, 144 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_omnibox_unittest.cc b/chrome/browser/extensions/extension_omnibox_unittest.cc
new file mode 100644
index 0000000..ca2d1e0
--- /dev/null
+++ b/chrome/browser/extensions/extension_omnibox_unittest.cc
@@ -0,0 +1,144 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/values.h"
+#include "chrome/browser/extensions/extension_omnibox_api.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+namespace {
+
+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());
+ 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;
+ }
+}
+
+} // namespace
+
+// Test output key: n = character with no styling, d = dim, m = match, u = url
+
+// 0123456789
+// mmmm
+// + ddd
+// = nmmmmndddn
+TEST(ExtensionOmniboxTest, DescriptionStylesSimple) {
+ ListValue styles_value;
+ AppendStyle("match", 1, 4, &styles_value);
+ AppendStyle("dim", 6, 3, &styles_value);
+
+ ACMatchClassifications styles_expected;
+ styles_expected.push_back(
+ ACMatchClassification(0, ACMatchClassification::NONE));
+ styles_expected.push_back(
+ ACMatchClassification(1, ACMatchClassification::MATCH));
+ styles_expected.push_back(
+ ACMatchClassification(5, ACMatchClassification::NONE));
+ styles_expected.push_back(
+ ACMatchClassification(6, ACMatchClassification::DIM));
+ styles_expected.push_back(
+ ACMatchClassification(9, ACMatchClassification::NONE));
+
+ ExtensionOmniboxSuggestion suggestions;
+ suggestions.description.resize(10);
+ EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value));
+ CompareClassification(styles_expected, suggestions.description_styles);
+
+ // 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);
+}
+
+// 0123456789
+// uuuuuu
+// + dd
+// + mm
+// + mmmm
+// + dd
+// = mddmunnnnm
+TEST(ExtensionOmniboxTest, DescriptionStylesOverlap) {
+ 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);
+
+ ACMatchClassifications styles_expected;
+ styles_expected.push_back(
+ ACMatchClassification(0, ACMatchClassification::MATCH));
+ styles_expected.push_back(
+ ACMatchClassification(1, ACMatchClassification::DIM));
+ styles_expected.push_back(
+ ACMatchClassification(3, ACMatchClassification::MATCH));
+ styles_expected.push_back(
+ ACMatchClassification(4, ACMatchClassification::URL));
+ styles_expected.push_back(
+ ACMatchClassification(5, ACMatchClassification::NONE));
+ styles_expected.push_back(
+ ACMatchClassification(9, ACMatchClassification::MATCH));
+
+ ExtensionOmniboxSuggestion suggestions;
+ suggestions.description.resize(10);
+ EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value));
+ CompareClassification(styles_expected, suggestions.description_styles);
+
+ // 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);
+}
+
+// 0123456789
+// uuuuu
+// + mmmmm
+// + mmm
+// + ddd
+// + ddd
+// = dddddnnnnn
+TEST(ExtensionOmniboxTest, DescriptionStylesOverlap2) {
+ 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);
+
+ // We don't merge adjacent identical styles, but the autocomplete system
+ // doesn't mind.
+ ACMatchClassifications styles_expected;
+ styles_expected.push_back(
+ ACMatchClassification(0, ACMatchClassification::DIM));
+ styles_expected.push_back(
+ ACMatchClassification(3, ACMatchClassification::DIM));
+ styles_expected.push_back(
+ ACMatchClassification(5, ACMatchClassification::NONE));
+
+ ExtensionOmniboxSuggestion suggestions;
+ suggestions.description.resize(10);
+ EXPECT_TRUE(suggestions.ReadStylesFromValue(styles_value));
+ CompareClassification(styles_expected, suggestions.description_styles);
+}