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

Side by Side Diff: chrome/browser/web_applications/web_app_mac_unittest.mm

Issue 1038573002: Fixed thread-unsafe use of gfx::Image in app shortcut creation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 5 years, 8 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
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/web_applications/web_app_mac.h" 5 #import "chrome/browser/web_applications/web_app_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <sys/xattr.h> 9 #include <sys/xattr.h>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
14 #include "base/mac/foundation_util.h" 14 #include "base/mac/foundation_util.h"
15 #include "base/mac/scoped_nsobject.h" 15 #include "base/mac/scoped_nsobject.h"
16 #include "base/memory/scoped_ptr.h"
16 #include "base/path_service.h" 17 #include "base/path_service.h"
17 #include "base/strings/sys_string_conversions.h" 18 #include "base/strings/sys_string_conversions.h"
18 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
19 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
21 #include "chrome/common/chrome_version_info.h" 22 #include "chrome/common/chrome_version_info.h"
22 #import "chrome/common/mac/app_mode_common.h" 23 #import "chrome/common/mac/app_mode_common.h"
23 #include "grit/theme_resources.h" 24 #include "grit/theme_resources.h"
24 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 27 matching lines...) Expand all
53 54
54 MOCK_CONST_METHOD0(GetApplicationsDirname, base::FilePath()); 55 MOCK_CONST_METHOD0(GetApplicationsDirname, base::FilePath());
55 MOCK_CONST_METHOD1(GetAppBundleById, 56 MOCK_CONST_METHOD1(GetAppBundleById,
56 base::FilePath(const std::string& bundle_id)); 57 base::FilePath(const std::string& bundle_id));
57 MOCK_CONST_METHOD0(RevealAppShimInFinder, void()); 58 MOCK_CONST_METHOD0(RevealAppShimInFinder, void());
58 59
59 private: 60 private:
60 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorMock); 61 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorMock);
61 }; 62 };
62 63
63 web_app::ShortcutInfo GetShortcutInfo() { 64 scoped_ptr<web_app::ShortcutInfo> GetShortcutInfo() {
64 web_app::ShortcutInfo info; 65 scoped_ptr<web_app::ShortcutInfo> info(new web_app::ShortcutInfo);
65 info.extension_id = "extensionid"; 66 info->extension_id = "extensionid";
66 info.extension_path = base::FilePath("/fake/extension/path"); 67 info->extension_path = base::FilePath("/fake/extension/path");
67 info.title = base::ASCIIToUTF16("Shortcut Title"); 68 info->title = base::ASCIIToUTF16("Shortcut Title");
68 info.url = GURL("http://example.com/"); 69 info->url = GURL("http://example.com/");
69 info.profile_path = base::FilePath("user_data_dir").Append("Profile 1"); 70 info->profile_path = base::FilePath("user_data_dir").Append("Profile 1");
70 info.profile_name = "profile name"; 71 info->profile_name = "profile name";
71 info.version_for_display = "stable 1.0"; 72 info->version_for_display = "stable 1.0";
72 return info; 73 return info;
73 } 74 }
74 75
75 class WebAppShortcutCreatorTest : public testing::Test { 76 class WebAppShortcutCreatorTest : public testing::Test {
76 protected: 77 protected:
77 WebAppShortcutCreatorTest() {} 78 WebAppShortcutCreatorTest() {}
78 79
79 void SetUp() override { 80 void SetUp() override {
80 base::mac::SetBaseBundleID(kFakeChromeBundleId); 81 base::mac::SetBaseBundleID(kFakeChromeBundleId);
81 82
82 EXPECT_TRUE(temp_app_data_dir_.CreateUniqueTempDir()); 83 EXPECT_TRUE(temp_app_data_dir_.CreateUniqueTempDir());
83 EXPECT_TRUE(temp_destination_dir_.CreateUniqueTempDir()); 84 EXPECT_TRUE(temp_destination_dir_.CreateUniqueTempDir());
84 app_data_dir_ = temp_app_data_dir_.path(); 85 app_data_dir_ = temp_app_data_dir_.path();
85 destination_dir_ = temp_destination_dir_.path(); 86 destination_dir_ = temp_destination_dir_.path();
86 87
87 info_ = GetShortcutInfo(); 88 info_ = GetShortcutInfo();
88 shim_base_name_ = base::FilePath( 89 shim_base_name_ = base::FilePath(info_->profile_path.BaseName().value() +
89 info_.profile_path.BaseName().value() + 90 " " + info_->extension_id + ".app");
90 " " + info_.extension_id + ".app");
91 internal_shim_path_ = app_data_dir_.Append(shim_base_name_); 91 internal_shim_path_ = app_data_dir_.Append(shim_base_name_);
92 shim_path_ = destination_dir_.Append(shim_base_name_); 92 shim_path_ = destination_dir_.Append(shim_base_name_);
93 } 93 }
94 94
95 base::ScopedTempDir temp_app_data_dir_; 95 base::ScopedTempDir temp_app_data_dir_;
96 base::ScopedTempDir temp_destination_dir_; 96 base::ScopedTempDir temp_destination_dir_;
97 base::FilePath app_data_dir_; 97 base::FilePath app_data_dir_;
98 base::FilePath destination_dir_; 98 base::FilePath destination_dir_;
99 99
100 web_app::ShortcutInfo info_; 100 scoped_ptr<web_app::ShortcutInfo> info_;
101 base::FilePath shim_base_name_; 101 base::FilePath shim_base_name_;
102 base::FilePath internal_shim_path_; 102 base::FilePath internal_shim_path_;
103 base::FilePath shim_path_; 103 base::FilePath shim_path_;
104 104
105 private: 105 private:
106 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorTest); 106 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorTest);
107 }; 107 };
108 108
109 109
110 } // namespace 110 } // namespace
111 111
112 namespace web_app { 112 namespace web_app {
113 113
114 TEST_F(WebAppShortcutCreatorTest, CreateShortcuts) { 114 TEST_F(WebAppShortcutCreatorTest, CreateShortcuts) {
115 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 115 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, *info_);
116 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 116 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
117 .WillRepeatedly(Return(destination_dir_)); 117 .WillRepeatedly(Return(destination_dir_));
118 118
119 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 119 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
120 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 120 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
121 EXPECT_TRUE(base::PathExists(shim_path_)); 121 EXPECT_TRUE(base::PathExists(shim_path_));
122 EXPECT_TRUE(base::PathExists(destination_dir_)); 122 EXPECT_TRUE(base::PathExists(destination_dir_));
123 EXPECT_EQ(shim_base_name_, shortcut_creator.GetShortcutBasename()); 123 EXPECT_EQ(shim_base_name_, shortcut_creator.GetShortcutBasename());
124 124
125 base::FilePath plist_path = 125 base::FilePath plist_path =
126 shim_path_.Append("Contents").Append("Info.plist"); 126 shim_path_.Append("Contents").Append("Info.plist");
127 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: 127 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile:
128 base::mac::FilePathToNSString(plist_path)]; 128 base::mac::FilePathToNSString(plist_path)];
129 EXPECT_NSEQ(base::SysUTF8ToNSString(info_.extension_id), 129 EXPECT_NSEQ(base::SysUTF8ToNSString(info_->extension_id),
130 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); 130 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]);
131 EXPECT_NSEQ(base::SysUTF16ToNSString(info_.title), 131 EXPECT_NSEQ(base::SysUTF16ToNSString(info_->title),
132 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); 132 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]);
133 EXPECT_NSEQ(base::SysUTF8ToNSString(info_.url.spec()), 133 EXPECT_NSEQ(base::SysUTF8ToNSString(info_->url.spec()),
134 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); 134 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]);
135 135
136 EXPECT_NSEQ(base::SysUTF8ToNSString(chrome::VersionInfo().Version()), 136 EXPECT_NSEQ(base::SysUTF8ToNSString(chrome::VersionInfo().Version()),
137 [plist objectForKey:app_mode::kCrBundleVersionKey]); 137 [plist objectForKey:app_mode::kCrBundleVersionKey]);
138 EXPECT_NSEQ(base::SysUTF8ToNSString(info_.version_for_display), 138 EXPECT_NSEQ(base::SysUTF8ToNSString(info_->version_for_display),
139 [plist objectForKey:app_mode::kCFBundleShortVersionStringKey]); 139 [plist objectForKey:app_mode::kCFBundleShortVersionStringKey]);
140 140
141 // Make sure all values in the plist are actually filled in. 141 // Make sure all values in the plist are actually filled in.
142 for (id key in plist) { 142 for (id key in plist) {
143 id value = [plist valueForKey:key]; 143 id value = [plist valueForKey:key];
144 if (!base::mac::ObjCCast<NSString>(value)) 144 if (!base::mac::ObjCCast<NSString>(value))
145 continue; 145 continue;
146 146
147 EXPECT_EQ([value rangeOfString:@"@APP_"].location, NSNotFound) 147 EXPECT_EQ([value rangeOfString:@"@APP_"].location, NSNotFound)
148 << [key UTF8String] << ":" << [value UTF8String]; 148 << [key UTF8String] << ":" << [value UTF8String];
149 } 149 }
150 } 150 }
151 151
152 TEST_F(WebAppShortcutCreatorTest, UpdateShortcuts) { 152 TEST_F(WebAppShortcutCreatorTest, UpdateShortcuts) {
153 base::ScopedTempDir other_folder_temp_dir; 153 base::ScopedTempDir other_folder_temp_dir;
154 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir()); 154 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir());
155 base::FilePath other_folder = other_folder_temp_dir.path(); 155 base::FilePath other_folder = other_folder_temp_dir.path();
156 base::FilePath other_shim_path = other_folder.Append(shim_base_name_); 156 base::FilePath other_shim_path = other_folder.Append(shim_base_name_);
157 157
158 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 158 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, *info_);
159 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 159 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
160 .WillRepeatedly(Return(destination_dir_)); 160 .WillRepeatedly(Return(destination_dir_));
161 161
162 std::string expected_bundle_id = kFakeChromeBundleId; 162 std::string expected_bundle_id = kFakeChromeBundleId;
163 expected_bundle_id += ".app.Profile-1-" + info_.extension_id; 163 expected_bundle_id += ".app.Profile-1-" + info_->extension_id;
164 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) 164 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id))
165 .WillOnce(Return(other_shim_path)); 165 .WillOnce(Return(other_shim_path));
166 166
167 EXPECT_TRUE(shortcut_creator.BuildShortcut(other_shim_path)); 167 EXPECT_TRUE(shortcut_creator.BuildShortcut(other_shim_path));
168 168
169 EXPECT_TRUE(base::DeleteFile(other_shim_path.Append("Contents"), true)); 169 EXPECT_TRUE(base::DeleteFile(other_shim_path.Append("Contents"), true));
170 170
171 EXPECT_TRUE(shortcut_creator.UpdateShortcuts()); 171 EXPECT_TRUE(shortcut_creator.UpdateShortcuts());
172 EXPECT_FALSE(base::PathExists(shim_path_)); 172 EXPECT_FALSE(base::PathExists(shim_path_));
173 EXPECT_TRUE(base::PathExists(other_shim_path.Append("Contents"))); 173 EXPECT_TRUE(base::PathExists(other_shim_path.Append("Contents")));
(...skipping 15 matching lines...) Expand all
189 // When using PathService::Override, it calls base::MakeAbsoluteFilePath. 189 // When using PathService::Override, it calls base::MakeAbsoluteFilePath.
190 // On Mac this prepends "/private" to the path, but points to the same 190 // On Mac this prepends "/private" to the path, but points to the same
191 // directory in the file system. 191 // directory in the file system.
192 app_data_dir_ = base::MakeAbsoluteFilePath(app_data_dir_); 192 app_data_dir_ = base::MakeAbsoluteFilePath(app_data_dir_);
193 193
194 base::ScopedTempDir other_folder_temp_dir; 194 base::ScopedTempDir other_folder_temp_dir;
195 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir()); 195 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir());
196 base::FilePath other_folder = other_folder_temp_dir.path(); 196 base::FilePath other_folder = other_folder_temp_dir.path();
197 base::FilePath other_shim_path = other_folder.Append(shim_base_name_); 197 base::FilePath other_shim_path = other_folder.Append(shim_base_name_);
198 198
199 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 199 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, *info_);
200 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 200 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
201 .WillRepeatedly(Return(destination_dir_)); 201 .WillRepeatedly(Return(destination_dir_));
202 202
203 std::string expected_bundle_id = kFakeChromeBundleId; 203 std::string expected_bundle_id = kFakeChromeBundleId;
204 expected_bundle_id += ".app.Profile-1-" + info_.extension_id; 204 expected_bundle_id += ".app.Profile-1-" + info_->extension_id;
205 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) 205 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id))
206 .WillOnce(Return(other_shim_path)); 206 .WillOnce(Return(other_shim_path));
207 207
208 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 208 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
209 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 209 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
210 EXPECT_TRUE(base::PathExists(internal_shim_path_)); 210 EXPECT_TRUE(base::PathExists(internal_shim_path_));
211 EXPECT_TRUE(base::PathExists(shim_path_)); 211 EXPECT_TRUE(base::PathExists(shim_path_));
212 212
213 // Create an extra shim in another folder. It should be deleted since its 213 // Create an extra shim in another folder. It should be deleted since its
214 // bundle id matches. 214 // bundle id matches.
(...skipping 14 matching lines...) Expand all
229 EXPECT_TRUE(PathService::Override(chrome::DIR_USER_DATA, app_data_dir_)); 229 EXPECT_TRUE(PathService::Override(chrome::DIR_USER_DATA, app_data_dir_));
230 shortcut_creator.DeleteShortcuts(); 230 shortcut_creator.DeleteShortcuts();
231 EXPECT_FALSE(base::PathExists(internal_shim_path_)); 231 EXPECT_FALSE(base::PathExists(internal_shim_path_));
232 EXPECT_TRUE(base::PathExists(shim_path_)); 232 EXPECT_TRUE(base::PathExists(shim_path_));
233 EXPECT_FALSE(base::PathExists(other_shim_path)); 233 EXPECT_FALSE(base::PathExists(other_shim_path));
234 } 234 }
235 235
236 TEST_F(WebAppShortcutCreatorTest, CreateAppListShortcut) { 236 TEST_F(WebAppShortcutCreatorTest, CreateAppListShortcut) {
237 // With an empty |profile_name|, the shortcut path should not have the profile 237 // With an empty |profile_name|, the shortcut path should not have the profile
238 // directory prepended to the extension id on the app bundle name. 238 // directory prepended to the extension id on the app bundle name.
239 info_.profile_name.clear(); 239 info_->profile_name.clear();
240 base::FilePath dst_path = 240 base::FilePath dst_path =
241 destination_dir_.Append(info_.extension_id + ".app"); 241 destination_dir_.Append(info_->extension_id + ".app");
242 242
243 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(base::FilePath(), info_); 243 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(base::FilePath(),
244 *info_);
244 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 245 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
245 .WillRepeatedly(Return(destination_dir_)); 246 .WillRepeatedly(Return(destination_dir_));
246 EXPECT_EQ(dst_path.BaseName(), shortcut_creator.GetShortcutBasename()); 247 EXPECT_EQ(dst_path.BaseName(), shortcut_creator.GetShortcutBasename());
247 } 248 }
248 249
249 TEST_F(WebAppShortcutCreatorTest, RunShortcut) { 250 TEST_F(WebAppShortcutCreatorTest, RunShortcut) {
250 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 251 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, *info_);
251 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 252 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
252 .WillRepeatedly(Return(destination_dir_)); 253 .WillRepeatedly(Return(destination_dir_));
253 254
254 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 255 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
255 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 256 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
256 EXPECT_TRUE(base::PathExists(shim_path_)); 257 EXPECT_TRUE(base::PathExists(shim_path_));
257 258
258 ssize_t status = getxattr( 259 ssize_t status = getxattr(
259 shim_path_.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); 260 shim_path_.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0);
260 EXPECT_EQ(-1, status); 261 EXPECT_EQ(-1, status);
261 EXPECT_EQ(ENOATTR, errno); 262 EXPECT_EQ(ENOATTR, errno);
262 } 263 }
263 264
264 TEST_F(WebAppShortcutCreatorTest, CreateFailure) { 265 TEST_F(WebAppShortcutCreatorTest, CreateFailure) {
265 base::FilePath non_existent_path = 266 base::FilePath non_existent_path =
266 destination_dir_.Append("not-existent").Append("name.app"); 267 destination_dir_.Append("not-existent").Append("name.app");
267 268
268 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 269 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, *info_);
269 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 270 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
270 .WillRepeatedly(Return(non_existent_path)); 271 .WillRepeatedly(Return(non_existent_path));
271 EXPECT_FALSE(shortcut_creator.CreateShortcuts( 272 EXPECT_FALSE(shortcut_creator.CreateShortcuts(
272 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 273 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
273 } 274 }
274 275
275 TEST_F(WebAppShortcutCreatorTest, UpdateIcon) { 276 TEST_F(WebAppShortcutCreatorTest, UpdateIcon) {
276 gfx::Image product_logo = 277 gfx::Image product_logo =
277 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( 278 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
278 IDR_PRODUCT_LOGO_32); 279 IDR_PRODUCT_LOGO_32);
279 info_.favicon.Add(product_logo); 280 info_->favicon.Add(product_logo);
280 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, info_); 281 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, *info_);
281 282
282 ASSERT_TRUE(shortcut_creator.UpdateIcon(shim_path_)); 283 ASSERT_TRUE(shortcut_creator.UpdateIcon(shim_path_));
283 base::FilePath icon_path = 284 base::FilePath icon_path =
284 shim_path_.Append("Contents").Append("Resources").Append("app.icns"); 285 shim_path_.Append("Contents").Append("Resources").Append("app.icns");
285 286
286 base::scoped_nsobject<NSImage> image([[NSImage alloc] 287 base::scoped_nsobject<NSImage> image([[NSImage alloc]
287 initWithContentsOfFile:base::mac::FilePathToNSString(icon_path)]); 288 initWithContentsOfFile:base::mac::FilePathToNSString(icon_path)]);
288 EXPECT_TRUE(image); 289 EXPECT_TRUE(image);
289 EXPECT_EQ(product_logo.Width(), [image size].width); 290 EXPECT_EQ(product_logo.Width(), [image size].width);
290 EXPECT_EQ(product_logo.Height(), [image size].height); 291 EXPECT_EQ(product_logo.Height(), [image size].height);
291 } 292 }
292 293
293 TEST_F(WebAppShortcutCreatorTest, RevealAppShimInFinder) { 294 TEST_F(WebAppShortcutCreatorTest, RevealAppShimInFinder) {
294 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, info_); 295 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, *info_);
295 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 296 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
296 .WillRepeatedly(Return(destination_dir_)); 297 .WillRepeatedly(Return(destination_dir_));
297 298
298 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()) 299 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder())
299 .Times(0); 300 .Times(0);
300 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 301 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
301 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 302 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
302 303
303 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()); 304 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder());
304 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 305 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
305 SHORTCUT_CREATION_BY_USER, web_app::ShortcutLocations())); 306 SHORTCUT_CREATION_BY_USER, web_app::ShortcutLocations()));
306 } 307 }
307 308
308 TEST_F(WebAppShortcutCreatorTest, FileHandlers) { 309 TEST_F(WebAppShortcutCreatorTest, FileHandlers) {
309 base::CommandLine::ForCurrentProcess()->AppendSwitch( 310 base::CommandLine::ForCurrentProcess()->AppendSwitch(
310 switches::kEnableAppsFileAssociations); 311 switches::kEnableAppsFileAssociations);
311 extensions::FileHandlersInfo file_handlers_info; 312 extensions::FileHandlersInfo file_handlers_info;
312 extensions::FileHandlerInfo handler_0; 313 extensions::FileHandlerInfo handler_0;
313 handler_0.extensions.insert("ext0"); 314 handler_0.extensions.insert("ext0");
314 handler_0.extensions.insert("ext1"); 315 handler_0.extensions.insert("ext1");
315 handler_0.types.insert("type0"); 316 handler_0.types.insert("type0");
316 handler_0.types.insert("type1"); 317 handler_0.types.insert("type1");
317 file_handlers_info.push_back(handler_0); 318 file_handlers_info.push_back(handler_0);
318 extensions::FileHandlerInfo handler_1; 319 extensions::FileHandlerInfo handler_1;
319 handler_1.extensions.insert("ext2"); 320 handler_1.extensions.insert("ext2");
320 handler_1.types.insert("type2"); 321 handler_1.types.insert("type2");
321 file_handlers_info.push_back(handler_1); 322 file_handlers_info.push_back(handler_1);
322 323
323 NiceMock<WebAppShortcutCreatorMock> shortcut_creator( 324 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, *info_,
324 app_data_dir_, info_, file_handlers_info); 325 file_handlers_info);
325 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 326 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
326 .WillRepeatedly(Return(destination_dir_)); 327 .WillRepeatedly(Return(destination_dir_));
327 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 328 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
328 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 329 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
329 330
330 base::FilePath plist_path = 331 base::FilePath plist_path =
331 shim_path_.Append("Contents").Append("Info.plist"); 332 shim_path_.Append("Contents").Append("Info.plist");
332 NSDictionary* plist = [NSDictionary 333 NSDictionary* plist = [NSDictionary
333 dictionaryWithContentsOfFile:base::mac::FilePathToNSString(plist_path)]; 334 dictionaryWithContentsOfFile:base::mac::FilePathToNSString(plist_path)];
334 NSArray* file_handlers = 335 NSArray* file_handlers =
(...skipping 16 matching lines...) Expand all
351 [file_handler_1 objectForKey:app_mode::kCFBundleTypeRoleKey]); 352 [file_handler_1 objectForKey:app_mode::kCFBundleTypeRoleKey]);
352 NSArray* file_handler_1_extensions = 353 NSArray* file_handler_1_extensions =
353 [file_handler_1 objectForKey:app_mode::kCFBundleTypeExtensionsKey]; 354 [file_handler_1 objectForKey:app_mode::kCFBundleTypeExtensionsKey];
354 EXPECT_TRUE([file_handler_1_extensions containsObject:@"ext2"]); 355 EXPECT_TRUE([file_handler_1_extensions containsObject:@"ext2"]);
355 NSArray* file_handler_1_types = 356 NSArray* file_handler_1_types =
356 [file_handler_1 objectForKey:app_mode::kCFBundleTypeMIMETypesKey]; 357 [file_handler_1 objectForKey:app_mode::kCFBundleTypeMIMETypesKey];
357 EXPECT_TRUE([file_handler_1_types containsObject:@"type2"]); 358 EXPECT_TRUE([file_handler_1_types containsObject:@"type2"]);
358 } 359 }
359 360
360 } // namespace web_app 361 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698