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..3f6d6326b7cf85b6de7f1aba1a4b752835401edf |
--- /dev/null |
+++ b/chrome/installer/mac/app/testing/Unpacker_test.mm |
@@ -0,0 +1,110 @@ |
+// 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 "base/base_paths.h" |
+#include "base/files/file_path.h" |
+#include "base/path_service.h" |
+#include "base/strings/sys_string_conversions.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+#import "chrome/installer/mac/app/Downloader.h" |
+ |
+@interface TestDelegate : NSObject<UnpackDelegate> |
+@property(nonatomic) BOOL pass; |
+@property(nonatomic) dispatch_semaphore_t test_semaphore; |
+- (void)fail; |
+- (void)succeed; |
+- (void)wait; |
+@end |
+ |
+@implementation TestDelegate |
+@synthesize pass = pass_; |
+@synthesize test_semaphore = test_semaphore_; |
+ |
+- (id)init { |
+ if ((self = [super init])) { |
+ test_semaphore_ = dispatch_semaphore_create(0); |
+ pass_ = NO; |
+ } |
+ return self; |
+} |
+ |
+- (void)succeed { |
+ pass_ = YES; |
+ dispatch_semaphore_signal(test_semaphore_); |
+} |
+- (void)fail { |
+ pass_ = NO; |
+ dispatch_semaphore_signal(test_semaphore_); |
+} |
+- (void)wait { |
+ dispatch_semaphore_wait(test_semaphore_, DISPATCH_TIME_FOREVER); |
+} |
+ |
+- (void)unpacker:(Unpacker*)unpacker onMountSuccess:(NSString*)tempAppPath { |
+ if ([[NSFileManager defaultManager] fileExistsAtPath:tempAppPath]) { |
+ [self succeed]; |
+ } else { |
+ [self fail]; |
+ } |
+} |
+- (void)unpacker:(Unpacker*)unpacker onMountFailure:(NSError*)error { |
+ [self fail]; |
+} |
+ |
+- (void)unpacker:(Unpacker*)unpacker onUnmountSuccess:(NSString*)mountpath { |
+ if (![[NSFileManager defaultManager] |
+ fileExistsAtPath:[NSString pathWithComponents:@[ |
+ mountpath, @"Google Chrome.app" |
+ ]]]) { |
+ [self succeed]; |
+ } else { |
+ [self fail]; |
+ } |
+} |
+- (void)unpacker:(Unpacker*)unpacker onUnmountFailure:(NSError*)error { |
+ [self fail]; |
+} |
+ |
+@end |
+ |
+namespace { |
+ |
+TEST(UnpackerTest, IntegrationTest) { |
+ // create objects and semaphore |
+ Unpacker* unpack = [[Unpacker alloc] init]; |
+ TestDelegate* test_delegate = [[TestDelegate alloc] init]; |
+ unpack.delegate = test_delegate; |
+ |
+ // get a disk image to use to test |
+ base::FilePath originalPath; |
+ PathService::Get(base::DIR_SOURCE_ROOT, &originalPath); |
+ originalPath = originalPath.AppendASCII("chrome/test/data/mac_installer/"); |
+ base::FilePath copiedPath = base::FilePath(originalPath); |
+ NSString* diskImageOriginalPath = base::SysUTF8ToNSString( |
+ (originalPath.AppendASCII("test-dmg.dmg")).value()); |
+ NSString* diskImageCopiedPath = base::SysUTF8ToNSString( |
+ (originalPath.AppendASCII("test-dmg2.dmg")).value()); |
+ [[NSFileManager defaultManager] copyItemAtPath:diskImageOriginalPath |
+ toPath:diskImageCopiedPath |
+ error:nil]; |
+ NSURL* dmgURL = [NSURL fileURLWithPath:diskImageCopiedPath isDirectory:NO]; |
+ // start mount step |
+ [unpack mountDMGFromURL:dmgURL]; |
+ [test_delegate wait]; |
+ |
+ // is the disk image mounted? |
+ ASSERT_TRUE([test_delegate pass]); |
+ |
+ // start unmount step |
+ [unpack unmountDMG]; |
+ [test_delegate wait]; |
+ |
+ // is the disk image gone? |
+ EXPECT_TRUE([test_delegate pass]); |
+} |
+ |
+} // namespace |