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 "testing/gtest/include/gtest/gtest.h" |
| 8 |
| 9 #import "chrome/installer/mac/app/Downloader.h" |
| 10 |
| 11 extern dispatch_semaphore_t mount_semaphore; |
| 12 |
| 13 @interface TestDelegate : NSObject<UnpackDelegate> |
| 14 @end |
| 15 |
| 16 @implementation TestDelegate |
| 17 - (void)onUnpackSuccess { |
| 18 NSFileManager* fileManager = [NSFileManager defaultManager]; |
| 19 |
| 20 if ([fileManager removeItemAtPath:@"/Applications/Google Chromo.app" |
| 21 error:nil]) { |
| 22 NSLog(@"Application removed!"); |
| 23 } |
| 24 |
| 25 NSLog(@"test succeeded"); |
| 26 dispatch_semaphore_signal(mount_semaphore); |
| 27 } |
| 28 @end |
| 29 |
| 30 namespace { |
| 31 |
| 32 TEST(UnpackerTest, MountAndUnmount) { |
| 33 Unpacker* unpack = [[Unpacker alloc] init]; |
| 34 TestDelegate* test_delegate = [[TestDelegate alloc] init]; |
| 35 unpack.delegate = test_delegate; |
| 36 mount_semaphore = dispatch_semaphore_create(0); |
| 37 |
| 38 [unpack mountDMG]; |
| 39 dispatch_semaphore_wait(mount_semaphore, DISPATCH_TIME_FOREVER); |
| 40 |
| 41 DASessionRef session = DASessionCreate(nil); |
| 42 DADiskRef child_disk = DADiskCreateFromVolumePath( |
| 43 nil, session, |
| 44 (CFURLRef)[NSURL URLWithString:PATH_FROM_EXECUTABLE(@"tmp")]); |
| 45 DADiskRef whole_disk = DADiskCopyWholeDisk(child_disk); |
| 46 |
| 47 CFDictionaryRef disk_dictionary = DADiskCopyDescription(whole_disk); |
| 48 CFTypeRef mediaEjectableKey = CFDictionaryGetValue( |
| 49 disk_dictionary, kDADiskDescriptionMediaEjectableKey); |
| 50 ASSERT_TRUE(CFBooleanGetValue((CFBooleanRef)mediaEjectableKey)); |
| 51 CFRelease(whole_disk); |
| 52 CFRelease(child_disk); |
| 53 |
| 54 [unpack unmountDMG]; |
| 55 dispatch_semaphore_wait(mount_semaphore, DISPATCH_TIME_FOREVER); |
| 56 |
| 57 DADiskRef disk_check = DADiskCreateFromVolumePath( |
| 58 nil, session, |
| 59 (CFURLRef)[NSURL URLWithString:PATH_FROM_EXECUTABLE(@"tmp")]); |
| 60 EXPECT_FALSE(disk_check); |
| 61 } |
| 62 |
| 63 } // namespace |
OLD | NEW |