| Index: chrome/installer/mac/app/testing/Unpacker_test.mm
|
| diff --git a/chrome/installer/mac/app/testing/Unpacker_test.mm b/chrome/installer/mac/app/testing/Unpacker_test.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..352eccea97d8acf49da24513f45a2132b0588c40
|
| --- /dev/null
|
| +++ b/chrome/installer/mac/app/testing/Unpacker_test.mm
|
| @@ -0,0 +1,63 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "chrome/installer/mac/app/Unpacker.h"
|
| +
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +#import "chrome/installer/mac/app/Downloader.h"
|
| +
|
| +extern dispatch_semaphore_t mount_semaphore;
|
| +
|
| +@interface TestDelegate : NSObject<UnpackDelegate>
|
| +@end
|
| +
|
| +@implementation TestDelegate
|
| +- (void)onUnpackSuccess {
|
| + NSFileManager* fileManager = [NSFileManager defaultManager];
|
| +
|
| + if ([fileManager removeItemAtPath:@"/Applications/Google Chromo.app"
|
| + error:nil]) {
|
| + NSLog(@"Application removed!");
|
| + }
|
| +
|
| + NSLog(@"test succeeded");
|
| + dispatch_semaphore_signal(mount_semaphore);
|
| +}
|
| +@end
|
| +
|
| +namespace {
|
| +
|
| +TEST(UnpackerTest, MountAndUnmount) {
|
| + Unpacker* unpack = [[Unpacker alloc] init];
|
| + TestDelegate* test_delegate = [[TestDelegate alloc] init];
|
| + unpack.delegate = test_delegate;
|
| + mount_semaphore = dispatch_semaphore_create(0);
|
| +
|
| + [unpack mountDMG];
|
| + dispatch_semaphore_wait(mount_semaphore, DISPATCH_TIME_FOREVER);
|
| +
|
| + DASessionRef session = DASessionCreate(nil);
|
| + DADiskRef child_disk = DADiskCreateFromVolumePath(
|
| + nil, session,
|
| + (CFURLRef)[NSURL URLWithString:PATH_FROM_EXECUTABLE(@"tmp")]);
|
| + DADiskRef whole_disk = DADiskCopyWholeDisk(child_disk);
|
| +
|
| + CFDictionaryRef disk_dictionary = DADiskCopyDescription(whole_disk);
|
| + CFTypeRef mediaEjectableKey = CFDictionaryGetValue(
|
| + disk_dictionary, kDADiskDescriptionMediaEjectableKey);
|
| + ASSERT_TRUE(CFBooleanGetValue((CFBooleanRef)mediaEjectableKey));
|
| + CFRelease(whole_disk);
|
| + CFRelease(child_disk);
|
| +
|
| + [unpack unmountDMG];
|
| + dispatch_semaphore_wait(mount_semaphore, DISPATCH_TIME_FOREVER);
|
| +
|
| + DADiskRef disk_check = DADiskCreateFromVolumePath(
|
| + nil, session,
|
| + (CFURLRef)[NSURL URLWithString:PATH_FROM_EXECUTABLE(@"tmp")]);
|
| + EXPECT_FALSE(disk_check);
|
| +}
|
| +
|
| +} // namespace
|
|
|