Changeset 205329 in webkit
- Timestamp:
- Sep 1, 2016 6:16:56 PM (8 years ago)
- Location:
- trunk/Tools
- Files:
-
- 21 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r205326 r205329 1 2016-09-01 Tim Horton <timothy_horton@apple.com> 2 3 Provide a TestWebKitAPI-wide WKNavigationDelegate to simplify tests 4 https://bugs.webkit.org/show_bug.cgi?id=161413 5 6 Reviewed by Simon Fraser. 7 8 Add TestNavigationDelegate, which provides block properties to make 9 writing tests feel a little more natural (the callbacks can be inline), 10 and also add WKWebView _test_waitForDidFinishNavigation, so that many 11 tests don't even need to manually allocate a navigation delegate at all. 12 13 Adopt in some of the simpler tests; there are a few navigation delegates 14 left behind, which we can move to the new model in the future. 15 16 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 17 * TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm: 18 (TEST): 19 (-[WKBackForwardListTestNavigationDelegate webView:didFinishNavigation:]): Deleted. 20 * TestWebKitAPI/Tests/WebKit2Cocoa/AlwaysRevalidatedURLSchemes.mm: 21 (TEST): 22 (-[AlwaysRevalidatedURLSchemesDelegate webView:didFinishNavigation:]): Deleted. 23 * TestWebKitAPI/Tests/WebKit2Cocoa/AnimatedResize.mm: 24 (animatedResizeWebView): 25 (-[AnimatedResizeNavigationDelegate _webView:renderingProgressDidChange:]): Deleted. 26 * TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm: 27 (-[AutoLayoutWKWebView initWithFrame:configuration:]): 28 (-[AutoLayoutWKWebView load:withWidth:expectingContentSize:resettingWidth:]): 29 (TEST): 30 (-[AutoLayoutNavigationDelegate webView:didFinishNavigation:]): Deleted. 31 * TestWebKitAPI/Tests/WebKit2Cocoa/CancelFontSubresource.mm: 32 (TEST): 33 (-[CancelFontSubresourceNavigationDelegate webView:didFinishNavigation:]): Deleted. 34 * TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm: 35 (WebKit2_CommandBackForwardTestWKWebView::SetUp): 36 (WebKit2_CommandBackForwardTestWKWebView::loadFiles): 37 (TEST_F): 38 (-[CommandBackForwardNavigationDelegate webView:didFinishNavigation:]): Deleted. 39 * TestWebKitAPI/Tests/WebKit2Cocoa/DataDetection.mm: 40 (expectLinkCount): 41 (TEST): 42 (-[DataDetectionNavigationDelegate webView:didFinishNavigation:]): Deleted. 43 * TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm: 44 (TEST): 45 (-[FindInPageNavigationDelegate webView:didFinishNavigation:]): Deleted. 46 * TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm: 47 (TEST): 48 (-[FixedLayoutSizeNavigationDelegate webView:didFinishNavigation:]): Deleted. 49 * TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm: 50 (TEST): 51 (-[DatabaseProcessKillNavigationDelegate webView:didFinishNavigation:]): Deleted. 52 * TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBPersistence.mm: 53 (-[IndexedDBNavigationDelegate webView:didFinishNavigation:]): Deleted. 54 * TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLNotChange.mm: 55 (TEST): 56 (-[ProvisionalURLNotChangeController webView:didFinishNavigation:]): Deleted. 57 (-[ProvisionalURLNotChangeController webView:didFailProvisionalNavigation:withError:]): Deleted. 58 * TestWebKitAPI/Tests/WebKit2Cocoa/RequiresUserActionForPlayback.mm: 59 (RequiresUserActionForPlaybackTest::createWebView): 60 (RequiresUserActionForPlaybackTest::testVideoWithAudio): 61 (RequiresUserActionForPlaybackTest::testVideoWithoutAudio): 62 (RequiresUserActionForPlaybackTest::testAudioOnly): 63 (-[RequiresUserActionForPlaybackNavigationDelegate webView:didFinishNavigation:]): Deleted. 64 * TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm: 65 (TEST): 66 (-[ShrinkToFitNavigationDelegate webView:didFinishNavigation:]): Deleted. 67 * TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm: 68 (TEST): 69 (webViewForScriptMessageHandlerMultipleHandlerRemovalTest): 70 * TestWebKitAPI/Tests/WebKit2Cocoa/UserContentWorld.mm: 71 (TEST): 72 (-[SimpleDelegate webView:didFinishNavigation:]): Deleted. 73 * TestWebKitAPI/Tests/WebKit2Cocoa/WKPDFViewResizeCrash.mm: 74 (TEST): 75 (-[WKPDFViewResizeNavigationDelegate webView:didFinishNavigation:]): Deleted. 76 * TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm: 77 (TEST): 78 (-[EvaluateJavaScriptNavigationDelegate webView:didFinishNavigation:]): Deleted. 79 * TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewTextInput.mm: 80 (TEST): 81 (-[DummyNavigationDelegate webView:didFinishNavigation:]): Deleted. 82 * TestWebKitAPI/cocoa/TestNavigationDelegate.h: Added. 83 * TestWebKitAPI/cocoa/TestNavigationDelegate.mm: Added. 84 (-[TestNavigationDelegate webView:didFailProvisionalNavigation:withError:]): 85 (-[TestNavigationDelegate webView:didFinishNavigation:]): 86 (-[TestNavigationDelegate _webView:renderingProgressDidChange:]): 87 (-[TestNavigationDelegate waitForDidFinishNavigation]): 88 (-[WKWebView _test_waitForDidFinishNavigation]): 89 1 90 2016-09-01 Ricky Mondello <rmondello@apple.com> 2 91 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r205313 r205329 53 53 2D00065F1C1F589A0088E6A7 /* WKPDFViewResizeCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */; }; 54 54 2D1646E21D1862CD00015A1A /* DeferredViewInWindowStateChange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1646E11D1862CD00015A1A /* DeferredViewInWindowStateChange.mm */; }; 55 2D1C04A71D76298B000A6816 /* TestNavigationDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */; }; 55 56 2D51A0C71C8BF00C00765C45 /* DOMHTMLVideoElementWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */; }; 56 57 2DC4CF771D2D9DD800ECCC94 /* DataDetection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DC4CF761D2D9DD800ECCC94 /* DataDetection.mm */; }; … … 724 725 2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKPDFViewResizeCrash.mm; sourceTree = "<group>"; }; 725 726 2D1646E11D1862CD00015A1A /* DeferredViewInWindowStateChange.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = DeferredViewInWindowStateChange.mm; path = WebKit2/DeferredViewInWindowStateChange.mm; sourceTree = "<group>"; }; 727 2D1C04A51D76298B000A6816 /* TestNavigationDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TestNavigationDelegate.h; path = cocoa/TestNavigationDelegate.h; sourceTree = "<group>"; }; 728 2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = TestNavigationDelegate.mm; path = cocoa/TestNavigationDelegate.mm; sourceTree = "<group>"; }; 726 729 2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FixedLayoutSize.mm; sourceTree = "<group>"; }; 727 730 2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMHTMLVideoElementWrapper.mm; sourceTree = "<group>"; }; … … 1229 1232 5C726D6E1D3EE06800C5E1A1 /* InstanceMethodSwizzler.mm */, 1230 1233 0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */, 1234 2D1C04A51D76298B000A6816 /* TestNavigationDelegate.h */, 1235 2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */, 1231 1236 A14FC58D1B8AE36500D107EB /* TestProtocol.h */, 1232 1237 A14FC58E1B8AE36500D107EB /* TestProtocol.mm */, … … 2203 2208 7CCE7EE81A411AE600447C4C /* CookieManager.cpp in Sources */, 2204 2209 7CCE7EAC1A411A3400447C4C /* Counters.cpp in Sources */, 2210 2D1C04A71D76298B000A6816 /* TestNavigationDelegate.mm in Sources */, 2205 2211 7CCE7EDB1A411A9200447C4C /* CSSParser.cpp in Sources */, 2206 2212 7CCE7F291A411B1000447C4C /* CustomProtocolsInvalidScheme.mm in Sources */, -
trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm
r203508 r205329 27 27 #import "PlatformUtilities.h" 28 28 #import "Test.h" 29 #import "TestNavigationDelegate.h" 29 30 30 31 #import <WebKit/WKBackForwardListPrivate.h> 31 #import <WebKit/WKNavigationDelegate.h>32 32 #import <WebKit/WKNavigationPrivate.h> 33 33 #import <WebKit/WKWebViewPrivate.h> … … 36 36 37 37 #if WK_API_ENABLED 38 39 static bool isDone;40 41 @interface WKBackForwardListTestNavigationDelegate : NSObject <WKNavigationDelegate>42 @end43 44 @implementation WKBackForwardListTestNavigationDelegate45 46 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation47 {48 isDone = true;49 }50 51 @end52 38 53 39 static NSString *loadableURL1 = @"data:text/html,no%20error%20A"; … … 58 44 { 59 45 auto webView = adoptNS([[WKWebView alloc] init]); 60 auto controller = adoptNS([[WKBackForwardListTestNavigationDelegate alloc] init]);61 [webView setNavigationDelegate:controller.get()];62 46 63 47 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL1]]]; 64 TestWebKitAPI::Util::run(&isDone); 65 isDone = false; 48 [webView _test_waitForDidFinishNavigation]; 66 49 67 50 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL2]]]; 68 TestWebKitAPI::Util::run(&isDone); 69 isDone = false; 51 [webView _test_waitForDidFinishNavigation]; 70 52 71 53 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL3]]]; 72 TestWebKitAPI::Util::run(&isDone); 73 isDone = false; 54 [webView _test_waitForDidFinishNavigation]; 74 55 75 56 WKBackForwardList *list = [webView backForwardList]; -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AlwaysRevalidatedURLSchemes.mm
r194880 r205329 29 29 30 30 #import "PlatformUtilities.h" 31 #import "TestNavigationDelegate.h" 31 32 #import <WebKit/WKBrowsingContextController.h> 32 33 #import <WebKit/WKProcessPoolPrivate.h> … … 35 36 36 37 static NSString * const customScheme = @"custom"; 37 static bool isDone;38 38 static size_t loadsStarted; 39 39 … … 75 75 @end 76 76 77 @interface AlwaysRevalidatedURLSchemesDelegate : NSObject <WKNavigationDelegate>78 @end79 80 @implementation AlwaysRevalidatedURLSchemesDelegate81 82 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation83 {84 isDone = true;85 }86 87 @end88 89 77 TEST(WebKit2, AlwaysRevalidatedURLSchemes) 90 78 { … … 100 88 [webViewConfiguration setProcessPool:processPool.get()]; 101 89 102 auto navigationDelegate = adoptNS([[AlwaysRevalidatedURLSchemesDelegate alloc] init]);103 90 auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:webViewConfiguration.get()]); 104 [webView setNavigationDelegate:navigationDelegate.get()];105 91 106 92 NSString *htmlString = [NSString stringWithFormat:@"<!DOCTYPE html><body><img src='%@://image'>", customScheme]; 107 93 [webView loadHTMLString:htmlString baseURL:nil]; 108 TestWebKitAPI::Util::run(&isDone);94 [webView _test_waitForDidFinishNavigation]; 109 95 EXPECT_EQ(1UL, loadsStarted); 110 96 111 isDone = false;112 97 [webView loadHTMLString:htmlString baseURL:nil]; 113 TestWebKitAPI::Util::run(&isDone);98 [webView _test_waitForDidFinishNavigation]; 114 99 EXPECT_EQ(2UL, loadsStarted); 115 100 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AnimatedResize.mm
r204194 r205329 27 27 28 28 #import "PlatformUtilities.h" 29 #import <WebKit/WKNavigationDelegatePrivate.h>29 #import "TestNavigationDelegate.h" 30 30 #import <WebKit/WKPreferences.h> 31 31 #import <WebKit/WKProcessPoolPrivate.h> … … 40 40 static bool didLayout; 41 41 static bool didEndAnimatedResize; 42 43 @interface AnimatedResizeNavigationDelegate : NSObject <WKNavigationDelegate>44 @end45 46 @implementation AnimatedResizeNavigationDelegate47 48 - (void)_webView:(WKWebView *)webView renderingProgressDidChange:(_WKRenderingProgressEvents)progressEvents49 {50 if (progressEvents & _WKRenderingProgressEventFirstVisuallyNonEmptyLayout)51 didLayout = true;52 }53 54 @end55 42 56 43 @interface AnimatedResizeWebView : WKWebView … … 71 58 static RetainPtr<WKWebView> animatedResizeWebView() 72 59 { 73 RetainPtr<_WKProcessPoolConfiguration> processPoolConfiguration = [[_WKProcessPoolConfiguration alloc] init];60 RetainPtr<_WKProcessPoolConfiguration> processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]); 74 61 [processPoolConfiguration setIgnoreSynchronousMessagingTimeoutsForTesting:YES]; 75 RetainPtr<WKProcessPool> processPool = [[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()];62 RetainPtr<WKProcessPool> processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]); 76 63 77 RetainPtr<WKWebViewConfiguration> webViewConfiguration = [[WKWebViewConfiguration alloc] init];64 RetainPtr<WKWebViewConfiguration> webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]); 78 65 [webViewConfiguration setProcessPool:processPool.get()]; 79 66 80 67 RetainPtr<WKWebView> webView = adoptNS([[AnimatedResizeWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]); 81 68 82 AnimatedResizeNavigationDelegate *navigationDelegate = [[AnimatedResizeNavigationDelegate alloc] init]; 83 [webView setNavigationDelegate:navigationDelegate]; 69 auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]); 70 [navigationDelegate setRenderingProgressDidChange:^(WKWebView *, _WKRenderingProgressEvents progressEvents) { 71 if (progressEvents & _WKRenderingProgressEventFirstVisuallyNonEmptyLayout) 72 didLayout = true; 73 }]; 74 [webView setNavigationDelegate:navigationDelegate.get()]; 84 75 85 76 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"blinking-div" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm
r202120 r205329 27 27 28 28 #import "PlatformUtilities.h" 29 #import "TestNavigationDelegate.h" 29 30 #import <WebKit/WKWebViewPrivate.h> 30 31 #import <wtf/RetainPtr.h> … … 32 33 #if WK_API_ENABLED && PLATFORM(MAC) 33 34 34 static bool didFinishNavigation;35 35 static bool didInvalidateIntrinsicContentSize; 36 36 static bool didEvaluateJavaScript; 37 38 @interface AutoLayoutNavigationDelegate : NSObject <WKNavigationDelegate>39 @end40 41 @implementation AutoLayoutNavigationDelegate42 43 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation44 {45 didFinishNavigation = true;46 }47 48 @end49 37 50 38 @interface AutoLayoutWKWebView : WKWebView … … 54 42 BOOL _expectingIntrinsicContentSizeChange; 55 43 NSSize _expectedIntrinsicContentSize; 44 } 45 46 - (instancetype)initWithFrame:(NSRect)frame configuration:(WKWebViewConfiguration *)configuration 47 { 48 self = [super initWithFrame:frame configuration:configuration]; 49 if (!self) 50 return nil; 51 52 return self; 56 53 } 57 54 … … 74 71 "</style>"; 75 72 76 didFinishNavigation = false;77 73 [self loadHTMLString:[baseHTML stringByAppendingString:HTMLString] baseURL:nil]; 78 TestWebKitAPI::Util::run(&didFinishNavigation);74 [self _test_waitForDidFinishNavigation]; 79 75 80 76 [self layoutAtMinimumWidth:width andExpectContentSizeChange:size resettingWidth:resetAfter]; … … 116 112 { 117 113 RetainPtr<AutoLayoutWKWebView> webView = adoptNS([[AutoLayoutWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 1000, 1000)]); 118 119 AutoLayoutNavigationDelegate *delegate = [[AutoLayoutNavigationDelegate alloc] init];120 [webView setNavigationDelegate:delegate];121 114 122 115 // 10x10 rect with the constraint (width >= 50) -> 50x10 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CancelFontSubresource.mm
r197570 r205329 31 31 #import "PlatformUtilities.h" 32 32 #import "Test.h" 33 #import "TestNavigationDelegate.h" 33 34 #import "UserContentWorldProtocol.h" 34 35 #import "WKWebViewConfigurationExtras.h" … … 45 46 #import <wtf/RetainPtr.h> 46 47 47 @interface CancelFontSubresourceNavigationDelegate : NSObject <WKNavigationDelegate>48 @end49 50 @implementation CancelFontSubresourceNavigationDelegate51 52 static bool navigationComplete = false;53 54 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation55 {56 navigationComplete = true;57 }58 59 @end60 61 48 TEST(CancelLoading, CancelFontSubresource) 62 49 { … … 67 54 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 68 55 69 CancelFontSubresourceNavigationDelegate *delegate = [[CancelFontSubresourceNavigationDelegate alloc] init];70 [webView setNavigationDelegate:delegate];71 72 56 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"webfont" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 73 57 [webView loadRequest:request]; 74 75 TestWebKitAPI::Util::run(&navigationComplete); 58 [webView _test_waitForDidFinishNavigation]; 76 59 } 77 60 -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm
r202129 r205329 30 30 #import "PlatformUtilities.h" 31 31 #import "Test.h" 32 #import "TestNavigationDelegate.h" 32 33 #import <Carbon/Carbon.h> // for GetCurrentEventTime() 33 34 #import <WebKit/WKRetainPtr.h> … … 153 154 #if WK_API_ENABLED 154 155 155 @interface CommandBackForwardNavigationDelegate : NSObject <WKNavigationDelegate>156 @end157 158 @implementation CommandBackForwardNavigationDelegate159 160 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation161 {162 didFinishNavigation = true;163 }164 165 @end166 167 168 156 class WebKit2_CommandBackForwardTestWKWebView : public WebKit2_CommandBackForwardTest { 169 157 public: … … 176 164 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); 177 165 [[window contentView] addSubview:webView.get()]; 178 179 CommandBackForwardNavigationDelegate *delegate = [[CommandBackForwardNavigationDelegate alloc] init];180 [webView setNavigationDelegate:delegate];181 166 } 182 167 … … 185 170 NSURL *file1 = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]; 186 171 [webView loadFileURL:file1 allowingReadAccessToURL:file1]; 187 188 TestWebKitAPI::Util::run(&didFinishNavigation); 189 didFinishNavigation = false; 172 [webView _test_waitForDidFinishNavigation]; 190 173 191 174 NSURL *file2 = [[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]; 192 175 [webView loadFileURL:file2 allowingReadAccessToURL:file2]; 193 194 TestWebKitAPI::Util::run(&didFinishNavigation); 195 didFinishNavigation = false; 176 [webView _test_waitForDidFinishNavigation]; 196 177 } 197 178 }; … … 207 188 // Attempt to go back (using command-left). 208 189 simulateCommandArrow(webView.get(), Left); 209 TestWebKitAPI::Util::run(&didFinishNavigation); 210 didFinishNavigation = false; 190 [webView _test_waitForDidFinishNavigation]; 211 191 212 192 EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple.html"); … … 214 194 // Attempt to go back (using command-right). 215 195 simulateCommandArrow(webView.get(), Right); 216 TestWebKitAPI::Util::run(&didFinishNavigation); 217 didFinishNavigation = false; 196 [webView _test_waitForDidFinishNavigation]; 218 197 219 198 EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple2.html"); … … 231 210 // Attempt to go back (using command-right) 232 211 simulateCommandArrow(webView.get(), Right); 233 TestWebKitAPI::Util::run(&didFinishNavigation); 234 didFinishNavigation = false; 212 [webView _test_waitForDidFinishNavigation]; 235 213 236 214 EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple.html"); … … 238 216 // Attempt to go back (using command-left). 239 217 simulateCommandArrow(webView.get(), Left); 240 TestWebKitAPI::Util::run(&didFinishNavigation); 241 didFinishNavigation = false; 218 [webView _test_waitForDidFinishNavigation]; 242 219 243 220 EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple2.html"); -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DataDetection.mm
r202889 r205329 28 28 #import "PlatformUtilities.h" 29 29 #import "Test.h" 30 #import "TestNavigationDelegate.h" 30 31 #import <WebKit/WebKit.h> 31 32 #import <wtf/RetainPtr.h> … … 33 34 #if WK_API_ENABLED && PLATFORM(IOS) 34 35 35 static bool finishedLoading;36 36 static bool ranScript; 37 38 @interface DataDetectionNavigationDelegate : NSObject <WKNavigationDelegate>39 @end40 41 @implementation DataDetectionNavigationDelegate42 43 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation44 {45 finishedLoading = true;46 }47 48 @end49 37 50 38 @interface DataDetectionUIDelegate : NSObject <WKUIDelegate> … … 71 59 { 72 60 [webView loadHTMLString:HTMLString baseURL:nil]; 73 74 TestWebKitAPI::Util::run(&finishedLoading); 75 finishedLoading = false; 61 [webView _test_waitForDidFinishNavigation]; 76 62 77 63 [webView evaluateJavaScript:@"document.getElementsByTagName('a').length" completionHandler:^(id value, NSError *error) { … … 90 76 91 77 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 92 93 RetainPtr<DataDetectionNavigationDelegate> navigationDelegate = adoptNS([[DataDetectionNavigationDelegate alloc] init]);94 [webView setNavigationDelegate:navigationDelegate.get()];95 78 96 79 RetainPtr<DataDetectionUIDelegate> UIDelegate = adoptNS([[DataDetectionUIDelegate alloc] init]); -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm
r198363 r205329 27 27 28 28 #import "PlatformUtilities.h" 29 #import "TestNavigationDelegate.h" 29 30 #import <WebKit/WKWebViewPrivate.h> 30 31 #import <wtf/RetainPtr.h> … … 47 48 @end 48 49 49 static bool navigationDone;50 50 static bool findMatchesDone; 51 52 @interface FindInPageNavigationDelegate : NSObject <WKNavigationDelegate>53 @end54 55 @implementation FindInPageNavigationDelegate56 57 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation58 {59 navigationDone = true;60 }61 62 @end63 51 64 52 TEST(WebKit2, FindInPage) … … 67 55 [webView _setOverrideDeviceScaleFactor:2]; 68 56 69 RetainPtr<FindInPageNavigationDelegate> delegate = adoptNS([[FindInPageNavigationDelegate alloc] init]);70 [webView setNavigationDelegate:delegate.get()];71 72 57 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"lots-of-text" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 73 58 [webView loadRequest:request]; 74 75 TestWebKitAPI::Util::run(&navigationDone); 59 [webView _test_waitForDidFinishNavigation]; 76 60 77 61 NSTextFinderAsynchronousDocumentFindOptions noFindOptions = (NSTextFinderAsynchronousDocumentFindOptions)0; -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm
r182802 r205329 27 27 28 28 #import "PlatformUtilities.h" 29 #import "TestNavigationDelegate.h" 29 30 #import <WebKit/WKPreferences.h> 30 31 #import <WebKit/WKWebViewPrivate.h> … … 37 38 static bool fixedLayoutSizeDisabledDone; 38 39 39 @interface FixedLayoutSizeNavigationDelegate : NSObject <WKNavigationDelegate>40 @end41 42 @implementation FixedLayoutSizeNavigationDelegate43 44 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation45 {46 // After navigating, fixed layout size should be persisted.47 [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {48 EXPECT_EQ(200, [result integerValue]);49 fixedLayoutSizeAfterNavigationDone = true;50 }];51 }52 53 @end54 55 40 TEST(WebKit2, FixedLayoutSize) 56 41 { 57 42 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); 58 59 FixedLayoutSizeNavigationDelegate *delegate = [[FixedLayoutSizeNavigationDelegate alloc] init];60 [webView setNavigationDelegate:delegate];61 43 62 44 [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) { … … 77 59 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 78 60 [webView loadRequest:request]; 61 [webView _test_waitForDidFinishNavigation]; 62 63 // After navigating, fixed layout size should be persisted. 64 [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) { 65 EXPECT_EQ(200, [result integerValue]); 66 fixedLayoutSizeAfterNavigationDone = true; 67 }]; 79 68 80 69 TestWebKitAPI::Util::run(&fixedLayoutSizeAfterNavigationDone); -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm
r203700 r205329 28 28 #import "PlatformUtilities.h" 29 29 #import "Test.h" 30 #import "TestNavigationDelegate.h" 30 31 #import <WebKit/WKProcessPoolPrivate.h> 31 32 #import <WebKit/WKUserContentControllerPrivate.h> … … 36 37 37 38 #if WK_API_ENABLED 38 39 static bool isDoneWithNavigation;40 41 @interface DatabaseProcessKillNavigationDelegate : NSObject <WKNavigationDelegate>42 @end43 44 @implementation DatabaseProcessKillNavigationDelegate45 46 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation47 {48 isDoneWithNavigation = true;49 }50 51 @end52 39 53 40 static bool receivedScriptMessage; … … 95 82 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 96 83 97 DatabaseProcessKillNavigationDelegate *delegate = [[DatabaseProcessKillNavigationDelegate alloc] init];98 [webView setNavigationDelegate:delegate];99 100 84 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"IndexedDBDatabaseProcessKill-1" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 101 85 [webView loadRequest:request]; 102 103 TestWebKitAPI::Util::run(&isDoneWithNavigation); 86 [webView _test_waitForDidFinishNavigation]; 104 87 105 88 bool killedDBProcess = false; -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBPersistence.mm
r203700 r205329 37 37 38 38 #if WK_API_ENABLED 39 40 static bool isDoneWithNavigation;41 42 @interface IndexedDBNavigationDelegate : NSObject <WKNavigationDelegate>43 @end44 45 @implementation IndexedDBNavigationDelegate46 47 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation48 {49 isDoneWithNavigation = true;50 }51 52 @end53 39 54 40 static bool receivedScriptMessage; -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLNotChange.mm
r198964 r205329 31 31 #import "PlatformUtilities.h" 32 32 #import "Test.h" 33 #import "TestNavigationDelegate.h" 33 34 #import <wtf/RetainPtr.h> 34 35 35 36 static bool isDone; 36 37 37 @interface ProvisionalURLNotChangeController : NSObject <WKNavigationDelegate>38 @end39 40 @implementation ProvisionalURLNotChangeController41 42 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation43 {44 isDone = true;45 }46 47 - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error48 {49 isDone = true;50 }51 52 @end53 54 38 TEST(WKWebView, ProvisionalURLNotChange) 55 39 { 56 40 auto webView = adoptNS([[WKWebView alloc] init]); 57 auto controller = adoptNS([[ProvisionalURLNotChangeController alloc] init]); 58 [webView setNavigationDelegate:controller.get()]; 41 42 auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]); 43 [navigationDelegate setDidFinishNavigation:^(WKWebView *, WKNavigation *) { 44 isDone = true; 45 }]; 46 [navigationDelegate setDidFailProvisionalNavigation:^(WKWebView *, WKNavigation *, NSError *) { 47 isDone = true; 48 }]; 49 [webView setNavigationDelegate:navigationDelegate.get()]; 59 50 60 51 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,start"]]]; -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RequiresUserActionForPlayback.mm
r203855 r205329 28 28 #import "PlatformUtilities.h" 29 29 #import "Test.h" 30 #import "TestNavigationDelegate.h" 30 31 #import <WebCore/SoftLinking.h> 31 32 #import <WebKit/WKWebViewConfigurationPrivate.h> … … 40 41 #endif 41 42 42 static bool isDoneWithNavigation;43 44 @interface RequiresUserActionForPlaybackNavigationDelegate : NSObject <WKNavigationDelegate>45 @end46 47 @implementation RequiresUserActionForPlaybackNavigationDelegate48 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation49 {50 isDoneWithNavigation = true;51 }52 @end53 54 43 static bool receivedScriptMessage; 55 44 static RetainPtr<WKScriptMessage> lastScriptMessage; … … 83 72 void createWebView() 84 73 { 85 delegate = adoptNS([[RequiresUserActionForPlaybackNavigationDelegate alloc] init]);86 74 webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 87 [webView setNavigationDelegate:delegate.get()];88 75 #if TARGET_OS_IPHONE 89 76 window = adoptNS([[getUIWindowClass() alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); … … 99 86 NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]; 100 87 [webView loadFileURL:fileURL allowingReadAccessToURL:fileURL]; 101 TestWebKitAPI::Util::run(&isDoneWithNavigation); 102 isDoneWithNavigation = false; 88 [webView _test_waitForDidFinishNavigation]; 103 89 104 90 TestWebKitAPI::Util::run(&receivedScriptMessage); … … 110 96 NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"video-without-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]; 111 97 [webView loadFileURL:fileURL allowingReadAccessToURL:fileURL]; 112 TestWebKitAPI::Util::run(&isDoneWithNavigation); 113 isDoneWithNavigation = false; 98 [webView _test_waitForDidFinishNavigation]; 114 99 115 100 TestWebKitAPI::Util::run(&receivedScriptMessage); … … 121 106 NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"audio-only" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]; 122 107 [webView loadFileURL:fileURL allowingReadAccessToURL:fileURL]; 123 TestWebKitAPI::Util::run(&isDoneWithNavigation); 124 isDoneWithNavigation = false; 108 [webView _test_waitForDidFinishNavigation]; 125 109 126 110 TestWebKitAPI::Util::run(&receivedScriptMessage); … … 130 114 RetainPtr<RequiresUserActionForPlaybackMessageHandler> handler; 131 115 RetainPtr<WKWebViewConfiguration> configuration; 132 RetainPtr<RequiresUserActionForPlaybackNavigationDelegate> delegate;133 116 RetainPtr<WKWebView> webView; 134 117 #if TARGET_OS_IPHONE -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm
r185661 r205329 27 27 28 28 #import "PlatformUtilities.h" 29 #import "TestNavigationDelegate.h" 29 30 #import <WebKit/WKWebViewPrivate.h> 30 31 #import <wtf/RetainPtr.h> … … 36 37 static bool shrinkToFitDisabledDone; 37 38 38 @interface ShrinkToFitNavigationDelegate : NSObject <WKNavigationDelegate>39 @end40 41 @implementation ShrinkToFitNavigationDelegate42 43 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation44 {45 // After loading a wide page, the view should be scaled to fit the width of the document.46 [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {47 EXPECT_EQ(808, [result integerValue]);48 shrinkToFitAfterNavigationDone = true;49 }];50 }51 52 @end53 54 39 TEST(WebKit2, ShrinkToFit) 55 40 { 56 41 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]); 57 58 ShrinkToFitNavigationDelegate *delegate = [[ShrinkToFitNavigationDelegate alloc] init];59 [webView setNavigationDelegate:delegate];60 42 61 43 [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) { … … 70 52 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"lots-of-text" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 71 53 [webView loadRequest:request]; 54 [webView _test_waitForDidFinishNavigation]; 55 56 // After loading a wide page, the view should be scaled to fit the width of the document. 57 [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) { 58 EXPECT_EQ(808, [result integerValue]); 59 shrinkToFitAfterNavigationDone = true; 60 }]; 72 61 73 62 TestWebKitAPI::Util::run(&shrinkToFitAfterNavigationDone); -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm
r199020 r205329 28 28 #import "PlatformUtilities.h" 29 29 #import "Test.h" 30 #import "TestNavigationDelegate.h" 30 31 #import <WebKit/WKProcessPoolPrivate.h> 31 32 #import <WebKit/WKUserContentControllerPrivate.h> … … 79 80 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 80 81 81 RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]); 82 [webView setNavigationDelegate:delegate.get()]; 83 84 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 85 86 [webView loadRequest:request]; 87 88 TestWebKitAPI::Util::run(&isDoneWithNavigation); 82 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 83 84 [webView loadRequest:request]; 85 [webView _test_waitForDidFinishNavigation]; 89 86 90 87 [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('Hello')" completionHandler:nil]; … … 155 152 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 156 153 157 RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]); 158 [webView setNavigationDelegate:delegate.get()]; 159 160 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 161 162 [webView loadRequest:request]; 163 164 TestWebKitAPI::Util::run(&isDoneWithNavigation); 154 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 155 156 [webView loadRequest:request]; 157 [webView _test_waitForDidFinishNavigation]; 165 158 166 159 // Test that handlerToRemove was succesfully added. … … 203 196 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 204 197 205 RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]); 206 [webView setNavigationDelegate:delegate.get()]; 207 208 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 209 210 [webView loadRequest:request]; 211 212 TestWebKitAPI::Util::run(&isDoneWithNavigation); 198 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 199 200 [webView loadRequest:request]; 201 [webView _test_waitForDidFinishNavigation]; 213 202 214 203 [webView evaluateJavaScript:@"var handlerToRemove = window.webkit.messageHandlers.handlerToRemove;" completionHandler:nil]; … … 238 227 [[configurationCopy userContentController] addScriptMessageHandler:handler.get() name:@"handlerToPost"]; 239 228 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configurationCopy.get()]); 240 RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]); 241 [webView setNavigationDelegate:delegate.get()]; 242 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 243 [webView loadRequest:request]; 244 TestWebKitAPI::Util::run(&isDoneWithNavigation); 245 isDoneWithNavigation = false; 229 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 230 [webView loadRequest:request]; 231 [webView _test_waitForDidFinishNavigation]; 246 232 247 233 return webView; … … 283 269 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 284 270 285 RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]); 286 [webView setNavigationDelegate:delegate.get()]; 287 288 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 289 [webView loadRequest:request]; 290 291 TestWebKitAPI::Util::run(&isDoneWithNavigation); 292 isDoneWithNavigation = false; 271 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 272 [webView loadRequest:request]; 273 [webView _test_waitForDidFinishNavigation]; 293 274 294 275 [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('First Message')" completionHandler:nil]; … … 301 282 lastScriptMessage = nullptr; 302 283 303 304 [webView loadRequest:request]; 305 TestWebKitAPI::Util::run(&isDoneWithNavigation); 306 isDoneWithNavigation = false; 284 [webView loadRequest:request]; 285 [webView _test_waitForDidFinishNavigation]; 307 286 308 287 [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('Second Message')" completionHandler:nil]; … … 323 302 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 324 303 325 RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]); 326 [webView setNavigationDelegate:delegate.get()]; 327 328 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 329 330 [webView loadRequest:request]; 331 332 TestWebKitAPI::Util::run(&isDoneWithNavigation); 304 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 305 306 [webView loadRequest:request]; 307 [webView _test_waitForDidFinishNavigation]; 333 308 334 309 // Test that handlerToReplace was succesfully added. … … 382 357 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 383 358 384 RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);385 [webView setNavigationDelegate:delegate.get()];386 387 359 [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil]; 388 TestWebKitAPI::Util::run(&isDoneWithNavigation); 389 isDoneWithNavigation = false; 360 [webView _test_waitForDidFinishNavigation]; 390 361 391 362 expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, greenInRGB); … … 396 367 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 397 368 398 RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);399 [webView setNavigationDelegate:delegate.get()];400 401 369 [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil]; 402 TestWebKitAPI::Util::run(&isDoneWithNavigation); 403 isDoneWithNavigation = false; 370 [webView _test_waitForDidFinishNavigation]; 404 371 405 372 expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, redInRGB); … … 420 387 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 421 388 422 RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);423 [webView setNavigationDelegate:delegate.get()];424 425 389 [webView loadHTMLString:@"<body style='background-color: red;'><iframe></iframe></body>" baseURL:nil]; 426 TestWebKitAPI::Util::run(&isDoneWithNavigation); 427 isDoneWithNavigation = false; 390 [webView _test_waitForDidFinishNavigation]; 428 391 429 392 // The main frame should be affected. … … 443 406 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 444 407 445 RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);446 [webView setNavigationDelegate:delegate.get()];447 448 408 [webView loadHTMLString:@"<body style='background-color: red;'><iframe></iframe></body>" baseURL:nil]; 449 TestWebKitAPI::Util::run(&isDoneWithNavigation); 450 isDoneWithNavigation = false; 409 [webView _test_waitForDidFinishNavigation]; 451 410 452 411 // The main frame should be affected. -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentWorld.mm
r197172 r205329 31 31 #import "PlatformUtilities.h" 32 32 #import "Test.h" 33 #import "TestNavigationDelegate.h" 33 34 #import "UserContentWorldProtocol.h" 34 35 #import "WKWebViewConfigurationExtras.h" … … 44 45 #import <WebKit/_WKUserStyleSheet.h> 45 46 #import <wtf/RetainPtr.h> 46 47 static bool isDoneWithNavigation;48 49 @interface SimpleDelegate : NSObject <WKNavigationDelegate>50 @end51 52 @implementation SimpleDelegate53 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation54 {55 isDoneWithNavigation = true;56 }57 @end58 59 47 60 48 TEST(UserContentWorld, NormalWorld) … … 74 62 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 75 63 76 RetainPtr<SimpleDelegate> delegate = adoptNS([[SimpleDelegate alloc] init]);77 [webView setNavigationDelegate:delegate.get()];78 79 64 [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil]; 80 TestWebKitAPI::Util::run(&isDoneWithNavigation); 81 isDoneWithNavigation = false; 65 [webView _test_waitForDidFinishNavigation]; 82 66 83 67 __block bool isDone = false; … … 113 97 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 114 98 115 RetainPtr<SimpleDelegate> delegate = adoptNS([[SimpleDelegate alloc] init]);116 [webView setNavigationDelegate:delegate.get()];117 118 99 [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil]; 119 TestWebKitAPI::Util::run(&isDoneWithNavigation); 120 isDoneWithNavigation = false; 100 [webView _test_waitForDidFinishNavigation]; 121 101 122 102 __block bool isDone = false; -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKPDFViewResizeCrash.mm
r194060 r205329 26 26 #include "config.h" 27 27 28 #import <WebKit/WKNavigationDelegate.h> 28 #import "PlatformUtilities.h" 29 #import "Test.h" 30 #import "TestNavigationDelegate.h" 29 31 #import <WebKit/WKWebView.h> 30 32 #import <wtf/RetainPtr.h> 31 #import "PlatformUtilities.h"32 #import "Test.h"33 33 34 34 #if WK_API_ENABLED 35 35 36 static bool finishedLoading;37 36 static bool finishedDispatch; 38 39 @interface WKPDFViewResizeNavigationDelegate : NSObject <WKNavigationDelegate>40 @end41 42 @implementation WKPDFViewResizeNavigationDelegate43 44 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation45 {46 finishedLoading = true;47 }48 49 @end50 37 51 38 TEST(WebKit2, WKPDFViewResizeCrash) … … 53 40 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 54 41 55 RetainPtr<WKPDFViewResizeNavigationDelegate> delegate = adoptNS([[WKPDFViewResizeNavigationDelegate alloc] init]);56 [webView setNavigationDelegate:delegate.get()];57 58 42 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"test" withExtension:@"pdf" subdirectory:@"TestWebKitAPI.resources"]]; 59 43 [webView loadRequest:request]; 60 61 TestWebKitAPI::Util::run(&finishedLoading); 44 [webView _test_waitForDidFinishNavigation]; 62 45 63 46 [webView setFrame:NSMakeRect(0, 0, 100, 100)]; -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm
r191543 r205329 31 31 #import "PlatformUtilities.h" 32 32 #import "Test.h" 33 #import "TestNavigationDelegate.h" 33 34 #import <WebKit/WKWebView.h> 34 35 #import <WebKit/WKErrorPrivate.h> … … 36 37 37 38 static bool isDone; 38 39 @interface EvaluateJavaScriptNavigationDelegate : NSObject <WKNavigationDelegate>40 @end41 42 @implementation EvaluateJavaScriptNavigationDelegate43 44 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation45 {46 isDone = true;47 }48 49 @end50 39 51 40 TEST(WKWebView, EvaluateJavaScriptBlockCrash) … … 77 66 { 78 67 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 79 RetainPtr<EvaluateJavaScriptNavigationDelegate> delegate = adoptNS([[EvaluateJavaScriptNavigationDelegate alloc] init]);80 [webView setNavigationDelegate:delegate.get()];81 68 82 69 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 83 70 [webView loadRequest:request]; 84 TestWebKitAPI::Util::run(&isDone);71 [webView _test_waitForDidFinishNavigation]; 85 72 86 73 [webView evaluateJavaScript:@"document.body" completionHandler:^(id result, NSError *error) { -
trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewTextInput.mm
r201592 r205329 29 29 #if PLATFORM(MAC) 30 30 31 #import <WebKit/WKFoundation.h>32 31 #import "PlatformUtilities.h" 33 32 #import "Test.h" 34 #import <WebKit/WKWebView.h> 33 #import "TestNavigationDelegate.h" 34 #import <WebKit/WebKit.h> 35 35 #import <wtf/RetainPtr.h> 36 37 static bool isDone;38 39 @interface DummyNavigationDelegate : NSObject <WKNavigationDelegate>40 @end41 42 @implementation DummyNavigationDelegate43 44 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation45 {46 isDone = true;47 }48 49 @end50 36 51 37 TEST(WKWebView, ShouldHaveInputContextForEditableContent) 52 38 { 53 39 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 54 RetainPtr<DummyNavigationDelegate> delegate = adoptNS([[DummyNavigationDelegate alloc] init]);55 [webView setNavigationDelegate:delegate.get()];56 40 57 41 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"editable-body" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 58 42 [webView loadRequest:request]; 59 TestWebKitAPI::Util::run(&isDone);43 [webView _test_waitForDidFinishNavigation]; 60 44 61 45 EXPECT_NOT_NULL([webView inputContext]); -
trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h
r205328 r205329 24 24 */ 25 25 26 # import "config.h"26 #pragma once 27 27 28 28 #if WK_API_ENABLED 29 #if PLATFORM(MAC)30 29 31 #import <WebKit/WKFoundation.h> 32 #import "PlatformUtilities.h" 33 #import "Test.h" 34 #import <WebKit/WKWebView.h> 35 #import <wtf/RetainPtr.h> 30 #import <WebKit/WKNavigationDelegatePrivate.h> 31 #import <WebKit/WebKit.h> 36 32 37 static bool isDone; 33 @interface TestNavigationDelegate : NSObject <WKNavigationDelegate> 38 34 39 @interface DummyNavigationDelegate : NSObject <WKNavigationDelegate> 40 @end 35 @property (nonatomic, copy) void (^didFailProvisionalNavigation)(WKWebView *, WKNavigation *, NSError *); 36 @property (nonatomic, copy) void (^didFinishNavigation)(WKWebView *, WKNavigation *); 37 @property (nonatomic, copy) void (^renderingProgressDidChange)(WKWebView *, _WKRenderingProgressEvents); 41 38 42 @implementation DummyNavigationDelegate 43 44 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation 45 { 46 isDone = true; 47 } 39 - (void)waitForDidFinishNavigation; 48 40 49 41 @end 50 42 51 TEST(WKWebView, ShouldHaveInputContextForEditableContent) 52 { 53 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 54 RetainPtr<DummyNavigationDelegate> delegate = adoptNS([[DummyNavigationDelegate alloc] init]); 55 [webView setNavigationDelegate:delegate.get()]; 56 57 NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"editable-body" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]]; 58 [webView loadRequest:request]; 59 TestWebKitAPI::Util::run(&isDone); 60 61 EXPECT_NOT_NULL([webView inputContext]); 62 } 43 @interface WKWebView (TestWebKitAPIExtras) 44 - (void)_test_waitForDidFinishNavigation; 45 @end 63 46 64 47 #endif 65 #endif -
trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm
r205328 r205329 1 1 /* 2 * Copyright (C) 201 5Apple Inc. All rights reserved.2 * Copyright (C) 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 25 25 26 26 #import "config.h" 27 #import <WebKit/WKFoundation.h> 27 #import "TestNavigationDelegate.h" 28 29 #import "Utilities.h" 30 #import <wtf/RetainPtr.h> 28 31 29 32 #if WK_API_ENABLED 30 33 31 #import "PlatformUtilities.h" 32 #import "Test.h" 33 #import <wtf/RetainPtr.h> 34 @implementation TestNavigationDelegate 34 35 35 static bool isDone; 36 37 @interface ProvisionalURLNotChangeController : NSObject <WKNavigationDelegate> 38 @end 39 40 @implementation ProvisionalURLNotChangeController 36 - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error 37 { 38 if (_didFailProvisionalNavigation) 39 _didFailProvisionalNavigation(webView, navigation, error); 40 } 41 41 42 42 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation 43 43 { 44 isDone = true; 44 if (_didFinishNavigation) 45 _didFinishNavigation(webView, navigation); 45 46 } 46 47 47 - (void) webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error48 - (void)_webView:(WKWebView *)webView renderingProgressDidChange:(_WKRenderingProgressEvents)progressEvents 48 49 { 49 isDone = true; 50 if (_renderingProgressDidChange) 51 _renderingProgressDidChange(webView, progressEvents); 52 } 53 54 - (void)waitForDidFinishNavigation 55 { 56 EXPECT_FALSE(self.didFinishNavigation); 57 58 __block bool finished = false; 59 self.didFinishNavigation = ^(WKWebView *, WKNavigation *) { 60 finished = true; 61 }; 62 63 TestWebKitAPI::Util::run(&finished); 64 65 self.didFinishNavigation = nil; 50 66 } 51 67 52 68 @end 53 69 54 TEST(WKWebView, ProvisionalURLNotChange) 70 @implementation WKWebView (TestWebKitAPIExtras) 71 72 - (void)_test_waitForDidFinishNavigation 55 73 { 56 auto webView = adoptNS([[WKWebView alloc] init]); 57 auto controller = adoptNS([[ProvisionalURLNotChangeController alloc] init]); 58 [webView setNavigationDelegate:controller.get()]; 74 EXPECT_FALSE(self.navigationDelegate); 59 75 60 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,start"]]];61 TestWebKitAPI::Util::run(&isDone);62 isDone = false;76 auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]); 77 self.navigationDelegate = navigationDelegate.get(); 78 [navigationDelegate waitForDidFinishNavigation]; 63 79 64 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.webkit.org!"]]]; 65 TestWebKitAPI::Util::run(&isDone); 66 isDone = false; 67 68 EXPECT_STREQ([webView URL].absoluteString.UTF8String, "data:text/html,start"); 80 self.navigationDelegate = nil; 69 81 } 70 82 83 @end 84 71 85 #endif
Note: See TracChangeset
for help on using the changeset viewer.