Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/installer/mac/app/testing/Unpacker_test.mm

Issue 2203583002: Added unpacking step (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added in SecCodeCheckValidity in place of the hdiutil checksum Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "base/base_paths.h"
8 #include "base/files/file_path.h"
9 #include "base/path_service.h"
10 #include "base/strings/sys_string_conversions.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 #import "chrome/installer/mac/app/Downloader.h"
14
15 @interface TestDelegate : NSObject<UnpackDelegate>
16 @property(nonatomic) BOOL pass;
17 @property(nonatomic) dispatch_semaphore_t test_semaphore;
18 - (void)fail;
19 - (void)succeed;
20 - (void)wait;
21 @end
22
23 @implementation TestDelegate
24 @synthesize pass = pass_;
25 @synthesize test_semaphore = test_semaphore_;
26
27 - (id)init {
28 if ((self = [super init])) {
29 test_semaphore_ = dispatch_semaphore_create(0);
30 pass_ = NO;
31 }
32 return self;
33 }
34
35 - (void)succeed {
36 pass_ = YES;
37 dispatch_semaphore_signal(test_semaphore_);
38 }
39 - (void)fail {
40 pass_ = NO;
41 dispatch_semaphore_signal(test_semaphore_);
42 }
43 - (void)wait {
44 dispatch_semaphore_wait(test_semaphore_, DISPATCH_TIME_FOREVER);
45 }
46
47 - (void)unpacker:(Unpacker*)unpacker onMountSuccess:(NSString*)mountpath {
48 if ([[NSFileManager defaultManager]
49 fileExistsAtPath:[NSString pathWithComponents:@[
50 mountpath, @"Google Chrome.app"
51 ]]]) {
52 [self succeed];
53 } else {
54 [self fail];
55 }
56 }
57 - (void)unpacker:(Unpacker*)unpacker onMountFailure:(NSError*)error {
58 [self fail];
59 }
60
61 - (void)unpacker:(Unpacker*)unpacker onUnmountSuccess:(NSString*)mountpath {
62 if (![[NSFileManager defaultManager]
63 fileExistsAtPath:[NSString pathWithComponents:@[
64 mountpath, @"Google Chrome.app"
65 ]]]) {
66 [self succeed];
67 } else {
68 [self fail];
69 }
70 }
71 - (void)unpacker:(Unpacker*)unpacker onUnmountFailure:(NSError*)error {
72 [self fail];
73 }
74
75 @end
76
77 namespace {
78
79 TEST(UnpackerTest, IntegrationTest) {
80 // create objects and semaphore
81 Unpacker* unpack = [[Unpacker alloc] init];
82 TestDelegate* test_delegate = [[TestDelegate alloc] init];
83 unpack.delegate = test_delegate;
84
85 // get a disk image to use to test
86 base::FilePath originalPath;
87 PathService::Get(base::DIR_SOURCE_ROOT, &originalPath);
88 originalPath = originalPath.AppendASCII("chrome/test/data/mac_installer/");
89 base::FilePath copiedPath = base::FilePath(originalPath);
90 NSString* diskImageOriginalPath = base::SysUTF8ToNSString(
91 (originalPath.AppendASCII("test-dmg.dmg")).value());
92 NSString* diskImageCopiedPath = base::SysUTF8ToNSString(
93 (originalPath.AppendASCII("test-dmg2.dmg")).value());
94 [[NSFileManager defaultManager] copyItemAtPath:diskImageOriginalPath
95 toPath:diskImageCopiedPath
96 error:nil];
97 NSURL* dmgURL = [NSURL fileURLWithPath:diskImageCopiedPath isDirectory:NO];
98 // start mount step
99 [unpack mountDMGFromURL:dmgURL];
100 [test_delegate wait];
101
102 // is the disk image mounted?
103 ASSERT_TRUE([test_delegate pass]);
104
105 // start unmount step
106 [unpack unmountDMG];
107 [test_delegate wait];
108
109 // is the disk image gone?
110 EXPECT_TRUE([test_delegate pass]);
111 }
112
113 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698