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

Side by Side Diff: ash/system/night_light/time_of_day_unittest.cc

Issue 2887913004: [Night Light] CL4: Automatic schedule backend. (Closed)
Patch Set: Nits Created 3 years, 6 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
« no previous file with comments | « ash/system/night_light/time_of_day.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 "ash/system/night_light/time_of_day.h"
6
7 #include "base/i18n/rtl.h"
8 #include "base/test/icu_test_util.h"
9 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace ash {
13
14 namespace {
15
16 TEST(TimeOfDayTest, TestEquality) {
17 // Test created TimeOfDay objects with equal offsets are equal.
18 TimeOfDay time1(18 * 60 + 32); // 6:32 PM.
19 TimeOfDay time2(18 * 60 + 32); // 6:32 PM.
20 EXPECT_EQ(time1, time2);
21 TimeOfDay time3(time1);
22 EXPECT_EQ(time1, time3);
23 EXPECT_EQ(time2, time3);
24 TimeOfDay time4(9 * 60 + 59); // 9:59 AM.
25 EXPECT_FALSE(time1 == time4);
26 time1 = time4;
27 EXPECT_EQ(time1, time4);
28 }
29
30 TEST(TimeOfDayTest, TestSeveralOffsets) {
31 // Ensure US locale to make sure time format is expected.
32 base::test::ScopedRestoreICUDefaultLocale restore_locale;
33 base::i18n::SetICUDefaultLocale("en_US");
34
35 // 6:32 PM ==> 18:32.
36 TimeOfDay time1(18 * 60 + 32);
37 EXPECT_EQ("6:32 PM", time1.ToString());
38
39 // 9:59 AM.
40 TimeOfDay time2(9 * 60 + 59);
41 EXPECT_EQ("9:59 AM", time2.ToString());
42
43 // Border times: 00:00 and 24:00.
44 TimeOfDay time3(0);
45 TimeOfDay time4(24 * 60);
46 EXPECT_EQ("12:00 AM", time3.ToString());
47 EXPECT_EQ("12:00 AM", time4.ToString());
48 }
49
50 TEST(TimeOfDayTest, TestFromTime) {
51 // "Now" today and "now" tomorrow should have the same minutes offset from
52 // 00:00.
53 // Assume that "now" is Tuesday May 23, 2017 at 10:30 AM.
54 base::Time::Exploded now;
55 now.year = 2017;
56 now.month = 5; // May.
57 now.day_of_week = 2; // Tuesday.
58 now.day_of_month = 23;
59 now.hour = 10;
60 now.minute = 30;
61 now.second = 0;
62 now.millisecond = 0;
63
64 base::Time now_today = base::Time::Now();
65 ASSERT_TRUE(base::Time::FromLocalExploded(now, &now_today));
66 base::Time now_tomorrow = now_today + base::TimeDelta::FromDays(1);
67 EXPECT_EQ(TimeOfDay::FromTime(now_today), TimeOfDay::FromTime(now_tomorrow));
68 }
69
70 } // namespace
71
72 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/night_light/time_of_day.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698