Changeset 205329 in webkit


Ignore:
Timestamp:
Sep 1, 2016 6:16:56 PM (8 years ago)
Author:
timothy_horton@apple.com
Message:

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]):

Location:
trunk/Tools
Files:
21 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r205326 r205329  
     12016-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
    1902016-09-01  Ricky Mondello  <rmondello@apple.com>
    291
  • trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj

    r205313 r205329  
    5353                2D00065F1C1F589A0088E6A7 /* WKPDFViewResizeCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */; };
    5454                2D1646E21D1862CD00015A1A /* DeferredViewInWindowStateChange.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1646E11D1862CD00015A1A /* DeferredViewInWindowStateChange.mm */; };
     55                2D1C04A71D76298B000A6816 /* TestNavigationDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */; };
    5556                2D51A0C71C8BF00C00765C45 /* DOMHTMLVideoElementWrapper.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */; };
    5657                2DC4CF771D2D9DD800ECCC94 /* DataDetection.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DC4CF761D2D9DD800ECCC94 /* DataDetection.mm */; };
     
    724725                2D00065D1C1F58940088E6A7 /* WKPDFViewResizeCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKPDFViewResizeCrash.mm; sourceTree = "<group>"; };
    725726                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>"; };
    726729                2D1FE0AF1AD465C1006CD9E6 /* FixedLayoutSize.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FixedLayoutSize.mm; sourceTree = "<group>"; };
    727730                2D51A0C51C8BF00400765C45 /* DOMHTMLVideoElementWrapper.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMHTMLVideoElementWrapper.mm; sourceTree = "<group>"; };
     
    12291232                                5C726D6E1D3EE06800C5E1A1 /* InstanceMethodSwizzler.mm */,
    12301233                                0F139E721A423A2B00F590F5 /* PlatformUtilitiesCocoa.mm */,
     1234                                2D1C04A51D76298B000A6816 /* TestNavigationDelegate.h */,
     1235                                2D1C04A61D76298B000A6816 /* TestNavigationDelegate.mm */,
    12311236                                A14FC58D1B8AE36500D107EB /* TestProtocol.h */,
    12321237                                A14FC58E1B8AE36500D107EB /* TestProtocol.mm */,
     
    22032208                                7CCE7EE81A411AE600447C4C /* CookieManager.cpp in Sources */,
    22042209                                7CCE7EAC1A411A3400447C4C /* Counters.cpp in Sources */,
     2210                                2D1C04A71D76298B000A6816 /* TestNavigationDelegate.mm in Sources */,
    22052211                                7CCE7EDB1A411A9200447C4C /* CSSParser.cpp in Sources */,
    22062212                                7CCE7F291A411B1000447C4C /* CustomProtocolsInvalidScheme.mm in Sources */,
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKBackForwardList.mm

    r203508 r205329  
    2727#import "PlatformUtilities.h"
    2828#import "Test.h"
     29#import "TestNavigationDelegate.h"
    2930
    3031#import <WebKit/WKBackForwardListPrivate.h>
    31 #import <WebKit/WKNavigationDelegate.h>
    3232#import <WebKit/WKNavigationPrivate.h>
    3333#import <WebKit/WKWebViewPrivate.h>
     
    3636
    3737#if WK_API_ENABLED
    38 
    39 static bool isDone;
    40 
    41 @interface WKBackForwardListTestNavigationDelegate : NSObject <WKNavigationDelegate>
    42 @end
    43 
    44 @implementation WKBackForwardListTestNavigationDelegate
    45 
    46 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    47 {
    48     isDone = true;
    49 }
    50 
    51 @end
    5238
    5339static NSString *loadableURL1 = @"data:text/html,no%20error%20A";
     
    5844{
    5945    auto webView = adoptNS([[WKWebView alloc] init]);
    60     auto controller = adoptNS([[WKBackForwardListTestNavigationDelegate alloc] init]);
    61     [webView setNavigationDelegate:controller.get()];
    6246
    6347    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL1]]];
    64     TestWebKitAPI::Util::run(&isDone);
    65     isDone = false;
     48    [webView _test_waitForDidFinishNavigation];
    6649
    6750    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL2]]];
    68     TestWebKitAPI::Util::run(&isDone);
    69     isDone = false;
     51    [webView _test_waitForDidFinishNavigation];
    7052
    7153    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:loadableURL3]]];
    72     TestWebKitAPI::Util::run(&isDone);
    73     isDone = false;
     54    [webView _test_waitForDidFinishNavigation];
    7455
    7556    WKBackForwardList *list = [webView backForwardList];
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AlwaysRevalidatedURLSchemes.mm

    r194880 r205329  
    2929
    3030#import "PlatformUtilities.h"
     31#import "TestNavigationDelegate.h"
    3132#import <WebKit/WKBrowsingContextController.h>
    3233#import <WebKit/WKProcessPoolPrivate.h>
     
    3536
    3637static NSString * const customScheme = @"custom";
    37 static bool isDone;
    3838static size_t loadsStarted;
    3939
     
    7575@end
    7676
    77 @interface AlwaysRevalidatedURLSchemesDelegate : NSObject <WKNavigationDelegate>
    78 @end
    79 
    80 @implementation AlwaysRevalidatedURLSchemesDelegate
    81 
    82 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    83 {
    84     isDone = true;
    85 }
    86 
    87 @end
    88 
    8977TEST(WebKit2, AlwaysRevalidatedURLSchemes)
    9078{
     
    10088        [webViewConfiguration setProcessPool:processPool.get()];
    10189
    102         auto navigationDelegate = adoptNS([[AlwaysRevalidatedURLSchemesDelegate alloc] init]);
    10390        auto webView = adoptNS([[WKWebView alloc] initWithFrame:CGRectZero configuration:webViewConfiguration.get()]);
    104         [webView setNavigationDelegate:navigationDelegate.get()];
    10591
    10692        NSString *htmlString = [NSString stringWithFormat:@"<!DOCTYPE html><body><img src='%@://image'>", customScheme];
    10793        [webView loadHTMLString:htmlString baseURL:nil];
    108         TestWebKitAPI::Util::run(&isDone);
     94        [webView _test_waitForDidFinishNavigation];
    10995        EXPECT_EQ(1UL, loadsStarted);
    11096
    111         isDone = false;
    11297        [webView loadHTMLString:htmlString baseURL:nil];
    113         TestWebKitAPI::Util::run(&isDone);
     98        [webView _test_waitForDidFinishNavigation];
    11499        EXPECT_EQ(2UL, loadsStarted);
    115100
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AnimatedResize.mm

    r204194 r205329  
    2727
    2828#import "PlatformUtilities.h"
    29 #import <WebKit/WKNavigationDelegatePrivate.h>
     29#import "TestNavigationDelegate.h"
    3030#import <WebKit/WKPreferences.h>
    3131#import <WebKit/WKProcessPoolPrivate.h>
     
    4040static bool didLayout;
    4141static bool didEndAnimatedResize;
    42 
    43 @interface AnimatedResizeNavigationDelegate : NSObject <WKNavigationDelegate>
    44 @end
    45 
    46 @implementation AnimatedResizeNavigationDelegate
    47 
    48 - (void)_webView:(WKWebView *)webView renderingProgressDidChange:(_WKRenderingProgressEvents)progressEvents
    49 {
    50     if (progressEvents & _WKRenderingProgressEventFirstVisuallyNonEmptyLayout)
    51         didLayout = true;
    52 }
    53 
    54 @end
    5542
    5643@interface AnimatedResizeWebView : WKWebView
     
    7158static RetainPtr<WKWebView> animatedResizeWebView()
    7259{
    73     RetainPtr<_WKProcessPoolConfiguration> processPoolConfiguration = [[_WKProcessPoolConfiguration alloc] init];
     60    RetainPtr<_WKProcessPoolConfiguration> processPoolConfiguration = adoptNS([[_WKProcessPoolConfiguration alloc] init]);
    7461    [processPoolConfiguration setIgnoreSynchronousMessagingTimeoutsForTesting:YES];
    75     RetainPtr<WKProcessPool> processPool = [[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()];
     62    RetainPtr<WKProcessPool> processPool = adoptNS([[WKProcessPool alloc] _initWithConfiguration:processPoolConfiguration.get()]);
    7663
    77     RetainPtr<WKWebViewConfiguration> webViewConfiguration = [[WKWebViewConfiguration alloc] init];
     64    RetainPtr<WKWebViewConfiguration> webViewConfiguration = adoptNS([[WKWebViewConfiguration alloc] init]);
    7865    [webViewConfiguration setProcessPool:processPool.get()];
    7966
    8067    RetainPtr<WKWebView> webView = adoptNS([[AnimatedResizeWebView alloc] initWithFrame:CGRectMake(0, 0, 800, 600) configuration:webViewConfiguration.get()]);
    8168
    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()];
    8475
    8576    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"blinking-div" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/AutoLayoutIntegration.mm

    r202120 r205329  
    2727
    2828#import "PlatformUtilities.h"
     29#import "TestNavigationDelegate.h"
    2930#import <WebKit/WKWebViewPrivate.h>
    3031#import <wtf/RetainPtr.h>
     
    3233#if WK_API_ENABLED && PLATFORM(MAC)
    3334
    34 static bool didFinishNavigation;
    3535static bool didInvalidateIntrinsicContentSize;
    3636static bool didEvaluateJavaScript;
    37 
    38 @interface AutoLayoutNavigationDelegate : NSObject <WKNavigationDelegate>
    39 @end
    40 
    41 @implementation AutoLayoutNavigationDelegate
    42 
    43 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    44 {
    45     didFinishNavigation = true;
    46 }
    47 
    48 @end
    4937
    5038@interface AutoLayoutWKWebView : WKWebView
     
    5442    BOOL _expectingIntrinsicContentSizeChange;
    5543    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;
    5653}
    5754
     
    7471    "</style>";
    7572
    76     didFinishNavigation = false;
    7773    [self loadHTMLString:[baseHTML stringByAppendingString:HTMLString] baseURL:nil];
    78     TestWebKitAPI::Util::run(&didFinishNavigation);
     74    [self _test_waitForDidFinishNavigation];
    7975
    8076    [self layoutAtMinimumWidth:width andExpectContentSizeChange:size resettingWidth:resetAfter];
     
    116112{
    117113    RetainPtr<AutoLayoutWKWebView> webView = adoptNS([[AutoLayoutWKWebView alloc] initWithFrame:NSMakeRect(0, 0, 1000, 1000)]);
    118 
    119     AutoLayoutNavigationDelegate *delegate = [[AutoLayoutNavigationDelegate alloc] init];
    120     [webView setNavigationDelegate:delegate];
    121114
    122115    // 10x10 rect with the constraint (width >= 50) -> 50x10
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CancelFontSubresource.mm

    r197570 r205329  
    3131#import "PlatformUtilities.h"
    3232#import "Test.h"
     33#import "TestNavigationDelegate.h"
    3334#import "UserContentWorldProtocol.h"
    3435#import "WKWebViewConfigurationExtras.h"
     
    4546#import <wtf/RetainPtr.h>
    4647
    47 @interface CancelFontSubresourceNavigationDelegate : NSObject <WKNavigationDelegate>
    48 @end
    49 
    50 @implementation CancelFontSubresourceNavigationDelegate
    51 
    52 static bool navigationComplete = false;
    53 
    54 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    55 {
    56     navigationComplete = true;
    57 }
    58 
    59 @end
    60 
    6148TEST(CancelLoading, CancelFontSubresource)
    6249{
     
    6754    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    6855
    69     CancelFontSubresourceNavigationDelegate *delegate = [[CancelFontSubresourceNavigationDelegate alloc] init];
    70     [webView setNavigationDelegate:delegate];
    71 
    7256    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"webfont" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
    7357    [webView loadRequest:request];
    74 
    75     TestWebKitAPI::Util::run(&navigationComplete);
     58    [webView _test_waitForDidFinishNavigation];
    7659}
    7760
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/CommandBackForward.mm

    r202129 r205329  
    3030#import "PlatformUtilities.h"
    3131#import "Test.h"
     32#import "TestNavigationDelegate.h"
    3233#import <Carbon/Carbon.h> // for GetCurrentEventTime()
    3334#import <WebKit/WKRetainPtr.h>
     
    153154#if WK_API_ENABLED
    154155
    155 @interface CommandBackForwardNavigationDelegate : NSObject <WKNavigationDelegate>
    156 @end
    157 
    158 @implementation CommandBackForwardNavigationDelegate
    159 
    160 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    161 {
    162     didFinishNavigation = true;
    163 }
    164 
    165 @end
    166 
    167 
    168156class WebKit2_CommandBackForwardTestWKWebView : public WebKit2_CommandBackForwardTest {
    169157public:
     
    176164        webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
    177165        [[window contentView] addSubview:webView.get()];
    178 
    179         CommandBackForwardNavigationDelegate *delegate = [[CommandBackForwardNavigationDelegate alloc] init];
    180         [webView setNavigationDelegate:delegate];
    181166    }
    182167   
     
    185170        NSURL *file1 = [[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
    186171        [webView loadFileURL:file1 allowingReadAccessToURL:file1];
    187 
    188         TestWebKitAPI::Util::run(&didFinishNavigation);
    189         didFinishNavigation = false;
     172        [webView _test_waitForDidFinishNavigation];
    190173
    191174        NSURL *file2 = [[NSBundle mainBundle] URLForResource:@"simple2" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
    192175        [webView loadFileURL:file2 allowingReadAccessToURL:file2];
    193 
    194         TestWebKitAPI::Util::run(&didFinishNavigation);
    195         didFinishNavigation = false;
     176        [webView _test_waitForDidFinishNavigation];
    196177    }
    197178};
     
    207188    // Attempt to go back (using command-left).
    208189    simulateCommandArrow(webView.get(), Left);
    209     TestWebKitAPI::Util::run(&didFinishNavigation);
    210     didFinishNavigation = false;
     190    [webView _test_waitForDidFinishNavigation];
    211191
    212192    EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple.html");
     
    214194    // Attempt to go back (using command-right).
    215195    simulateCommandArrow(webView.get(), Right);
    216     TestWebKitAPI::Util::run(&didFinishNavigation);
    217     didFinishNavigation = false;
     196    [webView _test_waitForDidFinishNavigation];
    218197
    219198    EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple2.html");
     
    231210    // Attempt to go back (using command-right)
    232211    simulateCommandArrow(webView.get(), Right);
    233     TestWebKitAPI::Util::run(&didFinishNavigation);
    234     didFinishNavigation = false;
     212    [webView _test_waitForDidFinishNavigation];
    235213
    236214    EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple.html");
     
    238216    // Attempt to go back (using command-left).
    239217    simulateCommandArrow(webView.get(), Left);
    240     TestWebKitAPI::Util::run(&didFinishNavigation);
    241     didFinishNavigation = false;
     218    [webView _test_waitForDidFinishNavigation];
    242219
    243220    EXPECT_WK_STREQ([webView URL].path.lastPathComponent, @"simple2.html");
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/DataDetection.mm

    r202889 r205329  
    2828#import "PlatformUtilities.h"
    2929#import "Test.h"
     30#import "TestNavigationDelegate.h"
    3031#import <WebKit/WebKit.h>
    3132#import <wtf/RetainPtr.h>
     
    3334#if WK_API_ENABLED && PLATFORM(IOS)
    3435
    35 static bool finishedLoading;
    3636static bool ranScript;
    37 
    38 @interface DataDetectionNavigationDelegate : NSObject <WKNavigationDelegate>
    39 @end
    40 
    41 @implementation DataDetectionNavigationDelegate
    42 
    43 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    44 {
    45     finishedLoading = true;
    46 }
    47 
    48 @end
    4937
    5038@interface DataDetectionUIDelegate : NSObject <WKUIDelegate>
     
    7159{
    7260    [webView loadHTMLString:HTMLString baseURL:nil];
    73 
    74     TestWebKitAPI::Util::run(&finishedLoading);
    75     finishedLoading = false;
     61    [webView _test_waitForDidFinishNavigation];
    7662
    7763    [webView evaluateJavaScript:@"document.getElementsByTagName('a').length" completionHandler:^(id value, NSError *error) {
     
    9076
    9177    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()];
    9578
    9679    RetainPtr<DataDetectionUIDelegate> UIDelegate = adoptNS([[DataDetectionUIDelegate alloc] init]);
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FindInPage.mm

    r198363 r205329  
    2727
    2828#import "PlatformUtilities.h"
     29#import "TestNavigationDelegate.h"
    2930#import <WebKit/WKWebViewPrivate.h>
    3031#import <wtf/RetainPtr.h>
     
    4748@end
    4849
    49 static bool navigationDone;
    5050static bool findMatchesDone;
    51 
    52 @interface FindInPageNavigationDelegate : NSObject <WKNavigationDelegate>
    53 @end
    54 
    55 @implementation FindInPageNavigationDelegate
    56 
    57 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    58 {
    59     navigationDone = true;
    60 }
    61 
    62 @end
    6351
    6452TEST(WebKit2, FindInPage)
     
    6755    [webView _setOverrideDeviceScaleFactor:2];
    6856
    69     RetainPtr<FindInPageNavigationDelegate> delegate = adoptNS([[FindInPageNavigationDelegate alloc] init]);
    70     [webView setNavigationDelegate:delegate.get()];
    71 
    7257    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"lots-of-text" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
    7358    [webView loadRequest:request];
    74 
    75     TestWebKitAPI::Util::run(&navigationDone);
     59    [webView _test_waitForDidFinishNavigation];
    7660
    7761    NSTextFinderAsynchronousDocumentFindOptions noFindOptions = (NSTextFinderAsynchronousDocumentFindOptions)0;
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/FixedLayoutSize.mm

    r182802 r205329  
    2727
    2828#import "PlatformUtilities.h"
     29#import "TestNavigationDelegate.h"
    2930#import <WebKit/WKPreferences.h>
    3031#import <WebKit/WKWebViewPrivate.h>
     
    3738static bool fixedLayoutSizeDisabledDone;
    3839
    39 @interface FixedLayoutSizeNavigationDelegate : NSObject <WKNavigationDelegate>
    40 @end
    41 
    42 @implementation FixedLayoutSizeNavigationDelegate
    43 
    44 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    45 {
    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 @end
    54 
    5540TEST(WebKit2, FixedLayoutSize)
    5641{
    5742    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
    58 
    59     FixedLayoutSizeNavigationDelegate *delegate = [[FixedLayoutSizeNavigationDelegate alloc] init];
    60     [webView setNavigationDelegate:delegate];
    6143
    6244    [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
     
    7759    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
    7860    [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    }];
    7968
    8069    TestWebKitAPI::Util::run(&fixedLayoutSizeAfterNavigationDone);
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBDatabaseProcessKill.mm

    r203700 r205329  
    2828#import "PlatformUtilities.h"
    2929#import "Test.h"
     30#import "TestNavigationDelegate.h"
    3031#import <WebKit/WKProcessPoolPrivate.h>
    3132#import <WebKit/WKUserContentControllerPrivate.h>
     
    3637
    3738#if WK_API_ENABLED
    38 
    39 static bool isDoneWithNavigation;
    40 
    41 @interface DatabaseProcessKillNavigationDelegate : NSObject <WKNavigationDelegate>
    42 @end
    43 
    44 @implementation DatabaseProcessKillNavigationDelegate
    45 
    46 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    47 {
    48     isDoneWithNavigation = true;
    49 }
    50 
    51 @end
    5239
    5340static bool receivedScriptMessage;
     
    9582    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    9683
    97     DatabaseProcessKillNavigationDelegate *delegate = [[DatabaseProcessKillNavigationDelegate alloc] init];
    98     [webView setNavigationDelegate:delegate];
    99 
    10084    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"IndexedDBDatabaseProcessKill-1" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
    10185    [webView loadRequest:request];
    102 
    103     TestWebKitAPI::Util::run(&isDoneWithNavigation);
     86    [webView _test_waitForDidFinishNavigation];
    10487
    10588    bool killedDBProcess = false;
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/IndexedDBPersistence.mm

    r203700 r205329  
    3737
    3838#if WK_API_ENABLED
    39 
    40 static bool isDoneWithNavigation;
    41 
    42 @interface IndexedDBNavigationDelegate : NSObject <WKNavigationDelegate>
    43 @end
    44 
    45 @implementation IndexedDBNavigationDelegate
    46 
    47 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    48 {
    49     isDoneWithNavigation = true;
    50 }
    51 
    52 @end
    5339
    5440static bool receivedScriptMessage;
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ProvisionalURLNotChange.mm

    r198964 r205329  
    3131#import "PlatformUtilities.h"
    3232#import "Test.h"
     33#import "TestNavigationDelegate.h"
    3334#import <wtf/RetainPtr.h>
    3435
    3536static bool isDone;
    3637
    37 @interface ProvisionalURLNotChangeController : NSObject <WKNavigationDelegate>
    38 @end
    39 
    40 @implementation ProvisionalURLNotChangeController
    41 
    42 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    43 {
    44     isDone = true;
    45 }
    46 
    47 - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error
    48 {
    49     isDone = true;
    50 }
    51 
    52 @end
    53 
    5438TEST(WKWebView, ProvisionalURLNotChange)
    5539{
    5640    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()];
    5950
    6051    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"data:text/html,start"]]];
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/RequiresUserActionForPlayback.mm

    r203855 r205329  
    2828#import "PlatformUtilities.h"
    2929#import "Test.h"
     30#import "TestNavigationDelegate.h"
    3031#import <WebCore/SoftLinking.h>
    3132#import <WebKit/WKWebViewConfigurationPrivate.h>
     
    4041#endif
    4142
    42 static bool isDoneWithNavigation;
    43 
    44 @interface RequiresUserActionForPlaybackNavigationDelegate : NSObject <WKNavigationDelegate>
    45 @end
    46 
    47 @implementation RequiresUserActionForPlaybackNavigationDelegate
    48 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    49 {
    50     isDoneWithNavigation = true;
    51 }
    52 @end
    53 
    5443static bool receivedScriptMessage;
    5544static RetainPtr<WKScriptMessage> lastScriptMessage;
     
    8372    void createWebView()
    8473    {
    85         delegate = adoptNS([[RequiresUserActionForPlaybackNavigationDelegate alloc] init]);
    8674        webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    87         [webView setNavigationDelegate:delegate.get()];
    8875#if TARGET_OS_IPHONE
    8976        window = adoptNS([[getUIWindowClass() alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
     
    9986        NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"video-with-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
    10087        [webView loadFileURL:fileURL allowingReadAccessToURL:fileURL];
    101         TestWebKitAPI::Util::run(&isDoneWithNavigation);
    102         isDoneWithNavigation = false;
     88        [webView _test_waitForDidFinishNavigation];
    10389
    10490        TestWebKitAPI::Util::run(&receivedScriptMessage);
     
    11096        NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"video-without-audio" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
    11197        [webView loadFileURL:fileURL allowingReadAccessToURL:fileURL];
    112         TestWebKitAPI::Util::run(&isDoneWithNavigation);
    113         isDoneWithNavigation = false;
     98        [webView _test_waitForDidFinishNavigation];
    11499
    115100        TestWebKitAPI::Util::run(&receivedScriptMessage);
     
    121106        NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"audio-only" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"];
    122107        [webView loadFileURL:fileURL allowingReadAccessToURL:fileURL];
    123         TestWebKitAPI::Util::run(&isDoneWithNavigation);
    124         isDoneWithNavigation = false;
     108        [webView _test_waitForDidFinishNavigation];
    125109
    126110        TestWebKitAPI::Util::run(&receivedScriptMessage);
     
    130114    RetainPtr<RequiresUserActionForPlaybackMessageHandler> handler;
    131115    RetainPtr<WKWebViewConfiguration> configuration;
    132     RetainPtr<RequiresUserActionForPlaybackNavigationDelegate> delegate;
    133116    RetainPtr<WKWebView> webView;
    134117#if TARGET_OS_IPHONE
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/ShrinkToFit.mm

    r185661 r205329  
    2727
    2828#import "PlatformUtilities.h"
     29#import "TestNavigationDelegate.h"
    2930#import <WebKit/WKWebViewPrivate.h>
    3031#import <wtf/RetainPtr.h>
     
    3637static bool shrinkToFitDisabledDone;
    3738
    38 @interface ShrinkToFitNavigationDelegate : NSObject <WKNavigationDelegate>
    39 @end
    40 
    41 @implementation ShrinkToFitNavigationDelegate
    42 
    43 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    44 {
    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 @end
    53 
    5439TEST(WebKit2, ShrinkToFit)
    5540{
    5641    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 100, 100)]);
    57 
    58     ShrinkToFitNavigationDelegate *delegate = [[ShrinkToFitNavigationDelegate alloc] init];
    59     [webView setNavigationDelegate:delegate];
    6042
    6143    [webView evaluateJavaScript:@"document.body.clientWidth" completionHandler:^(id result, NSError *error) {
     
    7052    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"lots-of-text" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
    7153    [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    }];
    7261
    7362    TestWebKitAPI::Util::run(&shrinkToFitAfterNavigationDone);
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentController.mm

    r199020 r205329  
    2828#import "PlatformUtilities.h"
    2929#import "Test.h"
     30#import "TestNavigationDelegate.h"
    3031#import <WebKit/WKProcessPoolPrivate.h>
    3132#import <WebKit/WKUserContentControllerPrivate.h>
     
    7980    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    8081
    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];
    8986
    9087    [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('Hello')" completionHandler:nil];
     
    155152    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    156153
    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];
    165158
    166159    // Test that handlerToRemove was succesfully added.
     
    203196    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    204197
    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];
    213202
    214203    [webView evaluateJavaScript:@"var handlerToRemove = window.webkit.messageHandlers.handlerToRemove;" completionHandler:nil];
     
    238227    [[configurationCopy userContentController] addScriptMessageHandler:handler.get() name:@"handlerToPost"];
    239228    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];
    246232
    247233    return webView;
     
    283269    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    284270
    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];
    293274
    294275    [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('First Message')" completionHandler:nil];
     
    301282    lastScriptMessage = nullptr;
    302283
    303 
    304     [webView loadRequest:request];
    305     TestWebKitAPI::Util::run(&isDoneWithNavigation);
    306     isDoneWithNavigation = false;
     284    [webView loadRequest:request];
     285    [webView _test_waitForDidFinishNavigation];
    307286
    308287    [webView evaluateJavaScript:@"window.webkit.messageHandlers.testHandler.postMessage('Second Message')" completionHandler:nil];
     
    323302    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    324303
    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];
    333308
    334309    // Test that handlerToReplace was succesfully added.
     
    382357    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    383358
    384     RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
    385     [webView setNavigationDelegate:delegate.get()];
    386 
    387359    [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil];
    388     TestWebKitAPI::Util::run(&isDoneWithNavigation);
    389     isDoneWithNavigation = false;
     360    [webView _test_waitForDidFinishNavigation];
    390361
    391362    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, greenInRGB);
     
    396367    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
    397368
    398     RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
    399     [webView setNavigationDelegate:delegate.get()];
    400 
    401369    [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil];
    402     TestWebKitAPI::Util::run(&isDoneWithNavigation);
    403     isDoneWithNavigation = false;
     370    [webView _test_waitForDidFinishNavigation];
    404371
    405372    expectScriptEvaluatesToColor(webView.get(), backgroundColorScript, redInRGB);
     
    420387    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    421388
    422     RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
    423     [webView setNavigationDelegate:delegate.get()];
    424 
    425389    [webView loadHTMLString:@"<body style='background-color: red;'><iframe></iframe></body>" baseURL:nil];
    426     TestWebKitAPI::Util::run(&isDoneWithNavigation);
    427     isDoneWithNavigation = false;
     390    [webView _test_waitForDidFinishNavigation];
    428391
    429392    // The main frame should be affected.
     
    443406    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    444407
    445     RetainPtr<SimpleNavigationDelegate> delegate = adoptNS([[SimpleNavigationDelegate alloc] init]);
    446     [webView setNavigationDelegate:delegate.get()];
    447 
    448408    [webView loadHTMLString:@"<body style='background-color: red;'><iframe></iframe></body>" baseURL:nil];
    449     TestWebKitAPI::Util::run(&isDoneWithNavigation);
    450     isDoneWithNavigation = false;
     409    [webView _test_waitForDidFinishNavigation];
    451410
    452411    // The main frame should be affected.
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/UserContentWorld.mm

    r197172 r205329  
    3131#import "PlatformUtilities.h"
    3232#import "Test.h"
     33#import "TestNavigationDelegate.h"
    3334#import "UserContentWorldProtocol.h"
    3435#import "WKWebViewConfigurationExtras.h"
     
    4445#import <WebKit/_WKUserStyleSheet.h>
    4546#import <wtf/RetainPtr.h>
    46 
    47 static bool isDoneWithNavigation;
    48 
    49 @interface SimpleDelegate : NSObject <WKNavigationDelegate>
    50 @end
    51 
    52 @implementation SimpleDelegate
    53 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    54 {
    55     isDoneWithNavigation = true;
    56 }
    57 @end
    58 
    5947
    6048TEST(UserContentWorld, NormalWorld)
     
    7462    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    7563
    76     RetainPtr<SimpleDelegate> delegate = adoptNS([[SimpleDelegate alloc] init]);
    77     [webView setNavigationDelegate:delegate.get()];
    78 
    7964    [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil];
    80     TestWebKitAPI::Util::run(&isDoneWithNavigation);
    81     isDoneWithNavigation = false;
     65    [webView _test_waitForDidFinishNavigation];
    8266
    8367    __block bool isDone = false;
     
    11397    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]);
    11498
    115     RetainPtr<SimpleDelegate> delegate = adoptNS([[SimpleDelegate alloc] init]);
    116     [webView setNavigationDelegate:delegate.get()];
    117 
    11899    [webView loadHTMLString:@"<body style='background-color: red;'></body>" baseURL:nil];
    119     TestWebKitAPI::Util::run(&isDoneWithNavigation);
    120     isDoneWithNavigation = false;
     100    [webView _test_waitForDidFinishNavigation];
    121101
    122102    __block bool isDone = false;
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKPDFViewResizeCrash.mm

    r194060 r205329  
    2626#include "config.h"
    2727
    28 #import <WebKit/WKNavigationDelegate.h>
     28#import "PlatformUtilities.h"
     29#import "Test.h"
     30#import "TestNavigationDelegate.h"
    2931#import <WebKit/WKWebView.h>
    3032#import <wtf/RetainPtr.h>
    31 #import "PlatformUtilities.h"
    32 #import "Test.h"
    3333
    3434#if WK_API_ENABLED
    3535
    36 static bool finishedLoading;
    3736static bool finishedDispatch;
    38 
    39 @interface WKPDFViewResizeNavigationDelegate : NSObject <WKNavigationDelegate>
    40 @end
    41 
    42 @implementation WKPDFViewResizeNavigationDelegate
    43 
    44 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    45 {
    46     finishedLoading = true;
    47 }
    48 
    49 @end
    5037
    5138TEST(WebKit2, WKPDFViewResizeCrash)
     
    5340    RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
    5441
    55     RetainPtr<WKPDFViewResizeNavigationDelegate> delegate = adoptNS([[WKPDFViewResizeNavigationDelegate alloc] init]);
    56     [webView setNavigationDelegate:delegate.get()];
    57 
    5842    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"test" withExtension:@"pdf" subdirectory:@"TestWebKitAPI.resources"]];
    5943    [webView loadRequest:request];
    60 
    61     TestWebKitAPI::Util::run(&finishedLoading);
     44    [webView _test_waitForDidFinishNavigation];
    6245
    6346    [webView setFrame:NSMakeRect(0, 0, 100, 100)];
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewEvaluateJavaScript.mm

    r191543 r205329  
    3131#import "PlatformUtilities.h"
    3232#import "Test.h"
     33#import "TestNavigationDelegate.h"
    3334#import <WebKit/WKWebView.h>
    3435#import <WebKit/WKErrorPrivate.h>
     
    3637
    3738static bool isDone;
    38 
    39 @interface EvaluateJavaScriptNavigationDelegate : NSObject <WKNavigationDelegate>
    40 @end
    41 
    42 @implementation EvaluateJavaScriptNavigationDelegate
    43 
    44 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    45 {
    46     isDone = true;
    47 }
    48 
    49 @end
    5039
    5140TEST(WKWebView, EvaluateJavaScriptBlockCrash)
     
    7766{
    7867    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()];
    8168
    8269    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"simple" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
    8370    [webView loadRequest:request];
    84     TestWebKitAPI::Util::run(&isDone);
     71    [webView _test_waitForDidFinishNavigation];
    8572
    8673    [webView evaluateJavaScript:@"document.body" completionHandler:^(id result, NSError *error) {
  • trunk/Tools/TestWebKitAPI/Tests/WebKit2Cocoa/WKWebViewTextInput.mm

    r201592 r205329  
    2929#if PLATFORM(MAC)
    3030
    31 #import <WebKit/WKFoundation.h>
    3231#import "PlatformUtilities.h"
    3332#import "Test.h"
    34 #import <WebKit/WKWebView.h>
     33#import "TestNavigationDelegate.h"
     34#import <WebKit/WebKit.h>
    3535#import <wtf/RetainPtr.h>
    36 
    37 static bool isDone;
    38 
    39 @interface DummyNavigationDelegate : NSObject <WKNavigationDelegate>
    40 @end
    41 
    42 @implementation DummyNavigationDelegate
    43 
    44 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    45 {
    46     isDone = true;
    47 }
    48 
    49 @end
    5036
    5137TEST(WKWebView, ShouldHaveInputContextForEditableContent)
    5238{
    5339    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()];
    5640
    5741    NSURLRequest *request = [NSURLRequest requestWithURL:[[NSBundle mainBundle] URLForResource:@"editable-body" withExtension:@"html" subdirectory:@"TestWebKitAPI.resources"]];
    5842    [webView loadRequest:request];
    59     TestWebKitAPI::Util::run(&isDone);
     43    [webView _test_waitForDidFinishNavigation];
    6044
    6145    EXPECT_NOT_NULL([webView inputContext]);
  • trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.h

    r205328 r205329  
    2424 */
    2525
    26 #import "config.h"
     26#pragma once
    2727
    2828#if WK_API_ENABLED
    29 #if PLATFORM(MAC)
    3029
    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>
    3632
    37 static bool isDone;
     33@interface TestNavigationDelegate : NSObject <WKNavigationDelegate>
    3834
    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);
    4138
    42 @implementation DummyNavigationDelegate
    43 
    44 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    45 {
    46     isDone = true;
    47 }
     39- (void)waitForDidFinishNavigation;
    4840
    4941@end
    5042
    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
    6346
    6447#endif
    65 #endif
  • trunk/Tools/TestWebKitAPI/cocoa/TestNavigationDelegate.mm

    r205328 r205329  
    11/*
    2  * Copyright (C) 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626#import "config.h"
    27 #import <WebKit/WKFoundation.h>
     27#import "TestNavigationDelegate.h"
     28
     29#import "Utilities.h"
     30#import <wtf/RetainPtr.h>
    2831
    2932#if WK_API_ENABLED
    3033
    31 #import "PlatformUtilities.h"
    32 #import "Test.h"
    33 #import <wtf/RetainPtr.h>
     34@implementation TestNavigationDelegate
    3435
    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}
    4141
    4242- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
    4343{
    44     isDone = true;
     44    if (_didFinishNavigation)
     45        _didFinishNavigation(webView, navigation);
    4546}
    4647
    47 - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error
     48- (void)_webView:(WKWebView *)webView renderingProgressDidChange:(_WKRenderingProgressEvents)progressEvents
    4849{
    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;
    5066}
    5167
    5268@end
    5369
    54 TEST(WKWebView, ProvisionalURLNotChange)
     70@implementation WKWebView (TestWebKitAPIExtras)
     71
     72- (void)_test_waitForDidFinishNavigation
    5573{
    56     auto webView = adoptNS([[WKWebView alloc] init]);
    57     auto controller = adoptNS([[ProvisionalURLNotChangeController alloc] init]);
    58     [webView setNavigationDelegate:controller.get()];
     74    EXPECT_FALSE(self.navigationDelegate);
    5975
    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];
    6379
    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;
    6981}
    7082
     83@end
     84
    7185#endif
Note: See TracChangeset for help on using the changeset viewer.