Cookie API: cookie creation time is wrong
authorsihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Jun 2018 17:03:24 +0000 (17:03 +0000)
committersihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 28 Jun 2018 17:03:24 +0000 (17:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=187101

Reviewed by Geoffrey Garen.

Source/WebCore:

Covered by API test: WebKit.WKHTTPCookieStoreCreationTime.

* platform/network/cocoa/CookieCocoa.mm:
(WebCore::Cookie::operator NSHTTPCookie * _Nullable  const):

Tools:

Add test coverage: make sure the cookie creation time returned is the same as set.

* TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm:
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@233308 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/network/cocoa/CookieCocoa.mm
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm

index ee9a8bd..71ae9e1 100644 (file)
@@ -1,3 +1,15 @@
+2018-06-28  Sihui Liu  <sihui_liu@apple.com>
+
+        Cookie API: cookie creation time is wrong
+        https://bugs.webkit.org/show_bug.cgi?id=187101
+
+        Reviewed by Geoffrey Garen.
+
+        Covered by API test: WebKit.WKHTTPCookieStoreCreationTime.
+
+        * platform/network/cocoa/CookieCocoa.mm:
+        (WebCore::Cookie::operator NSHTTPCookie * _Nullable  const):
+
 2018-06-28  Zalan Bujtas  <zalan@apple.com>
 
         [LFC] Add Display::Box::nonCollapsedMarginBox for verification purposes.
index 174c784..688d995 100644 (file)
@@ -161,7 +161,7 @@ Cookie::operator NSHTTPCookie * _Nullable () const
         [properties setObject:[NSString stringWithFormat:@"%f", maxAge] forKey:NSHTTPCookieMaximumAge];
 
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
-    [properties setObject:[NSNumber numberWithDouble:created / 1000.0] forKey:@"Created"];
+    [properties setObject:[NSNumber numberWithDouble:created / 1000.0 - NSTimeIntervalSince1970] forKey:@"Created"];
 #endif
 
     auto* portString = portStringFromVector(ports);
index 5ea571a..95862c2 100644 (file)
@@ -1,3 +1,15 @@
+2018-06-28  Sihui Liu  <sihui_liu@apple.com>
+
+        Cookie API: cookie creation time is wrong
+        https://bugs.webkit.org/show_bug.cgi?id=187101
+
+        Reviewed by Geoffrey Garen.
+
+        Add test coverage: make sure the cookie creation time returned is the same as set.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm:
+        (TEST):
+
 2018-06-28  Simon Fraser  <simon.fraser@apple.com>
 
         The lldb vector summary provider always shows zero capacity
index 82fdedf..8e19ed3 100644 (file)
@@ -367,12 +367,14 @@ TEST(WebKit, WKHTTPCookieStoreCreationTime)
 
     globalCookieStore = dataStore.httpCookieStore;
 
-    RetainPtr<NSHTTPCookie> cookie = [NSHTTPCookie cookieWithProperties:@{
-        NSHTTPCookiePath: @"/path",
-        NSHTTPCookieName: @"CookieName",
-        NSHTTPCookieValue: @"CookieValue",
-        NSHTTPCookieDomain: @".www.webkit.org",
-    }];
+    NSMutableDictionary *cookieProperties = [[NSMutableDictionary alloc] init];
+    [cookieProperties setObject:@"cookieName" forKey:NSHTTPCookieName];
+    [cookieProperties setObject:@"cookieValue" forKey:NSHTTPCookieValue];
+    [cookieProperties setObject:@".www.webkit.org" forKey:NSHTTPCookieDomain];
+    [cookieProperties setObject:@"/path" forKey:NSHTTPCookiePath];
+    RetainPtr<NSNumber> creationTime = [NSNumber numberWithDouble:100000];
+    [cookieProperties setObject:creationTime.get() forKey:@"Created"];
+    RetainPtr<NSHTTPCookie> cookie = [NSHTTPCookie cookieWithProperties:cookieProperties];
 
     [globalCookieStore setCookie:cookie.get() completionHandler:[]() {
         gotFlag = true;
@@ -380,10 +382,10 @@ TEST(WebKit, WKHTTPCookieStoreCreationTime)
     TestWebKitAPI::Util::run(&gotFlag);
     gotFlag = false;
 
-    RetainPtr<NSNumber> creationTime = nil;
     [globalCookieStore getAllCookies:[&](NSArray<NSHTTPCookie *> *cookies) {
         ASSERT_EQ(1u, cookies.count);
-        creationTime = [cookies objectAtIndex:0].properties[@"Created"];
+        NSNumber* createdTime = [cookies objectAtIndex:0].properties[@"Created"];
+        EXPECT_TRUE([creationTime.get() isEqual:createdTime]);
         gotFlag = true;
     }];
     TestWebKitAPI::Util::run(&gotFlag);
@@ -393,8 +395,8 @@ TEST(WebKit, WKHTTPCookieStoreCreationTime)
 
     [globalCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
         ASSERT_EQ(1u, cookies.count);
-        NSNumber* creationTime2 = [cookies objectAtIndex:0].properties[@"Created"];
-        EXPECT_TRUE([creationTime.get() isEqual:creationTime2]);
+        NSNumber* createdTime = [cookies objectAtIndex:0].properties[@"Created"];
+        EXPECT_TRUE([creationTime.get() isEqual:createdTime]);
         gotFlag = true;
     }];
     TestWebKitAPI::Util::run(&gotFlag);