iOS web browser with a focus on security and privacy
at master 56 lines 1.8 kB view raw
1#import <UIKit/UIKit.h> 2#import <XCTest/XCTest.h> 3#import <OCMock/OCMock.h> 4 5#import "URLBlocker.h" 6 7#define TRACE_URL_BLOCKER 8 9@interface URLBlocker_Tests : XCTestCase 10@end 11 12@implementation URLBlocker_Tests { 13 id HEMocked; 14} 15 16- (void)setUp 17{ 18 [super setUp]; 19 20 HEMocked = OCMClassMock([URLBlocker class]); 21 22 NSFileManager *fm = [NSFileManager defaultManager]; 23 NSString *tpath = [[NSBundle bundleForClass:[self class]] pathForResource:@"urlblocker_mock_targets" ofType:@"plist"]; 24 if (![fm fileExistsAtPath:tpath]) 25 abort(); 26 27 OCMStub([URLBlocker targets]).andReturn([NSDictionary dictionaryWithContentsOfFile:tpath]); 28} 29 30- (void)testShouldBlockURL 31{ 32 BOOL block = [URLBlocker shouldBlockURL:[NSURL URLWithString:@"https://twitter.com/"]]; 33 XCTAssert(block == YES); 34 35 BOOL block2 = [URLBlocker shouldBlockURL:[NSURL URLWithString:@"https://platform.twitter.com/widgets.js"]]; 36 XCTAssert(block2 == YES); 37 38 BOOL block3 = [URLBlocker shouldBlockURL:[NSURL URLWithString:@"https://platform.twitter-com/widgets.js"]]; 39 XCTAssert(block3 == NO); 40} 41 42- (void)testNotBlockingFromSameSite 43{ 44 NSString *block; 45 46 block = [URLBlocker blockingTargetForURL:[NSURL URLWithString:@"https://twitter.com/"] fromMainDocumentURL:[NSURL URLWithString:@"https://www.twitter.com/"]]; 47 XCTAssert(block == nil); 48 49 block = [URLBlocker blockingTargetForURL:[NSURL URLWithString:@"https://platform.twitter.com/widgets.js"] fromMainDocumentURL:[NSURL URLWithString:@"https://twitter.com/jcs/status/548344727771545600"]]; 50 XCTAssert(block == nil); 51 52 block = [URLBlocker blockingTargetForURL:[NSURL URLWithString:@"https://platform.twitter.com/widgets.js"] fromMainDocumentURL:[NSURL URLWithString:@"https://jcs.org/statuses/2014/12/25/548344727771545600/"]]; 53 XCTAssert(block != nil); 54} 55 56@end