Title: [232191] trunk
Revision
232191
Author
sihui_...@apple.com
Date
2018-05-25 11:35:13 -0700 (Fri, 25 May 2018)

Log Message

[WKHTTPCookieStore getAllCookies] returns inconsistent creation time
https://bugs.webkit.org/show_bug.cgi?id=185041
<rdar://problem/34684214>

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):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (232190 => 232191)


--- trunk/Source/WebCore/ChangeLog	2018-05-25 17:23:13 UTC (rev 232190)
+++ trunk/Source/WebCore/ChangeLog	2018-05-25 18:35:13 UTC (rev 232191)
@@ -1,3 +1,18 @@
+2018-05-25  Sihui Liu  <sihui_...@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-25  Zalan Bujtas  <za...@apple.com>
 
         [LFC] Implement border and padding computation

Modified: trunk/Source/WebCore/platform/network/cocoa/CookieCocoa.mm (232190 => 232191)


--- trunk/Source/WebCore/platform/network/cocoa/CookieCocoa.mm	2018-05-25 17:23:13 UTC (rev 232190)
+++ trunk/Source/WebCore/platform/network/cocoa/CookieCocoa.mm	2018-05-25 18:35:13 UTC (rev 232191)
@@ -92,7 +92,7 @@
     if (isNull())
         return nil;
 
-    NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithCapacity:12];
+    NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithCapacity:13];
 
     if (!comment.isNull())
         [properties setObject:(NSString *)comment forKey:NSHTTPCookieComment];
@@ -117,6 +117,10 @@
     if (maxAge > 0)
         [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"];
+#endif
+
     auto* portString = portStringFromVector(ports);
     if (portString)
         [properties setObject:portString forKey:NSHTTPCookiePort];

Modified: trunk/Tools/ChangeLog (232190 => 232191)


--- trunk/Tools/ChangeLog	2018-05-25 17:23:13 UTC (rev 232190)
+++ trunk/Tools/ChangeLog	2018-05-25 18:35:13 UTC (rev 232191)
@@ -1,3 +1,16 @@
+2018-05-25  Sihui Liu  <sihui_...@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-24  Chris Dumez  <cdu...@apple.com>
 
         Reduce copying of FontCascadeDescription objects by moving them around

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm (232190 => 232191)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm	2018-05-25 17:23:13 UTC (rev 232190)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm	2018-05-25 18:35:13 UTC (rev 232191)
@@ -33,6 +33,7 @@
 #import <WebKit/WKWebsiteDataStorePrivate.h>
 #import <WebKit/_WKWebsiteDataStoreConfiguration.h>
 #import <wtf/RetainPtr.h>
+#import <wtf/Seconds.h>
 #import <wtf/text/WTFString.h>
 
 #if WK_API_ENABLED
@@ -311,6 +312,60 @@
     [cookies release];
 }
 
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
+TEST(WebKit, WKHTTPCookieStoreCreationTime) 
+{   
+    auto 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;
+}
+#endif // (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101400) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 120000)
+
 // 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)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to