Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / components / omnibox / autocomplete_match_unittest.cc
blob2fba94c1dfe8189fc7239ea53be8d8975e78fe11
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/omnibox/autocomplete_match.h"
7 #include "base/basictypes.h"
8 #include "testing/gtest/include/gtest/gtest.h"
10 TEST(AutocompleteMatchTest, MoreRelevant) {
11 struct RelevantCases {
12 int r1;
13 int r2;
14 bool expected_result;
15 } cases[] = {
16 { 10, 0, true },
17 { 10, -5, true },
18 { -5, 10, false },
19 { 0, 10, false },
20 { -10, -5, false },
21 { -5, -10, true },
24 AutocompleteMatch m1(NULL, 0, false,
25 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
26 AutocompleteMatch m2(NULL, 0, false,
27 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
29 for (size_t i = 0; i < arraysize(cases); ++i) {
30 m1.relevance = cases[i].r1;
31 m2.relevance = cases[i].r2;
32 EXPECT_EQ(cases[i].expected_result,
33 AutocompleteMatch::MoreRelevant(m1, m2));
37 TEST(AutocompleteMatchTest, MergeClassifications) {
38 // Merging two empty vectors should result in an empty vector.
39 EXPECT_EQ(std::string(),
40 AutocompleteMatch::ClassificationsToString(
41 AutocompleteMatch::MergeClassifications(
42 AutocompleteMatch::ACMatchClassifications(),
43 AutocompleteMatch::ACMatchClassifications())));
45 // If one vector is empty and the other is "trivial" but non-empty (i.e. (0,
46 // NONE)), the non-empty vector should be returned.
47 EXPECT_EQ("0,0",
48 AutocompleteMatch::ClassificationsToString(
49 AutocompleteMatch::MergeClassifications(
50 AutocompleteMatch::ClassificationsFromString("0,0"),
51 AutocompleteMatch::ACMatchClassifications())));
52 EXPECT_EQ("0,0",
53 AutocompleteMatch::ClassificationsToString(
54 AutocompleteMatch::MergeClassifications(
55 AutocompleteMatch::ACMatchClassifications(),
56 AutocompleteMatch::ClassificationsFromString("0,0"))));
58 // Ditto if the one-entry vector is non-trivial.
59 EXPECT_EQ("0,1",
60 AutocompleteMatch::ClassificationsToString(
61 AutocompleteMatch::MergeClassifications(
62 AutocompleteMatch::ClassificationsFromString("0,1"),
63 AutocompleteMatch::ACMatchClassifications())));
64 EXPECT_EQ("0,1",
65 AutocompleteMatch::ClassificationsToString(
66 AutocompleteMatch::MergeClassifications(
67 AutocompleteMatch::ACMatchClassifications(),
68 AutocompleteMatch::ClassificationsFromString("0,1"))));
70 // Merge an unstyled one-entry vector with a styled one-entry vector.
71 EXPECT_EQ("0,1",
72 AutocompleteMatch::ClassificationsToString(
73 AutocompleteMatch::MergeClassifications(
74 AutocompleteMatch::ClassificationsFromString("0,0"),
75 AutocompleteMatch::ClassificationsFromString("0,1"))));
77 // Test simple cases of overlap.
78 EXPECT_EQ("0,3," "1,2",
79 AutocompleteMatch::ClassificationsToString(
80 AutocompleteMatch::MergeClassifications(
81 AutocompleteMatch::ClassificationsFromString("0,1," "1,0"),
82 AutocompleteMatch::ClassificationsFromString("0,2"))));
83 EXPECT_EQ("0,3," "1,2",
84 AutocompleteMatch::ClassificationsToString(
85 AutocompleteMatch::MergeClassifications(
86 AutocompleteMatch::ClassificationsFromString("0,2"),
87 AutocompleteMatch::ClassificationsFromString("0,1," "1,0"))));
89 // Test the case where both vectors have classifications at the same
90 // positions.
91 EXPECT_EQ("0,3",
92 AutocompleteMatch::ClassificationsToString(
93 AutocompleteMatch::MergeClassifications(
94 AutocompleteMatch::ClassificationsFromString("0,1," "1,2"),
95 AutocompleteMatch::ClassificationsFromString("0,2," "1,1"))));
97 // Test an arbitrary complicated case.
98 EXPECT_EQ("0,2," "1,0," "2,1," "4,3," "5,7," "6,3," "7,7," "15,1," "17,0",
99 AutocompleteMatch::ClassificationsToString(
100 AutocompleteMatch::MergeClassifications(
101 AutocompleteMatch::ClassificationsFromString(
102 "0,0," "2,1," "4,3," "7,7," "10,6," "15,0"),
103 AutocompleteMatch::ClassificationsFromString(
104 "0,2," "1,0," "5,7," "6,1," "17,0"))));
107 TEST(AutocompleteMatchTest, SupportsDeletion) {
108 // A non-deletable match with no duplicates.
109 AutocompleteMatch m(NULL, 0, false,
110 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
111 EXPECT_FALSE(m.SupportsDeletion());
113 // A deletable match with no duplicates.
114 AutocompleteMatch m1(NULL, 0, true,
115 AutocompleteMatchType::URL_WHAT_YOU_TYPED);
116 EXPECT_TRUE(m1.SupportsDeletion());
118 // A non-deletable match, with non-deletable duplicates.
119 m.duplicate_matches.push_back(AutocompleteMatch(
120 NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED));
121 m.duplicate_matches.push_back(AutocompleteMatch(
122 NULL, 0, false, AutocompleteMatchType::URL_WHAT_YOU_TYPED));
123 EXPECT_FALSE(m.SupportsDeletion());
125 // A non-deletable match, with at least one deletable duplicate.
126 m.duplicate_matches.push_back(AutocompleteMatch(
127 NULL, 0, true, AutocompleteMatchType::URL_WHAT_YOU_TYPED));
128 EXPECT_TRUE(m.SupportsDeletion());