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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ash/system/night_light/time_of_day.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/system/night_light/time_of_day_unittest.cc
diff --git a/ash/system/night_light/time_of_day_unittest.cc b/ash/system/night_light/time_of_day_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5b5cbd0092f309c7323383c5834efc163006441d
--- /dev/null
+++ b/ash/system/night_light/time_of_day_unittest.cc
@@ -0,0 +1,72 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/system/night_light/time_of_day.h"
+
+#include "base/i18n/rtl.h"
+#include "base/test/icu_test_util.h"
+#include "base/time/time.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace ash {
+
+namespace {
+
+TEST(TimeOfDayTest, TestEquality) {
+ // Test created TimeOfDay objects with equal offsets are equal.
+ TimeOfDay time1(18 * 60 + 32); // 6:32 PM.
+ TimeOfDay time2(18 * 60 + 32); // 6:32 PM.
+ EXPECT_EQ(time1, time2);
+ TimeOfDay time3(time1);
+ EXPECT_EQ(time1, time3);
+ EXPECT_EQ(time2, time3);
+ TimeOfDay time4(9 * 60 + 59); // 9:59 AM.
+ EXPECT_FALSE(time1 == time4);
+ time1 = time4;
+ EXPECT_EQ(time1, time4);
+}
+
+TEST(TimeOfDayTest, TestSeveralOffsets) {
+ // Ensure US locale to make sure time format is expected.
+ base::test::ScopedRestoreICUDefaultLocale restore_locale;
+ base::i18n::SetICUDefaultLocale("en_US");
+
+ // 6:32 PM ==> 18:32.
+ TimeOfDay time1(18 * 60 + 32);
+ EXPECT_EQ("6:32 PM", time1.ToString());
+
+ // 9:59 AM.
+ TimeOfDay time2(9 * 60 + 59);
+ EXPECT_EQ("9:59 AM", time2.ToString());
+
+ // Border times: 00:00 and 24:00.
+ TimeOfDay time3(0);
+ TimeOfDay time4(24 * 60);
+ EXPECT_EQ("12:00 AM", time3.ToString());
+ EXPECT_EQ("12:00 AM", time4.ToString());
+}
+
+TEST(TimeOfDayTest, TestFromTime) {
+ // "Now" today and "now" tomorrow should have the same minutes offset from
+ // 00:00.
+ // Assume that "now" is Tuesday May 23, 2017 at 10:30 AM.
+ base::Time::Exploded now;
+ now.year = 2017;
+ now.month = 5; // May.
+ now.day_of_week = 2; // Tuesday.
+ now.day_of_month = 23;
+ now.hour = 10;
+ now.minute = 30;
+ now.second = 0;
+ now.millisecond = 0;
+
+ base::Time now_today = base::Time::Now();
+ ASSERT_TRUE(base::Time::FromLocalExploded(now, &now_today));
+ base::Time now_tomorrow = now_today + base::TimeDelta::FromDays(1);
+ EXPECT_EQ(TimeOfDay::FromTime(now_today), TimeOfDay::FromTime(now_tomorrow));
+}
+
+} // namespace
+
+} // namespace ash
« 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