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..c458e5374a97021630a800518c056c12917f44b7 |
| --- /dev/null |
| +++ b/chrome/installer/mac/app/testing/Unpacker_test.mm |
| @@ -0,0 +1,115 @@ |
| +// 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 test_semaphore; |
| + |
| +@interface TestDelegate : NSObject<UnpackDelegate> |
| +@property(nonatomic) BOOL pass; |
| +- (void)fail; |
| +- (void)succeed; |
| +@end |
| + |
| +@implementation TestDelegate |
| +@synthesize pass = pass_; |
| + |
| +- (void)succeed { |
| + pass_ = YES; |
| + dispatch_semaphore_signal(test_semaphore); |
| +} |
| +- (void)fail { |
| + pass_ = NO; |
| + dispatch_semaphore_signal(test_semaphore); |
| +} |
| + |
| +- (void)unpacker:(Unpacker*)unpacker onMountSuccess:(NSString*)mountpath { |
| + if ([[NSFileManager defaultManager] |
| + fileExistsAtPath:[NSString pathWithComponents:@[ |
| + mountpath, @"Google Chrome.app" |
| + ]]]) { |
| + [unpacker extractChrome]; |
| + } else { |
| + [self fail]; |
| + } |
| +} |
| +- (void)unpacker:(Unpacker*)unpacker onMountFailure:(NSError*)error { |
| + [self fail]; |
| +} |
| + |
| +- (void)unpacker:(Unpacker*)unpacker onSuccess:(NSString*)appPath { |
| + [self succeed]; |
| +} |
| +- (void)unpacker:(Unpacker*)unpacker onFailure:(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 a temporary directory where the app should go |
| + NSURL* tempURL = [[NSFileManager defaultManager] |
| + URLForDirectory:NSItemReplacementDirectory |
| + inDomain:NSUserDomainMask |
| + appropriateForURL:[NSURL fileURLWithPath:@"/" isDirectory:YES] |
| + create:YES |
| + error:nil]; |
| + NSString* tempAppPath = |
| + [NSString pathWithComponents:@[ [tempURL path], @"Google Chrome.app" ]]; |
| + |
| + // create objects and semaphore |
| + Unpacker* unpack = [[Unpacker alloc] initWithFinalAppPath:tempAppPath]; |
| + TestDelegate* test_delegate = [[TestDelegate alloc] init]; |
| + unpack.delegate = test_delegate; |
| + test_semaphore = dispatch_semaphore_create(0); |
|
Sidney San Martín
2016/08/17 22:09:06
I think it would be better to make test_semaphore
Anna Zeng
2016/08/18 19:41:09
Good point! Done.
|
| + |
| + // identify where the disk image is now and start mount/extract step |
| + NSString* downloadDirectory = [NSSearchPathForDirectoriesInDomains( |
| + NSDownloadsDirectory, NSUserDomainMask, YES) firstObject]; |
|
Sidney San Martín
2016/08/17 22:09:06
Does this test only work if you already have Googl
Anna Zeng
2016/08/18 19:41:09
Doing.
|
| + NSURL* diskImageOriginalPath = |
| + [NSURL fileURLWithPath:[NSString pathWithComponents:@[ |
| + downloadDirectory, @"GoogleChrome.dmg" |
| + ]] |
| + isDirectory:NO]; |
| + [unpack mountDMGFromURL:diskImageOriginalPath]; |
| + dispatch_semaphore_wait(test_semaphore, DISPATCH_TIME_FOREVER); |
| + |
| + // was this correctly executed? |
| + ASSERT_TRUE([test_delegate pass]); |
| + // is the app file moved to the correct place we expect? |
| + ASSERT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:tempAppPath]); |
| + |
| + // start unmounting step |
| + [unpack unmountDMG]; |
| + dispatch_semaphore_wait(test_semaphore, DISPATCH_TIME_FOREVER); |
| + |
| + // was this correctly executed? |
| + EXPECT_TRUE([test_delegate pass]); |
| + // is the app still there? |
| + EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:tempAppPath]); |
| + |
| + [[NSFileManager defaultManager] removeItemAtURL:tempURL error:nil]; |
| +} |
| + |
| +} // namespace |