[WKHTTPCookieStore getAllCookies] returns inconsistent creation time
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 May 2018 17:44:02 +0000 (17:44 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 8 May 2018 17:44:02 +0000 (17:44 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185041
<rdar://problem/34684214>

Patch by Sihui Liu <sihui_liu@apple.com> on 2018-05-08
Reviewed by Geoffrey Garen.

Source/WebCore:

Set creationtime property when creating Cookie object to keep consistency after conversion.

New API test: WebKit.WKHTTPCookieStoreCreationTime.

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

Tools:

Add API test Coverage.

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

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

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

index fd01576..a326d41 100644 (file)
@@ -1,3 +1,18 @@
+2018-05-08  Sihui Liu  <sihui_liu@apple.com>
+
+        [WKHTTPCookieStore getAllCookies] returns inconsistent creation time
+        https://bugs.webkit.org/show_bug.cgi?id=185041
+        <rdar://problem/34684214>
+
+        Reviewed by Geoffrey Garen.
+
+        Set creationtime property when creating Cookie object to keep consistency after conversion.
+
+        New API test: WebKit.WKHTTPCookieStoreCreationTime.
+
+        * platform/network/cocoa/CookieCocoa.mm:
+        (WebCore::Cookie::operator NSHTTPCookie * const):
+
 2018-05-08  Eric Carlson  <eric.carlson@apple.com>
 
         Text track cue logging should include cue text
index 575579d..1b69e7b 100644 (file)
@@ -82,7 +82,7 @@ Cookie::operator NSHTTPCookie *() const
     if (isNull())
         return nil;
 
-    NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithCapacity:12];
+    NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithCapacity:13];
 
     if (!comment.isNull())
         [properties setObject:(NSString *)comment forKey:NSHTTPCookieComment];
@@ -106,6 +106,8 @@ Cookie::operator NSHTTPCookie *() const
     auto maxAge = ceil([expirationDate timeIntervalSinceNow]);
     if (maxAge > 0)
         [properties setObject:[NSString stringWithFormat:@"%f", maxAge] forKey:NSHTTPCookieMaximumAge];
+    
+    [properties setObject:[NSNumber numberWithDouble:created / 1000.0] forKey:@"Created"];
 
     auto* portString = portStringFromVector(ports);
     if (portString)
index 6283973..73077f7 100644 (file)
@@ -1,3 +1,16 @@
+2018-05-08  Sihui Liu  <sihui_liu@apple.com>
+
+        [WKHTTPCookieStore getAllCookies] returns inconsistent creation time
+        https://bugs.webkit.org/show_bug.cgi?id=185041
+        <rdar://problem/34684214>
+
+        Reviewed by Geoffrey Garen.
+
+        Add API test Coverage.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm:
+        (TEST):
+
 2018-05-08  Chris Dumez  <cdumez@apple.com>
 
         Unreviewed, fix issue with running Speedometer PerfTest after r231450.
index 9d5d7ec..48350f6 100644 (file)
@@ -33,6 +33,7 @@
 #import <WebKit/WKWebsiteDataStorePrivate.h>
 #import <WebKit/_WKWebsiteDataStoreConfiguration.h>
 #import <wtf/RetainPtr.h>
+#import <wtf/Seconds.h>
 
 #if WK_API_ENABLED
 
@@ -310,6 +311,59 @@ TEST(WebKit, WKHTTPCookieStoreHttpOnly)
     [cookies release];
 }
 
+TEST(WebKit, WKHTTPCookieStoreCreationTime) 
+{   
+    WKWebsiteDataStore* dataStore = [WKWebsiteDataStore defaultDataStore];
+
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    configuration.get().websiteDataStore = dataStore;
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+
+    [webView loadHTMLString:@"WebKit Test" baseURL:[NSURL URLWithString:@"http://webkit.org"]];
+    [webView _test_waitForDidFinishNavigation];
+
+    [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:[] {
+        gotFlag = true;
+    }];
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    globalCookieStore = dataStore.httpCookieStore;
+
+    RetainPtr<NSHTTPCookie> cookie = [NSHTTPCookie cookieWithProperties:@{
+        NSHTTPCookiePath: @"/path",
+        NSHTTPCookieName: @"CookieName",
+        NSHTTPCookieValue: @"CookieValue",
+        NSHTTPCookieDomain: @".www.webkit.org",
+    }];
+
+    [globalCookieStore setCookie:cookie.get() completionHandler:[]() {
+        gotFlag = true;
+    }];
+    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"];
+        gotFlag = true;
+    }];
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    sleep(1_s);
+
+    [globalCookieStore getAllCookies:^(NSArray<NSHTTPCookie *> *cookies) {
+        ASSERT_EQ(1u, cookies.count);
+        NSNumber* creationTime2 = [cookies objectAtIndex:0].properties[@"Created"];
+        EXPECT_TRUE([creationTime.get() isEqual:creationTime2]);
+        gotFlag = true;
+    }];
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+}
+
 // FIXME: This should be removed once <rdar://problem/35344202> is resolved and bots are updated.
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED <= 101301) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MAX_ALLOWED <= 110102)
 TEST(WebKit, WKHTTPCookieStoreNonPersistent)