1 | /*
|
---|
2 | * Copyright (C) 2016-2020 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 <WebKit/WebKit.h>
|
---|
27 | #import <wtf/RetainPtr.h>
|
---|
28 |
|
---|
29 | @class _WKProcessPoolConfiguration;
|
---|
30 |
|
---|
31 | #if PLATFORM(IOS_FAMILY)
|
---|
32 | @class _WKActivatedElementInfo;
|
---|
33 | @class _WKTextInputContext;
|
---|
34 | @protocol UITextInputInternal;
|
---|
35 | @protocol UITextInputMultiDocument;
|
---|
36 | @protocol UITextInputPrivate;
|
---|
37 | @protocol UIWKInteractionViewProtocol;
|
---|
38 | #endif
|
---|
39 |
|
---|
40 | @interface WKWebView (AdditionalDeclarations)
|
---|
41 | #if PLATFORM(MAC)
|
---|
42 | - (void)paste:(id)sender;
|
---|
43 | - (void)changeAttributes:(id)sender;
|
---|
44 | - (void)changeColor:(id)sender;
|
---|
45 | - (void)superscript:(id)sender;
|
---|
46 | - (void)subscript:(id)sender;
|
---|
47 | - (void)unscript:(id)sender;
|
---|
48 | #endif
|
---|
49 | @end
|
---|
50 |
|
---|
51 | @interface WKWebView (TestWebKitAPI)
|
---|
52 | #if PLATFORM(IOS_FAMILY)
|
---|
53 | @property (nonatomic, readonly) UIView <UITextInputPrivate, UITextInputInternal, UITextInputMultiDocument, UIWKInteractionViewProtocol, UITextInputTokenizer> *textInputContentView;
|
---|
54 | - (NSArray<_WKTextInputContext *> *)synchronouslyRequestTextInputContextsInRect:(CGRect)rect;
|
---|
55 | #endif
|
---|
56 | @property (nonatomic, readonly) NSUInteger gpuToWebProcessConnectionCount;
|
---|
57 | @property (nonatomic, readonly) NSString *contentsAsString;
|
---|
58 | @property (nonatomic, readonly) NSArray<NSString *> *tagsInBody;
|
---|
59 | - (void)loadTestPageNamed:(NSString *)pageName;
|
---|
60 | - (void)synchronouslyGoBack;
|
---|
61 | - (void)synchronouslyGoForward;
|
---|
62 | - (void)synchronouslyLoadHTMLString:(NSString *)html;
|
---|
63 | - (void)synchronouslyLoadHTMLString:(NSString *)html baseURL:(NSURL *)url;
|
---|
64 | - (void)synchronouslyLoadHTMLString:(NSString *)html preferences:(WKWebpagePreferences *)preferences;
|
---|
65 | - (void)synchronouslyLoadRequest:(NSURLRequest *)request;
|
---|
66 | - (void)synchronouslyLoadTestPageNamed:(NSString *)pageName;
|
---|
67 | - (BOOL)_synchronouslyExecuteEditCommand:(NSString *)command argument:(NSString *)argument;
|
---|
68 | - (void)expectElementTagsInOrder:(NSArray<NSString *> *)tagNames;
|
---|
69 | - (void)expectElementCount:(NSInteger)count querySelector:(NSString *)querySelector;
|
---|
70 | - (void)expectElementTag:(NSString *)tagName toComeBefore:(NSString *)otherTagName;
|
---|
71 | - (BOOL)evaluateMediaQuery:(NSString *)query;
|
---|
72 | - (NSString *)stringByEvaluatingJavaScript:(NSString *)script;
|
---|
73 | - (id)objectByEvaluatingJavaScriptWithUserGesture:(NSString *)script;
|
---|
74 | - (id)objectByEvaluatingJavaScript:(NSString *)script;
|
---|
75 | - (id)objectByCallingAsyncFunction:(NSString *)script withArguments:(NSDictionary *)arguments error:(NSError **)errorOut;
|
---|
76 | - (unsigned)waitUntilClientWidthIs:(unsigned)expectedClientWidth;
|
---|
77 | @end
|
---|
78 |
|
---|
79 | @interface TestMessageHandler : NSObject <WKScriptMessageHandler>
|
---|
80 | - (void)addMessage:(NSString *)message withHandler:(dispatch_block_t)handler;
|
---|
81 | @end
|
---|
82 |
|
---|
83 | @interface TestWKWebView : WKWebView
|
---|
84 | - (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration processPoolConfiguration:(_WKProcessPoolConfiguration *)processPoolConfiguration;
|
---|
85 | - (instancetype)initWithFrame:(CGRect)frame configuration:(WKWebViewConfiguration *)configuration addToWindow:(BOOL)addToWindow;
|
---|
86 | - (void)synchronouslyLoadHTMLStringAndWaitUntilAllImmediateChildFramesPaint:(NSString *)html;
|
---|
87 | - (void)clearMessageHandlers:(NSArray *)messageNames;
|
---|
88 | - (void)performAfterReceivingMessage:(NSString *)message action:(dispatch_block_t)action;
|
---|
89 | - (void)performAfterReceivingAnyMessage:(void (^)(NSString *))action;
|
---|
90 | - (void)waitForMessage:(NSString *)message;
|
---|
91 |
|
---|
92 | // This function waits until a DOM load event is fired.
|
---|
93 | // FIXME: Rename this function to better describe what "after loading" means.
|
---|
94 | - (void)performAfterLoading:(dispatch_block_t)actions;
|
---|
95 |
|
---|
96 | - (void)waitForNextPresentationUpdate;
|
---|
97 | - (void)waitUntilActivityStateUpdateDone;
|
---|
98 | - (void)forceDarkMode;
|
---|
99 | - (NSString *)stylePropertyAtSelectionStart:(NSString *)propertyName;
|
---|
100 | - (NSString *)stylePropertyAtSelectionEnd:(NSString *)propertyName;
|
---|
101 | - (void)collapseToStart;
|
---|
102 | - (void)collapseToEnd;
|
---|
103 | - (void)addToTestWindow;
|
---|
104 | - (BOOL)selectionRangeHasStartOffset:(int)start endOffset:(int)end;
|
---|
105 | - (void)clickOnElementID:(NSString *)elementID;
|
---|
106 | - (void)waitForPendingMouseEvents;
|
---|
107 | - (void)focus;
|
---|
108 | @end
|
---|
109 |
|
---|
110 | #if PLATFORM(IOS_FAMILY)
|
---|
111 | @interface UIView (WKTestingUIViewUtilities)
|
---|
112 | - (UIView *)wkFirstSubviewWithClass:(Class)targetClass;
|
---|
113 | - (UIView *)wkFirstSubviewWithBoundsSize:(CGSize)size;
|
---|
114 | @end
|
---|
115 | #endif
|
---|
116 |
|
---|
117 | #if PLATFORM(IOS_FAMILY)
|
---|
118 | @interface WKContentView : UIView
|
---|
119 | @end
|
---|
120 |
|
---|
121 | @interface TestWKWebView (IOSOnly)
|
---|
122 | @property (nonatomic, readonly) RetainPtr<NSArray> selectionRectsAfterPresentationUpdate;
|
---|
123 | @property (nonatomic, readonly) CGRect caretViewRectInContentCoordinates;
|
---|
124 | @property (nonatomic, readonly) NSArray<NSValue *> *selectionViewRectsInContentCoordinates;
|
---|
125 | - (_WKActivatedElementInfo *)activatedElementAtPosition:(CGPoint)position;
|
---|
126 | - (void)evaluateJavaScriptAndWaitForInputSessionToChange:(NSString *)script;
|
---|
127 | - (WKContentView *)wkContentView;
|
---|
128 | @end
|
---|
129 | #endif
|
---|
130 |
|
---|
131 | #if PLATFORM(MAC)
|
---|
132 | @interface TestWKWebView (MacOnly)
|
---|
133 | // Simulates clicking with a pressure-sensitive device, if possible.
|
---|
134 | - (void)mouseDownAtPoint:(NSPoint)pointInWindow simulatePressure:(BOOL)simulatePressure;
|
---|
135 | - (void)mouseDownAtPoint:(NSPoint)pointInWindow simulatePressure:(BOOL)simulatePressure withFlags:(NSEventModifierFlags)flags eventType:(NSEventType)eventType;
|
---|
136 | - (void)mouseDragToPoint:(NSPoint)pointInWindow;
|
---|
137 | - (void)mouseEnterAtPoint:(NSPoint)pointInWindow;
|
---|
138 | - (void)mouseUpAtPoint:(NSPoint)pointInWindow;
|
---|
139 | - (void)mouseUpAtPoint:(NSPoint)pointInWindow withFlags:(NSEventModifierFlags)flags eventType:(NSEventType)eventType;
|
---|
140 | - (void)mouseMoveToPoint:(NSPoint)pointInWindow withFlags:(NSEventModifierFlags)flags;
|
---|
141 | - (void)sendClicksAtPoint:(NSPoint)pointInWindow numberOfClicks:(NSUInteger)numberOfClicks;
|
---|
142 | - (void)sendClickAtPoint:(NSPoint)pointInWindow;
|
---|
143 | - (void)wheelEventAtPoint:(CGPoint)pointInWindow wheelDelta:(CGSize)delta;
|
---|
144 | - (NSWindow *)hostWindow;
|
---|
145 | - (void)typeCharacter:(char)character modifiers:(NSEventModifierFlags)modifiers;
|
---|
146 | - (void)typeCharacter:(char)character;
|
---|
147 | - (void)setEventTimestampOffset:(NSTimeInterval)offset;
|
---|
148 | @property (nonatomic, readonly) NSTimeInterval eventTimestamp;
|
---|
149 | @end
|
---|
150 | #endif
|
---|
151 |
|
---|