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

Side by Side Diff: chrome/browser/ui/title_prefix_matcher_unittest.cc

Issue 6579050: Elides the beginning of tab titles that have common prefixes. ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Elides the beginning of tab titles that have common prefixes. ... Created 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/title_prefix_matcher.cc ('k') | chrome/browser/ui/views/tabs/base_tab.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2011 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.
4
5 #include "base/logging.h"
6 #include "base/utf_string_conversions.h"
7 #include "chrome/browser/ui/title_prefix_matcher.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace {
11
12 const string16 kFoofooAbcdef(ASCIIToUTF16("Foofoo abcdef"));
13 const string16 kFoofooAbcdeg(ASCIIToUTF16("Foofoo abcdeg"));
14 const string16 kFooAbcdef(ASCIIToUTF16("Foo abcdef"));
15 const string16 kFooAbcdeg(ASCIIToUTF16("Foo abcdeg"));
16 const string16 kBarAbcDef(ASCIIToUTF16("Bar abc def"));
17 const string16 kBarAbcDeg(ASCIIToUTF16("Bar abc deg"));
18 const string16 kBarAbdDef(ASCIIToUTF16("Bar abd def"));
19 const string16 kBar(ASCIIToUTF16("Bar"));
20 const string16 kFoo(ASCIIToUTF16("Foo"));
21
22 }
23
24 TEST(TitlePrefixMatcherTest, BasicTests) {
25 std::vector<TitlePrefixMatcher::TitleInfo> tab_title_infos;
26 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdef, 0));
27 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdeg, 1));
28
29 TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos);
30 EXPECT_EQ(0, tab_title_infos[0].caller_value);
31 EXPECT_EQ(7U, tab_title_infos[0].prefix_length);
32
33 EXPECT_EQ(1, tab_title_infos[1].caller_value);
34 EXPECT_EQ(7U, tab_title_infos[1].prefix_length);
35
36 tab_title_infos.clear();
37 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdef, 0));
38 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdeg, 1));
39 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdef, 2));
40 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdeg, 3));
41
42 TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos);
43 EXPECT_EQ(0, tab_title_infos[0].caller_value);
44 EXPECT_EQ(7U, tab_title_infos[0].prefix_length);
45
46 EXPECT_EQ(1, tab_title_infos[1].caller_value);
47 EXPECT_EQ(7U, tab_title_infos[1].prefix_length);
48
49 EXPECT_EQ(2, tab_title_infos[2].caller_value);
50 EXPECT_EQ(4U, tab_title_infos[2].prefix_length);
51
52 EXPECT_EQ(3, tab_title_infos[3].caller_value);
53 EXPECT_EQ(4U, tab_title_infos[3].prefix_length);
54 }
55
56 TEST(TitlePrefixMatcherTest, Duplicates) {
57 std::vector<TitlePrefixMatcher::TitleInfo> tab_title_infos;
58 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdef, 0));
59 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdeg, 1));
60 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdef, 2));
61 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdeg, 3));
62 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoofooAbcdef, 4));
63
64 TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos);
65 EXPECT_EQ(0, tab_title_infos[0].caller_value);
66 EXPECT_EQ(0U, tab_title_infos[0].prefix_length);
67
68 EXPECT_EQ(1, tab_title_infos[1].caller_value);
69 EXPECT_EQ(0U, tab_title_infos[1].prefix_length);
70
71 EXPECT_EQ(2, tab_title_infos[2].caller_value);
72 EXPECT_EQ(4U, tab_title_infos[2].prefix_length);
73
74 EXPECT_EQ(3, tab_title_infos[3].caller_value);
75 EXPECT_EQ(4U, tab_title_infos[3].prefix_length);
76
77 EXPECT_EQ(4, tab_title_infos[4].caller_value);
78 EXPECT_EQ(0U, tab_title_infos[4].prefix_length);
79 }
80
81 TEST(TitlePrefixMatcherTest, MultiplePrefixes) {
82 std::vector<TitlePrefixMatcher::TitleInfo> tab_title_infos;
83 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdef, 0));
84 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFooAbcdeg, 1));
85 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kBarAbcDef, 2));
86 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kBarAbcDeg, 3));
87 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kBarAbdDef, 4));
88 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kBar, 5));
89 tab_title_infos.push_back(TitlePrefixMatcher::TitleInfo(&kFoo, 6));
90
91 TitlePrefixMatcher::CalculatePrefixLengths(&tab_title_infos);
92 EXPECT_EQ(0, tab_title_infos[0].caller_value);
93 EXPECT_EQ(4U, tab_title_infos[0].prefix_length);
94
95 EXPECT_EQ(1, tab_title_infos[1].caller_value);
96 EXPECT_EQ(4U, tab_title_infos[1].prefix_length);
97
98 EXPECT_EQ(2, tab_title_infos[2].caller_value);
99 EXPECT_EQ(8U, tab_title_infos[2].prefix_length);
100
101 EXPECT_EQ(3, tab_title_infos[3].caller_value);
102 EXPECT_EQ(8U, tab_title_infos[3].prefix_length);
103
104 EXPECT_EQ(4, tab_title_infos[4].caller_value);
105 EXPECT_EQ(4U, tab_title_infos[4].prefix_length);
106
107 EXPECT_EQ(5, tab_title_infos[5].caller_value);
108 EXPECT_EQ(0U, tab_title_infos[5].prefix_length);
109
110 EXPECT_EQ(6, tab_title_infos[6].caller_value);
111 EXPECT_EQ(0U, tab_title_infos[6].prefix_length);
112 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/title_prefix_matcher.cc ('k') | chrome/browser/ui/views/tabs/base_tab.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698