OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "chrome/installer/mac/app/Unpacker.h" |
| 6 |
| 7 #include "base/base_paths.h" |
| 8 #include "base/files/file_path.h" |
| 9 #include "base/path_service.h" |
| 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 |
| 13 #import "chrome/installer/mac/app/Downloader.h" |
| 14 |
| 15 @interface TestDelegate : NSObject<UnpackDelegate> |
| 16 @property(nonatomic) BOOL pass; |
| 17 @property(nonatomic) dispatch_semaphore_t test_semaphore; |
| 18 - (void)fail; |
| 19 - (void)succeed; |
| 20 - (void)wait; |
| 21 @end |
| 22 |
| 23 @implementation TestDelegate |
| 24 @synthesize pass = pass_; |
| 25 @synthesize test_semaphore = test_semaphore_; |
| 26 |
| 27 - (id)init { |
| 28 if ((self = [super init])) { |
| 29 test_semaphore_ = dispatch_semaphore_create(0); |
| 30 pass_ = NO; |
| 31 } |
| 32 return self; |
| 33 } |
| 34 |
| 35 - (void)succeed { |
| 36 pass_ = YES; |
| 37 dispatch_semaphore_signal(test_semaphore_); |
| 38 } |
| 39 - (void)fail { |
| 40 pass_ = NO; |
| 41 dispatch_semaphore_signal(test_semaphore_); |
| 42 } |
| 43 - (void)wait { |
| 44 dispatch_semaphore_wait(test_semaphore_, DISPATCH_TIME_FOREVER); |
| 45 } |
| 46 |
| 47 - (void)unpacker:(Unpacker*)unpacker onMountSuccess:(NSString*)tempAppPath { |
| 48 if ([[NSFileManager defaultManager] fileExistsAtPath:tempAppPath]) { |
| 49 [self succeed]; |
| 50 } else { |
| 51 [self fail]; |
| 52 } |
| 53 } |
| 54 - (void)unpacker:(Unpacker*)unpacker onMountFailure:(NSError*)error { |
| 55 [self fail]; |
| 56 } |
| 57 |
| 58 - (void)unpacker:(Unpacker*)unpacker onUnmountSuccess:(NSString*)mountpath { |
| 59 if (![[NSFileManager defaultManager] |
| 60 fileExistsAtPath:[NSString pathWithComponents:@[ |
| 61 mountpath, @"Google Chrome.app" |
| 62 ]]]) { |
| 63 [self succeed]; |
| 64 } else { |
| 65 [self fail]; |
| 66 } |
| 67 } |
| 68 - (void)unpacker:(Unpacker*)unpacker onUnmountFailure:(NSError*)error { |
| 69 [self fail]; |
| 70 } |
| 71 |
| 72 @end |
| 73 |
| 74 namespace { |
| 75 |
| 76 TEST(UnpackerTest, IntegrationTest) { |
| 77 // create objects and semaphore |
| 78 Unpacker* unpack = [[Unpacker alloc] init]; |
| 79 TestDelegate* test_delegate = [[TestDelegate alloc] init]; |
| 80 unpack.delegate = test_delegate; |
| 81 |
| 82 // get a disk image to use to test |
| 83 base::FilePath originalPath; |
| 84 PathService::Get(base::DIR_SOURCE_ROOT, &originalPath); |
| 85 originalPath = originalPath.AppendASCII("chrome/test/data/mac_installer/"); |
| 86 base::FilePath copiedPath = base::FilePath(originalPath); |
| 87 NSString* diskImageOriginalPath = base::SysUTF8ToNSString( |
| 88 (originalPath.AppendASCII("test-dmg.dmg")).value()); |
| 89 NSString* diskImageCopiedPath = base::SysUTF8ToNSString( |
| 90 (originalPath.AppendASCII("test-dmg2.dmg")).value()); |
| 91 [[NSFileManager defaultManager] copyItemAtPath:diskImageOriginalPath |
| 92 toPath:diskImageCopiedPath |
| 93 error:nil]; |
| 94 NSURL* dmgURL = [NSURL fileURLWithPath:diskImageCopiedPath isDirectory:NO]; |
| 95 // start mount step |
| 96 [unpack mountDMGFromURL:dmgURL]; |
| 97 [test_delegate wait]; |
| 98 |
| 99 // is the disk image mounted? |
| 100 ASSERT_TRUE([test_delegate pass]); |
| 101 |
| 102 // start unmount step |
| 103 [unpack unmountDMG]; |
| 104 [test_delegate wait]; |
| 105 |
| 106 // is the disk image gone? |
| 107 EXPECT_TRUE([test_delegate pass]); |
| 108 } |
| 109 |
| 110 } // namespace |
OLD | NEW |