forked from BlocksKit/BlocksKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUIWebViewBlocksKitTest.m
More file actions
98 lines (72 loc) · 2.71 KB
/
Copy pathUIWebViewBlocksKitTest.m
File metadata and controls
98 lines (72 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// UIWebViewBlocksKitTest.m
// BlocksKit Unit Tests
//
#import <XCTest/XCTest.h>
#import <BlocksKit/UIWebView+BlocksKit.h>
#import <BlocksKit/A2DynamicDelegate.h>
@interface UIWebViewBlocksKitTest : XCTestCase <UIWebViewDelegate>
@end
@implementation UIWebViewBlocksKitTest {
UIWebView *_subject;
BOOL shouldStartLoadDelegate, didStartLoadDelegate, didFinishLoadDelegate, didFinishWithErrorDelegate;
}
- (void)setUp {
_subject = [[UIWebView alloc] initWithFrame:CGRectZero];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
shouldStartLoadDelegate = YES;
return YES;
}
- (void)webViewDidStartLoad:(UIWebView *)webView {
didStartLoadDelegate = YES;
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
didFinishLoadDelegate = YES;
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
didFinishWithErrorDelegate = YES;
}
- (void)testShouldStartLoad {
_subject.delegate = self;
__block BOOL shouldStartLoadBlock = NO;
_subject.bk_shouldStartLoadBlock = ^BOOL(UIWebView *view, NSURLRequest *req, UIWebViewNavigationType type) {
shouldStartLoadBlock = YES;
return YES;
};
BOOL shouldStartLoad = [_subject.bk_dynamicDelegate webView:_subject shouldStartLoadWithRequest:nil navigationType:UIWebViewNavigationTypeLinkClicked];
XCTAssertTrue(shouldStartLoad, @"Web view is allowed to load");
XCTAssertTrue(shouldStartLoadBlock, @"Block handler was called");
XCTAssertTrue(shouldStartLoadDelegate, @"Delegate was called");
}
- (void)testDidStartLoad {
_subject.delegate = self;
__block BOOL didStartLoadBlock = NO;
_subject.bk_didStartLoadBlock = ^(UIWebView *view) {
didStartLoadBlock = YES;
};
[_subject.bk_dynamicDelegate webViewDidStartLoad:_subject];
XCTAssertTrue(didStartLoadBlock, @"Block handler was called");
XCTAssertTrue(didStartLoadDelegate, @"Delegate was called");
}
- (void)testDidFinishLoad {
_subject.delegate = self;
__block BOOL didFinishLoadBlock = NO;
_subject.bk_didFinishLoadBlock = ^(UIWebView *view) {
didFinishLoadBlock = YES;
};
[_subject.bk_dynamicDelegate webViewDidFinishLoad:_subject];
XCTAssertTrue(didFinishLoadBlock, @"Block handler was called");
XCTAssertTrue(didFinishLoadDelegate, @"Delegate was called");
}
- (void)testDidFinishWithError {
_subject.delegate = self;
__block BOOL didFinishWithErrorBlock = NO;
_subject.bk_didFinishWithErrorBlock = ^(UIWebView *view, NSError *err) {
didFinishWithErrorBlock = YES;
};
[_subject.bk_dynamicDelegate webView:_subject didFailLoadWithError:nil];
XCTAssertTrue(didFinishWithErrorBlock, @"Block handler was called");
XCTAssertTrue(didFinishWithErrorDelegate, @"Delegate was called");
}
@end