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

Side by Side Diff: ui/message_center/views/bounded_label_unittest.cc

Issue 117983002: Prefix string16 with base:: in ui/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 7 years 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 | « ui/message_center/views/bounded_label.cc ('k') | ui/message_center/views/group_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ui/message_center/views/bounded_label.h" 5 #include "ui/message_center/views/bounded_label.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 17 matching lines...) Expand all
28 ellipsis_pixels_ = gfx::GetStringWidth(UTF8ToUTF16("\xE2\x80\xA6"), 28 ellipsis_pixels_ = gfx::GetStringWidth(UTF8ToUTF16("\xE2\x80\xA6"),
29 font_list_); 29 font_list_);
30 } 30 }
31 31
32 virtual ~BoundedLabelTest() {} 32 virtual ~BoundedLabelTest() {}
33 33
34 // Replaces all occurences of three periods ("...") in the specified string 34 // Replaces all occurences of three periods ("...") in the specified string
35 // with an ellipses character (UTF8 "\xE2\x80\xA6") and returns a string16 35 // with an ellipses character (UTF8 "\xE2\x80\xA6") and returns a string16
36 // with the results. This allows test strings to be specified as ASCII const 36 // with the results. This allows test strings to be specified as ASCII const
37 // char* strings, making tests more readable and easier to write. 37 // char* strings, making tests more readable and easier to write.
38 string16 ToString(const char* string) { 38 base::string16 ToString(const char* string) {
39 const string16 periods = UTF8ToUTF16("..."); 39 const base::string16 periods = UTF8ToUTF16("...");
40 const string16 ellipses = UTF8ToUTF16("\xE2\x80\xA6"); 40 const base::string16 ellipses = UTF8ToUTF16("\xE2\x80\xA6");
41 string16 result = UTF8ToUTF16(string); 41 base::string16 result = UTF8ToUTF16(string);
42 ReplaceSubstringsAfterOffset(&result, 0, periods, ellipses); 42 ReplaceSubstringsAfterOffset(&result, 0, periods, ellipses);
43 return result; 43 return result;
44 } 44 }
45 45
46 // Converts the specified elision width to pixels. To make tests somewhat 46 // Converts the specified elision width to pixels. To make tests somewhat
47 // independent of the fonts of the platform on which they're run, the elision 47 // independent of the fonts of the platform on which they're run, the elision
48 // widths are specified as XYZ integers, with the corresponding width in 48 // widths are specified as XYZ integers, with the corresponding width in
49 // pixels being X times the width of digit characters plus Y times the width 49 // pixels being X times the width of digit characters plus Y times the width
50 // of spaces plus Z times the width of ellipses in the default font of the 50 // of spaces plus Z times the width of ellipses in the default font of the
51 // test plaform. It is assumed that all digits have the same width in that 51 // test plaform. It is assumed that all digits have the same width in that
52 // font, that this width is greater than the width of spaces, and that the 52 // font, that this width is greater than the width of spaces, and that the
53 // width of 3 digits is greater than the width of ellipses. 53 // width of 3 digits is greater than the width of ellipses.
54 int ToPixels(int width) { 54 int ToPixels(int width) {
55 return digit_pixels_ * width / 100 + 55 return digit_pixels_ * width / 100 +
56 space_pixels_ * (width % 100) / 10 + 56 space_pixels_ * (width % 100) / 10 +
57 ellipsis_pixels_ * (width % 10); 57 ellipsis_pixels_ * (width % 10);
58 } 58 }
59 59
60 // Exercise BounderLabel::GetWrappedText() using the fixture's test label. 60 // Exercise BounderLabel::GetWrappedText() using the fixture's test label.
61 string16 GetWrappedText(int width) { 61 base::string16 GetWrappedText(int width) {
62 return label_->GetWrappedTextForTest(width, lines_); 62 return label_->GetWrappedTextForTest(width, lines_);
63 } 63 }
64 64
65 // Exercise BounderLabel::GetLinesForWidthAndLimit() using the test label. 65 // Exercise BounderLabel::GetLinesForWidthAndLimit() using the test label.
66 int GetLinesForWidth(int width) { 66 int GetLinesForWidth(int width) {
67 label_->SetBounds(0, 0, width, font_list_.GetHeight() * lines_); 67 label_->SetBounds(0, 0, width, font_list_.GetHeight() * lines_);
68 return label_->GetLinesForWidthAndLimit(width, lines_); 68 return label_->GetLinesForWidthAndLimit(width, lines_);
69 } 69 }
70 70
71 protected: 71 protected:
72 // Creates a label to test with. Returns this fixture, which can be used to 72 // Creates a label to test with. Returns this fixture, which can be used to
73 // test the newly created label using the exercise methods above. 73 // test the newly created label using the exercise methods above.
74 BoundedLabelTest& Label(string16 text, int lines) { 74 BoundedLabelTest& Label(base::string16 text, int lines) {
75 lines_ = lines; 75 lines_ = lines;
76 label_.reset(new BoundedLabel(text, font_list_)); 76 label_.reset(new BoundedLabel(text, font_list_));
77 label_->SetLineLimit(lines_); 77 label_->SetLineLimit(lines_);
78 return *this; 78 return *this;
79 } 79 }
80 80
81 private: 81 private:
82 // The default font list, which will be used for tests. 82 // The default font list, which will be used for tests.
83 gfx::FontList font_list_; 83 gfx::FontList font_list_;
84 int digit_pixels_; 84 int digit_pixels_;
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 211
212 // TODO(dharcourt): Add test cases to verify that: 212 // TODO(dharcourt): Add test cases to verify that:
213 // - SetMaxLines() affects the return values of some methods but not others. 213 // - SetMaxLines() affects the return values of some methods but not others.
214 // - Bound changes affects GetPreferredLines(), GetTextSize(), and 214 // - Bound changes affects GetPreferredLines(), GetTextSize(), and
215 // GetWrappedText() return values. 215 // GetWrappedText() return values.
216 // - GetTextFlags are as expected. 216 // - GetTextFlags are as expected.
217 217
218 } // namespace test 218 } // namespace test
219 219
220 } // namespace message_center 220 } // namespace message_center
OLDNEW
« no previous file with comments | « ui/message_center/views/bounded_label.cc ('k') | ui/message_center/views/group_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698