1 // Copyright 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.
5 #include "ios/chrome/browser/net/cookie_util.h"
7 #import <Foundation/Foundation.h>
9 #include "testing/gtest/include/gtest/gtest.h"
13 // Date of the last cookie deletion.
14 NSString* const kLastCookieDeletionDate = @"LastCookieDeletionDate";
18 TEST(CookieUtil, ShouldClearSessionCookies) {
19 time_t start_test_time;
20 time(&start_test_time);
21 NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
22 // Delete cookies if the key is not present.
23 [defaults removeObjectForKey:kLastCookieDeletionDate];
24 EXPECT_TRUE(cookie_util::ShouldClearSessionCookies());
25 // The deletion time should be created.
26 time_t deletion_time = [defaults integerForKey:kLastCookieDeletionDate];
29 EXPECT_LE(start_test_time, deletion_time);
30 EXPECT_LE(deletion_time, now);
31 // Cookies are not deleted again.
32 EXPECT_FALSE(cookie_util::ShouldClearSessionCookies());
34 // Set the deletion time before the machine was started.
35 // Sometime in year 1980.
36 [defaults setInteger:328697227 forKey:kLastCookieDeletionDate];
37 EXPECT_TRUE(cookie_util::ShouldClearSessionCookies());
38 EXPECT_LE(now, [defaults integerForKey:kLastCookieDeletionDate]);