Universal links from Google search results pages don't open the app.
[WebKit-https.git] / Tools / TestWebKitAPI / cocoa / TestNavigationDelegate.mm
1 /*
2  * Copyright (C) 2016 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #import "config.h"
27 #import "TestNavigationDelegate.h"
28
29 #import "Utilities.h"
30 #import <wtf/RetainPtr.h>
31
32 #if WK_API_ENABLED
33
34 @implementation TestNavigationDelegate
35
36 - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler
37 {
38     if (_decidePolicyForNavigationAction)
39         _decidePolicyForNavigationAction(navigationAction, decisionHandler);
40     else
41         decisionHandler(WKNavigationActionPolicyAllow);
42 }
43
44 - (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation
45 {
46     if (_didStartProvisionalNavigation)
47         _didStartProvisionalNavigation(webView, navigation);
48 }
49
50 - (void)webView:(WKWebView *)webView didFailProvisionalNavigation:(WKNavigation *)navigation withError:(NSError *)error
51 {
52     if (_didFailProvisionalNavigation)
53         _didFailProvisionalNavigation(webView, navigation, error);
54 }
55
56 - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
57 {
58     if (_didFinishNavigation)
59         _didFinishNavigation(webView, navigation);
60 }
61
62 - (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView
63 {
64     if (_webContentProcessDidTerminate)
65         _webContentProcessDidTerminate(webView);
66 }
67
68 - (void)_webView:(WKWebView *)webView renderingProgressDidChange:(_WKRenderingProgressEvents)progressEvents
69 {
70     if (_renderingProgressDidChange)
71         _renderingProgressDidChange(webView, progressEvents);
72 }
73
74 - (void)waitForDidStartProvisionalNavigation
75 {
76     EXPECT_FALSE(self.didStartProvisionalNavigation);
77
78     __block bool finished = false;
79     self.didStartProvisionalNavigation = ^(WKWebView *, WKNavigation *) {
80         finished = true;
81     };
82
83     TestWebKitAPI::Util::run(&finished);
84
85     self.didStartProvisionalNavigation = nil;
86 }
87
88 - (void)waitForDidFinishNavigation
89 {
90     EXPECT_FALSE(self.didFinishNavigation);
91
92     __block bool finished = false;
93     self.didFinishNavigation = ^(WKWebView *, WKNavigation *) {
94         finished = true;
95     };
96
97     TestWebKitAPI::Util::run(&finished);
98
99     self.didFinishNavigation = nil;
100 }
101
102 @end
103
104 @implementation WKWebView (TestWebKitAPIExtras)
105
106 - (void)_test_waitForDidStartProvisionalNavigation
107 {
108     EXPECT_FALSE(self.navigationDelegate);
109
110     auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]);
111     self.navigationDelegate = navigationDelegate.get();
112     [navigationDelegate waitForDidStartProvisionalNavigation];
113
114     self.navigationDelegate = nil;
115 }
116
117 - (void)_test_waitForDidFinishNavigation
118 {
119     EXPECT_FALSE(self.navigationDelegate);
120
121     auto navigationDelegate = adoptNS([[TestNavigationDelegate alloc] init]);
122     self.navigationDelegate = navigationDelegate.get();
123     [navigationDelegate waitForDidFinishNavigation];
124
125     self.navigationDelegate = nil;
126
127 #if PLATFORM(IOS_FAMILY)
128     __block bool presentationUpdateHappened = false;
129     [self _doAfterNextPresentationUpdateWithoutWaitingForAnimatedResizeForTesting:^{
130         presentationUpdateHappened = true;
131     }];
132     TestWebKitAPI::Util::run(&presentationUpdateHappened);
133 #endif
134 }
135
136 @end
137
138 #endif