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

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

Issue 231673005: Move ShortcutInfo, ShortcutLocations from ShellIntegration to web_app. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 6 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 | Annotate | Revision Log
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
(...skipping 19 matching lines...) Expand all
30 using ::testing::NiceMock; 30 using ::testing::NiceMock;
31 31
32 namespace { 32 namespace {
33 33
34 const char kFakeChromeBundleId[] = "fake.cfbundleidentifier"; 34 const char kFakeChromeBundleId[] = "fake.cfbundleidentifier";
35 35
36 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { 36 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator {
37 public: 37 public:
38 explicit WebAppShortcutCreatorMock( 38 explicit WebAppShortcutCreatorMock(
39 const base::FilePath& app_data_dir, 39 const base::FilePath& app_data_dir,
40 const ShellIntegration::ShortcutInfo& shortcut_info) 40 const web_app::ShortcutInfo& shortcut_info)
41 : WebAppShortcutCreator(app_data_dir, 41 : WebAppShortcutCreator(app_data_dir,
42 shortcut_info) { 42 shortcut_info) {
43 } 43 }
44 44
45 MOCK_CONST_METHOD0(GetApplicationsDirname, base::FilePath()); 45 MOCK_CONST_METHOD0(GetApplicationsDirname, base::FilePath());
46 MOCK_CONST_METHOD1(GetAppBundleById, 46 MOCK_CONST_METHOD1(GetAppBundleById,
47 base::FilePath(const std::string& bundle_id)); 47 base::FilePath(const std::string& bundle_id));
48 MOCK_CONST_METHOD0(RevealAppShimInFinder, void()); 48 MOCK_CONST_METHOD0(RevealAppShimInFinder, void());
49 49
50 private: 50 private:
51 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorMock); 51 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorMock);
52 }; 52 };
53 53
54 ShellIntegration::ShortcutInfo GetShortcutInfo() { 54 web_app::ShortcutInfo GetShortcutInfo() {
55 ShellIntegration::ShortcutInfo info; 55 web_app::ShortcutInfo info;
56 info.extension_id = "extensionid"; 56 info.extension_id = "extensionid";
57 info.extension_path = base::FilePath("/fake/extension/path"); 57 info.extension_path = base::FilePath("/fake/extension/path");
58 info.title = base::ASCIIToUTF16("Shortcut Title"); 58 info.title = base::ASCIIToUTF16("Shortcut Title");
59 info.url = GURL("http://example.com/"); 59 info.url = GURL("http://example.com/");
60 info.profile_path = base::FilePath("user_data_dir").Append("Profile 1"); 60 info.profile_path = base::FilePath("user_data_dir").Append("Profile 1");
61 info.profile_name = "profile name"; 61 info.profile_name = "profile name";
62 return info; 62 return info;
63 } 63 }
64 64
65 class WebAppShortcutCreatorTest : public testing::Test { 65 class WebAppShortcutCreatorTest : public testing::Test {
(...skipping 14 matching lines...) Expand all
80 " " + info_.extension_id + ".app"); 80 " " + info_.extension_id + ".app");
81 internal_shim_path_ = app_data_dir_.Append(shim_base_name_); 81 internal_shim_path_ = app_data_dir_.Append(shim_base_name_);
82 shim_path_ = destination_dir_.Append(shim_base_name_); 82 shim_path_ = destination_dir_.Append(shim_base_name_);
83 } 83 }
84 84
85 base::ScopedTempDir temp_app_data_dir_; 85 base::ScopedTempDir temp_app_data_dir_;
86 base::ScopedTempDir temp_destination_dir_; 86 base::ScopedTempDir temp_destination_dir_;
87 base::FilePath app_data_dir_; 87 base::FilePath app_data_dir_;
88 base::FilePath destination_dir_; 88 base::FilePath destination_dir_;
89 89
90 ShellIntegration::ShortcutInfo info_; 90 web_app::ShortcutInfo info_;
91 base::FilePath shim_base_name_; 91 base::FilePath shim_base_name_;
92 base::FilePath internal_shim_path_; 92 base::FilePath internal_shim_path_;
93 base::FilePath shim_path_; 93 base::FilePath shim_path_;
94 94
95 private: 95 private:
96 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorTest); 96 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorTest);
97 }; 97 };
98 98
99 99
100 } // namespace 100 } // namespace
101 101
102 namespace web_app { 102 namespace web_app {
103 103
104 TEST_F(WebAppShortcutCreatorTest, CreateShortcuts) { 104 TEST_F(WebAppShortcutCreatorTest, CreateShortcuts) {
105 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 105 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_);
106 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 106 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
107 .WillRepeatedly(Return(destination_dir_)); 107 .WillRepeatedly(Return(destination_dir_));
108 108
109 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 109 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
110 SHORTCUT_CREATION_AUTOMATED, ShellIntegration::ShortcutLocations())); 110 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
111 EXPECT_TRUE(base::PathExists(shim_path_)); 111 EXPECT_TRUE(base::PathExists(shim_path_));
112 EXPECT_TRUE(base::PathExists(destination_dir_)); 112 EXPECT_TRUE(base::PathExists(destination_dir_));
113 EXPECT_EQ(shim_base_name_, shortcut_creator.GetShortcutBasename()); 113 EXPECT_EQ(shim_base_name_, shortcut_creator.GetShortcutBasename());
114 114
115 base::FilePath plist_path = 115 base::FilePath plist_path =
116 shim_path_.Append("Contents").Append("Info.plist"); 116 shim_path_.Append("Contents").Append("Info.plist");
117 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: 117 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile:
118 base::mac::FilePathToNSString(plist_path)]; 118 base::mac::FilePathToNSString(plist_path)];
119 EXPECT_NSEQ(base::SysUTF8ToNSString(info_.extension_id), 119 EXPECT_NSEQ(base::SysUTF8ToNSString(info_.extension_id),
120 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); 120 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 184 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_);
185 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 185 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
186 .WillRepeatedly(Return(destination_dir_)); 186 .WillRepeatedly(Return(destination_dir_));
187 187
188 std::string expected_bundle_id = kFakeChromeBundleId; 188 std::string expected_bundle_id = kFakeChromeBundleId;
189 expected_bundle_id += ".app.Profile-1-" + info_.extension_id; 189 expected_bundle_id += ".app.Profile-1-" + info_.extension_id;
190 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) 190 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id))
191 .WillOnce(Return(other_shim_path)); 191 .WillOnce(Return(other_shim_path));
192 192
193 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 193 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
194 SHORTCUT_CREATION_AUTOMATED, ShellIntegration::ShortcutLocations())); 194 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
195 EXPECT_TRUE(base::PathExists(internal_shim_path_)); 195 EXPECT_TRUE(base::PathExists(internal_shim_path_));
196 EXPECT_TRUE(base::PathExists(shim_path_)); 196 EXPECT_TRUE(base::PathExists(shim_path_));
197 197
198 // Create an extra shim in another folder. It should be deleted since its 198 // Create an extra shim in another folder. It should be deleted since its
199 // bundle id matches. 199 // bundle id matches.
200 EXPECT_TRUE(shortcut_creator.BuildShortcut(other_shim_path)); 200 EXPECT_TRUE(shortcut_creator.BuildShortcut(other_shim_path));
201 EXPECT_TRUE(base::PathExists(other_shim_path)); 201 EXPECT_TRUE(base::PathExists(other_shim_path));
202 202
203 // Change the user_data_dir of the shim at shim_path_. It should not be 203 // Change the user_data_dir of the shim at shim_path_. It should not be
204 // deleted since its user_data_dir does not match. 204 // deleted since its user_data_dir does not match.
(...skipping 25 matching lines...) Expand all
230 .WillRepeatedly(Return(destination_dir_)); 230 .WillRepeatedly(Return(destination_dir_));
231 EXPECT_EQ(dst_path.BaseName(), shortcut_creator.GetShortcutBasename()); 231 EXPECT_EQ(dst_path.BaseName(), shortcut_creator.GetShortcutBasename());
232 } 232 }
233 233
234 TEST_F(WebAppShortcutCreatorTest, RunShortcut) { 234 TEST_F(WebAppShortcutCreatorTest, RunShortcut) {
235 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 235 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_);
236 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 236 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
237 .WillRepeatedly(Return(destination_dir_)); 237 .WillRepeatedly(Return(destination_dir_));
238 238
239 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 239 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
240 SHORTCUT_CREATION_AUTOMATED, ShellIntegration::ShortcutLocations())); 240 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
241 EXPECT_TRUE(base::PathExists(shim_path_)); 241 EXPECT_TRUE(base::PathExists(shim_path_));
242 242
243 ssize_t status = getxattr( 243 ssize_t status = getxattr(
244 shim_path_.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); 244 shim_path_.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0);
245 EXPECT_EQ(-1, status); 245 EXPECT_EQ(-1, status);
246 EXPECT_EQ(ENOATTR, errno); 246 EXPECT_EQ(ENOATTR, errno);
247 } 247 }
248 248
249 TEST_F(WebAppShortcutCreatorTest, CreateFailure) { 249 TEST_F(WebAppShortcutCreatorTest, CreateFailure) {
250 base::FilePath non_existent_path = 250 base::FilePath non_existent_path =
251 destination_dir_.Append("not-existent").Append("name.app"); 251 destination_dir_.Append("not-existent").Append("name.app");
252 252
253 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_); 253 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, info_);
254 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 254 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
255 .WillRepeatedly(Return(non_existent_path)); 255 .WillRepeatedly(Return(non_existent_path));
256 EXPECT_FALSE(shortcut_creator.CreateShortcuts( 256 EXPECT_FALSE(shortcut_creator.CreateShortcuts(
257 SHORTCUT_CREATION_AUTOMATED, ShellIntegration::ShortcutLocations())); 257 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
258 } 258 }
259 259
260 TEST_F(WebAppShortcutCreatorTest, UpdateIcon) { 260 TEST_F(WebAppShortcutCreatorTest, UpdateIcon) {
261 gfx::Image product_logo = 261 gfx::Image product_logo =
262 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( 262 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
263 IDR_PRODUCT_LOGO_32); 263 IDR_PRODUCT_LOGO_32);
264 info_.favicon.Add(product_logo); 264 info_.favicon.Add(product_logo);
265 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, info_); 265 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, info_);
266 266
267 ASSERT_TRUE(shortcut_creator.UpdateIcon(shim_path_)); 267 ASSERT_TRUE(shortcut_creator.UpdateIcon(shim_path_));
268 base::FilePath icon_path = 268 base::FilePath icon_path =
269 shim_path_.Append("Contents").Append("Resources").Append("app.icns"); 269 shim_path_.Append("Contents").Append("Resources").Append("app.icns");
270 270
271 base::scoped_nsobject<NSImage> image([[NSImage alloc] 271 base::scoped_nsobject<NSImage> image([[NSImage alloc]
272 initWithContentsOfFile:base::mac::FilePathToNSString(icon_path)]); 272 initWithContentsOfFile:base::mac::FilePathToNSString(icon_path)]);
273 EXPECT_TRUE(image); 273 EXPECT_TRUE(image);
274 EXPECT_EQ(product_logo.Width(), [image size].width); 274 EXPECT_EQ(product_logo.Width(), [image size].width);
275 EXPECT_EQ(product_logo.Height(), [image size].height); 275 EXPECT_EQ(product_logo.Height(), [image size].height);
276 } 276 }
277 277
278 TEST_F(WebAppShortcutCreatorTest, RevealAppShimInFinder) { 278 TEST_F(WebAppShortcutCreatorTest, RevealAppShimInFinder) {
279 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, info_); 279 WebAppShortcutCreatorMock shortcut_creator(app_data_dir_, info_);
280 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) 280 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
281 .WillRepeatedly(Return(destination_dir_)); 281 .WillRepeatedly(Return(destination_dir_));
282 282
283 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()) 283 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder())
284 .Times(0); 284 .Times(0);
285 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 285 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
286 SHORTCUT_CREATION_AUTOMATED, ShellIntegration::ShortcutLocations())); 286 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
287 287
288 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()); 288 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder());
289 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 289 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
290 SHORTCUT_CREATION_BY_USER, ShellIntegration::ShortcutLocations())); 290 SHORTCUT_CREATION_BY_USER, web_app::ShortcutLocations()));
291 } 291 }
292 292
293 } // namespace web_app 293 } // 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