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

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: Fix dependency problem 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 "chrome/browser/chromeos/system/timezone_settings.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace gdata {
14 namespace util {
15 namespace {
16
17 std::string FormatTime(const base::Time& time) {
18 return UTF16ToUTF8(TimeFormatShortDateAndTime(time));
19 }
20
21 } // namespace
22
23 TEST(GDataUtilTest, GetTimeFromStringLocalTimezone) {
24 // Creates time object GMT.
25 base::Time::Exploded exploded = {2012, 7, 0, 14, 1, 3, 21, 151};
26 base::Time target_time = base::Time::FromUTCExploded(exploded);
27
28 // Creates time object as the local time.
29 base::Time test_time;
30 ASSERT_TRUE(GetTimeFromString("2012-07-14T01:03:21.151", &test_time));
31
32 // Gets the offset between the local time and GMT.
33 const icu::TimeZone& tz =
34 chromeos::system::TimezoneSettings::GetInstance()->GetTimezone();
35 UErrorCode status = U_ZERO_ERROR;
36 int millisecond_in_day = ((1 * 60 + 3) * 60 + 21) * 1000 + 151;
37 int offset = tz.getOffset(1, 2012, 7, 14, 1, millisecond_in_day, status);
38 ASSERT_TRUE(U_SUCCESS(status));
39
40 EXPECT_EQ((target_time - test_time).InMilliseconds(), offset);
41 }
42
43 TEST(GDataUtilTest, GetTimeFromStringTimezone) {
44 // Sets the current timezone to GMT.
45 chromeos::system::TimezoneSettings::GetInstance()->
46 SetTimezone(*icu::TimeZone::getGMT());
47
48 base::Time target_time;
49 base::Time test_time;
50 // Creates the target time.
51 EXPECT_TRUE(GetTimeFromString("2012-07-14T01:03:21.151Z", &target_time));
52
53 // Tests positive offset (hour only).
54 EXPECT_TRUE(GetTimeFromString("2012-07-14T02:03:21.151+01", &test_time));
55 EXPECT_EQ(FormatTime(target_time), FormatTime(test_time));
56
57 // Tests positive offset (hour and minutes).
58 EXPECT_TRUE(GetTimeFromString("2012-07-14T07:33:21.151+06:30", &test_time));
59 EXPECT_EQ(FormatTime(target_time), FormatTime(test_time));
60
61 // Tests negative offset.
62 EXPECT_TRUE(GetTimeFromString("2012-07-13T18:33:21.151-06:30", &test_time));
63 EXPECT_EQ(FormatTime(target_time), FormatTime(test_time));
64 }
65
66 TEST(GDataUtilTest, GetTimeFromString) {
67 // Sets the current timezone to GMT.
68 chromeos::system::TimezoneSettings::GetInstance()->
69 SetTimezone(*icu::TimeZone::getGMT());
70
71 base::Time test_time;
72
73 base::Time::Exploded target_time1 = {2005, 1, 0, 7, 8, 2, 0, 0};
74 EXPECT_TRUE(GetTimeFromString("2005-01-07T08:02:00Z", &test_time));
75 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time1)),
76 FormatTime(test_time));
77
78 base::Time::Exploded target_time2 = {2005, 8, 0, 9, 17, 57, 0, 0};
79 EXPECT_TRUE(GetTimeFromString("2005-08-09T09:57:00-08:00", &test_time));
80 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time2)),
81 FormatTime(test_time));
82
83 base::Time::Exploded target_time3 = {2005, 1, 0, 7, 8, 2, 0, 123};
84 EXPECT_TRUE(GetTimeFromString("2005-01-07T08:02:00.123Z", &test_time));
85 EXPECT_EQ(FormatTime(base::Time::FromUTCExploded(target_time3)),
86 FormatTime(test_time));
87 }
88
89 TEST(GDataUtilTest, FormatTimeAsString) {
90 base::Time::Exploded exploded_time = {2012, 7, 0, 19, 15, 59, 13, 123};
91 base::Time time = base::Time::FromUTCExploded(exploded_time);
92 EXPECT_EQ("2012-07-19T15:59:13.123Z", FormatTimeAsString(time));
93 }
94
95 } // namespace util
96 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698