/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. #import "GTMSenTestCase.h"
  18. #import "GTMUnitTestDevLog.h"
  19. static BOOL sURLHandlerWasHit;
  20. @interface GTMGetURLHandlerBadClassWarning : NSObject
  21. @end
  22. @implementation GTMGetURLHandlerBadClassWarning : NSObject
  23. @end
  24. @interface GTMGetURLHandlerTest : GTMTestCase
  25. @end
  26. @implementation GTMGetURLHandlerTest
  27. - (BOOL)openURLString:(NSString *)url {
  28. ProcessSerialNumber psn = { 0, kCurrentProcess };
  29. NSAppleEventDescriptor *currentProcess
  30. = [NSAppleEventDescriptor descriptorWithDescriptorType:typeProcessSerialNumber
  31. bytes:&psn
  32. length:sizeof(ProcessSerialNumber)];
  33. NSAppleEventDescriptor *event
  34. = [NSAppleEventDescriptor appleEventWithEventClass:kInternetEventClass
  35. eventID:kAEGetURL
  36. targetDescriptor:currentProcess
  37. returnID:kAutoGenerateReturnID
  38. transactionID:kAnyTransactionID];
  39. NSAppleEventDescriptor *keyDesc
  40. = [NSAppleEventDescriptor descriptorWithString:url];
  41. [event setParamDescriptor:keyDesc forKeyword:keyDirectObject];
  42. OSStatus err = AESendMessage([event aeDesc], NULL, kAEWaitReply, 60);
  43. return err == noErr ? YES : NO;
  44. }
  45. + (BOOL)gtm_openURL:(NSURL*)url {
  46. sURLHandlerWasHit = !sURLHandlerWasHit;
  47. return YES;
  48. }
  49. - (void)testURLCall {
  50. sURLHandlerWasHit = NO;
  51. [GTMUnitTestDevLogDebug expectPattern:@"Class GTMGetURLHandlerBadClassWarning "
  52. @"for URL handler GTMGetURLHandlerBadClassURL .*"];
  53. [GTMUnitTestDevLogDebug expectPattern:@"Unable to get class "
  54. @"GTMGetURLHandlerMissingClassWarning for URL handler "
  55. @"GTMGetURLHandlerMissingClassURL .*"];
  56. [GTMUnitTestDevLogDebug expectPattern:@"Missing GTMBundleURLClass for URL handler "
  57. @"GTMGetURLHandlerMissingHandlerURL .*"];
  58. STAssertTrue([self openURLString:@"gtmgeturlhandlertest://test.foo"], nil);
  59. STAssertTrue(sURLHandlerWasHit, @"URL handler not called");
  60. STAssertTrue([self openURLString:@"gtmgeturlhandlertest://test.foo"], nil);
  61. STAssertFalse(sURLHandlerWasHit, @"URL handler not called 2");
  62. // test the two URL schemes with bad entries
  63. STAssertTrue([self openURLString:@"gtmgeturlhandlerbadclasstest://test.foo"],
  64. nil);
  65. STAssertTrue([self openURLString:@"gtmgeturlhandlermissingclasstest://test.foo"],
  66. nil);
  67. STAssertTrue([self openURLString:@"gtmgeturlhandlermissinghandlerurl://test.foo"],
  68. nil);
  69. }
  70. @end