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

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

Issue 16304005: Create a copy of each app's shim bundle in the app's app_data_path. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 8
9 #include <sys/xattr.h> 9 #include <sys/xattr.h>
10 #include <errno.h> 10 #include <errno.h>
(...skipping 15 matching lines...) Expand all
26 26
27 using ::testing::_; 27 using ::testing::_;
28 using ::testing::Return; 28 using ::testing::Return;
29 using ::testing::NiceMock; 29 using ::testing::NiceMock;
30 30
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 base::FilePath user_data_dir,
tapted 2013/06/11 06:15:12 pass as const-reference?
jackhou1 2013/06/12 06:54:46 Done.
36 const ShellIntegration::ShortcutInfo& shortcut_info) 37 const ShellIntegration::ShortcutInfo& shortcut_info)
37 : WebAppShortcutCreator(base::FilePath("/fake/path"), shortcut_info, 38 : WebAppShortcutCreator(user_data_dir, shortcut_info,
38 UTF8ToUTF16("fake.cfbundleidentifier")) { 39 UTF8ToUTF16("fake.cfbundleidentifier")) {
39 } 40 }
40 41
41 MOCK_CONST_METHOD0(GetDestinationPath, base::FilePath()); 42 MOCK_CONST_METHOD0(GetDestinationPath, base::FilePath());
42 MOCK_CONST_METHOD1(RevealGeneratedBundleInFinder, 43 MOCK_CONST_METHOD1(RevealGeneratedBundleInFinder,
43 void (const base::FilePath&)); 44 void (const base::FilePath&));
44 }; 45 };
45 46
46 ShellIntegration::ShortcutInfo GetShortcutInfo() { 47 ShellIntegration::ShortcutInfo GetShortcutInfo() {
47 ShellIntegration::ShortcutInfo info; 48 ShellIntegration::ShortcutInfo info;
48 info.extension_id = "extension_id"; 49 info.extension_id = "extension_id";
49 info.extension_path = base::FilePath("/fake/extension/path"); 50 info.extension_path = base::FilePath("/fake/extension/path");
50 info.title = ASCIIToUTF16("Shortcut Title"); 51 info.title = ASCIIToUTF16("Shortcut Title");
51 info.url = GURL("http://example.com/"); 52 info.url = GURL("http://example.com/");
52 info.profile_path = base::FilePath("Default"); 53 info.profile_path = base::FilePath("Default");
53 info.profile_name = "profile name"; 54 info.profile_name = "profile name";
54 return info; 55 return info;
55 } 56 }
56 57
57 } // namespace 58 } // namespace
58 59
59 namespace web_app { 60 namespace web_app {
60 61
61 TEST(WebAppShortcutCreatorTest, CreateShortcut) { 62 TEST(WebAppShortcutCreatorTest, CreateShortcut) {
62 base::ScopedTempDir scoped_temp_dir; 63 base::ScopedTempDir temp_user_data_dir;
63 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); 64 EXPECT_TRUE(temp_user_data_dir.CreateUniqueTempDir());
65 base::ScopedTempDir temp_dst_dir;
66 EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir());
64 67
65 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); 68 ShellIntegration::ShortcutInfo info = GetShortcutInfo();
66 69
67 base::FilePath dst_folder = scoped_temp_dir.path(); 70
68 base::FilePath dst_path = dst_folder.Append( 71 base::FilePath app_name(
69 info.profile_path.value() + " " + info.extension_id + ".app"); 72 info.profile_path.value() + " " + info.extension_id + ".app");
73 base::FilePath app_in_user_data_dir_path =
74 temp_user_data_dir.path().Append(app_name);
75 base::FilePath dst_folder = temp_dst_dir.path();
76 base::FilePath dst_path = dst_folder.Append(app_name);
70 77
71 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); 78 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(
79 temp_user_data_dir.path(), info);
72 EXPECT_CALL(shortcut_creator, GetDestinationPath()) 80 EXPECT_CALL(shortcut_creator, GetDestinationPath())
73 .WillRepeatedly(Return(dst_folder)); 81 .WillRepeatedly(Return(dst_folder));
74 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); 82 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path));
75 83
76 EXPECT_TRUE(shortcut_creator.CreateShortcut()); 84 EXPECT_TRUE(shortcut_creator.CreateShortcut());
85 EXPECT_TRUE(file_util::PathExists(app_in_user_data_dir_path));
77 EXPECT_TRUE(file_util::PathExists(dst_path)); 86 EXPECT_TRUE(file_util::PathExists(dst_path));
78 EXPECT_EQ(dst_path.value(), shortcut_creator.GetShortcutPath().value()); 87 EXPECT_EQ(dst_path.value(), shortcut_creator.GetShortcutPath().value());
79 88
80 base::FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); 89 base::FilePath plist_path = dst_path.Append("Contents").Append("Info.plist");
81 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: 90 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile:
82 base::mac::FilePathToNSString(plist_path)]; 91 base::mac::FilePathToNSString(plist_path)];
83 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), 92 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id),
84 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); 93 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]);
85 EXPECT_NSEQ(base::SysUTF16ToNSString(info.title), 94 EXPECT_NSEQ(base::SysUTF16ToNSString(info.title),
86 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); 95 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]);
87 EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()), 96 EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()),
88 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); 97 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]);
89 98
90 // Make sure all values in the plist are actually filled in. 99 // Make sure all values in the plist are actually filled in.
91 for (id key in plist) { 100 for (id key in plist) {
92 id value = [plist valueForKey:key]; 101 id value = [plist valueForKey:key];
93 if (!base::mac::ObjCCast<NSString>(value)) 102 if (!base::mac::ObjCCast<NSString>(value))
94 continue; 103 continue;
95 104
96 EXPECT_EQ([value rangeOfString:@"@APP_"].location, NSNotFound) 105 EXPECT_EQ([value rangeOfString:@"@APP_"].location, NSNotFound)
97 << [key UTF8String] << ":" << [value UTF8String]; 106 << [key UTF8String] << ":" << [value UTF8String];
98 } 107 }
99 } 108 }
100 109
101 TEST(WebAppShortcutCreatorTest, RunShortcut) { 110 TEST(WebAppShortcutCreatorTest, RunShortcut) {
102 base::ScopedTempDir scoped_temp_dir; 111 base::ScopedTempDir temp_user_data_dir;
103 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); 112 EXPECT_TRUE(temp_user_data_dir.CreateUniqueTempDir());
113 base::ScopedTempDir temp_dst_dir;
114 EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir());
104 115
105 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); 116 ShellIntegration::ShortcutInfo info = GetShortcutInfo();
106 117
107 base::FilePath dst_folder = scoped_temp_dir.path(); 118 base::FilePath dst_folder = temp_dst_dir.path();
108 base::FilePath dst_path = dst_folder.Append( 119 base::FilePath dst_path = dst_folder.Append(
109 info.profile_path.value() + " " + info.extension_id + ".app"); 120 info.profile_path.value() + " " + info.extension_id + ".app");
110 121
111 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); 122 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(
123 temp_user_data_dir.path(), info);
112 EXPECT_CALL(shortcut_creator, GetDestinationPath()) 124 EXPECT_CALL(shortcut_creator, GetDestinationPath())
113 .WillRepeatedly(Return(dst_folder)); 125 .WillRepeatedly(Return(dst_folder));
114 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); 126 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path));
115 127
116 EXPECT_TRUE(shortcut_creator.CreateShortcut()); 128 EXPECT_TRUE(shortcut_creator.CreateShortcut());
117 EXPECT_TRUE(file_util::PathExists(dst_path)); 129 EXPECT_TRUE(file_util::PathExists(dst_path));
118 130
119 ssize_t status = getxattr( 131 ssize_t status = getxattr(
120 dst_path.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0); 132 dst_path.value().c_str(), "com.apple.quarantine", NULL, 0, 0, 0);
121 EXPECT_EQ(-1, status); 133 EXPECT_EQ(-1, status);
122 EXPECT_EQ(ENOATTR, errno); 134 EXPECT_EQ(ENOATTR, errno);
123 } 135 }
124 136
125 TEST(WebAppShortcutCreatorTest, CreateFailure) { 137 TEST(WebAppShortcutCreatorTest, CreateFailure) {
126 base::ScopedTempDir scoped_temp_dir; 138 base::ScopedTempDir temp_user_data_dir;
127 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); 139 EXPECT_TRUE(temp_user_data_dir.CreateUniqueTempDir());
140 base::ScopedTempDir temp_dst_dir;
141 EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir());
128 142
129 base::FilePath non_existent_path = 143 base::FilePath non_existent_path =
130 scoped_temp_dir.path().Append("not-existent").Append("name.app"); 144 temp_dst_dir.path().Append("not-existent").Append("name.app");
131 145
132 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); 146 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(
147 temp_user_data_dir.path(), GetShortcutInfo());
133 EXPECT_CALL(shortcut_creator, GetDestinationPath()) 148 EXPECT_CALL(shortcut_creator, GetDestinationPath())
134 .WillRepeatedly(Return(non_existent_path)); 149 .WillRepeatedly(Return(non_existent_path));
135 EXPECT_FALSE(shortcut_creator.CreateShortcut()); 150 EXPECT_FALSE(shortcut_creator.CreateShortcut());
136 } 151 }
137 152
138 TEST(WebAppShortcutCreatorTest, UpdateIcon) { 153 TEST(WebAppShortcutCreatorTest, UpdateIcon) {
139 base::ScopedTempDir scoped_temp_dir; 154 base::ScopedTempDir temp_user_data_dir;
140 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); 155 EXPECT_TRUE(temp_user_data_dir.CreateUniqueTempDir());
141 base::FilePath dst_path = scoped_temp_dir.path(); 156 base::ScopedTempDir temp_dst_dir;
157 EXPECT_TRUE(temp_dst_dir.CreateUniqueTempDir());
158 base::FilePath dst_path = temp_dst_dir.path();
142 159
143 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); 160 ShellIntegration::ShortcutInfo info = GetShortcutInfo();
144 gfx::Image product_logo = 161 gfx::Image product_logo =
145 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( 162 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
146 IDR_PRODUCT_LOGO_32); 163 IDR_PRODUCT_LOGO_32);
147 info.favicon.Add(product_logo); 164 info.favicon.Add(product_logo);
148 WebAppShortcutCreatorMock shortcut_creator(info); 165 WebAppShortcutCreatorMock shortcut_creator(temp_user_data_dir.path(), info);
149 166
150 ASSERT_TRUE(shortcut_creator.UpdateIcon(dst_path)); 167 ASSERT_TRUE(shortcut_creator.UpdateIcon(dst_path));
151 base::FilePath icon_path = 168 base::FilePath icon_path =
152 dst_path.Append("Contents").Append("Resources").Append("app.icns"); 169 dst_path.Append("Contents").Append("Resources").Append("app.icns");
153 170
154 scoped_nsobject<NSImage> image([[NSImage alloc] initWithContentsOfFile: 171 scoped_nsobject<NSImage> image([[NSImage alloc] initWithContentsOfFile:
155 base::mac::FilePathToNSString(icon_path)]); 172 base::mac::FilePathToNSString(icon_path)]);
156 EXPECT_TRUE(image); 173 EXPECT_TRUE(image);
157 EXPECT_EQ(product_logo.Width(), [image size].width); 174 EXPECT_EQ(product_logo.Width(), [image size].width);
158 EXPECT_EQ(product_logo.Height(), [image size].height); 175 EXPECT_EQ(product_logo.Height(), [image size].height);
159 } 176 }
160 177
161 } // namespace web_app 178 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698