| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/public/test/test_updatable_resource_provider.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/mac/scoped_nsobject.h" | |
| 9 | |
| 10 #pragma mark - TestUpdatabeResourceDescriptor | |
| 11 | |
| 12 // Dummy UpdatableResourceDescriptorBridge implementation. | |
| 13 @interface TestUpdatabeResourceDescriptor | |
| 14 : NSObject<UpdatableResourceDescriptorBridge> | |
| 15 @property(nonatomic, readonly) NSURL* updateURL; | |
| 16 @property(nonatomic, copy) NSString* applicationIdentifier; | |
| 17 @property(nonatomic, copy) NSString* applicationVersion; | |
| 18 @property(nonatomic, copy) NSString* bundleResourcePath; | |
| 19 @property(nonatomic, copy) NSString* updateResourcePath; | |
| 20 @end | |
| 21 | |
| 22 @implementation TestUpdatabeResourceDescriptor | |
| 23 @synthesize updateURL; | |
| 24 @synthesize applicationIdentifier; | |
| 25 @synthesize applicationVersion; | |
| 26 @synthesize bundleResourcePath; | |
| 27 @synthesize updateResourcePath; | |
| 28 | |
| 29 - (void)updateCheckDidFinishWithSuccess:(BOOL)wasSuccessful { | |
| 30 } | |
| 31 | |
| 32 - (NSString*)resourcePath { | |
| 33 return nil; | |
| 34 } | |
| 35 @end | |
| 36 | |
| 37 #pragma mark - TestUpdatableResource | |
| 38 | |
| 39 // Dummy UpdatableResourceDescriptorBridge implementation that simply loads data | |
| 40 // from the specified plist file. | |
| 41 @interface TestUpdatableResource : NSObject<UpdatableResourceBridge> | |
| 42 @property(nonatomic, readonly) id<UpdatableResourceDescriptorBridge> descriptor; | |
| 43 - (instancetype)initWithDelegate:(id<UpdatableResourceDelegate>)delegate | |
| 44 plist:(NSString*)resource_identifier | |
| 45 NS_DESIGNATED_INITIALIZER; | |
| 46 - (instancetype)init NS_UNAVAILABLE; | |
| 47 @end | |
| 48 | |
| 49 @implementation TestUpdatableResource { | |
| 50 base::scoped_nsprotocol<id<UpdatableResourceDelegate>> _delegate; | |
| 51 base::scoped_nsprotocol<id<UpdatableResourceDescriptorBridge>> _descriptor; | |
| 52 } | |
| 53 | |
| 54 - (instancetype)initWithDelegate:(id<UpdatableResourceDelegate>)delegate | |
| 55 plist:(NSString*)resourceIdentifier { | |
| 56 if (self = [super init]) { | |
| 57 _delegate.reset([delegate retain]); | |
| 58 _descriptor.reset([[TestUpdatabeResourceDescriptor alloc] init]); | |
| 59 DCHECK([resourceIdentifier hasSuffix:@".plist"]) | |
| 60 << "TestUpdatableResource supports only the plist format"; | |
| 61 [_descriptor setBundleResourcePath:resourceIdentifier]; | |
| 62 } | |
| 63 return self; | |
| 64 } | |
| 65 | |
| 66 - (instancetype)init { | |
| 67 NOTREACHED(); | |
| 68 return nil; | |
| 69 } | |
| 70 | |
| 71 - (id<UpdatableResourceDescriptorBridge>)descriptor { | |
| 72 return _descriptor.get(); | |
| 73 } | |
| 74 | |
| 75 - (id<UpdatableResourceDelegate>)delegate { | |
| 76 return _delegate; | |
| 77 } | |
| 78 | |
| 79 - (NSDictionary*)resourceData { | |
| 80 return [NSDictionary | |
| 81 dictionaryWithContentsOfFile:[_descriptor bundleResourcePath]]; | |
| 82 } | |
| 83 - (void)loadDefaults { | |
| 84 [_delegate loadDefaults:self]; | |
| 85 } | |
| 86 | |
| 87 @end | |
| 88 | |
| 89 #pragma mark - TestUpdatableResourceProvider | |
| 90 | |
| 91 namespace ios { | |
| 92 | |
| 93 NSString* TestUpdatableResourceProvider::GetUpdateNotificationName() { | |
| 94 return @"ResourceUpdatedTest"; | |
| 95 } | |
| 96 | |
| 97 id<UpdatableResourceBridge> | |
| 98 TestUpdatableResourceProvider::CreateUpdatableResource( | |
| 99 NSString* resource_identifier, | |
| 100 id<UpdatableResourceDelegate> delegate) { | |
| 101 NSString* path = | |
| 102 [NSString stringWithFormat:@"%@/gm-config/ANY/%@", | |
| 103 [[NSBundle mainBundle] resourcePath], | |
| 104 resource_identifier]; | |
| 105 return [[TestUpdatableResource alloc] initWithDelegate:delegate plist:path]; | |
| 106 } | |
| 107 | |
| 108 } // namespace ios | |
| OLD | NEW |