| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/autocomplete/autocomplete_match.h" | 5 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 TEST(AutocompleteMatchTest, MoreRelevant) { | 10 TEST(AutocompleteMatchTest, MoreRelevant) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 AutocompleteMatch m1(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED); | 24 AutocompleteMatch m1(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED); |
| 25 AutocompleteMatch m2(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED); | 25 AutocompleteMatch m2(NULL, 0, false, AutocompleteMatch::URL_WHAT_YOU_TYPED); |
| 26 | 26 |
| 27 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { | 27 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(cases); ++i) { |
| 28 m1.relevance = cases[i].r1; | 28 m1.relevance = cases[i].r1; |
| 29 m2.relevance = cases[i].r2; | 29 m2.relevance = cases[i].r2; |
| 30 EXPECT_EQ(cases[i].expected_result, | 30 EXPECT_EQ(cases[i].expected_result, |
| 31 AutocompleteMatch::MoreRelevant(m1, m2)); | 31 AutocompleteMatch::MoreRelevant(m1, m2)); |
| 32 } | 32 } |
| 33 } | 33 } |
| 34 |
| 35 TEST(AutocompleteMatchTest, MergeClassifications) { |
| 36 // Merging two empty vectors should result in an empty vector. |
| 37 EXPECT_EQ(std::string(), |
| 38 AutocompleteMatch::ClassificationsToString( |
| 39 AutocompleteMatch::MergeClassifications( |
| 40 AutocompleteMatch::ACMatchClassifications(), |
| 41 AutocompleteMatch::ACMatchClassifications()))); |
| 42 |
| 43 // If one vector is empty and the other is "trivial" but non-empty (i.e. (0, |
| 44 // NONE)), the non-empty vector should be returned. |
| 45 EXPECT_EQ("0,0", |
| 46 AutocompleteMatch::ClassificationsToString( |
| 47 AutocompleteMatch::MergeClassifications( |
| 48 AutocompleteMatch::ClassificationsFromString("0,0"), |
| 49 AutocompleteMatch::ACMatchClassifications()))); |
| 50 EXPECT_EQ("0,0", |
| 51 AutocompleteMatch::ClassificationsToString( |
| 52 AutocompleteMatch::MergeClassifications( |
| 53 AutocompleteMatch::ACMatchClassifications(), |
| 54 AutocompleteMatch::ClassificationsFromString("0,0")))); |
| 55 |
| 56 // Ditto if the one-entry vector is non-trivial. |
| 57 EXPECT_EQ("0,1", |
| 58 AutocompleteMatch::ClassificationsToString( |
| 59 AutocompleteMatch::MergeClassifications( |
| 60 AutocompleteMatch::ClassificationsFromString("0,1"), |
| 61 AutocompleteMatch::ACMatchClassifications()))); |
| 62 EXPECT_EQ("0,1", |
| 63 AutocompleteMatch::ClassificationsToString( |
| 64 AutocompleteMatch::MergeClassifications( |
| 65 AutocompleteMatch::ACMatchClassifications(), |
| 66 AutocompleteMatch::ClassificationsFromString("0,1")))); |
| 67 |
| 68 // Merge an unstyled one-entry vector with a styled one-entry vector. |
| 69 EXPECT_EQ("0,1", |
| 70 AutocompleteMatch::ClassificationsToString( |
| 71 AutocompleteMatch::MergeClassifications( |
| 72 AutocompleteMatch::ClassificationsFromString("0,0"), |
| 73 AutocompleteMatch::ClassificationsFromString("0,1")))); |
| 74 |
| 75 // Test simple cases of overlap. |
| 76 EXPECT_EQ("0,3," "1,2", |
| 77 AutocompleteMatch::ClassificationsToString( |
| 78 AutocompleteMatch::MergeClassifications( |
| 79 AutocompleteMatch::ClassificationsFromString("0,1," "1,0"), |
| 80 AutocompleteMatch::ClassificationsFromString("0,2")))); |
| 81 EXPECT_EQ("0,3," "1,2", |
| 82 AutocompleteMatch::ClassificationsToString( |
| 83 AutocompleteMatch::MergeClassifications( |
| 84 AutocompleteMatch::ClassificationsFromString("0,2"), |
| 85 AutocompleteMatch::ClassificationsFromString("0,1," "1,0")))); |
| 86 |
| 87 // Test the case where both vectors have classifications at the same |
| 88 // positions. |
| 89 EXPECT_EQ("0,3", |
| 90 AutocompleteMatch::ClassificationsToString( |
| 91 AutocompleteMatch::MergeClassifications( |
| 92 AutocompleteMatch::ClassificationsFromString("0,1," "1,2"), |
| 93 AutocompleteMatch::ClassificationsFromString("0,2," "1,1")))); |
| 94 |
| 95 // Test an arbitrary complicated case. |
| 96 EXPECT_EQ("0,2," "1,0," "2,1," "4,3," "5,7," "6,3," "7,7," "15,1," "17,0", |
| 97 AutocompleteMatch::ClassificationsToString( |
| 98 AutocompleteMatch::MergeClassifications( |
| 99 AutocompleteMatch::ClassificationsFromString( |
| 100 "0,0," "2,1," "4,3," "7,7," "10,6," "15,0"), |
| 101 AutocompleteMatch::ClassificationsFromString( |
| 102 "0,2," "1,0," "5,7," "6,1," "17,0")))); |
| 103 } |
| OLD | NEW |