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

Side by Side Diff: ui/base/l10n/time_format_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/base/l10n/l10n_util_win.cc ('k') | ui/base/resource/resource_bundle_unittest.cc » ('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 (c) 2011 The Chromium Authors. All rights reserved. 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 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/base/l10n/time_format.h" 5 #include "ui/base/l10n/time_format.h"
6 6
7 #include "base/strings/string16.h" 7 #include "base/strings/string16.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
12 12
13 namespace ui { 13 namespace ui {
14 namespace { 14 namespace {
15 15
16 using base::TimeDelta; 16 using base::TimeDelta;
17 17
18 void TestTimeFormats(const TimeDelta& delta, const char* expected_ascii) { 18 void TestTimeFormats(const TimeDelta& delta, const char* expected_ascii) {
19 string16 expected = ASCIIToUTF16(expected_ascii); 19 base::string16 expected = ASCIIToUTF16(expected_ascii);
20 string16 expected_left = expected + ASCIIToUTF16(" left"); 20 base::string16 expected_left = expected + ASCIIToUTF16(" left");
21 string16 expected_ago = expected + ASCIIToUTF16(" ago"); 21 base::string16 expected_ago = expected + ASCIIToUTF16(" ago");
22 EXPECT_EQ(expected, TimeFormat::TimeRemainingShort(delta)); 22 EXPECT_EQ(expected, TimeFormat::TimeRemainingShort(delta));
23 EXPECT_EQ(expected_left, TimeFormat::TimeRemaining(delta)); 23 EXPECT_EQ(expected_left, TimeFormat::TimeRemaining(delta));
24 EXPECT_EQ(expected_ago, TimeFormat::TimeElapsed(delta)); 24 EXPECT_EQ(expected_ago, TimeFormat::TimeElapsed(delta));
25 } 25 }
26 26
27 TEST(TimeFormat, FormatTime) { 27 TEST(TimeFormat, FormatTime) {
28 const TimeDelta one_day = TimeDelta::FromDays(1); 28 const TimeDelta one_day = TimeDelta::FromDays(1);
29 const TimeDelta three_days = TimeDelta::FromDays(3); 29 const TimeDelta three_days = TimeDelta::FromDays(3);
30 const TimeDelta one_hour = TimeDelta::FromHours(1); 30 const TimeDelta one_hour = TimeDelta::FromHours(1);
31 const TimeDelta four_hours = TimeDelta::FromHours(4); 31 const TimeDelta four_hours = TimeDelta::FromHours(4);
(...skipping 14 matching lines...) Expand all
46 TestTimeFormats(one_hour + five_secs, "1 hour"); 46 TestTimeFormats(one_hour + five_secs, "1 hour");
47 TestTimeFormats(four_hours + five_secs, "4 hours"); 47 TestTimeFormats(four_hours + five_secs, "4 hours");
48 TestTimeFormats(one_day + five_secs, "1 day"); 48 TestTimeFormats(one_day + five_secs, "1 day");
49 TestTimeFormats(three_days, "3 days"); 49 TestTimeFormats(three_days, "3 days");
50 TestTimeFormats(three_days + four_hours, "3 days"); 50 TestTimeFormats(three_days + four_hours, "3 days");
51 } 51 }
52 52
53 // crbug.com/159388: This test fails when daylight savings time ends. 53 // crbug.com/159388: This test fails when daylight savings time ends.
54 TEST(TimeFormat, RelativeDate) { 54 TEST(TimeFormat, RelativeDate) {
55 base::Time now = base::Time::Now(); 55 base::Time now = base::Time::Now();
56 string16 today_str = TimeFormat::RelativeDate(now, NULL); 56 base::string16 today_str = TimeFormat::RelativeDate(now, NULL);
57 EXPECT_EQ(ASCIIToUTF16("Today"), today_str); 57 EXPECT_EQ(ASCIIToUTF16("Today"), today_str);
58 58
59 base::Time yesterday = now - TimeDelta::FromDays(1); 59 base::Time yesterday = now - TimeDelta::FromDays(1);
60 string16 yesterday_str = TimeFormat::RelativeDate(yesterday, NULL); 60 base::string16 yesterday_str = TimeFormat::RelativeDate(yesterday, NULL);
61 EXPECT_EQ(ASCIIToUTF16("Yesterday"), yesterday_str); 61 EXPECT_EQ(ASCIIToUTF16("Yesterday"), yesterday_str);
62 62
63 base::Time two_days_ago = now - TimeDelta::FromDays(2); 63 base::Time two_days_ago = now - TimeDelta::FromDays(2);
64 string16 two_days_ago_str = TimeFormat::RelativeDate(two_days_ago, NULL); 64 base::string16 two_days_ago_str =
65 TimeFormat::RelativeDate(two_days_ago, NULL);
65 EXPECT_TRUE(two_days_ago_str.empty()); 66 EXPECT_TRUE(two_days_ago_str.empty());
66 67
67 base::Time a_week_ago = now - TimeDelta::FromDays(7); 68 base::Time a_week_ago = now - TimeDelta::FromDays(7);
68 string16 a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL); 69 base::string16 a_week_ago_str = TimeFormat::RelativeDate(a_week_ago, NULL);
69 EXPECT_TRUE(a_week_ago_str.empty()); 70 EXPECT_TRUE(a_week_ago_str.empty());
70 } 71 }
71 72
72 } // namespace 73 } // namespace
73 } // namespace ui 74 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/l10n/l10n_util_win.cc ('k') | ui/base/resource/resource_bundle_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698