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

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"
26 #import "testing/gtest_mac.h" 27 #import "testing/gtest_mac.h"
27 #include "third_party/skia/include/core/SkBitmap.h" 28 #include "third_party/skia/include/core/SkBitmap.h"
28 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/gfx/image/image.h" 30 #include "ui/gfx/image/image.h"
30 31
31 using ::testing::_; 32 using ::testing::_;
32 using ::testing::Return; 33 using ::testing::Return;
33 using ::testing::NiceMock; 34 using ::testing::NiceMock;
34 35
35 namespace { 36 namespace {
36 37
37 const char kFakeChromeBundleId[] = "fake.cfbundleidentifier"; 38 const char kFakeChromeBundleId[] = "fake.cfbundleidentifier";
38 39
39 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { 40 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator {
40 public: 41 public:
41 WebAppShortcutCreatorMock(const base::FilePath& app_data_dir, 42 WebAppShortcutCreatorMock(const base::FilePath& app_data_dir,
42 const web_app::ShortcutInfo& shortcut_info) 43 const web_app::ShortcutInfo* shortcut_info)
43 : WebAppShortcutCreator(app_data_dir, 44 : WebAppShortcutCreator(app_data_dir,
44 shortcut_info, 45 shortcut_info,
45 extensions::FileHandlersInfo()) {} 46 extensions::FileHandlersInfo()) {}
46 47
47 WebAppShortcutCreatorMock( 48 WebAppShortcutCreatorMock(
48 const base::FilePath& app_data_dir, 49 const base::FilePath& app_data_dir,
49 const web_app::ShortcutInfo& shortcut_info, 50 const web_app::ShortcutInfo* shortcut_info,
50 const extensions::FileHandlersInfo& file_handlers_info) 51 const extensions::FileHandlersInfo& file_handlers_info)
51 : WebAppShortcutCreator(app_data_dir, shortcut_info, file_handlers_info) { 52 : WebAppShortcutCreator(app_data_dir, shortcut_info, file_handlers_info) {
52 } 53 }
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_,
116 info_.get());
116 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 117 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
117 .WillRepeatedly(Return(destination_dir_)); 118 .WillRepeatedly(Return(destination_dir_));
118 119
119 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 120 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
120 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 121 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
121 EXPECT_TRUE(base::PathExists(shim_path_)); 122 EXPECT_TRUE(base::PathExists(shim_path_));
122 EXPECT_TRUE(base::PathExists(destination_dir_)); 123 EXPECT_TRUE(base::PathExists(destination_dir_));
123 EXPECT_EQ(shim_base_name_, shortcut_creator.GetShortcutBasename()); 124 EXPECT_EQ(shim_base_name_, shortcut_creator.GetShortcutBasename());
124 125
125 base::FilePath plist_path = 126 base::FilePath plist_path =
126 shim_path_.Append("Contents").Append("Info.plist"); 127 shim_path_.Append("Contents").Append("Info.plist");
127 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: 128 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile:
128 base::mac::FilePathToNSString(plist_path)]; 129 base::mac::FilePathToNSString(plist_path)];
129 EXPECT_NSEQ(base::SysUTF8ToNSString(info_.extension_id), 130 EXPECT_NSEQ(base::SysUTF8ToNSString(info_->extension_id),
130 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); 131 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]);
131 EXPECT_NSEQ(base::SysUTF16ToNSString(info_.title), 132 EXPECT_NSEQ(base::SysUTF16ToNSString(info_->title),
132 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); 133 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]);
133 EXPECT_NSEQ(base::SysUTF8ToNSString(info_.url.spec()), 134 EXPECT_NSEQ(base::SysUTF8ToNSString(info_->url.spec()),
134 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); 135 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]);
135 136
136 EXPECT_NSEQ(base::SysUTF8ToNSString(chrome::VersionInfo().Version()), 137 EXPECT_NSEQ(base::SysUTF8ToNSString(chrome::VersionInfo().Version()),
137 [plist objectForKey:app_mode::kCrBundleVersionKey]); 138 [plist objectForKey:app_mode::kCrBundleVersionKey]);
138 EXPECT_NSEQ(base::SysUTF8ToNSString(info_.version_for_display), 139 EXPECT_NSEQ(base::SysUTF8ToNSString(info_->version_for_display),
139 [plist objectForKey:app_mode::kCFBundleShortVersionStringKey]); 140 [plist objectForKey:app_mode::kCFBundleShortVersionStringKey]);
140 141
141 // Make sure all values in the plist are actually filled in. 142 // Make sure all values in the plist are actually filled in.
142 for (id key in plist) { 143 for (id key in plist) {
143 id value = [plist valueForKey:key]; 144 id value = [plist valueForKey:key];
144 if (!base::mac::ObjCCast<NSString>(value)) 145 if (!base::mac::ObjCCast<NSString>(value))
145 continue; 146 continue;
146 147
147 EXPECT_EQ([value rangeOfString:@"@APP_"].location, NSNotFound) 148 EXPECT_EQ([value rangeOfString:@"@APP_"].location, NSNotFound)
148 << [key UTF8String] << ":" << [value UTF8String]; 149 << [key UTF8String] << ":" << [value UTF8String];
149 } 150 }
150 } 151 }
151 152
152 TEST_F(WebAppShortcutCreatorTest, UpdateShortcuts) { 153 TEST_F(WebAppShortcutCreatorTest, UpdateShortcuts) {
153 base::ScopedTempDir other_folder_temp_dir; 154 base::ScopedTempDir other_folder_temp_dir;
154 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir()); 155 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir());
155 base::FilePath other_folder = other_folder_temp_dir.path(); 156 base::FilePath other_folder = other_folder_temp_dir.path();
156 base::FilePath other_shim_path = other_folder.Append(shim_base_name_); 157 base::FilePath other_shim_path = other_folder.Append(shim_base_name_);
157 158
158 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 159 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_,
160 info_.get());
159 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 161 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
160 .WillRepeatedly(Return(destination_dir_)); 162 .WillRepeatedly(Return(destination_dir_));
161 163
162 std::string expected_bundle_id = kFakeChromeBundleId; 164 std::string expected_bundle_id = kFakeChromeBundleId;
163 expected_bundle_id += ".app.Profile-1-" + info_.extension_id; 165 expected_bundle_id += ".app.Profile-1-" + info_->extension_id;
164 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) 166 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id))
165 .WillOnce(Return(other_shim_path)); 167 .WillOnce(Return(other_shim_path));
166 168
167 EXPECT_TRUE(shortcut_creator.BuildShortcut(other_shim_path)); 169 EXPECT_TRUE(shortcut_creator.BuildShortcut(other_shim_path));
168 170
169 EXPECT_TRUE(base::DeleteFile(other_shim_path.Append("Contents"), true)); 171 EXPECT_TRUE(base::DeleteFile(other_shim_path.Append("Contents"), true));
170 172
171 EXPECT_TRUE(shortcut_creator.UpdateShortcuts()); 173 EXPECT_TRUE(shortcut_creator.UpdateShortcuts());
172 EXPECT_FALSE(base::PathExists(shim_path_)); 174 EXPECT_FALSE(base::PathExists(shim_path_));
173 EXPECT_TRUE(base::PathExists(other_shim_path.Append("Contents"))); 175 EXPECT_TRUE(base::PathExists(other_shim_path.Append("Contents")));
(...skipping 15 matching lines...) Expand all
189 // When using PathService::Override, it calls base::MakeAbsoluteFilePath. 191 // When using PathService::Override, it calls base::MakeAbsoluteFilePath.
190 // On Mac this prepends "/private" to the path, but points to the same 192 // On Mac this prepends "/private" to the path, but points to the same
191 // directory in the file system. 193 // directory in the file system.
192 app_data_dir_ = base::MakeAbsoluteFilePath(app_data_dir_); 194 app_data_dir_ = base::MakeAbsoluteFilePath(app_data_dir_);
193 195
194 base::ScopedTempDir other_folder_temp_dir; 196 base::ScopedTempDir other_folder_temp_dir;
195 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir()); 197 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir());
196 base::FilePath other_folder = other_folder_temp_dir.path(); 198 base::FilePath other_folder = other_folder_temp_dir.path();
197 base::FilePath other_shim_path = other_folder.Append(shim_base_name_); 199 base::FilePath other_shim_path = other_folder.Append(shim_base_name_);
198 200
199 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 201 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_,
202 info_.get());
200 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 203 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
201 .WillRepeatedly(Return(destination_dir_)); 204 .WillRepeatedly(Return(destination_dir_));
202 205
203 std::string expected_bundle_id = kFakeChromeBundleId; 206 std::string expected_bundle_id = kFakeChromeBundleId;
204 expected_bundle_id += ".app.Profile-1-" + info_.extension_id; 207 expected_bundle_id += ".app.Profile-1-" + info_->extension_id;
205 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) 208 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id))
206 .WillOnce(Return(other_shim_path)); 209 .WillOnce(Return(other_shim_path));
207 210
208 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 211 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
209 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 212 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
210 EXPECT_TRUE(base::PathExists(internal_shim_path_)); 213 EXPECT_TRUE(base::PathExists(internal_shim_path_));
211 EXPECT_TRUE(base::PathExists(shim_path_)); 214 EXPECT_TRUE(base::PathExists(shim_path_));
212 215
213 // Create an extra shim in another folder. It should be deleted since its 216 // Create an extra shim in another folder. It should be deleted since its
214 // bundle id matches. 217 // bundle id matches.
(...skipping 14 matching lines...) Expand all
229 EXPECT_TRUE(PathService::Override(chrome::DIR_USER_DATA, app_data_dir_)); 232 EXPECT_TRUE(PathService::Override(chrome::DIR_USER_DATA, app_data_dir_));
230 shortcut_creator.DeleteShortcuts(); 233 shortcut_creator.DeleteShortcuts();
231 EXPECT_FALSE(base::PathExists(internal_shim_path_)); 234 EXPECT_FALSE(base::PathExists(internal_shim_path_));
232 EXPECT_TRUE(base::PathExists(shim_path_)); 235 EXPECT_TRUE(base::PathExists(shim_path_));
233 EXPECT_FALSE(base::PathExists(other_shim_path)); 236 EXPECT_FALSE(base::PathExists(other_shim_path));
234 } 237 }
235 238
236 TEST_F(WebAppShortcutCreatorTest, CreateAppListShortcut) { 239 TEST_F(WebAppShortcutCreatorTest, CreateAppListShortcut) {
237 // With an empty |profile_name|, the shortcut path should not have the profile 240 // 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. 241 // directory prepended to the extension id on the app bundle name.
239 info_.profile_name.clear(); 242 info_->profile_name.clear();
240 base::FilePath dst_path = 243 base::FilePath dst_path =
241 destination_dir_.Append(info_.extension_id + ".app"); 244 destination_dir_.Append(info_->extension_id + ".app");
242 245
243 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(base::FilePath(), info_); 246 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(base::FilePath(),
247 info_.get());
244 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 248 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
245 .WillRepeatedly(Return(destination_dir_)); 249 .WillRepeatedly(Return(destination_dir_));
246 EXPECT_EQ(dst_path.BaseName(), shortcut_creator.GetShortcutBasename()); 250 EXPECT_EQ(dst_path.BaseName(), shortcut_creator.GetShortcutBasename());
247 } 251 }
248 252
249 TEST_F(WebAppShortcutCreatorTest, RunShortcut) { 253 TEST_F(WebAppShortcutCreatorTest, RunShortcut) {
250 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 254 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_,
255 info_.get());
251 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 256 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
252 .WillRepeatedly(Return(destination_dir_)); 257 .WillRepeatedly(Return(destination_dir_));
253 258
254 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 259 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
255 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 260 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
256 EXPECT_TRUE(base::PathExists(shim_path_)); 261 EXPECT_TRUE(base::PathExists(shim_path_));
257 262
258 ssize_t status = getxattr( 263 ssize_t status = getxattr(
259 shim_path_.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); 264 shim_path_.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0);
260 EXPECT_EQ(-1, status); 265 EXPECT_EQ(-1, status);
261 EXPECT_EQ(ENOATTR, errno); 266 EXPECT_EQ(ENOATTR, errno);
262 } 267 }
263 268
264 TEST_F(WebAppShortcutCreatorTest, CreateFailure) { 269 TEST_F(WebAppShortcutCreatorTest, CreateFailure) {
265 base::FilePath non_existent_path = 270 base::FilePath non_existent_path =
266 destination_dir_.Append("not-existent").Append("name.app"); 271 destination_dir_.Append("not-existent").Append("name.app");
267 272
268 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 273 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_,
274 info_.get());
269 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 275 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
270 .WillRepeatedly(Return(non_existent_path)); 276 .WillRepeatedly(Return(non_existent_path));
271 EXPECT_FALSE(shortcut_creator.CreateShortcuts( 277 EXPECT_FALSE(shortcut_creator.CreateShortcuts(
272 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 278 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
273 } 279 }
274 280
275 TEST_F(WebAppShortcutCreatorTest, UpdateIcon) { 281 TEST_F(WebAppShortcutCreatorTest, UpdateIcon) {
276 gfx::Image product_logo = 282 gfx::Image product_logo =
277 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( 283 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
278 IDR_PRODUCT_LOGO_32); 284 IDR_PRODUCT_LOGO_32);
279 info_.favicon.Add(product_logo); 285 info_->favicon.Add(product_logo);
280 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, info_); 286 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, info_.get());
281 287
282 ASSERT_TRUE(shortcut_creator.UpdateIcon(shim_path_)); 288 ASSERT_TRUE(shortcut_creator.UpdateIcon(shim_path_));
283 base::FilePath icon_path = 289 base::FilePath icon_path =
284 shim_path_.Append("Contents").Append("Resources").Append("app.icns"); 290 shim_path_.Append("Contents").Append("Resources").Append("app.icns");
285 291
286 base::scoped_nsobject<NSImage> image([[NSImage alloc] 292 base::scoped_nsobject<NSImage> image([[NSImage alloc]
287 initWithContentsOfFile:base::mac::FilePathToNSString(icon_path)]); 293 initWithContentsOfFile:base::mac::FilePathToNSString(icon_path)]);
288 EXPECT_TRUE(image); 294 EXPECT_TRUE(image);
289 EXPECT_EQ(product_logo.Width(), [image size].width); 295 EXPECT_EQ(product_logo.Width(), [image size].width);
290 EXPECT_EQ(product_logo.Height(), [image size].height); 296 EXPECT_EQ(product_logo.Height(), [image size].height);
291 } 297 }
292 298
293 TEST_F(WebAppShortcutCreatorTest, RevealAppShimInFinder) { 299 TEST_F(WebAppShortcutCreatorTest, RevealAppShimInFinder) {
294 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, info_); 300 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, info_.get());
295 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 301 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
296 .WillRepeatedly(Return(destination_dir_)); 302 .WillRepeatedly(Return(destination_dir_));
297 303
298 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()) 304 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder())
299 .Times(0); 305 .Times(0);
300 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 306 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
301 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 307 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
302 308
303 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()); 309 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder());
304 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 310 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
305 SHORTCUT_CREATION_BY_USER, web_app::ShortcutLocations())); 311 SHORTCUT_CREATION_BY_USER, web_app::ShortcutLocations()));
306 } 312 }
307 313
308 TEST_F(WebAppShortcutCreatorTest, FileHandlers) { 314 TEST_F(WebAppShortcutCreatorTest, FileHandlers) {
309 base::CommandLine::ForCurrentProcess()->AppendSwitch( 315 base::CommandLine::ForCurrentProcess()->AppendSwitch(
310 switches::kEnableAppsFileAssociations); 316 switches::kEnableAppsFileAssociations);
311 extensions::FileHandlersInfo file_handlers_info; 317 extensions::FileHandlersInfo file_handlers_info;
312 extensions::FileHandlerInfo handler_0; 318 extensions::FileHandlerInfo handler_0;
313 handler_0.extensions.insert("ext0"); 319 handler_0.extensions.insert("ext0");
314 handler_0.extensions.insert("ext1"); 320 handler_0.extensions.insert("ext1");
315 handler_0.types.insert("type0"); 321 handler_0.types.insert("type0");
316 handler_0.types.insert("type1"); 322 handler_0.types.insert("type1");
317 file_handlers_info.push_back(handler_0); 323 file_handlers_info.push_back(handler_0);
318 extensions::FileHandlerInfo handler_1; 324 extensions::FileHandlerInfo handler_1;
319 handler_1.extensions.insert("ext2"); 325 handler_1.extensions.insert("ext2");
320 handler_1.types.insert("type2"); 326 handler_1.types.insert("type2");
321 file_handlers_info.push_back(handler_1); 327 file_handlers_info.push_back(handler_1);
322 328
323 NiceMock<WebAppShortcutCreatorMock> shortcut_creator( 329 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(
324 app_data_dir_, info_, file_handlers_info); 330 app_data_dir_, info_.get(), file_handlers_info);
325 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 331 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
326 .WillRepeatedly(Return(destination_dir_)); 332 .WillRepeatedly(Return(destination_dir_));
327 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 333 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
328 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 334 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
329 335
330 base::FilePath plist_path = 336 base::FilePath plist_path =
331 shim_path_.Append("Contents").Append("Info.plist"); 337 shim_path_.Append("Contents").Append("Info.plist");
332 NSDictionary* plist = [NSDictionary 338 NSDictionary* plist = [NSDictionary
333 dictionaryWithContentsOfFile:base::mac::FilePathToNSString(plist_path)]; 339 dictionaryWithContentsOfFile:base::mac::FilePathToNSString(plist_path)];
334 NSArray* file_handlers = 340 NSArray* file_handlers =
(...skipping 16 matching lines...) Expand all
351 [file_handler_1 objectForKey:app_mode::kCFBundleTypeRoleKey]); 357 [file_handler_1 objectForKey:app_mode::kCFBundleTypeRoleKey]);
352 NSArray* file_handler_1_extensions = 358 NSArray* file_handler_1_extensions =
353 [file_handler_1 objectForKey:app_mode::kCFBundleTypeExtensionsKey]; 359 [file_handler_1 objectForKey:app_mode::kCFBundleTypeExtensionsKey];
354 EXPECT_TRUE([file_handler_1_extensions containsObject:@"ext2"]); 360 EXPECT_TRUE([file_handler_1_extensions containsObject:@"ext2"]);
355 NSArray* file_handler_1_types = 361 NSArray* file_handler_1_types =
356 [file_handler_1 objectForKey:app_mode::kCFBundleTypeMIMETypesKey]; 362 [file_handler_1 objectForKey:app_mode::kCFBundleTypeMIMETypesKey];
357 EXPECT_TRUE([file_handler_1_types containsObject:@"type2"]); 363 EXPECT_TRUE([file_handler_1_types containsObject:@"type2"]);
358 } 364 }
359 365
360 } // namespace web_app 366 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app_mac.mm ('k') | chrome/browser/web_applications/web_app_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698