Diff
Modified: branches/safari-602-branch/Tools/ChangeLog (207600 => 207601)
--- branches/safari-602-branch/Tools/ChangeLog 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/ChangeLog 2016-10-20 09:59:42 UTC (rev 207601)
@@ -1,5 +1,98 @@
2016-10-20 Matthew Hanson <matthew_han...@apple.com>
+ Merge r205329. rdar://problem/28634858
+
+ 2016-09-01 Tim Horton <timothy_hor...@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-10-20 Matthew Hanson <matthew_han...@apple.com>
+
Merge r206247. rdar://problem/28216256
2016-09-21 Dan Bernstein <m...@apple.com>
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2016-10-20 09:59:42 UTC (rev 207601)
@@ -51,6 +51,7 @@
2D00065F1C1F589A0088E6A7 /* WKPDFViewResizeCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */; };
2D1646E21D1862CD00015A1A /* DeferredViewInWindowStateChange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1646E11D1862CD00015A1A /* DeferredViewInWindowStateChange.mm */; };
2D4CF8BD1D8360CC0001CE8D /* WKThumbnailView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D4CF8BC1D8360CC0001CE8D /* WKThumbnailView.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 */; };
@@ -743,6 +744,8 @@
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>"; };
2D4CF8BC1D8360CC0001CE8D /* WKThumbnailView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = WKThumbnailView.mm; path = WebKit2/WKThumbnailView.mm; sourceTree = "<group>"; };
2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMHTMLVideoElementWrapper.mm; sourceTree = "<group>"; };
@@ -1261,6 +1264,8 @@
5C726D6E1D3EE06800C5E1A1 /* InstanceMethodSwizzler.mm */,
A13EBB441B87332B00097110 /* WebProcessPlugIn */,
0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */,
+ 2D1C04A51D76298B000A6816 /* TestNavigationDelegate.h */,
+ 2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */,
A14FC58D1B8AE36500D107EB /* TestProtocol.h */,
A14FC58E1B8AE36500D107EB /* TestProtocol.mm */,
7C83E0391D0A602700FEBCF3 /* UtilitiesCocoa.mm */,
@@ -2228,6 +2233,7 @@
7CCE7EB81A411A7E00447C4C /* ContextMenuCanCopyURL.mm in Sources */,
7CCE7EE81A411AE600447C4C /* CookieManager.cpp in Sources */,
7CCE7EAC1A411A3400447C4C /* Counters.cpp in Sources */,
+ 2D1C04A71D76298B000A6816 /* TestNavigationDelegate.mm in Sources */,
7CCE7EDB1A411A9200447C4C /* CSSParser.cpp in Sources */,
7C83E0401D0A63E300FEBCF3 /* FirstResponderScrollingPosition.mm in Sources */,
7C83E0521D0A641800FEBCF3 /* SharedBuffer.cpp in Sources */,
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -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>
@@ -36,20 +36,6 @@
#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 @@
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);
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AlwaysRevalidatedURLSchemes.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AlwaysRevalidatedURLSchemes.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AlwaysRevalidatedURLSchemes.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -28,6 +28,7 @@
#if WK_API_ENABLED
#import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
#import <WebKit/WKBrowsingContextController.h>
#import <WebKit/WKProcessPoolPrivate.h>
#import <WebKit/_WKProcessPoolConfiguration.h>
@@ -34,7 +35,6 @@
#import <wtf/RetainPtr.h>
static NSString * const customScheme = @"custom";
-static bool isDone;
static size_t loadsStarted;
@interface AlwaysRevalidatedURLSchemeProtocol : NSURLProtocol
@@ -74,18 +74,6 @@
@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 @@
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=''>", 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];
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AnimatedResize.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AnimatedResize.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AnimatedResize.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -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>
@@ -40,19 +40,6 @@
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 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];
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -26,27 +26,15 @@
#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
@property (nonatomic) BOOL expectingIntrinsicContentSizeChange;
@property (nonatomic) NSSize expectedIntrinsicContentSize;
@@ -54,6 +42,15 @@
@implementation AutoLayoutWKWebView
+- (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];
@@ -72,9 +69,8 @@
".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];
}
@@ -115,9 +111,6 @@
{
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)];
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CancelFontSubresource.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CancelFontSubresource.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CancelFontSubresource.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -30,6 +30,7 @@
#import "PlatformUtilities.h"
#import "Test.h"
+#import "TestNavigationDelegate.h"
#import "UserContentWorldProtocol.h"
#import "WKWebViewConfigurationExtras.h"
#import <WebKit/WKProcessPoolPrivate.h>
@@ -44,20 +45,6 @@
#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 @@
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
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -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 @@
#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,9 +163,6 @@
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()
@@ -184,15 +169,11 @@
{
NSURL *file1 = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
[webView loadFileURL:file1 allowingReadAccessToURL:file1];
+ [webView _test_waitForDidFinishNavigation];
- TestWebKitAPI::Util::run(&didFinishNavigation);
- didFinishNavigation = false;
-
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 @@
// 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 @@
// 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");
}
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DataDetection.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DataDetection.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DataDetection.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -27,26 +27,14 @@
#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,10 +58,8 @@
void expectLinkCount(WKWebView *webView, NSString *HTMLString, unsigned linkCount)
{
[webView loadHTMLString:HTMLString baseURL:nil];
+ [webView _test_waitForDidFinishNavigation];
- TestWebKitAPI::Util::run(&finishedLoading);
- finishedLoading = false;
-
[webView evaluateJavaScript:@"document.getElementsByTagName('a').length" completionHandler:^(id value, NSError *error) {
EXPECT_EQ(linkCount, [value unsignedIntValue]);
ranScript = true;
@@ -90,9 +76,6 @@
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()];
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -26,6 +26,7 @@
#include "config.h"
#import "PlatformUtilities.h"
+#import "TestNavigationDelegate.h"
#import <WebKit/WKWebViewPrivate.h>
#import <wtf/RetainPtr.h>
@@ -46,34 +47,17 @@
@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];
+ [webView _test_waitForDidFinishNavigation];
- TestWebKitAPI::Util::run(&navigationDone);
-
NSTextFinderAsynchronousDocumentFindOptions noFindOptions = (NSTextFinderAsynchronousDocumentFindOptions)0;
// Find all matches.
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -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 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,7 +58,14 @@
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);
[webView _setLayoutMode:_WKLayoutModeViewSize];
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -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>
@@ -36,20 +37,6 @@
#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,14 +81,10 @@
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];
+ [webView _test_waitForDidFinishNavigation];
- TestWebKitAPI::Util::run(&isDoneWithNavigation);
-
bool killedDBProcess = false;
while (true) {
if (databaseErrorReceived)
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBPersistence.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBPersistence.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBPersistence.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -37,20 +37,6 @@
#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;
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLNotChange.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLNotChange.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLNotChange.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -30,33 +30,24 @@
#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);
isDone = false;
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RequiresUserActionForPlayback.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RequiresUserActionForPlayback.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RequiresUserActionForPlayback.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -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_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 @@
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 @@
{
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 @@
{
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 @@
{
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 @@
RetainPtr<RequiresUserActionForPlaybackMessageHandler> handler;
RetainPtr<WKWebViewConfiguration> configuration;
- RetainPtr<RequiresUserActionForPlaybackNavigationDelegate> delegate;
RetainPtr<WKWebView> webView;
#if TARGET_OS_IPHONE
RetainPtr<UIWindow> window;
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -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 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,7 +51,14 @@
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);
[webView _setLayoutMode:_WKLayoutModeViewSize];
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -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,15 +79,11 @@
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];
+ [webView _test_waitForDidFinishNavigation];
- TestWebKitAPI::Util::run(&isDoneWithNavigation);
-
[webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('Hello')" completionHandler:nil];
TestWebKitAPI::Util::run(&receivedScriptMessage);
@@ -154,15 +151,11 @@
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];
+ [webView _test_waitForDidFinishNavigation];
- TestWebKitAPI::Util::run(&isDoneWithNavigation);
-
// Test that handlerToRemove was succesfully added.
[webView evaluateJavaScript:
@"if (window.webkit.messageHandlers.handlerToRemove) {"
@@ -202,15 +195,11 @@
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];
+ [webView _test_waitForDidFinishNavigation];
- TestWebKitAPI::Util::run(&isDoneWithNavigation);
-
[webView evaluateJavaScript:@"var handlerToRemove = window.webkit.messageHandlers.handlerToRemove;" completionHandler:nil];
[userContentController removeScriptMessageHandlerForName:@"handlerToRemove"];
@@ -237,12 +226,9 @@
[[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,15 +268,10 @@
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];
+ [webView _test_waitForDidFinishNavigation];
- TestWebKitAPI::Util::run(&isDoneWithNavigation);
- isDoneWithNavigation = false;
-
[webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('First Message')" completionHandler:nil];
TestWebKitAPI::Util::run(&receivedScriptMessage);
@@ -300,10 +281,8 @@
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,15 +301,11 @@
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];
+ [webView _test_waitForDidFinishNavigation];
- TestWebKitAPI::Util::run(&isDoneWithNavigation);
-
// Test that handlerToReplace was succesfully added.
[webView evaluateJavaScript:@"window.webkit.messageHandlers.handlerToReplace.postMessage('PASS1');" completionHandler:nil];
@@ -381,12 +356,8 @@
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 @@
{
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 @@
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 @@
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);
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentWorld.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentWorld.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentWorld.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -30,6 +30,7 @@
#import "PlatformUtilities.h"
#import "Test.h"
+#import "TestNavigationDelegate.h"
#import "UserContentWorldProtocol.h"
#import "WKWebViewConfigurationExtras.h"
#import <WebKit/WKProcessPoolPrivate.h>
@@ -44,19 +45,6 @@
#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 @@
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 @@
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) {
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKPDFViewResizeCrash.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKPDFViewResizeCrash.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKPDFViewResizeCrash.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -25,41 +25,24 @@
#include "config.h"
-#import <WebKit/WKNavigationDelegate.h>
+#import "PlatformUtilities.h"
+#import "Test.h"
+#import "TestNavigationDelegate.h"
#import <WebKit/WKWebView.h>
#import <wtf/RetainPtr.h>
-#import "PlatformUtilities.h"
-#import "Test.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];
+ [webView _test_waitForDidFinishNavigation];
- TestWebKitAPI::Util::run(&finishedLoading);
-
[webView setFrame:NSMakeRect(0, 0, 100, 100)];
webView = nil;
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -30,6 +30,7 @@
#import "PlatformUtilities.h"
#import "Test.h"
+#import "TestNavigationDelegate.h"
#import <WebKit/WKWebView.h>
#import <WebKit/WKErrorPrivate.h>
#import <wtf/RetainPtr.h>
@@ -36,18 +37,6 @@
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, 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);
Modified: branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewTextInput.mm (207600 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewTextInput.mm 2016-10-20 09:59:35 UTC (rev 207600)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewTextInput.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -28,35 +28,19 @@
#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]);
}
Copied: branches/safari-602-branch/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h (from rev 207600, branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewTextInput.mm) (0 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h (rev 0)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h 2016-10-20 09:59:42 UTC (rev 207601)
@@ -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
Copied: branches/safari-602-branch/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm (from rev 207600, branches/safari-602-branch/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLNotChange.mm) (0 => 207601)
--- branches/safari-602-branch/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm (rev 0)
+++ branches/safari-602-branch/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm 2016-10-20 09:59:42 UTC (rev 207601)
@@ -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