| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/net/cookies/cookie_creation_time_manager.h" | 5 #include "ios/net/cookies/cookie_creation_time_manager.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/ios/ios_util.h" | 10 #include "base/ios/ios_util.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 TEST_F(CookieCreationTimeManagerTest, GetFromSystemCookie) { | 40 TEST_F(CookieCreationTimeManagerTest, GetFromSystemCookie) { |
| 41 NSHTTPCookie* cookie = GetCookie(@"A=B"); | 41 NSHTTPCookie* cookie = GetCookie(@"A=B"); |
| 42 | 42 |
| 43 // The creation time of a cookie that was never set through the | 43 // The creation time of a cookie that was never set through the |
| 44 // CookieCreationTimeManager should be retrieved from the system with 1 | 44 // CookieCreationTimeManager should be retrieved from the system with 1 |
| 45 // second precision. | 45 // second precision. |
| 46 base::Time time = creation_time_manager_.GetCreationTime(cookie); | 46 base::Time time = creation_time_manager_.GetCreationTime(cookie); |
| 47 base::Time now = base::Time::Now(); | 47 base::Time now = base::Time::Now(); |
| 48 ASSERT_FALSE(time.is_null()); | 48 ASSERT_FALSE(time.is_null()); |
| 49 int64_t delta = (now - time).InMilliseconds(); | 49 int64_t delta = (now - time).InMilliseconds(); |
| 50 // On iOS 8, the range is (0, 1000) ms, but on earlier iOS versions the range | 50 // On iOS 8, the range is (0, 1000) ms. The intervals tested are actually |
| 51 // is (-500, 500) ms. The intervals tested are actually 1200 ms to allow some | 51 // 1200 ms to allow some imprecision. |
| 52 // imprecision. | 52 EXPECT_GT(delta, -100); |
| 53 if (base::ios::IsRunningOnIOS8OrLater()) { | 53 EXPECT_LT(delta, 1100); |
| 54 EXPECT_GT(delta, -100); | |
| 55 EXPECT_LT(delta, 1100); | |
| 56 } else { | |
| 57 EXPECT_GT(delta, -600); | |
| 58 EXPECT_LT(delta, 600); | |
| 59 } | |
| 60 } | 54 } |
| 61 | 55 |
| 62 TEST_F(CookieCreationTimeManagerTest, MakeUniqueCreationTime) { | 56 TEST_F(CookieCreationTimeManagerTest, MakeUniqueCreationTime) { |
| 63 base::Time now = base::Time::Now(); | 57 base::Time now = base::Time::Now(); |
| 64 | 58 |
| 65 // |now| is not used yet, so MakeUniqueCreationTime() should return that. | 59 // |now| is not used yet, so MakeUniqueCreationTime() should return that. |
| 66 base::Time creation_time = creation_time_manager_.MakeUniqueCreationTime(now); | 60 base::Time creation_time = creation_time_manager_.MakeUniqueCreationTime(now); |
| 67 EXPECT_EQ(now, creation_time); | 61 EXPECT_EQ(now, creation_time); |
| 68 | 62 |
| 69 NSHTTPCookie* cookie1 = GetCookie(@"A=B"); | 63 NSHTTPCookie* cookie1 = GetCookie(@"A=B"); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 creation_time_manager_.SetCreationTime( | 112 creation_time_manager_.SetCreationTime( |
| 119 GetCookie(@"G=H"), | 113 GetCookie(@"G=H"), |
| 120 base::Time::FromInternalValue(time_internal_value + 4)); | 114 base::Time::FromInternalValue(time_internal_value + 4)); |
| 121 | 115 |
| 122 // MakeUniqueCreationTime() should use the available slot. | 116 // MakeUniqueCreationTime() should use the available slot. |
| 123 time = creation_time_manager_.MakeUniqueCreationTime(creation_time); | 117 time = creation_time_manager_.MakeUniqueCreationTime(creation_time); |
| 124 EXPECT_EQ(time_internal_value + 3, time.ToInternalValue()); | 118 EXPECT_EQ(time_internal_value + 3, time.ToInternalValue()); |
| 125 } | 119 } |
| 126 | 120 |
| 127 } // namespace net | 121 } // namespace net |
| OLD | NEW |