Commit cd0b297c authored by Eugene But's avatar Eugene But Committed by Commit Bot

Added web::WKCookieStoreForBrowserState helper.

This function will be used in New Download API and can also be used for
SystemCookieStore creation.

TBR=michaeldo@chromium.org

Bug: None
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I5f85c59a6e759f226b01937e598db866273f1838
Reviewed-on: https://chromium-review.googlesource.com/744325Reviewed-by: default avatarMike Dougherty <michaeldo@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513224}
parent 5d3fecfe
......@@ -269,6 +269,7 @@ source_set("ios_web_net_unittests") {
"//ios/testing:ios_test_support",
"//ios/testing:ocmock_support",
"//ios/web/navigation",
"//ios/web/net/cookies",
"//ios/web/public",
"//ios/web/public/test",
"//ios/web/public/test/fakes",
......@@ -288,6 +289,7 @@ source_set("ios_web_net_unittests") {
sources = [
"net/cert_host_pair_unittest.cc",
"net/cert_policy_unittest.cc",
"net/cookies/wk_cookie_util_unittest.mm",
"net/crw_cert_verification_controller_unittest.mm",
"net/crw_ssl_status_updater_unittest.mm",
"net/request_group_util_unittest.mm",
......
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//ios/build/config.gni")
source_set("cookies") {
deps = [
"//ios/web/web_state/ui:wk_web_view_configuration_provider",
]
sources = [
"wk_cookie_util.h",
"wk_cookie_util.mm",
]
libs = [ "WebKit.framework" ]
configs += [ "//build/config/compiler:enable_arc" ]
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_NET_COOKIES_WK_COOKIE_UTIL_H_
#define IOS_WEB_NET_COOKIES_WK_COOKIE_UTIL_H_
#include "base/mac/availability.h"
@class WKHTTPCookieStore;
namespace web {
class BrowserState;
// Returns WKHTTPCookieStore for the given BrowserState. If BrowserState is
// OffTheRecord then the resulting WKHTTPCookieStore will be a part of
// ephemeral WKWebsiteDataStore.
WKHTTPCookieStore* WKCookieStoreForBrowserState(BrowserState* browser_state)
API_AVAILABLE(ios(11.0));
} // namespace web
#endif // IOS_WEB_NET_COOKIES_WK_COOKIE_UTIL_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/net/cookies/wk_cookie_util.h"
#import <WebKit/WebKit.h>
#import "ios/web/web_state/ui/wk_web_view_configuration_provider.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web {
WKHTTPCookieStore* WKCookieStoreForBrowserState(BrowserState* browser_state) {
if (@available(iOS 11, *)) {
WKWebViewConfigurationProvider& config_provider =
WKWebViewConfigurationProvider::FromBrowserState(browser_state);
WKWebViewConfiguration* config = config_provider.GetWebViewConfiguration();
return config.websiteDataStore.httpCookieStore;
}
return nil;
}
} // namespace web
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/web/net/cookies/wk_cookie_util.h"
#import <WebKit/WebKit.h>
#import "ios/web/public/test/web_test.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace web {
// Tests that web::WKCookieStoreForBrowserState returns valid WKHTTPCookieStore
// object on iOS 11.
using WKCookieUtilTest = WebTest;
TEST_F(WKCookieUtilTest, WKCookieStoreForBrowserState) {
if (@available(iOS 11, *)) {
WKHTTPCookieStore* store = WKCookieStoreForBrowserState(GetBrowserState());
EXPECT_TRUE([store isKindOfClass:[WKHTTPCookieStore class]]);
}
}
} // namespace web
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment