Provide a TestWebKitAPI-wide WKNavigationDelegate to simplify tests
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Sep 2016 01:16:56 +0000 (01:16 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 2 Sep 2016 01:16:56 +0000 (01:16 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161413

Reviewed by Simon Fraser.

Add TestNavigationDelegate, which provides block properties to make
writing tests feel a little more natural (the callbacks can be inline),
and also add WKWebView _test_waitForDidFinishNavigation, so that many
tests don't even need to manually allocate a navigation delegate at all.

Adopt in some of the simpler tests; there are a few navigation delegates
left behind, which we can move to the new model in the future.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm:
(TEST):
(-[WKBackForwardListTestNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/AlwaysRevalidatedURLSchemes.mm:
(TEST):
(-[AlwaysRevalidatedURLSchemesDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/AnimatedResize.mm:
(animatedResizeWebView):
(-[AnimatedResizeNavigationDelegate _webView:renderingProgressDidChange:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm:
(-[AutoLayoutWKWebView initWithFrame:configuration:]):
(-[AutoLayoutWKWebView load:withWidth:expectingContentSize:resettingWidth:]):
(TEST):
(-[AutoLayoutNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/CancelFontSubresource.mm:
(TEST):
(-[CancelFontSubresourceNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm:
(WebKit2_CommandBackForwardTestWKWebView::SetUp):
(WebKit2_CommandBackForwardTestWKWebView::loadFiles):
(TEST_F):
(-[CommandBackForwardNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/DataDetection.mm:
(expectLinkCount):
(TEST):
(-[DataDetectionNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm:
(TEST):
(-[FindInPageNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm:
(TEST):
(-[FixedLayoutSizeNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm:
(TEST):
(-[DatabaseProcessKillNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBPersistence.mm:
(-[IndexedDBNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLNotChange.mm:
(TEST):
(-[ProvisionalURLNotChangeController webView:didFinishNavigation:]): Deleted.
(-[ProvisionalURLNotChangeController webView:didFailProvisionalNavigation:withError:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/RequiresUserActionForPlayback.mm:
(RequiresUserActionForPlaybackTest::createWebView):
(RequiresUserActionForPlaybackTest::testVideoWithAudio):
(RequiresUserActionForPlaybackTest::testVideoWithoutAudio):
(RequiresUserActionForPlaybackTest::testAudioOnly):
(-[RequiresUserActionForPlaybackNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm:
(TEST):
(-[ShrinkToFitNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm:
(TEST):
(webViewForScriptMessageHandlerMultipleHandlerRemovalTest):
* TestWebKitAPI/Tests/WebKit2Cocoa/UserContentWorld.mm:
(TEST):
(-[SimpleDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/WKPDFViewResizeCrash.mm:
(TEST):
(-[WKPDFViewResizeNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm:
(TEST):
(-[EvaluateJavaScriptNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewTextInput.mm:
(TEST):
(-[DummyNavigationDelegate webView:didFinishNavigation:]): Deleted.
* TestWebKitAPI/cocoa/TestNavigationDelegate.h: Added.
* TestWebKitAPI/cocoa/TestNavigationDelegate.mm: Added.
(-[TestNavigationDelegate webView:didFailProvisionalNavigation:withError:]):
(-[TestNavigationDelegate webView:didFinishNavigation:]):
(-[TestNavigationDelegate _webView:renderingProgressDidChange:]):
(-[TestNavigationDelegate waitForDidFinishNavigation]):
(-[WKWebView _test_waitForDidFinishNavigation]):

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

23 files changed:
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AlwaysRevalidatedURLSchemes.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AnimatedResize.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CancelFontSubresource.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DataDetection.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBPersistence.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLNotChange.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RequiresUserActionForPlayback.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentWorld.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKPDFViewResizeCrash.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm
Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewTextInput.mm
Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h [new file with mode: 0644]
Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm [new file with mode: 0644]

index 201470b1d81eb04e41c8565e19fad3ea95460a7c..cea7f32512fe846529db71c4be63e58746120191 100644 (file)
@@ -1,3 +1,92 @@
+2016-09-01  Tim Horton  <timothy_horton@apple.com>
+
+        Provide a TestWebKitAPI-wide WKNavigationDelegate to simplify tests
+        https://bugs.webkit.org/show_bug.cgi?id=161413
+
+        Reviewed by Simon Fraser.
+
+        Add TestNavigationDelegate, which provides block properties to make
+        writing tests feel a little more natural (the callbacks can be inline),
+        and also add WKWebView _test_waitForDidFinishNavigation, so that many
+        tests don't even need to manually allocate a navigation delegate at all.
+
+        Adopt in some of the simpler tests; there are a few navigation delegates
+        left behind, which we can move to the new model in the future.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm:
+        (TEST):
+        (-[WKBackForwardListTestNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/AlwaysRevalidatedURLSchemes.mm:
+        (TEST):
+        (-[AlwaysRevalidatedURLSchemesDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/AnimatedResize.mm:
+        (animatedResizeWebView):
+        (-[AnimatedResizeNavigationDelegate _webView:renderingProgressDidChange:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm:
+        (-[AutoLayoutWKWebView initWithFrame:configuration:]):
+        (-[AutoLayoutWKWebView load:withWidth:expectingContentSize:resettingWidth:]):
+        (TEST):
+        (-[AutoLayoutNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/CancelFontSubresource.mm:
+        (TEST):
+        (-[CancelFontSubresourceNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm:
+        (WebKit2_CommandBackForwardTestWKWebView::SetUp):
+        (WebKit2_CommandBackForwardTestWKWebView::loadFiles):
+        (TEST_F):
+        (-[CommandBackForwardNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/DataDetection.mm:
+        (expectLinkCount):
+        (TEST):
+        (-[DataDetectionNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm:
+        (TEST):
+        (-[FindInPageNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm:
+        (TEST):
+        (-[FixedLayoutSizeNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm:
+        (TEST):
+        (-[DatabaseProcessKillNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBPersistence.mm:
+        (-[IndexedDBNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLNotChange.mm:
+        (TEST):
+        (-[ProvisionalURLNotChangeController webView:didFinishNavigation:]): Deleted.
+        (-[ProvisionalURLNotChangeController webView:didFailProvisionalNavigation:withError:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/RequiresUserActionForPlayback.mm:
+        (RequiresUserActionForPlaybackTest::createWebView):
+        (RequiresUserActionForPlaybackTest::testVideoWithAudio):
+        (RequiresUserActionForPlaybackTest::testVideoWithoutAudio):
+        (RequiresUserActionForPlaybackTest::testAudioOnly):
+        (-[RequiresUserActionForPlaybackNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm:
+        (TEST):
+        (-[ShrinkToFitNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm:
+        (TEST):
+        (webViewForScriptMessageHandlerMultipleHandlerRemovalTest):
+        * TestWebKitAPI/Tests/WebKit2Cocoa/UserContentWorld.mm:
+        (TEST):
+        (-[SimpleDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WKPDFViewResizeCrash.mm:
+        (TEST):
+        (-[WKPDFViewResizeNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm:
+        (TEST):
+        (-[EvaluateJavaScriptNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewTextInput.mm:
+        (TEST):
+        (-[DummyNavigationDelegate webView:didFinishNavigation:]): Deleted.
+        * TestWebKitAPI/cocoa/TestNavigationDelegate.h: Added.
+        * TestWebKitAPI/cocoa/TestNavigationDelegate.mm: Added.
+        (-[TestNavigationDelegate webView:didFailProvisionalNavigation:withError:]):
+        (-[TestNavigationDelegate webView:didFinishNavigation:]):
+        (-[TestNavigationDelegate _webView:renderingProgressDidChange:]):
+        (-[TestNavigationDelegate waitForDidFinishNavigation]):
+        (-[WKWebView _test_waitForDidFinishNavigation]):
+
 2016-09-01  Ricky Mondello  <rmondello@apple.com>
 
         YouTube Flash plug-in replacement facility should not insert showinfo=0 into iframe URLs
index b78ed11de49fc310c2eca3434f7ee87909b165bb..9a6a2013acf480a262a87d3e4a9b92212f256d6e 100644 (file)
@@ -52,6 +52,7 @@
                297234B7173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 297234B5173AFAC700983601 /* CustomProtocolsInvalidScheme_Bundle.cpp */; };
                2D00065F1C1F589A0088E6A7 /* WKPDFViewResizeCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */; };
                2D1646E21D1862CD00015A1A /* DeferredViewInWindowStateChange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1646E11D1862CD00015A1A /* DeferredViewInWindowStateChange.mm */; };
+               2D1C04A71D76298B000A6816 /* TestNavigationDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */; };
                2D51A0C71C8BF00C00765C45 /* DOMHTMLVideoElementWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */; };
                2DC4CF771D2D9DD800ECCC94 /* DataDetection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DC4CF761D2D9DD800ECCC94 /* DataDetection.mm */; };
                2DD7D3AF178227B30026E1E3 /* lots-of-text-vertical-lr.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 2DD7D3AE178227AC0026E1E3 /* lots-of-text-vertical-lr.html */; };
                29AB8AA3164C7A9300D49BEC /* TestBrowsingContextLoadDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TestBrowsingContextLoadDelegate.h; sourceTree = "<group>"; };
                2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKPDFViewResizeCrash.mm; sourceTree = "<group>"; };
                2D1646E11D1862CD00015A1A /* DeferredViewInWindowStateChange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DeferredViewInWindowStateChange.mm; path = WebKit2/DeferredViewInWindowStateChange.mm; sourceTree = "<group>"; };
+               2D1C04A51D76298B000A6816 /* TestNavigationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestNavigationDelegate.h; path = cocoa/TestNavigationDelegate.h; sourceTree = "<group>"; };
+               2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TestNavigationDelegate.mm; path = cocoa/TestNavigationDelegate.mm; sourceTree = "<group>"; };
                2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FixedLayoutSize.mm; sourceTree = "<group>"; };
                2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMHTMLVideoElementWrapper.mm; sourceTree = "<group>"; };
                2D640B5417875DFF00BFAF99 /* ScrollPinningBehaviors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScrollPinningBehaviors.cpp; sourceTree = "<group>"; };
                                5C726D6D1D3EE06800C5E1A1 /* InstanceMethodSwizzler.h */,
                                5C726D6E1D3EE06800C5E1A1 /* InstanceMethodSwizzler.mm */,
                                0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */,
+                               2D1C04A51D76298B000A6816 /* TestNavigationDelegate.h */,
+                               2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */,
                                A14FC58D1B8AE36500D107EB /* TestProtocol.h */,
                                A14FC58E1B8AE36500D107EB /* TestProtocol.mm */,
                                7C83E0391D0A602700FEBCF3 /* UtilitiesCocoa.mm */,
                                5C2936931D5BF70D00DEAB1E /* CookieAcceptPolicy.mm in Sources */,
                                7CCE7EE81A411AE600447C4C /* CookieManager.cpp in Sources */,
                                7CCE7EAC1A411A3400447C4C /* Counters.cpp in Sources */,
+                               2D1C04A71D76298B000A6816 /* TestNavigationDelegate.mm in Sources */,
                                7CCE7EDB1A411A9200447C4C /* CSSParser.cpp in Sources */,
                                7CCE7F291A411B1000447C4C /* CustomProtocolsInvalidScheme.mm in Sources */,
                                7CCE7F2A1A411B1000447C4C /* CustomProtocolsSyncXHRTest.mm in Sources */,
index 1dbaae414d1a2c8e4c7f90011b5127e0f6d6d643..20cf8d87e40fd9f1c7d6c7443ae9a98c42701052 100644 (file)
@@ -26,9 +26,9 @@
 #import "config.h"
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
 
 #import <WebKit/WKBackForwardListPrivate.h>
-#import <WebKit/WKNavigationDelegate.h>
 #import <WebKit/WKNavigationPrivate.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <WebKit/_WKSessionState.h>
 
 #if WK_API_ENABLED
 
-static bool isDone;
-
-@interface WKBackForwardListTestNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation WKBackForwardListTestNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    isDone = true;
-}
-
-@end
-
 static NSString *loadableURL1 = @"data:text/html,no%20error%20A";
 static NSString *loadableURL2 = @"data:text/html,no%20error%20B";
 static NSString *loadableURL3 = @"data:text/html,no%20error%20C";
@@ -57,20 +43,15 @@ static NSString *loadableURL3 = @"data:text/html,no%20error%20C";
 TEST(WKBackForwardList, RemoveCurrentItem)
 {
     auto webView = adoptNS([[WKWebView alloc] init]);
-    auto controller = adoptNS([[WKBackForwardListTestNavigationDelegate alloc] init]);
-    [webView setNavigationDelegate:controller.get()];
 
     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL1]]];
-    TestWebKitAPI::Util::run(&isDone);
-    isDone = false;
+    [webView _test_waitForDidFinishNavigation];
 
     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL2]]];
-    TestWebKitAPI::Util::run(&isDone);
-    isDone = false;
+    [webView _test_waitForDidFinishNavigation];
 
     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL3]]];
-    TestWebKitAPI::Util::run(&isDone);
-    isDone = false;
+    [webView _test_waitForDidFinishNavigation];
 
     WKBackForwardList *list = [webView backForwardList];
     EXPECT_EQ((NSUInteger)2, list.backList.count);
index e88f020d3b08a3dccd981ff29ec28fe4a34a6723..882daab60cf0b9fc223cd9ec9db1e93e6bd126a4 100644 (file)
 #if WK_API_ENABLED
 
 #import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
 #import <WebKit/WKBrowsingContextController.h>
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/_WKProcessPoolConfiguration.h>
 #import <wtf/RetainPtr.h>
 
 static NSString * const customScheme = @"custom";
-static bool isDone;
 static size_t loadsStarted;
 
 @interface AlwaysRevalidatedURLSchemeProtocol : NSURLProtocol
@@ -74,18 +74,6 @@ static size_t loadsStarted;
 
 @end
 
-@interface AlwaysRevalidatedURLSchemesDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation AlwaysRevalidatedURLSchemesDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    isDone = true;
-}
-
-@end
-
 TEST(WebKit2, AlwaysRevalidatedURLSchemes)
 {
     @autoreleasepool {
@@ -99,18 +87,15 @@ TEST(WebKit2, AlwaysRevalidatedURLSchemes)
         auto webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
         [webViewConfiguration setProcessPool:processPool.get()];
 
-        auto navigationDelegate = adoptNS([[AlwaysRevalidatedURLSchemesDelegate alloc] init]);
         auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:webViewConfiguration.get()]);
-        [webView setNavigationDelegate:navigationDelegate.get()];
 
         NSString *htmlString = [NSString stringWithFormat:@"<!DOCTYPE html><body><img src='%@://image'>", customScheme];
         [webView loadHTMLString:htmlString baseURL:nil];
-        TestWebKitAPI::Util::run(&isDone);
+        [webView _test_waitForDidFinishNavigation];
         EXPECT_EQ(1UL, loadsStarted);
 
-        isDone = false;
         [webView loadHTMLString:htmlString baseURL:nil];
-        TestWebKitAPI::Util::run(&isDone);
+        [webView _test_waitForDidFinishNavigation];
         EXPECT_EQ(2UL, loadsStarted);
 
         [WKBrowsingContextController unregisterSchemeForCustomProtocol:customScheme];
index b45b0e6d8e800444f0f68c5f30860067a0e6d415..5aa07f3f4cc192cf8c68e8346b9429825995c061 100644 (file)
@@ -26,7 +26,7 @@
 #include "config.h"
 
 #import "PlatformUtilities.h"
-#import <WebKit/WKNavigationDelegatePrivate.h>
+#import "TestNavigationDelegate.h"
 #import <WebKit/WKPreferences.h>
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKWebView.h>
 static bool didLayout;
 static bool didEndAnimatedResize;
 
-@interface AnimatedResizeNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation AnimatedResizeNavigationDelegate
-
-- (void)_webView:(WKWebView *)webView renderingProgressDidChange:(_WKRenderingProgressEvents)progressEvents
-{
-    if (progressEvents & _WKRenderingProgressEventFirstVisuallyNonEmptyLayout)
-        didLayout = true;
-}
-
-@end
-
 @interface AnimatedResizeWebView : WKWebView
 
 @end
@@ -70,17 +57,21 @@ static bool didEndAnimatedResize;
 
 static RetainPtr<WKWebView> animatedResizeWebView()
 {
-    RetainPtr<_WKProcessPoolConfiguration> processPoolConfiguration = [[_WKProcessPoolConfiguration alloc] init];
+    RetainPtr<_WKProcessPoolConfiguration> processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
     [processPoolConfiguration setIgnoreSynchronousMessagingTimeoutsForTesting:YES];
-    RetainPtr<WKProcessPool> processPool = [[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()];
+    RetainPtr<WKProcessPool> processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
 
-    RetainPtr<WKWebViewConfiguration> webViewConfiguration = [[WKWebViewConfiguration alloc] init];
+    RetainPtr<WKWebViewConfiguration> webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
     [webViewConfiguration setProcessPool:processPool.get()];
 
     RetainPtr<WKWebView> webView = adoptNS([[AnimatedResizeWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
 
-    AnimatedResizeNavigationDelegate *navigationDelegate = [[AnimatedResizeNavigationDelegate alloc] init];
-    [webView setNavigationDelegate:navigationDelegate];
+    auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]);
+    [navigationDelegate setRenderingProgressDidChange:^(WKWebView *, _WKRenderingProgressEvents progressEvents) {
+        if (progressEvents & _WKRenderingProgressEventFirstVisuallyNonEmptyLayout)
+            didLayout = true;
+    }];
+    [webView setNavigationDelegate:navigationDelegate.get()];
 
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"blinking-div" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
index 83829945e688ddc28bb7b1ec9030a6b43f5281ed..ad7886f292f0f59c26844e8f88ee8d130726f697 100644 (file)
 #include "config.h"
 
 #import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
 #import <WebKit/WKWebViewPrivate.h>
 #import <wtf/RetainPtr.h>
 
 #if WK_API_ENABLED && PLATFORM(MAC)
 
-static bool didFinishNavigation;
 static bool didInvalidateIntrinsicContentSize;
 static bool didEvaluateJavaScript;
 
-@interface AutoLayoutNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation AutoLayoutNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    didFinishNavigation = true;
-}
-
-@end
-
 @interface AutoLayoutWKWebView : WKWebView
 @end
 
@@ -55,6 +43,15 @@ static bool didEvaluateJavaScript;
     NSSize _expectedIntrinsicContentSize;
 }
 
+- (instancetype)initWithFrame:(NSRect)frame configuration:(WKWebViewConfiguration *)configuration
+{
+    self = [super initWithFrame:frame configuration:configuration];
+    if (!self)
+        return nil;
+
+    return self;
+}
+
 - (void)load:(NSString *)HTMLString withWidth:(CGFloat)width expectingContentSize:(NSSize)size
 {
     [self load:HTMLString withWidth:width expectingContentSize:size resettingWidth:YES];
@@ -73,9 +70,8 @@ static bool didEvaluateJavaScript;
     ".inline { display: inline-block; }"
     "</style>";
 
-    didFinishNavigation = false;
     [self loadHTMLString:[baseHTML stringByAppendingString:HTMLString] baseURL:nil];
-    TestWebKitAPI::Util::run(&didFinishNavigation);
+    [self _test_waitForDidFinishNavigation];
 
     [self layoutAtMinimumWidth:width andExpectContentSizeChange:size resettingWidth:resetAfter];
 }
@@ -116,9 +112,6 @@ TEST(WebKit2, AutoLayoutIntegration)
 {
     RetainPtr<AutoLayoutWKWebView> webView = adoptNS([[AutoLayoutWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 1000, 1000)]);
 
-    AutoLayoutNavigationDelegate *delegate = [[AutoLayoutNavigationDelegate alloc] init];
-    [webView setNavigationDelegate:delegate];
-
     // 10x10 rect with the constraint (width >= 50) -> 50x10
     [webView load:@"<div class='small'></div>" withWidth:50 expectingContentSize:NSMakeSize(50, 10)];
 
index 6ba4a071f9955120995794a536f9da21df5ab812..d3ca5d5ef16ca4eb149851a34689f23f2856e195 100644 (file)
@@ -30,6 +30,7 @@
 
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
 #import "UserContentWorldProtocol.h"
 #import "WKWebViewConfigurationExtras.h"
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/_WKUserStyleSheet.h>
 #import <wtf/RetainPtr.h>
 
-@interface CancelFontSubresourceNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation CancelFontSubresourceNavigationDelegate
-
-static bool navigationComplete = false;
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    navigationComplete = true;
-}
-
-@end
-
 TEST(CancelLoading, CancelFontSubresource)
 {
     NSString * const testPlugInClassName = @"CancelFontSubresourcePlugIn";
@@ -66,13 +53,9 @@ TEST(CancelLoading, CancelFontSubresource)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    CancelFontSubresourceNavigationDelegate *delegate = [[CancelFontSubresourceNavigationDelegate alloc] init];
-    [webView setNavigationDelegate:delegate];
-
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"webfont" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
-
-    TestWebKitAPI::Util::run(&navigationComplete);
+    [webView _test_waitForDidFinishNavigation];
 }
 
 #endif
index a9b6b9892289e9b78983b26e040740a433ea0136..6786700ed23d7aaa81c1e1601b69fd3a21d5ec52 100644 (file)
@@ -29,6 +29,7 @@
 
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
 #import <Carbon/Carbon.h> // for GetCurrentEventTime()
 #import <WebKit/WKRetainPtr.h>
 #import <WebKit/WKViewPrivate.h>
@@ -152,19 +153,6 @@ public:
 
 #if WK_API_ENABLED
 
-@interface CommandBackForwardNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation CommandBackForwardNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    didFinishNavigation = true;
-}
-
-@end
-
-
 class WebKit2_CommandBackForwardTestWKWebView : public WebKit2_CommandBackForwardTest {
 public:
     RetainPtr<WKWebView> webView;
@@ -175,24 +163,17 @@ public:
 
         webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
         [[window contentView] addSubview:webView.get()];
-
-        CommandBackForwardNavigationDelegate *delegate = [[CommandBackForwardNavigationDelegate alloc] init];
-        [webView setNavigationDelegate:delegate];
     }
     
     void loadFiles()
     {
         NSURL *file1 = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
         [webView loadFileURL:file1 allowingReadAccessToURL:file1];
-
-        TestWebKitAPI::Util::run(&didFinishNavigation);
-        didFinishNavigation = false;
+        [webView _test_waitForDidFinishNavigation];
 
         NSURL *file2 = [[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
         [webView loadFileURL:file2 allowingReadAccessToURL:file2];
-
-        TestWebKitAPI::Util::run(&didFinishNavigation);
-        didFinishNavigation = false;
+        [webView _test_waitForDidFinishNavigation];
     }
 };
 
@@ -206,15 +187,13 @@ TEST_F(WebKit2_CommandBackForwardTestWKWebView, LTR)
 
     // Attempt to go back (using command-left).
     simulateCommandArrow(webView.get(), Left);
-    TestWebKitAPI::Util::run(&didFinishNavigation);
-    didFinishNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple.html");
 
     // Attempt to go back (using command-right).
     simulateCommandArrow(webView.get(), Right);
-    TestWebKitAPI::Util::run(&didFinishNavigation);
-    didFinishNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple2.html");
 }
@@ -230,15 +209,13 @@ TEST_F(WebKit2_CommandBackForwardTestWKWebView, RTL)
 
     // Attempt to go back (using command-right)
     simulateCommandArrow(webView.get(), Right);
-    TestWebKitAPI::Util::run(&didFinishNavigation);
-    didFinishNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple.html");
 
     // Attempt to go back (using command-left).
     simulateCommandArrow(webView.get(), Left);
-    TestWebKitAPI::Util::run(&didFinishNavigation);
-    didFinishNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple2.html");
 }
index d143129867021c92f1c380c29598f2758cc51372..85e8252d8c102586a08fe460b5453f8686024979 100644 (file)
 
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
 #import <WebKit/WebKit.h>
 #import <wtf/RetainPtr.h>
 
 #if WK_API_ENABLED && PLATFORM(IOS)
 
-static bool finishedLoading;
 static bool ranScript;
 
-@interface DataDetectionNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation DataDetectionNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    finishedLoading = true;
-}
-
-@end
-
 @interface DataDetectionUIDelegate : NSObject <WKUIDelegate>
 
 @property (nonatomic, retain) NSDate *referenceDate;
@@ -70,9 +58,7 @@ static bool ranScript;
 void expectLinkCount(WKWebView *webView, NSString *HTMLString, unsigned linkCount)
 {
     [webView loadHTMLString:HTMLString baseURL:nil];
-
-    TestWebKitAPI::Util::run(&finishedLoading);
-    finishedLoading = false;
+    [webView _test_waitForDidFinishNavigation];
 
     [webView evaluateJavaScript:@"document.getElementsByTagName('a').length" completionHandler:^(id value, NSError *error) {
         EXPECT_EQ(linkCount, [value unsignedIntValue]);
@@ -90,9 +76,6 @@ TEST(WebKit2, DataDetectionReferenceDate)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    RetainPtr<DataDetectionNavigationDelegate> navigationDelegate = adoptNS([[DataDetectionNavigationDelegate alloc] init]);
-    [webView setNavigationDelegate:navigationDelegate.get()];
-
     RetainPtr<DataDetectionUIDelegate> UIDelegate = adoptNS([[DataDetectionUIDelegate alloc] init]);
     [webView setUIDelegate:UIDelegate.get()];
 
index 2e8b25237be12749c82bd5d6e8080649b84783ac..32ea3993ec9599ed439da2ee335ddc40df969069 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 
 #import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
 #import <WebKit/WKWebViewPrivate.h>
 #import <wtf/RetainPtr.h>
 
@@ -46,33 +47,16 @@ typedef enum : NSUInteger {
 
 @end
 
-static bool navigationDone;
 static bool findMatchesDone;
 
-@interface FindInPageNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation FindInPageNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    navigationDone = true;
-}
-
-@end
-
 TEST(WebKit2, FindInPage)
 {
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
     [webView _setOverrideDeviceScaleFactor:2];
 
-    RetainPtr<FindInPageNavigationDelegate> delegate = adoptNS([[FindInPageNavigationDelegate alloc] init]);
-    [webView setNavigationDelegate:delegate.get()];
-
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"lots-of-text" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
-
-    TestWebKitAPI::Util::run(&navigationDone);
+    [webView _test_waitForDidFinishNavigation];
 
     NSTextFinderAsynchronousDocumentFindOptions noFindOptions = (NSTextFinderAsynchronousDocumentFindOptions)0;
 
index 429535cb3cd8c0ae24c4e71ac3afe37be8333e15..fee1064b31f3c75b909e1e16d5fb1ee7282b8186 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 
 #import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
 #import <WebKit/WKPreferences.h>
 #import <WebKit/WKWebViewPrivate.h>
 #import <wtf/RetainPtr.h>
@@ -36,29 +37,10 @@ static bool fixedLayoutSizeDone;
 static bool fixedLayoutSizeAfterNavigationDone;
 static bool fixedLayoutSizeDisabledDone;
 
-@interface FixedLayoutSizeNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation FixedLayoutSizeNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    // After navigating, fixed layout size should be persisted.
-    [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
-        EXPECT_EQ(200, [result integerValue]);
-        fixedLayoutSizeAfterNavigationDone = true;
-    }];
-}
-
-@end
-
 TEST(WebKit2, FixedLayoutSize)
 {
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
 
-    FixedLayoutSizeNavigationDelegate *delegate = [[FixedLayoutSizeNavigationDelegate alloc] init];
-    [webView setNavigationDelegate:delegate];
-
     [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
         EXPECT_EQ(100, [result integerValue]);
 
@@ -76,6 +58,13 @@ TEST(WebKit2, FixedLayoutSize)
 
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
+    [webView _test_waitForDidFinishNavigation];
+
+    // After navigating, fixed layout size should be persisted.
+    [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
+        EXPECT_EQ(200, [result integerValue]);
+        fixedLayoutSizeAfterNavigationDone = true;
+    }];
 
     TestWebKitAPI::Util::run(&fixedLayoutSizeAfterNavigationDone);
 
index 6cf19fdf4a47772cab932570bbc79f2a5474a05b..7904fac668cebba6e3b18cdd5dad2781ec163ded 100644 (file)
@@ -27,6 +27,7 @@
 
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKUserContentControllerPrivate.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 
 #if WK_API_ENABLED
 
-static bool isDoneWithNavigation;
-
-@interface DatabaseProcessKillNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation DatabaseProcessKillNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    isDoneWithNavigation = true;
-}
-
-@end
-
 static bool receivedScriptMessage;
 static bool receivedAtLeastOneOpenError;
 static bool receivedAtLeastOneDeleteError;
@@ -94,13 +81,9 @@ TEST(IndexedDB, DatabaseProcessKill)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    DatabaseProcessKillNavigationDelegate *delegate = [[DatabaseProcessKillNavigationDelegate alloc] init];
-    [webView setNavigationDelegate:delegate];
-
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"IndexedDBDatabaseProcessKill-1" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
-
-    TestWebKitAPI::Util::run(&isDoneWithNavigation);
+    [webView _test_waitForDidFinishNavigation];
 
     bool killedDBProcess = false;
     while (true) {
index 449e8933829410f9f0a22761380ed29ac5a45599..cd1bc95d49643d1f44e3edf28c0f14f77b75af18 100644 (file)
 
 #if WK_API_ENABLED
 
-static bool isDoneWithNavigation;
-
-@interface IndexedDBNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation IndexedDBNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    isDoneWithNavigation = true;
-}
-
-@end
-
 static bool receivedScriptMessage;
 static RetainPtr<WKScriptMessage> lastScriptMessage;
 
index 007cf811b6951fe7f59039dcae1e220ce276ca43..2840f512960e128e328dc6694c35cabf74acb929 100644 (file)
 
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
 #import <wtf/RetainPtr.h>
 
 static bool isDone;
 
-@interface ProvisionalURLNotChangeController : NSObject <WKNavigationDelegate>
-@end
-
-@implementation ProvisionalURLNotChangeController
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    isDone = true;
-}
-
-- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error
-{
-    isDone = true;
-}
-
-@end
-
 TEST(WKWebView, ProvisionalURLNotChange)
 {
     auto webView = adoptNS([[WKWebView alloc] init]);
-    auto controller = adoptNS([[ProvisionalURLNotChangeController alloc] init]);
-    [webView setNavigationDelegate:controller.get()];
+
+    auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]);
+    [navigationDelegate setDidFinishNavigation:^(WKWebView *, WKNavigation *) {
+        isDone = true;
+    }];
+    [navigationDelegate setDidFailProvisionalNavigation:^(WKWebView *, WKNavigation *, NSError *) {
+        isDone = true;
+    }];
+    [webView setNavigationDelegate:navigationDelegate.get()];
 
     [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,start"]]];
     TestWebKitAPI::Util::run(&isDone);
index bdac0051ae2af96314e72116d1d6a2f0ebe7ebdc..307a49cd898be0ea33f27929982ee372ad565f5e 100644 (file)
@@ -27,6 +27,7 @@
 
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
 #import <WebCore/SoftLinking.h>
 #import <WebKit/WKWebViewConfigurationPrivate.h>
 #import <WebKit/WebKit.h>
@@ -39,18 +40,6 @@ SOFT_LINK_FRAMEWORK(UIKit)
 SOFT_LINK_CLASS(UIKit, UIWindow)
 #endif
 
-static bool isDoneWithNavigation;
-
-@interface RequiresUserActionForPlaybackNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation RequiresUserActionForPlaybackNavigationDelegate
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    isDoneWithNavigation = true;
-}
-@end
-
 static bool receivedScriptMessage;
 static RetainPtr<WKScriptMessage> lastScriptMessage;
 
@@ -82,9 +71,7 @@ public:
 
     void createWebView()
     {
-        delegate = adoptNS([[RequiresUserActionForPlaybackNavigationDelegate alloc] init]);
         webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
-        [webView setNavigationDelegate:delegate.get()];
 #if TARGET_OS_IPHONE
         window = adoptNS([[getUIWindowClass() alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
         [window addSubview:webView.get()];
@@ -98,8 +85,7 @@ public:
     {
         NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
         [webView loadFileURL:fileURL allowingReadAccessToURL:fileURL];
-        TestWebKitAPI::Util::run(&isDoneWithNavigation);
-        isDoneWithNavigation = false;
+        [webView _test_waitForDidFinishNavigation];
 
         TestWebKitAPI::Util::run(&receivedScriptMessage);
         receivedScriptMessage = false;
@@ -109,8 +95,7 @@ public:
     {
         NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"video-without-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
         [webView loadFileURL:fileURL allowingReadAccessToURL:fileURL];
-        TestWebKitAPI::Util::run(&isDoneWithNavigation);
-        isDoneWithNavigation = false;
+        [webView _test_waitForDidFinishNavigation];
 
         TestWebKitAPI::Util::run(&receivedScriptMessage);
         receivedScriptMessage = false;
@@ -120,8 +105,7 @@ public:
     {
         NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"audio-only" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
         [webView loadFileURL:fileURL allowingReadAccessToURL:fileURL];
-        TestWebKitAPI::Util::run(&isDoneWithNavigation);
-        isDoneWithNavigation = false;
+        [webView _test_waitForDidFinishNavigation];
 
         TestWebKitAPI::Util::run(&receivedScriptMessage);
         receivedScriptMessage = false;
@@ -129,7 +113,6 @@ public:
 
     RetainPtr<RequiresUserActionForPlaybackMessageHandler> handler;
     RetainPtr<WKWebViewConfiguration> configuration;
-    RetainPtr<RequiresUserActionForPlaybackNavigationDelegate> delegate;
     RetainPtr<WKWebView> webView;
 #if TARGET_OS_IPHONE
     RetainPtr<UIWindow> window;
index c3ad50c194a401310ef2824e3796bd4a254561bd..ec51b963830bd7a3c71072be6e448d6ae55ee78e 100644 (file)
@@ -26,6 +26,7 @@
 #include "config.h"
 
 #import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
 #import <WebKit/WKWebViewPrivate.h>
 #import <wtf/RetainPtr.h>
 
@@ -35,29 +36,10 @@ static bool shrinkToFitDone;
 static bool shrinkToFitAfterNavigationDone;
 static bool shrinkToFitDisabledDone;
 
-@interface ShrinkToFitNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation ShrinkToFitNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    // After loading a wide page, the view should be scaled to fit the width of the document.
-    [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
-        EXPECT_EQ(808, [result integerValue]);
-        shrinkToFitAfterNavigationDone = true;
-    }];
-}
-
-@end
-
 TEST(WebKit2, ShrinkToFit)
 {
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
 
-    ShrinkToFitNavigationDelegate *delegate = [[ShrinkToFitNavigationDelegate alloc] init];
-    [webView setNavigationDelegate:delegate];
-
     [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
         EXPECT_EQ(100, [result integerValue]);
 
@@ -69,6 +51,13 @@ TEST(WebKit2, ShrinkToFit)
 
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"lots-of-text" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
+    [webView _test_waitForDidFinishNavigation];
+
+    // After loading a wide page, the view should be scaled to fit the width of the document.
+    [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
+        EXPECT_EQ(808, [result integerValue]);
+        shrinkToFitAfterNavigationDone = true;
+    }];
 
     TestWebKitAPI::Util::run(&shrinkToFitAfterNavigationDone);
 
index 0b0c7332615ca4bc8fcd54da8071b356b06eb313..e5547778d95edbf700403735aa6411a14286f431 100644 (file)
@@ -27,6 +27,7 @@
 
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/WKUserContentControllerPrivate.h>
 #import <WebKit/WKUserScript.h>
@@ -78,14 +79,10 @@ TEST(WKUserContentController, ScriptMessageHandlerBasicPost)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate 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(&isDoneWithNavigation);
+    [webView _test_waitForDidFinishNavigation];
 
     [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('Hello')" completionHandler:nil];
 
@@ -154,14 +151,10 @@ TEST(WKUserContentController, ScriptMessageHandlerBasicRemove)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate 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(&isDoneWithNavigation);
+    [webView _test_waitForDidFinishNavigation];
 
     // Test that handlerToRemove was succesfully added.
     [webView evaluateJavaScript:
@@ -202,14 +195,10 @@ TEST(WKUserContentController, ScriptMessageHandlerCallRemovedHandler)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate 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(&isDoneWithNavigation);
+    [webView _test_waitForDidFinishNavigation];
 
     [webView evaluateJavaScript:@"var handlerToRemove = window.webkit.messageHandlers.handlerToRemove;" completionHandler:nil];
 
@@ -237,12 +226,9 @@ static RetainPtr<WKWebView> webViewForScriptMessageHandlerMultipleHandlerRemoval
     [[configurationCopy userContentController] addScriptMessageHandler:handler.get() name:@"handlerToRemove"];
     [[configurationCopy userContentController] addScriptMessageHandler:handler.get() name:@"handlerToPost"];
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configurationCopy.get()]);
-    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate 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(&isDoneWithNavigation);
-    isDoneWithNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     return webView;
 }
@@ -282,14 +268,9 @@ TEST(WKUserContentController, ScriptMessageHandlerWithNavigation)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate 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(&isDoneWithNavigation);
-    isDoneWithNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('First Message')" completionHandler:nil];
 
@@ -300,10 +281,8 @@ TEST(WKUserContentController, ScriptMessageHandlerWithNavigation)
     receivedScriptMessage = false;
     lastScriptMessage = nullptr;
 
-
     [webView loadRequest:request];
-    TestWebKitAPI::Util::run(&isDoneWithNavigation);
-    isDoneWithNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('Second Message')" completionHandler:nil];
 
@@ -322,14 +301,10 @@ TEST(WKUserContentController, ScriptMessageHandlerReplaceWithSameName)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate 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(&isDoneWithNavigation);
+    [webView _test_waitForDidFinishNavigation];
 
     // Test that handlerToReplace was succesfully added.
     [webView evaluateJavaScript:@"window.webkit.messageHandlers.handlerToReplace.postMessage('PASS1');" completionHandler:nil];
@@ -381,12 +356,8 @@ TEST(WKUserContentController, AddUserStyleSheetBeforeCreatingView)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
-    [webView setNavigationDelegate:delegate.get()];
-
     [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil];
-    TestWebKitAPI::Util::run(&isDoneWithNavigation);
-    isDoneWithNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, greenInRGB);
 }
@@ -395,12 +366,8 @@ TEST(WKUserContentController, AddUserStyleSheetAfterCreatingView)
 {
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
 
-    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
-    [webView setNavigationDelegate:delegate.get()];
-
     [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil];
-    TestWebKitAPI::Util::run(&isDoneWithNavigation);
-    isDoneWithNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, redInRGB);
 
@@ -419,12 +386,8 @@ TEST(WKUserContentController, UserStyleSheetAffectingOnlyMainFrame)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
-    [webView setNavigationDelegate:delegate.get()];
-
     [webView loadHTMLString:@"<body style='background-color: red;'><iframe></iframe></body>" baseURL:nil];
-    TestWebKitAPI::Util::run(&isDoneWithNavigation);
-    isDoneWithNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     // The main frame should be affected.
     expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, greenInRGB);
@@ -442,12 +405,8 @@ TEST(WKUserContentController, UserStyleSheetAffectingAllFrames)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
-    [webView setNavigationDelegate:delegate.get()];
-
     [webView loadHTMLString:@"<body style='background-color: red;'><iframe></iframe></body>" baseURL:nil];
-    TestWebKitAPI::Util::run(&isDoneWithNavigation);
-    isDoneWithNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     // The main frame should be affected.
     expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, greenInRGB);
index 9eb7016982eddd6f0e9d48f00bc427a50bdf0172..b5dda2dd6168735bd67fc581f6f862e57f047b1b 100644 (file)
@@ -30,6 +30,7 @@
 
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
 #import "UserContentWorldProtocol.h"
 #import "WKWebViewConfigurationExtras.h"
 #import <WebKit/WKProcessPoolPrivate.h>
 #import <WebKit/_WKUserStyleSheet.h>
 #import <wtf/RetainPtr.h>
 
-static bool isDoneWithNavigation;
-
-@interface SimpleDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation SimpleDelegate
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    isDoneWithNavigation = true;
-}
-@end
-
-
 TEST(UserContentWorld, NormalWorld)
 {
     RetainPtr<WKUserScript> basicUserScript = adoptNS([[WKUserScript alloc] initWithSource:@"" injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]);
@@ -73,12 +61,8 @@ TEST(UserContentWorld, NormalWorldUserScript)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    RetainPtr<SimpleDelegate> delegate = adoptNS([[SimpleDelegate alloc] init]);
-    [webView setNavigationDelegate:delegate.get()];
-
     [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil];
-    TestWebKitAPI::Util::run(&isDoneWithNavigation);
-    isDoneWithNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     __block bool isDone = false;
     [webView evaluateJavaScript:@"window.setFromUserScript ? 'variable accessible' : 'variable inaccessible';" completionHandler:^(id result, NSError *error) {
@@ -112,12 +96,8 @@ TEST(UserContentWorld, IsolatedWorldUserScript)
 
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
 
-    RetainPtr<SimpleDelegate> delegate = adoptNS([[SimpleDelegate alloc] init]);
-    [webView setNavigationDelegate:delegate.get()];
-
     [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil];
-    TestWebKitAPI::Util::run(&isDoneWithNavigation);
-    isDoneWithNavigation = false;
+    [webView _test_waitForDidFinishNavigation];
 
     __block bool isDone = false;
     [webView evaluateJavaScript:@"window.setFromUserScript ? 'variable accessible' : 'variable inaccessible';" completionHandler:^(id result, NSError *error) {
index ed47ccae3a64cc01ca6e408d68f7d3da12f1902e..0740c970669a106885bf006aa34ba81c5c076dea 100644 (file)
 
 #include "config.h"
 
-#import <WebKit/WKNavigationDelegate.h>
-#import <WebKit/WKWebView.h>
-#import <wtf/RetainPtr.h>
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
+#import <WebKit/WKWebView.h>
+#import <wtf/RetainPtr.h>
 
 #if WK_API_ENABLED
 
-static bool finishedLoading;
 static bool finishedDispatch;
 
-@interface WKPDFViewResizeNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation WKPDFViewResizeNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    finishedLoading = true;
-}
-
-@end
-
 TEST(WebKit2, WKPDFViewResizeCrash)
 {
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
 
-    RetainPtr<WKPDFViewResizeNavigationDelegate> delegate = adoptNS([[WKPDFViewResizeNavigationDelegate alloc] init]);
-    [webView setNavigationDelegate:delegate.get()];
-
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"test" withExtension:@"pdf" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
-
-    TestWebKitAPI::Util::run(&finishedLoading);
+    [webView _test_waitForDidFinishNavigation];
 
     [webView setFrame:NSMakeRect(0, 0, 100, 100)];
     webView = nil;
index 997fa8eeb7b977091162609263ccf1b30acd865e..cc68d7716ea7ae467000691bcb5f4a97f9231ecb 100644 (file)
 
 #import "PlatformUtilities.h"
 #import "Test.h"
+#import "TestNavigationDelegate.h"
 #import <WebKit/WKWebView.h>
 #import <WebKit/WKErrorPrivate.h>
 #import <wtf/RetainPtr.h>
 
 static bool isDone;
 
-@interface EvaluateJavaScriptNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation EvaluateJavaScriptNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    isDone = true;
-}
-
-@end
-
 TEST(WKWebView, EvaluateJavaScriptBlockCrash)
 {
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
@@ -76,12 +65,10 @@ TEST(WKWebView, EvaluateJavaScriptBlockCrash)
 TEST(WKWebView, EvaluateJavaScriptErrorCases)
 {
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
-    RetainPtr<EvaluateJavaScriptNavigationDelegate> delegate = adoptNS([[EvaluateJavaScriptNavigationDelegate 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(&isDone);
+    [webView _test_waitForDidFinishNavigation];
 
     [webView evaluateJavaScript:@"document.body" completionHandler:^(id result, NSError *error) {
         EXPECT_NULL(result);
index 106e62db6721c76cb2839e8b0ba5926a55c06e1d..53ab2297efc897d5b217c47e18c072c4f83e578d 100644 (file)
 #if WK_API_ENABLED
 #if PLATFORM(MAC)
 
-#import <WebKit/WKFoundation.h>
 #import "PlatformUtilities.h"
 #import "Test.h"
-#import <WebKit/WKWebView.h>
+#import "TestNavigationDelegate.h"
+#import <WebKit/WebKit.h>
 #import <wtf/RetainPtr.h>
 
-static bool isDone;
-
-@interface DummyNavigationDelegate : NSObject <WKNavigationDelegate>
-@end
-
-@implementation DummyNavigationDelegate
-
-- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
-{
-    isDone = true;
-}
-
-@end
-
 TEST(WKWebView, ShouldHaveInputContextForEditableContent)
 {
     RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
-    RetainPtr<DummyNavigationDelegate> delegate = adoptNS([[DummyNavigationDelegate alloc] init]);
-    [webView setNavigationDelegate:delegate.get()];
 
     NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"editable-body" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
     [webView loadRequest:request];
-    TestWebKitAPI::Util::run(&isDone);
+    [webView _test_waitForDidFinishNavigation];
 
     EXPECT_NOT_NULL([webView inputContext]);
 }
diff --git a/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h b/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h
new file mode 100644 (file)
index 0000000..4fffdb3
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if WK_API_ENABLED
+
+#import <WebKit/WKNavigationDelegatePrivate.h>
+#import <WebKit/WebKit.h>
+
+@interface TestNavigationDelegate : NSObject <WKNavigationDelegate>
+
+@property (nonatomic, copy) void (^didFailProvisionalNavigation)(WKWebView *, WKNavigation *, NSError *);
+@property (nonatomic, copy) void (^didFinishNavigation)(WKWebView *, WKNavigation *);
+@property (nonatomic, copy) void (^renderingProgressDidChange)(WKWebView *, _WKRenderingProgressEvents);
+
+- (void)waitForDidFinishNavigation;
+
+@end
+
+@interface WKWebView (TestWebKitAPIExtras)
+- (void)_test_waitForDidFinishNavigation;
+@end
+
+#endif
diff --git a/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm b/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm
new file mode 100644 (file)
index 0000000..9daf6f9
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "TestNavigationDelegate.h"
+
+#import "Utilities.h"
+#import <wtf/RetainPtr.h>
+
+#if WK_API_ENABLED
+
+@implementation TestNavigationDelegate
+
+- (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error
+{
+    if (_didFailProvisionalNavigation)
+        _didFailProvisionalNavigation(webView, navigation, error);
+}
+
+- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
+{
+    if (_didFinishNavigation)
+        _didFinishNavigation(webView, navigation);
+}
+
+- (void)_webView:(WKWebView *)webView renderingProgressDidChange:(_WKRenderingProgressEvents)progressEvents
+{
+    if (_renderingProgressDidChange)
+        _renderingProgressDidChange(webView, progressEvents);
+}
+
+- (void)waitForDidFinishNavigation
+{
+    EXPECT_FALSE(self.didFinishNavigation);
+
+    __block bool finished = false;
+    self.didFinishNavigation = ^(WKWebView *, WKNavigation *) {
+        finished = true;
+    };
+
+    TestWebKitAPI::Util::run(&finished);
+
+    self.didFinishNavigation = nil;
+}
+
+@end
+
+@implementation WKWebView (TestWebKitAPIExtras)
+
+- (void)_test_waitForDidFinishNavigation
+{
+    EXPECT_FALSE(self.navigationDelegate);
+
+    auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]);
+    self.navigationDelegate = navigationDelegate.get();
+    [navigationDelegate waitForDidFinishNavigation];
+
+    self.navigationDelegate = nil;
+}
+
+@end
+
+#endif