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

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

Issue 12912003: [mac] Create app shortcuts in a subfolder of /Applications (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fail if dirname of chrome apps dir doesn't exist or isn't a directory. Created 7 years, 9 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
« no previous file with comments | « chrome/browser/web_applications/web_app_mac.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8
9 #include <sys/xattr.h> 9 #include <sys/xattr.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 20 matching lines...) Expand all
31 namespace { 31 namespace {
32 32
33 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { 33 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator {
34 public: 34 public:
35 explicit WebAppShortcutCreatorMock( 35 explicit WebAppShortcutCreatorMock(
36 const ShellIntegration::ShortcutInfo& shortcut_info) 36 const ShellIntegration::ShortcutInfo& shortcut_info)
37 : WebAppShortcutCreator(base::FilePath("/fake/path"), shortcut_info, 37 : WebAppShortcutCreator(base::FilePath("/fake/path"), shortcut_info,
38 UTF8ToUTF16("fake.cfbundleidentifier")) { 38 UTF8ToUTF16("fake.cfbundleidentifier")) {
39 } 39 }
40 40
41 MOCK_CONST_METHOD1(GetDestinationPath, base::FilePath(const base::FilePath&)); 41 MOCK_CONST_METHOD0(GetDestinationPath, base::FilePath());
42 MOCK_CONST_METHOD1(RevealGeneratedBundleInFinder, 42 MOCK_CONST_METHOD1(RevealGeneratedBundleInFinder,
43 void (const base::FilePath&)); 43 void (const base::FilePath&));
44 }; 44 };
45 45
46 ShellIntegration::ShortcutInfo GetShortcutInfo() { 46 ShellIntegration::ShortcutInfo GetShortcutInfo() {
47 ShellIntegration::ShortcutInfo info; 47 ShellIntegration::ShortcutInfo info;
48 info.extension_id = "extension_id"; 48 info.extension_id = "extension_id";
49 info.extension_path = base::FilePath("/fake/extension/path"); 49 info.extension_path = base::FilePath("/fake/extension/path");
50 info.title = ASCIIToUTF16("Shortcut Title"); 50 info.title = ASCIIToUTF16("Shortcut Title");
51 info.url = GURL("http://example.com/"); 51 info.url = GURL("http://example.com/");
52 info.profile_path = base::FilePath("Default"); 52 info.profile_path = base::FilePath("Default");
53 return info; 53 return info;
54 } 54 }
55 55
56 } // namespace 56 } // namespace
57 57
58 namespace web_app { 58 namespace web_app {
59 59
60 TEST(WebAppShortcutCreatorTest, CreateShortcut) { 60 TEST(WebAppShortcutCreatorTest, CreateShortcut) {
61 base::ScopedTempDir scoped_temp_dir; 61 base::ScopedTempDir scoped_temp_dir;
62 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); 62 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
63 63
64 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); 64 ShellIntegration::ShortcutInfo info = GetShortcutInfo();
65 65
66 base::FilePath dst_folder = scoped_temp_dir.path(); 66 base::FilePath dst_folder = scoped_temp_dir.path();
67 base::FilePath dst_path = dst_folder.Append(UTF16ToUTF8(info.title) + ".app"); 67 base::FilePath dst_path = dst_folder.Append(UTF16ToUTF8(info.title) + ".app");
68 68
69 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); 69 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info);
70 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) 70 EXPECT_CALL(shortcut_creator, GetDestinationPath())
71 .WillRepeatedly(Return(dst_folder)); 71 .WillRepeatedly(Return(dst_folder));
72 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); 72 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path));
73 73
74 EXPECT_TRUE(shortcut_creator.CreateShortcut()); 74 EXPECT_TRUE(shortcut_creator.CreateShortcut());
75 EXPECT_TRUE(file_util::PathExists(dst_path)); 75 EXPECT_TRUE(file_util::PathExists(dst_path));
76 76
77 base::FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); 77 base::FilePath plist_path = dst_path.Append("Contents").Append("Info.plist");
78 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: 78 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile:
79 base::mac::FilePathToNSString(plist_path)]; 79 base::mac::FilePathToNSString(plist_path)];
80 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), 80 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id),
(...skipping 17 matching lines...) Expand all
98 TEST(WebAppShortcutCreatorTest, RunShortcut) { 98 TEST(WebAppShortcutCreatorTest, RunShortcut) {
99 base::ScopedTempDir scoped_temp_dir; 99 base::ScopedTempDir scoped_temp_dir;
100 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); 100 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
101 101
102 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); 102 ShellIntegration::ShortcutInfo info = GetShortcutInfo();
103 103
104 base::FilePath dst_folder = scoped_temp_dir.path(); 104 base::FilePath dst_folder = scoped_temp_dir.path();
105 base::FilePath dst_path = dst_folder.Append(UTF16ToUTF8(info.title) + ".app"); 105 base::FilePath dst_path = dst_folder.Append(UTF16ToUTF8(info.title) + ".app");
106 106
107 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); 107 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info);
108 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) 108 EXPECT_CALL(shortcut_creator, GetDestinationPath())
109 .WillRepeatedly(Return(dst_folder)); 109 .WillRepeatedly(Return(dst_folder));
110 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); 110 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path));
111 111
112 EXPECT_TRUE(shortcut_creator.CreateShortcut()); 112 EXPECT_TRUE(shortcut_creator.CreateShortcut());
113 EXPECT_TRUE(file_util::PathExists(dst_path)); 113 EXPECT_TRUE(file_util::PathExists(dst_path));
114 114
115 ssize_t status = getxattr( 115 ssize_t status = getxattr(
116 dst_path.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); 116 dst_path.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0);
117 EXPECT_EQ(-1, status); 117 EXPECT_EQ(-1, status);
118 EXPECT_EQ(ENOATTR, errno); 118 EXPECT_EQ(ENOATTR, errno);
119 } 119 }
120 120
121 TEST(WebAppShortcutCreatorTest, CreateFailure) { 121 TEST(WebAppShortcutCreatorTest, CreateFailure) {
122 base::ScopedTempDir scoped_temp_dir; 122 base::ScopedTempDir scoped_temp_dir;
123 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); 123 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
124 124
125 base::FilePath non_existent_path = 125 base::FilePath non_existent_path =
126 scoped_temp_dir.path().Append("not-existent").Append("name.app"); 126 scoped_temp_dir.path().Append("not-existent").Append("name.app");
127 127
128 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); 128 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo());
129 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) 129 EXPECT_CALL(shortcut_creator, GetDestinationPath())
130 .WillRepeatedly(Return(non_existent_path)); 130 .WillRepeatedly(Return(non_existent_path));
131 EXPECT_FALSE(shortcut_creator.CreateShortcut()); 131 EXPECT_FALSE(shortcut_creator.CreateShortcut());
132 } 132 }
133 133
134 TEST(WebAppShortcutCreatorTest, UpdateIcon) { 134 TEST(WebAppShortcutCreatorTest, UpdateIcon) {
135 base::ScopedTempDir scoped_temp_dir; 135 base::ScopedTempDir scoped_temp_dir;
136 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); 136 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir());
137 base::FilePath dst_path = scoped_temp_dir.path(); 137 base::FilePath dst_path = scoped_temp_dir.path();
138 138
139 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); 139 ShellIntegration::ShortcutInfo info = GetShortcutInfo();
140 info.favicon = ui::ResourceBundle::GetSharedInstance().GetImageNamed( 140 info.favicon = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
141 IDR_PRODUCT_LOGO_32); 141 IDR_PRODUCT_LOGO_32);
142 WebAppShortcutCreatorMock shortcut_creator(info); 142 WebAppShortcutCreatorMock shortcut_creator(info);
143 143
144 shortcut_creator.UpdateIcon(dst_path); 144 shortcut_creator.UpdateIcon(dst_path);
145 base::FilePath icon_path = 145 base::FilePath icon_path =
146 dst_path.Append("Contents").Append("Resources").Append("app.icns"); 146 dst_path.Append("Contents").Append("Resources").Append("app.icns");
147 147
148 scoped_nsobject<NSImage> image([[NSImage alloc] initWithContentsOfFile: 148 scoped_nsobject<NSImage> image([[NSImage alloc] initWithContentsOfFile:
149 base::mac::FilePathToNSString(icon_path)]); 149 base::mac::FilePathToNSString(icon_path)]);
150 EXPECT_TRUE(image); 150 EXPECT_TRUE(image);
151 EXPECT_EQ(info.favicon.ToSkBitmap()->width(), [image size].width); 151 EXPECT_EQ(info.favicon.ToSkBitmap()->width(), [image size].width);
152 EXPECT_EQ(info.favicon.ToSkBitmap()->height(), [image size].height); 152 EXPECT_EQ(info.favicon.ToSkBitmap()->height(), [image size].height);
153 } 153 }
154 154
155 } // namespace web_app 155 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app_mac.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698