PageRenderTime 45ms CodeModel.GetById 30ms app.highlight 13ms RepoModel.GetById 1ms app.codeStats 0ms

/core/externals/update-engine/externals/google-toolbox-for-mac/AppKit/GTMGetURLHandlerTest.m

http://macfuse.googlecode.com/
Objective C | 83 lines | 53 code | 13 blank | 17 comment | 1 complexity | 6e8aa980fa89c86276f28dbf9be886f3 MD5 | raw file
 1//  GTMGetURLHandlerTest.m
 2//
 3//  Copyright 2008 Google Inc.
 4//
 5//  Licensed under the Apache License, Version 2.0 (the "License"); you may not
 6//  use this file except in compliance with the License.  You may obtain a copy
 7//  of the License at
 8// 
 9//  http://www.apache.org/licenses/LICENSE-2.0
10// 
11//  Unless required by applicable law or agreed to in writing, software
12//  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13//  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14//  License for the specific language governing permissions and limitations under
15//  the License.
16//
17
18#import "GTMSenTestCase.h"
19#import "GTMUnitTestDevLog.h"
20
21static BOOL sURLHandlerWasHit;
22
23@interface GTMGetURLHandlerBadClassWarning : NSObject
24@end
25
26@implementation GTMGetURLHandlerBadClassWarning : NSObject
27@end
28
29@interface GTMGetURLHandlerTest : GTMTestCase
30@end
31
32@implementation GTMGetURLHandlerTest
33- (BOOL)openURLString:(NSString *)url {
34  ProcessSerialNumber psn = { 0, kCurrentProcess };
35  NSAppleEventDescriptor *currentProcess 
36    = [NSAppleEventDescriptor descriptorWithDescriptorType:typeProcessSerialNumber
37                                                     bytes:&psn
38                                                    length:sizeof(ProcessSerialNumber)];
39  NSAppleEventDescriptor *event 
40    = [NSAppleEventDescriptor appleEventWithEventClass:kInternetEventClass
41                                               eventID:kAEGetURL
42                                      targetDescriptor:currentProcess
43                                              returnID:kAutoGenerateReturnID
44                                         transactionID:kAnyTransactionID];
45  NSAppleEventDescriptor *keyDesc 
46    = [NSAppleEventDescriptor descriptorWithString:url];
47  [event setParamDescriptor:keyDesc forKeyword:keyDirectObject];
48  OSStatus err = AESendMessage([event aeDesc], NULL, kAEWaitReply, 60);
49  return err == noErr ? YES : NO;
50}
51
52+ (BOOL)gtm_openURL:(NSURL*)url {
53  sURLHandlerWasHit = !sURLHandlerWasHit;
54  return YES;
55}
56
57- (void)testURLCall {
58  sURLHandlerWasHit = NO;
59  
60  [GTMUnitTestDevLogDebug expectPattern:@"Class GTMGetURLHandlerBadClassWarning "
61   @"for URL handler GTMGetURLHandlerBadClassURL .*"];
62  [GTMUnitTestDevLogDebug expectPattern:@"Unable to get class "
63   @"GTMGetURLHandlerMissingClassWarning for URL handler "
64   @"GTMGetURLHandlerMissingClassURL .*"];
65  [GTMUnitTestDevLogDebug expectPattern:@"Missing GTMBundleURLClass for URL handler "
66   @"GTMGetURLHandlerMissingHandlerURL .*"];
67  STAssertTrue([self openURLString:@"gtmgeturlhandlertest://test.foo"], nil);
68  STAssertTrue(sURLHandlerWasHit, @"URL handler not called");
69  
70  STAssertTrue([self openURLString:@"gtmgeturlhandlertest://test.foo"], nil);
71  STAssertFalse(sURLHandlerWasHit, @"URL handler not called 2");
72  
73  // test the two URL schemes with bad entries
74  STAssertTrue([self openURLString:@"gtmgeturlhandlerbadclasstest://test.foo"], 
75               nil);
76  
77  STAssertTrue([self openURLString:@"gtmgeturlhandlermissingclasstest://test.foo"], 
78               nil);
79
80  STAssertTrue([self openURLString:@"gtmgeturlhandlermissinghandlerurl://test.foo"], 
81               nil);
82}
83@end