Add an API test to check process privilege when using Cookie API
authorsihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 May 2018 03:46:35 +0000 (03:46 +0000)
committersihui_liu@apple.com <sihui_liu@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 29 May 2018 03:46:35 +0000 (03:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=185406

Reviewed by Geoffrey Garen.

Add API test coverage.

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

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

Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm

index ab7261f..c65cfd9 100644 (file)
@@ -1,3 +1,15 @@
+2018-05-28  Sihui Liu  <sihui_liu@apple.com>
+
+        Add an API test to check process privilege when using Cookie API
+        https://bugs.webkit.org/show_bug.cgi?id=185406
+
+        Reviewed by Geoffrey Garen.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/WKHTTPCookieStore.mm:
+        (TEST):
+
 2018-05-28  Thibault Saunier  <tsaunier@igalia.com>
 
         [GStreamer] Handle changes in the "drm-preferred-decryption-system-id" NEED_CONTEXT message.
index 8f94b34..111b567 100644 (file)
@@ -32,6 +32,7 @@
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKWebsiteDataStorePrivate.h>
 #import <WebKit/_WKWebsiteDataStoreConfiguration.h>
+#import <wtf/ProcessPrivilege.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/Seconds.h>
 #import <wtf/text/WTFString.h>
@@ -194,6 +195,41 @@ TEST(WebKit, WKHTTPCookieStore)
     runTestWithWebsiteDataStore([WKWebsiteDataStore defaultDataStore]);
 }
 
+TEST(WebKit, WKHTTPCookieStoreProcessPrivilege)
+{
+    // Make sure UI process has no privilege at the beginning.
+    WTF::setProcessPrivileges({ });
+
+    [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:[] {
+        gotFlag = true;
+    }];
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+    globalCookieStore = [[WKWebsiteDataStore defaultDataStore] httpCookieStore];
+
+    RetainPtr<NSHTTPCookie> cookie = [NSHTTPCookie cookieWithProperties:@{
+        NSHTTPCookiePath: @"/",
+        NSHTTPCookieName: @"Cookie",
+        NSHTTPCookieValue: @"Value",
+        NSHTTPCookieDomain: @".www.webkit.org",
+    }];
+
+    [globalCookieStore setCookie:cookie.get() completionHandler:[]() {
+        gotFlag = true;
+    }];
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+
+
+    [globalCookieStore getAllCookies:^(NSArray<NSHTTPCookie *>*cookies) {
+        ASSERT_EQ(1u, cookies.count);
+        gotFlag = true;
+    }];
+    TestWebKitAPI::Util::run(&gotFlag);
+    gotFlag = false;
+}
+
 TEST(WebKit, WKHTTPCookieStoreHttpOnly) 
 {
     WKWebsiteDataStore* dataStore = [WKWebsiteDataStore defaultDataStore];