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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_util_unittest.cc

Issue 10920091: Move Drive API files to google_apis directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Reflect comments Created 8 years, 3 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
OLDNEW
(Empty)
1 // Copyright (c) 2012 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 "chrome/browser/chromeos/gdata/gdata_util.h"
6
7 #include "base/i18n/time_formatting.h"
8 #include "base/time.h"
9 #include "base/utf_string_conversions.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 #if defined(OS_CHROMEOS)
13 #include "chrome/browser/chromeos/system/timezone_settings.h"
14 #endif // OS_CHROMEOS
15
16 namespace gdata {
17 namespace util {
18 namespace {
19
20 std::string FormatTime(const base::Time& time) {
21 return UTF16ToUTF8(TimeFormatShortDateAndTime(time));
22 }
23
24 } // namespace
25
26 // TODO(yoshiki): Find platform independent way to get/set local timezone.
27 // (http://crbug.com/147524).
28 #if defined(OS_CHROMEOS)
29 TEST(GDataUtilTest, GetTimeFromStringLocalTimezone) {
30 // Creates time object GMT.
31 base::Time::Exploded exploded = {2012, 7, 0, 14, 1, 3, 21, 151};
32 base::Time target_time = base::Time::FromUTCExploded(exploded);
33
34 // Creates time object as the local time.
35 base::Time test_time;
36 ASSERT_TRUE(GetTimeFromString("2012-07-14T01:03:21.151", &test_time));
37
38 // Gets the offset between the local time and GMT.
39 const icu::TimeZone& tz =
40 chromeos::system::TimezoneSettings::GetInstance()->GetTimezone();
41 UErrorCode status = U_ZERO_ERROR;
42 int millisecond_in_day = ((1 * 60 + 3) * 60 + 21) * 1000 + 151;
43 int offset = tz.getOffset(1, 2012, 7, 14, 1, millisecond_in_day, status);
44 ASSERT_TRUE(U_SUCCESS(status));
45
46 EXPECT_EQ((target_time - test_time).InMilliseconds(), offset);
47 }
48
49 TEST(GDataUtilTest, GetTimeFromStringTimezone) {
50 // Sets the current timezone to GMT.
51 chromeos::system::TimezoneSettings::GetInstance()->
52 SetTimezone(*icu::TimeZone::getGMT());
53
54 base::Time target_time;
55 base::Time test_time;
56 // Creates the target time.
57 EXPECT_TRUE(GetTimeFromString("2012-07-14T01:03:21.151Z", &target_time));
58
59 // Tests positive offset (hour only).
60 EXPECT_TRUE(GetTimeFromString("2012-07-14T02:03:21.151+01", &test_time));
61 EXPECT_EQ(FormatTime(target_time), FormatTime(test_time));
62
63 // Tests positive offset (hour and minutes).
64 EXPECT_TRUE(GetTimeFromString("2012-07-14T07:33:21.151+06:30", &test_time));
65 EXPECT_EQ(FormatTime(target_time), FormatTime(test_time));
66
67 // Tests negative offset.
68 EXPECT_TRUE(GetTimeFromString("2012-07-13T18:33:21.151-06:30", &test_time));
69 EXPECT_EQ(FormatTime(target_time), FormatTime(test_time));
70 }
71
72 TEST(GDataUtilTest, GetTimeFromString) {
73 // Sets the current timezone to GMT.
74 chromeos::system::TimezoneSettings::GetInstance()->
75 SetTimezone(*icu::TimeZone::getGMT());
76
77 base::Time test_time;
78
79 base::Time::Exploded target_time1 = {2005, 1, 0, 7, 8, 2, 0, 0};
80 EXPECT_TRUE(GetTimeFromString("2005-01-07T08:02:00Z", &test_time));
81 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time1)),
82 FormatTime(test_time));
83
84 base::Time::Exploded target_time2 = {2005, 8, 0, 9, 17, 57, 0, 0};
85 EXPECT_TRUE(GetTimeFromString("2005-08-09T09:57:00-08:00", &test_time));
86 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time2)),
87 FormatTime(test_time));
88
89 base::Time::Exploded target_time3 = {2005, 1, 0, 7, 8, 2, 0, 123};
90 EXPECT_TRUE(GetTimeFromString("2005-01-07T08:02:00.123Z", &test_time));
91 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time3)),
92 FormatTime(test_time));
93 }
94 #endif // OS_CHROMEOS
95
96 TEST(GDataUtilTest, FormatTimeAsString) {
97 base::Time::Exploded exploded_time = {2012, 7, 0, 19, 15, 59, 13, 123};
98 base::Time time = base::Time::FromUTCExploded(exploded_time);
99 EXPECT_EQ("2012-07-19T15:59:13.123Z", FormatTimeAsString(time));
100 }
101
102 } // namespace util
103 } // namespace gdata
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/gdata/gdata_util.cc ('k') | chrome/browser/chromeos/gdata/gdata_wapi_feed_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698