Rewrite storage/domstorage/localstorage/private-browsing-affects-storage.html as...
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Sep 2019 05:11:48 +0000 (05:11 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 8 Sep 2019 05:11:48 +0000 (05:11 +0000)
https://bugs.webkit.org/show_bug.cgi?id=201547

Reviewed by Alex Christensen.

Tools:

Rewrite storage/domstorage/localstorage/private-browsing-affects-storage.html as an API test so
it can use a true ephemeral session instead of the testRunner.setPrivateBrowsingEnabled_DEPRECATED()
hack.

* TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
(-[LocalStorageNavigationDelegate webView:decidePolicyForNavigationAction:preferences:decisionHandler:]):
(-[LocalStorageNavigationDelegate webView:didFinishNavigation:]):
(TEST):

LayoutTests:

Drop outdated test.

* storage/domstorage/localstorage/private-browsing-affects-storage.html: Removed.
* storage/domstorage/localstorage/resources/private-browsing-1.html: Removed.
* storage/domstorage/localstorage/resources/private-browsing-2.html: Removed.

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

LayoutTests/ChangeLog
LayoutTests/platform/ios-simulator-wk2/TestExpectations
LayoutTests/platform/mac-wk2/TestExpectations
LayoutTests/storage/domstorage/localstorage/private-browsing-affects-storage-expected.txt [deleted file]
LayoutTests/storage/domstorage/localstorage/private-browsing-affects-storage.html [deleted file]
LayoutTests/storage/domstorage/localstorage/resources/private-browsing-1.html [deleted file]
LayoutTests/storage/domstorage/localstorage/resources/private-browsing-2.html [deleted file]
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm

index 429460c..0d085f0 100644 (file)
@@ -1,3 +1,16 @@
+2019-09-07  Chris Dumez  <cdumez@apple.com>
+
+        Rewrite storage/domstorage/localstorage/private-browsing-affects-storage.html as an API test
+        https://bugs.webkit.org/show_bug.cgi?id=201547
+
+        Reviewed by Alex Christensen.
+
+        Drop outdated test.
+
+        * storage/domstorage/localstorage/private-browsing-affects-storage.html: Removed.
+        * storage/domstorage/localstorage/resources/private-browsing-1.html: Removed.
+        * storage/domstorage/localstorage/resources/private-browsing-2.html: Removed.
+
 2019-09-07  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r249353.
index ca86f46..204bd6f 100644 (file)
@@ -66,8 +66,6 @@ http/wpt/cache-storage/cache-put-keys.https.any.worker.html [ Slow ]
 http/wpt/cache-storage/a-cache-open.https.html [ Slow ]
 http/wpt/cache-storage/cache-quota-add.any.html [ Slow ]
 
-webkit.org/b/196376 [ Debug ] storage/domstorage/localstorage/private-browsing-affects-storage.html [ Pass ]
-
 webkit.org/b/196403 imported/w3c/web-platform-tests/mediacapture-record/MediaRecorder-stop.html [ Pass Failure ]
 
 webkit.org/b/195341 fast/viewport/ios/constant-width-viewport-after-changing-view-scale.html [ Pass Failure ]
index 182e6ea..bb9a749 100644 (file)
@@ -921,8 +921,6 @@ webkit.org/b/194826 http/tests/resourceLoadStatistics/do-not-block-top-level-nav
 
 webkit.org/b/194916 fast/mediastream/MediaStream-video-element.html [ Pass Failure ]
 
-webkit.org/b/196376 storage/domstorage/localstorage/private-browsing-affects-storage.html [ Pass ]
-
 webkit.org/b/196400 fast/mediastream/MediaStreamTrack-getSettings.html [ Pass Failure ]
 
 webkit.org/b/196403 imported/w3c/web-platform-tests/mediacapture-record/MediaRecorder-stop.html [ Pass Failure ]
diff --git a/LayoutTests/storage/domstorage/localstorage/private-browsing-affects-storage-expected.txt b/LayoutTests/storage/domstorage/localstorage/private-browsing-affects-storage-expected.txt
deleted file mode 100644 (file)
index f9840de..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-ALERT: Persistent localStorage testItem is: Persistent item!
-ALERT: Start of private browsing test, testItem is: null
-ALERT: localStorage's length is: 0
-ALERT: After set attempt, testItem is: FirstValue
-ALERT: After second set attempt, testItem is: ChangedValue
-ALERT: Opening window...
-ALERT: localStorage's length is: 1
-ALERT: The item in new window starts out as: ChangedValue
-ALERT: The item in new window is now: NewWindowValue
-ALERT: Back in parent window, localStorage's length is: 1
-ALERT: Back in parent window, testItem is: NewWindowValue
-ALERT: Final window, localStorage's length is: 1
-ALERT: Final window, item is: Persistent item!
-
diff --git a/LayoutTests/storage/domstorage/localstorage/private-browsing-affects-storage.html b/LayoutTests/storage/domstorage/localstorage/private-browsing-affects-storage.html
deleted file mode 100644 (file)
index 98a32d6..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-<html>
-<head>
-<script>
-
-if (window.testRunner) {
-    testRunner.dumpAsText();
-    testRunner.waitUntilDone();
-}
-
-function log(a)
-{
-    alert(a + "");
-}
-
-function runTest()
-{
-    if (!window.testRunner) {
-        log("Test only designed to be run under DumpRenderTree or WebKitTestRunner");
-        return;
-    }
-
-    localStorage.setItem("testItem", "Persistent item!");
-    log("Persistent localStorage testItem is: " + localStorage.getItem("testItem"));
-    
-    testRunner.setPrivateBrowsingEnabled_DEPRECATED(true);
-    testRunner.setCanOpenWindows();
-    
-    window.location.href = "resources/private-browsing-1.html"
-}
-
-</script>
-</head>
-<body onload="runTest();">
-This is a test to make sure that when private browsing is on changes to local storage are not persistent.
-<div id="logger"></div>
-</body>
-</html>
diff --git a/LayoutTests/storage/domstorage/localstorage/resources/private-browsing-1.html b/LayoutTests/storage/domstorage/localstorage/resources/private-browsing-1.html
deleted file mode 100644 (file)
index 5a1962a..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-<html>
-<head>
-<script>
-
-if (window.testRunner) {
-    testRunner.dumpAsText();
-    testRunner.waitUntilDone();
-}
-
-function log(a)
-{
-    alert(a + "");
-}
-
-function runTest()
-{
-    window.logger = log;
-    window.allDone = function() {
-        log("Back in parent window, localStorage's length is: " + localStorage.length);
-        log("Back in parent window, testItem is: " + localStorage.getItem("testItem"));
-        
-        testRunner.setPrivateBrowsingEnabled_DEPRECATED(false);
-
-        window.location.href = "private-browsing-3.html";
-    }
-
-    log("Start of private browsing test, testItem is: " + localStorage.getItem("testItem"));
-    log("localStorage's length is: " + localStorage.length);
-
-    try {
-        localStorage.setItem("testItem", "FirstValue");
-    } catch(e) {
-        log("Caught exception trying to change item: " + e);
-    }
-
-    log("After set attempt, testItem is: " + localStorage.getItem("testItem"));
-    
-    try {
-        localStorage.setItem("testItem", "ChangedValue");
-    } catch(e) {
-        log("Caught exception trying to change item: " + e);
-    }
-
-    log("After second set attempt, testItem is: " + localStorage.getItem("testItem"));
-    log("Opening window...");
-
-    window.open("private-browsing-2.html", "_blank");
-}
-
-</script>
-</head>
-<body onload="runTest();">
-This is a test to make sure that when private browsing is on changes to local storage are not persistent.
-<div id="logger"></div>
-</body>
-</html>
diff --git a/LayoutTests/storage/domstorage/localstorage/resources/private-browsing-2.html b/LayoutTests/storage/domstorage/localstorage/resources/private-browsing-2.html
deleted file mode 100644 (file)
index d96ab7e..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<html>
-<head>
-<script>
-
-function log(a)
-{
-    opener.logger(a);
-}
-
-function runTest()
-{
-    if (!window.testRunner) {
-        log("Test only designed to be run under DumpRenderTree or WebKitTestRunner");
-        return;
-    }
-
-    testRunner.setPrivateBrowsingEnabled_DEPRECATED(true);
-    
-    log("localStorage's length is: " + localStorage.length);
-    log("The item in new window starts out as: " + localStorage.getItem("testItem"));
-    localStorage.setItem("testItem", "NewWindowValue");
-    log("The item in new window is now: " + localStorage.getItem("testItem"));
-
-    opener.allDone();
-}
-
-</script>
-</head>
-<body onload="runTest();">
-</body>
-</html>
index 0c7e38a..5fde9cd 100644 (file)
@@ -1,3 +1,19 @@
+2019-09-07  Chris Dumez  <cdumez@apple.com>
+
+        Rewrite storage/domstorage/localstorage/private-browsing-affects-storage.html as an API test
+        https://bugs.webkit.org/show_bug.cgi?id=201547
+
+        Reviewed by Alex Christensen.
+
+        Rewrite storage/domstorage/localstorage/private-browsing-affects-storage.html as an API test so
+        it can use a true ephemeral session instead of the testRunner.setPrivateBrowsingEnabled_DEPRECATED()
+        hack.
+
+        * TestWebKitAPI/Tests/WebKitCocoa/LocalStoragePersistence.mm:
+        (-[LocalStorageNavigationDelegate webView:decidePolicyForNavigationAction:preferences:decisionHandler:]):
+        (-[LocalStorageNavigationDelegate webView:didFinishNavigation:]):
+        (TEST):
+
 2019-09-07  Alex Christensen  <achristensen@webkit.org>
 
         Remove WebsiteDataStore::legacyDefaultDataStoreConfiguration
index 592bc29..4133ee7 100644 (file)
@@ -30,6 +30,7 @@
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKUserContentControllerPrivate.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
+#import <WebKit/WKWebpagePreferencesPrivate.h>
 #import <WebKit/WebKit.h>
 #import <WebKit/_WKProcessPoolConfiguration.h>
 #import <WebKit/_WKUserStyleSheet.h>
@@ -38,6 +39,7 @@
 
 static bool readyToContinue;
 static bool receivedScriptMessage;
+static bool didFinishNavigation;
 static RetainPtr<WKScriptMessage> lastScriptMessage;
 static RetainPtr<WKWebView> createdWebView;
 
@@ -54,7 +56,9 @@ static RetainPtr<WKWebView> createdWebView;
 
 @end
 
-@interface LocalStorageNavigationDelegate : NSObject <WKNavigationDelegate, WKUIDelegate>
+@interface LocalStorageNavigationDelegate : NSObject <WKNavigationDelegate, WKUIDelegate> {
+    @public void (^decidePolicyForNavigationActionHandler)(WKNavigationAction *, WKWebpagePreferences *, void (^)(WKNavigationActionPolicy, WKWebpagePreferences *));
+}
 @end
 
 @implementation LocalStorageNavigationDelegate
@@ -62,9 +66,23 @@ static RetainPtr<WKWebView> createdWebView;
 - (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
 {
     createdWebView = adoptNS([[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:configuration]);
+    [createdWebView setNavigationDelegate:self];
     return createdWebView.get();
 }
 
+- (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction preferences:(WKWebpagePreferences *)preferences decisionHandler:(void (^)(WKNavigationActionPolicy, WKWebpagePreferences *))decisionHandler
+{
+    if (decidePolicyForNavigationActionHandler)
+        decidePolicyForNavigationActionHandler(navigationAction, preferences, decisionHandler);
+    else
+        decisionHandler(WKNavigationActionPolicyAllow, preferences);
+}
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    didFinishNavigation = true;
+}
+
 @end
 
 TEST(WKWebView, LocalStorageProcessCrashes)
@@ -234,3 +252,165 @@ TEST(WKWebView, LocalStorageOpenWindowPrivate)
     TestWebKitAPI::Util::run(&receivedScriptMessage);
     EXPECT_WK_STREQ(@"local:storage", [lastScriptMessage body]);
 }
+
+TEST(WKWebView, PrivateBrowsingAffectsLocalStorage)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration _setAllowUniversalAccessFromFileURLs:YES];
+    [configuration setWebsiteDataStore:[WKWebsiteDataStore defaultDataStore]];
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    
+    auto delegate = adoptNS([[LocalStorageNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+    
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+    
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+    
+    bool finishedRunningScript = false;
+    [webView evaluateJavaScript:@"localStorage.setItem('testItem', 'Persistent item!');" completionHandler: [&] (id result, NSError *error) {
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+    
+    [webView evaluateJavaScript:@"localStorage.getItem('testItem');" completionHandler: [&] (id result, NSError *error) {
+        NSString *value = (NSString *)result;
+        EXPECT_WK_STREQ(@"Persistent item!", value);
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+    
+    delegate->decidePolicyForNavigationActionHandler = ^(WKNavigationAction *navigationAction, WKWebpagePreferences *preferences, void (^decisionHandler)(WKNavigationActionPolicy, WKWebpagePreferences *)) {
+        // Switch to an ephemeral session.
+        preferences._websiteDataStore = [WKWebsiteDataStore nonPersistentDataStore];
+        decisionHandler(WKNavigationActionPolicyAllow, preferences);
+    };
+    
+    [webView reload];
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+    
+    [webView evaluateJavaScript:@"localStorage.getItem('testItem');" completionHandler: [&] (id result, NSError *error) {
+        EXPECT_TRUE([result isEqual:NSNull.null]);
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+    
+    [webView evaluateJavaScript:@"localStorage.setItem('testItem', 'FirstValue');" completionHandler: [&] (id result, NSError *error) {
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+    
+    [webView evaluateJavaScript:@"localStorage.getItem('testItem');" completionHandler: [&] (id result, NSError *error) {
+        NSString *value = (NSString *)result;
+        EXPECT_WK_STREQ(@"FirstValue", value);
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+    
+    [webView evaluateJavaScript:@"localStorage.setItem('testItem', 'ChangedValue');" completionHandler: [&] (id result, NSError *error) {
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+    
+    [webView evaluateJavaScript:@"localStorage.getItem('testItem');" completionHandler: [&] (id result, NSError *error) {
+        NSString *value = (NSString *)result;
+        EXPECT_WK_STREQ(@"ChangedValue", value);
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+    
+    delegate->decidePolicyForNavigationActionHandler = ^(WKNavigationAction *navigationAction, WKWebpagePreferences *preferences, void (^decisionHandler)(WKNavigationActionPolicy, WKWebpagePreferences *)) {
+        // Switch back to the default session.
+        preferences._websiteDataStore = [WKWebsiteDataStore defaultDataStore];
+        decisionHandler(WKNavigationActionPolicyAllow, preferences);
+    };
+    
+    [webView reload];
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+    
+    [webView evaluateJavaScript:@"localStorage.getItem('testItem');" completionHandler: [&] (id result, NSError *error) {
+        NSString *value = (NSString *)result;
+        EXPECT_WK_STREQ(@"Persistent item!", value);
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+}
+
+TEST(WKWebView, AuxiliaryWindowsShareLocalStorage)
+{
+    auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]);
+    [configuration _setAllowUniversalAccessFromFileURLs:YES];
+    [configuration setWebsiteDataStore:[WKWebsiteDataStore nonPersistentDataStore]];
+    auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
+    
+    auto delegate = adoptNS([[LocalStorageNavigationDelegate alloc] init]);
+    [webView setNavigationDelegate:delegate.get()];
+    [webView setUIDelegate:delegate.get()];
+    
+    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
+    [webView loadRequest:request];
+    
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+    
+    bool finishedRunningScript = false;
+    [webView evaluateJavaScript:@"localStorage.setItem('testItem', 'Persistent item!');" completionHandler: [&] (id result, NSError *error) {
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+    
+    createdWebView = nullptr;
+    [webView evaluateJavaScript:@"open(window.location)" completionHandler: [&] (id result, NSError *error) {
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+        
+    TestWebKitAPI::Util::run(&didFinishNavigation);
+    didFinishNavigation = false;
+    
+    EXPECT_TRUE(!!createdWebView);
+    
+    [createdWebView evaluateJavaScript:@"localStorage.getItem('testItem');" completionHandler: [&] (id result, NSError *error) {
+        NSString *value = (NSString *)result;
+        EXPECT_WK_STREQ(@"Persistent item!", value);
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+    
+    [createdWebView evaluateJavaScript:@"localStorage.setItem('testItem', 'ChangedValue');" completionHandler: [&] (id result, NSError *error) {
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+    
+    [createdWebView evaluateJavaScript:@"localStorage.getItem('testItem');" completionHandler: [&] (id result, NSError *error) {
+        NSString *value = (NSString *)result;
+        EXPECT_WK_STREQ(@"ChangedValue", value);
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+    
+    [webView evaluateJavaScript:@"localStorage.getItem('testItem');" completionHandler: [&] (id result, NSError *error) {
+        NSString *value = (NSString *)result;
+        EXPECT_WK_STREQ(@"ChangedValue", value);
+        finishedRunningScript = true;
+    }];
+    TestWebKitAPI::Util::run(&finishedRunningScript);
+    finishedRunningScript = false;
+}