| OLD | NEW |
| 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 <stddef.h> | 9 #include <stddef.h> |
| 10 #include <sys/xattr.h> | 10 #include <sys/xattr.h> |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 class WebAppShortcutCreatorTest : public testing::Test { | 80 class WebAppShortcutCreatorTest : public testing::Test { |
| 81 protected: | 81 protected: |
| 82 WebAppShortcutCreatorTest() {} | 82 WebAppShortcutCreatorTest() {} |
| 83 | 83 |
| 84 void SetUp() override { | 84 void SetUp() override { |
| 85 base::mac::SetBaseBundleID(kFakeChromeBundleId); | 85 base::mac::SetBaseBundleID(kFakeChromeBundleId); |
| 86 | 86 |
| 87 EXPECT_TRUE(temp_app_data_dir_.CreateUniqueTempDir()); | 87 EXPECT_TRUE(temp_app_data_dir_.CreateUniqueTempDir()); |
| 88 EXPECT_TRUE(temp_destination_dir_.CreateUniqueTempDir()); | 88 EXPECT_TRUE(temp_destination_dir_.CreateUniqueTempDir()); |
| 89 app_data_dir_ = temp_app_data_dir_.path(); | 89 app_data_dir_ = temp_app_data_dir_.GetPath(); |
| 90 destination_dir_ = temp_destination_dir_.path(); | 90 destination_dir_ = temp_destination_dir_.GetPath(); |
| 91 | 91 |
| 92 info_ = GetShortcutInfo(); | 92 info_ = GetShortcutInfo(); |
| 93 shim_base_name_ = base::FilePath(info_->profile_path.BaseName().value() + | 93 shim_base_name_ = base::FilePath(info_->profile_path.BaseName().value() + |
| 94 " " + info_->extension_id + ".app"); | 94 " " + info_->extension_id + ".app"); |
| 95 internal_shim_path_ = app_data_dir_.Append(shim_base_name_); | 95 internal_shim_path_ = app_data_dir_.Append(shim_base_name_); |
| 96 shim_path_ = destination_dir_.Append(shim_base_name_); | 96 shim_path_ = destination_dir_.Append(shim_base_name_); |
| 97 } | 97 } |
| 98 | 98 |
| 99 base::ScopedTempDir temp_app_data_dir_; | 99 base::ScopedTempDir temp_app_data_dir_; |
| 100 base::ScopedTempDir temp_destination_dir_; | 100 base::ScopedTempDir temp_destination_dir_; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 151 |
| 152 EXPECT_EQ(static_cast<NSUInteger>(NSNotFound), | 152 EXPECT_EQ(static_cast<NSUInteger>(NSNotFound), |
| 153 [value rangeOfString:@"@APP_"].location) | 153 [value rangeOfString:@"@APP_"].location) |
| 154 << [key UTF8String] << ":" << [value UTF8String]; | 154 << [key UTF8String] << ":" << [value UTF8String]; |
| 155 } | 155 } |
| 156 } | 156 } |
| 157 | 157 |
| 158 TEST_F(WebAppShortcutCreatorTest, UpdateShortcuts) { | 158 TEST_F(WebAppShortcutCreatorTest, UpdateShortcuts) { |
| 159 base::ScopedTempDir other_folder_temp_dir; | 159 base::ScopedTempDir other_folder_temp_dir; |
| 160 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir()); | 160 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir()); |
| 161 base::FilePath other_folder = other_folder_temp_dir.path(); | 161 base::FilePath other_folder = other_folder_temp_dir.GetPath(); |
| 162 base::FilePath other_shim_path = other_folder.Append(shim_base_name_); | 162 base::FilePath other_shim_path = other_folder.Append(shim_base_name_); |
| 163 | 163 |
| 164 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, | 164 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, |
| 165 info_.get()); | 165 info_.get()); |
| 166 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) | 166 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) |
| 167 .WillRepeatedly(Return(destination_dir_)); | 167 .WillRepeatedly(Return(destination_dir_)); |
| 168 | 168 |
| 169 std::string expected_bundle_id = kFakeChromeBundleId; | 169 std::string expected_bundle_id = kFakeChromeBundleId; |
| 170 expected_bundle_id += ".app.Profile-1-" + info_->extension_id; | 170 expected_bundle_id += ".app.Profile-1-" + info_->extension_id; |
| 171 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) | 171 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 188 EXPECT_TRUE(base::DeleteFile(other_shim_path.Append("Contents"), true)); | 188 EXPECT_TRUE(base::DeleteFile(other_shim_path.Append("Contents"), true)); |
| 189 | 189 |
| 190 EXPECT_FALSE(shortcut_creator.UpdateShortcuts()); | 190 EXPECT_FALSE(shortcut_creator.UpdateShortcuts()); |
| 191 EXPECT_FALSE(base::PathExists(shim_path_)); | 191 EXPECT_FALSE(base::PathExists(shim_path_)); |
| 192 EXPECT_FALSE(base::PathExists(other_shim_path.Append("Contents"))); | 192 EXPECT_FALSE(base::PathExists(other_shim_path.Append("Contents"))); |
| 193 } | 193 } |
| 194 | 194 |
| 195 TEST_F(WebAppShortcutCreatorTest, UpdateBookmarkAppShortcut) { | 195 TEST_F(WebAppShortcutCreatorTest, UpdateBookmarkAppShortcut) { |
| 196 base::ScopedTempDir other_folder_temp_dir; | 196 base::ScopedTempDir other_folder_temp_dir; |
| 197 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir()); | 197 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir()); |
| 198 base::FilePath other_folder = other_folder_temp_dir.path(); | 198 base::FilePath other_folder = other_folder_temp_dir.GetPath(); |
| 199 base::FilePath other_shim_path = other_folder.Append(shim_base_name_); | 199 base::FilePath other_shim_path = other_folder.Append(shim_base_name_); |
| 200 info_->from_bookmark = true; | 200 info_->from_bookmark = true; |
| 201 | 201 |
| 202 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, | 202 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, |
| 203 info_.get()); | 203 info_.get()); |
| 204 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) | 204 EXPECT_CALL(shortcut_creator, GetApplicationsDirname()) |
| 205 .WillRepeatedly(Return(destination_dir_)); | 205 .WillRepeatedly(Return(destination_dir_)); |
| 206 | 206 |
| 207 std::string expected_bundle_id = kFakeChromeBundleId; | 207 std::string expected_bundle_id = kFakeChromeBundleId; |
| 208 expected_bundle_id += ".app.Profile-1-" + info_->extension_id; | 208 expected_bundle_id += ".app.Profile-1-" + info_->extension_id; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 221 } | 221 } |
| 222 | 222 |
| 223 TEST_F(WebAppShortcutCreatorTest, DeleteShortcuts) { | 223 TEST_F(WebAppShortcutCreatorTest, DeleteShortcuts) { |
| 224 // When using PathService::Override, it calls base::MakeAbsoluteFilePath. | 224 // When using PathService::Override, it calls base::MakeAbsoluteFilePath. |
| 225 // On Mac this prepends "/private" to the path, but points to the same | 225 // On Mac this prepends "/private" to the path, but points to the same |
| 226 // directory in the file system. | 226 // directory in the file system. |
| 227 app_data_dir_ = base::MakeAbsoluteFilePath(app_data_dir_); | 227 app_data_dir_ = base::MakeAbsoluteFilePath(app_data_dir_); |
| 228 | 228 |
| 229 base::ScopedTempDir other_folder_temp_dir; | 229 base::ScopedTempDir other_folder_temp_dir; |
| 230 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir()); | 230 EXPECT_TRUE(other_folder_temp_dir.CreateUniqueTempDir()); |
| 231 base::FilePath other_folder = other_folder_temp_dir.path(); | 231 base::FilePath other_folder = other_folder_temp_dir.GetPath(); |
| 232 base::FilePath other_shim_path = other_folder.Append(shim_base_name_); | 232 base::FilePath other_shim_path = other_folder.Append(shim_base_name_); |
| 233 | 233 |
| 234 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, | 234 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(app_data_dir_, |
| 235 info_.get()); | 235 info_.get()); |
| 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 std::string expected_bundle_id = kFakeChromeBundleId; | 239 std::string expected_bundle_id = kFakeChromeBundleId; |
| 240 expected_bundle_id += ".app.Profile-1-" + info_->extension_id; | 240 expected_bundle_id += ".app.Profile-1-" + info_->extension_id; |
| 241 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) | 241 EXPECT_CALL(shortcut_creator, GetAppBundleById(expected_bundle_id)) |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 [file_handler_1 objectForKey:app_mode::kCFBundleTypeRoleKey]); | 390 [file_handler_1 objectForKey:app_mode::kCFBundleTypeRoleKey]); |
| 391 NSArray* file_handler_1_extensions = | 391 NSArray* file_handler_1_extensions = |
| 392 [file_handler_1 objectForKey:app_mode::kCFBundleTypeExtensionsKey]; | 392 [file_handler_1 objectForKey:app_mode::kCFBundleTypeExtensionsKey]; |
| 393 EXPECT_TRUE([file_handler_1_extensions containsObject:@"ext2"]); | 393 EXPECT_TRUE([file_handler_1_extensions containsObject:@"ext2"]); |
| 394 NSArray* file_handler_1_types = | 394 NSArray* file_handler_1_types = |
| 395 [file_handler_1 objectForKey:app_mode::kCFBundleTypeMIMETypesKey]; | 395 [file_handler_1 objectForKey:app_mode::kCFBundleTypeMIMETypesKey]; |
| 396 EXPECT_TRUE([file_handler_1_types containsObject:@"type2"]); | 396 EXPECT_TRUE([file_handler_1_types containsObject:@"type2"]); |
| 397 } | 397 } |
| 398 | 398 |
| 399 } // namespace web_app | 399 } // namespace web_app |
| OLD | NEW |