⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243814 in webkit


Ignore:
Timestamp:
Apr 3, 2019, 10:54:44 AM (7 years ago)
Author:
youenn@apple.com
Message:

Add a test for DOMCache on multiple browsing in case of private browsing
https://bugs.webkit.org/show_bug.cgi?id=196524

Reviewed by Alex Christensen.

  • TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:

(-[SWMessageHandlerForCacheStorage userContentController:didReceiveScriptMessage:]):

Location:
trunk/Tools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r243803 r243814  
     12019-04-03  Youenn Fablet  <youenn@apple.com>
     2
     3        Add a test for DOMCache on multiple browsing in case of private browsing
     4        https://bugs.webkit.org/show_bug.cgi?id=196524
     5
     6        Reviewed by Alex Christensen.
     7
     8        * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm:
     9        (-[SWMessageHandlerForCacheStorage userContentController:didReceiveScriptMessage:]):
     10
    1112019-04-03  Jonathan Bedard  <jbedard@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm

    r242905 r243814  
    12731273}
    12741274
     1275static const char* readCacheBytes = R"SWRESOURCE(
     1276<script>
     1277
     1278function log(msg)
     1279{
     1280    window.webkit.messageHandlers.sw.postMessage(msg);
     1281}
     1282
     1283window.caches.keys().then(keys => {
     1284    log(keys.length && keys[0] === "test" ? "PASS" : "FAIL");
     1285}, () => {
     1286    log("FAIL");
     1287});
     1288
     1289</script>
     1290)SWRESOURCE";
     1291
     1292static const char* writeCacheBytes = R"SWRESOURCE(
     1293<script>
     1294
     1295function log(msg)
     1296{
     1297    window.webkit.messageHandlers.sw.postMessage(msg);
     1298}
     1299
     1300window.caches.open("test").then(() => {
     1301    log("PASS");
     1302}, () => {
     1303    log("FAIL");
     1304});
     1305
     1306</script>
     1307)SWRESOURCE";
     1308
     1309@interface SWMessageHandlerForCacheStorage : NSObject <WKScriptMessageHandler>
     1310@end
     1311
     1312@implementation SWMessageHandlerForCacheStorage
     1313- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
     1314{
     1315    EXPECT_WK_STREQ(@"PASS", [message body]);
     1316    done = true;
     1317}
     1318@end
     1319
     1320TEST(ServiceWorkers, CacheStorageInPrivateBrowsingMode)
     1321{
     1322    [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins];
     1323
     1324    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
     1325
     1326    auto messageHandler = adoptNS([[SWMessageHandlerForCacheStorage alloc] init]);
     1327    [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"];
     1328
     1329    auto handler = adoptNS([[SWSchemes alloc] init]);
     1330    handler->resources.set("sw://host/readCache.html", ResourceInfo { @"text/html", readCacheBytes });
     1331    handler->resources.set("sw://host/writeCache.html", ResourceInfo { @"text/html", writeCacheBytes });
     1332    [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"];
     1333
     1334    configuration.get().websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
     1335    [configuration.get().processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"];
     1336
     1337    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1338    auto *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/writeCache.html"]];
     1339    [webView loadRequest:request];
     1340    TestWebKitAPI::Util::run(&done);
     1341    done = false;
     1342
     1343    webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
     1344    request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/readCache.html"]];
     1345    [webView loadRequest:request];
     1346    TestWebKitAPI::Util::run(&done);
     1347    done = false;
     1348}
     1349
    12751350static const char* regularPageGrabbingCacheStorageDirectory = R"SWRESOURCE(
    12761351<script>
Note: See TracChangeset for help on using the changeset viewer.