Chromium Code Reviews| 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 dispatch_semaphore_t test_semaphore; | |
| 12 | |
| 13 @interface TestDelegate : NSObject<UnpackDelegate> | |
| 14 @property(nonatomic) BOOL pass; | |
| 15 - (void)fail; | |
| 16 - (void)succeed; | |
| 17 @end | |
| 18 | |
| 19 @implementation TestDelegate | |
| 20 @synthesize pass = pass_; | |
| 21 | |
| 22 - (void)succeed { | |
| 23 pass_ = YES; | |
| 24 dispatch_semaphore_signal(test_semaphore); | |
| 25 } | |
| 26 - (void)fail { | |
| 27 pass_ = NO; | |
| 28 dispatch_semaphore_signal(test_semaphore); | |
| 29 } | |
| 30 | |
| 31 - (void)unpacker:(Unpacker*)unpacker onMountSuccess:(NSString*)mountpath { | |
| 32 if ([[NSFileManager defaultManager] | |
| 33 fileExistsAtPath:[NSString pathWithComponents:@[ | |
| 34 mountpath, @"Google Chrome.app" | |
| 35 ]]]) { | |
| 36 [unpacker extractChrome]; | |
| 37 } else { | |
| 38 [self fail]; | |
| 39 } | |
| 40 } | |
| 41 - (void)unpacker:(Unpacker*)unpacker onMountFailure:(NSError*)error { | |
| 42 [self fail]; | |
| 43 } | |
| 44 | |
| 45 - (void)unpacker:(Unpacker*)unpacker onSuccess:(NSString*)appPath { | |
| 46 [self succeed]; | |
| 47 } | |
| 48 - (void)unpacker:(Unpacker*)unpacker onFailure:(NSError*)error { | |
| 49 [self fail]; | |
| 50 } | |
| 51 | |
| 52 - (void)unpacker:(Unpacker*)unpacker onUnmountSuccess:(NSString*)mountpath { | |
| 53 if (![[NSFileManager defaultManager] | |
| 54 fileExistsAtPath:[NSString pathWithComponents:@[ | |
| 55 mountpath, @"Google Chrome.app" | |
| 56 ]]]) { | |
| 57 [self succeed]; | |
| 58 } else { | |
| 59 [self fail]; | |
| 60 } | |
| 61 } | |
| 62 - (void)unpacker:(Unpacker*)unpacker onUnmountFailure:(NSError*)error { | |
| 63 [self fail]; | |
| 64 } | |
| 65 | |
| 66 @end | |
| 67 | |
| 68 namespace { | |
| 69 | |
| 70 TEST(UnpackerTest, IntegrationTest) { | |
| 71 // create a temporary directory where the app should go | |
| 72 NSURL* tempURL = [[NSFileManager defaultManager] | |
| 73 URLForDirectory:NSItemReplacementDirectory | |
| 74 inDomain:NSUserDomainMask | |
| 75 appropriateForURL:[NSURL fileURLWithPath:@"/" isDirectory:YES] | |
| 76 create:YES | |
| 77 error:nil]; | |
| 78 NSString* tempAppPath = | |
| 79 [NSString pathWithComponents:@[ [tempURL path], @"Google Chrome.app" ]]; | |
| 80 | |
| 81 // create objects and semaphore | |
| 82 Unpacker* unpack = [[Unpacker alloc] initWithFinalAppPath:tempAppPath]; | |
| 83 TestDelegate* test_delegate = [[TestDelegate alloc] init]; | |
| 84 unpack.delegate = test_delegate; | |
| 85 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.
| |
| 86 | |
| 87 // identify where the disk image is now and start mount/extract step | |
| 88 NSString* downloadDirectory = [NSSearchPathForDirectoriesInDomains( | |
| 89 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.
| |
| 90 NSURL* diskImageOriginalPath = | |
| 91 [NSURL fileURLWithPath:[NSString pathWithComponents:@[ | |
| 92 downloadDirectory, @"GoogleChrome.dmg" | |
| 93 ]] | |
| 94 isDirectory:NO]; | |
| 95 [unpack mountDMGFromURL:diskImageOriginalPath]; | |
| 96 dispatch_semaphore_wait(test_semaphore, DISPATCH_TIME_FOREVER); | |
| 97 | |
| 98 // was this correctly executed? | |
| 99 ASSERT_TRUE([test_delegate pass]); | |
| 100 // is the app file moved to the correct place we expect? | |
| 101 ASSERT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:tempAppPath]); | |
| 102 | |
| 103 // start unmounting step | |
| 104 [unpack unmountDMG]; | |
| 105 dispatch_semaphore_wait(test_semaphore, DISPATCH_TIME_FOREVER); | |
| 106 | |
| 107 // was this correctly executed? | |
| 108 EXPECT_TRUE([test_delegate pass]); | |
| 109 // is the app still there? | |
| 110 EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:tempAppPath]); | |
| 111 | |
| 112 [[NSFileManager defaultManager] removeItemAtURL:tempURL error:nil]; | |
| 113 } | |
| 114 | |
| 115 } // namespace | |
| OLD | NEW |