Chromium Code Reviews| 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..485e529ac2f804a7f79ac72d3e35944f95fd959b |
| --- /dev/null |
| +++ b/chrome/installer/mac/app/testing/Unpacker_test.mm |
| @@ -0,0 +1,66 @@ |
| +// 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" |
| + |
| +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" |
|
Elly Fong-Jones
2016/08/16 15:26:18
Chrome :)
Anna Zeng
2016/08/16 23:07:40
Acknowledged.
|
| + error:nil]) { |
| + NSLog(@"Application removed!"); |
| + } |
| + |
| + NSLog(@"test succeeded"); |
| + dispatch_semaphore_signal(mount_semaphore); |
| +} |
| +@end |
| + |
| +namespace { |
| + |
| +// TODO: edit the below test to work with the current protocol |
| +TEST(UnpackerTest, MountAndUnmount) { |
| + Unpacker* unpack = [[Unpacker alloc] |
| + // NOTE: purposefully misspelled Chrome in order to avoid overwriting the |
| + // current machine's Google Chrome installation. |
| + initWithFinalAppPath:@"/Applications/Google Chromo.app"]; |
|
Sidney San Martín
2016/08/13 12:37:19
It would be better if the test used a temporary fo
Anna Zeng
2016/08/16 23:07:40
Good point! Done.
|
| + TestDelegate* test_delegate = [[TestDelegate alloc] init]; |
| + unpack.delegate = test_delegate; |
| + mount_semaphore = dispatch_semaphore_create(0); |
| + |
| + [unpack mountDMG]; |
| + |
| + 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)); |
|
Sidney San Martín
2016/08/13 12:37:19
It would be way simpler to just look for a file (l
Anna Zeng
2016/08/16 23:07:40
Done.
|
| + 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); |
|
Sidney San Martín
2016/08/13 12:37:19
Ditto.
Anna Zeng
2016/08/16 23:07:40
Done.
|
| +} |
| + |
| +} // namespace |