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

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

Issue 64803005: File association for app shims. (Mac) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Redo after refactoring. Put behind flag. Tests. 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
11 #include "base/command_line.h"
11 #include "base/file_util.h" 12 #include "base/file_util.h"
12 #include "base/files/scoped_temp_dir.h" 13 #include "base/files/scoped_temp_dir.h"
13 #include "base/mac/foundation_util.h" 14 #include "base/mac/foundation_util.h"
14 #include "base/mac/scoped_nsobject.h" 15 #include "base/mac/scoped_nsobject.h"
15 #include "base/path_service.h" 16 #include "base/path_service.h"
16 #include "base/strings/sys_string_conversions.h" 17 #include "base/strings/sys_string_conversions.h"
17 #include "base/strings/utf_string_conversions.h" 18 #include "base/strings/utf_string_conversions.h"
18 #include "chrome/common/chrome_paths.h" 19 #include "chrome/common/chrome_paths.h"
20 #include "chrome/common/chrome_switches.h"
19 #import "chrome/common/mac/app_mode_common.h" 21 #import "chrome/common/mac/app_mode_common.h"
20 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
21 #include "testing/gmock/include/gmock/gmock.h" 23 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 #import "testing/gtest_mac.h" 25 #import "testing/gtest_mac.h"
24 #include "third_party/skia/include/core/SkBitmap.h" 26 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/image/image.h" 28 #include "ui/gfx/image/image.h"
27 29
28 using ::testing::_; 30 using ::testing::_;
29 using ::testing::Return; 31 using ::testing::Return;
30 using ::testing::NiceMock; 32 using ::testing::NiceMock;
31 33
32 namespace { 34 namespace {
33 35
34 const char kFakeChromeBundleId[] = "fake.cfbundleidentifier"; 36 const char kFakeChromeBundleId[] = "fake.cfbundleidentifier";
35 37
36 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { 38 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator {
37 public: 39 public:
38 explicit WebAppShortcutCreatorMock( 40 WebAppShortcutCreatorMock(
39 const base::FilePath& app_data_dir, 41 const base::FilePath& app_data_dir,
40 const ShellIntegration::ShortcutInfo& shortcut_info) 42 const ShellIntegration::ShortcutInfo& shortcut_info)
41 : WebAppShortcutCreator(app_data_dir, 43 : WebAppShortcutCreator(app_data_dir,
42 shortcut_info) { 44 shortcut_info,
45 extensions::FileHandlersInfo(NULL)) {
46 }
47
48 WebAppShortcutCreatorMock(
49 const base::FilePath& app_data_dir,
50 const ShellIntegration::ShortcutInfo& shortcut_info,
51 const extensions::FileHandlersInfo& file_handlers_info)
52 : WebAppShortcutCreator(app_data_dir,
53 shortcut_info,
54 file_handlers_info) {
43 } 55 }
44 56
45 MOCK_CONST_METHOD0(GetApplicationsDirname, base::FilePath()); 57 MOCK_CONST_METHOD0(GetApplicationsDirname, base::FilePath());
46 MOCK_CONST_METHOD1(GetAppBundleById, 58 MOCK_CONST_METHOD1(GetAppBundleById,
47 base::FilePath(const std::string& bundle_id)); 59 base::FilePath(const std::string& bundle_id));
48 MOCK_CONST_METHOD0(RevealAppShimInFinder, void()); 60 MOCK_CONST_METHOD0(RevealAppShimInFinder, void());
49 61
50 private: 62 private:
51 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorMock); 63 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorMock);
52 }; 64 };
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()) 295 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder())
284 .Times(0); 296 .Times(0);
285 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 297 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
286 SHORTCUT_CREATION_AUTOMATED, ShellIntegration::ShortcutLocations())); 298 SHORTCUT_CREATION_AUTOMATED, ShellIntegration::ShortcutLocations()));
287 299
288 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()); 300 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder());
289 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 301 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
290 SHORTCUT_CREATION_BY_USER, ShellIntegration::ShortcutLocations())); 302 SHORTCUT_CREATION_BY_USER, ShellIntegration::ShortcutLocations()));
291 } 303 }
292 304
305 TEST_F(WebAppShortcutCreatorTest, FileHandlers) {
306 CommandLine::ForCurrentProcess()->AppendSwitch(
307 switches::kEnableAppsFileAssociations);
308 std::vector<extensions::FileHandlerInfo> handlers;
309 extensions::FileHandlerInfo handler_0;
310 handler_0.extensions.insert("ext0");
311 handler_0.extensions.insert("ext1");
312 handler_0.types.insert("type0");
313 handler_0.types.insert("type1");
314 handlers.push_back(handler_0);
315 extensions::FileHandlerInfo handler_1;
316 handler_1.extensions.insert("ext2");
317 handler_1.types.insert("type2");
318 handlers.push_back(handler_1);
319
320 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(
321 app_data_dir_, info_, extensions::FileHandlersInfo(&handlers));
322 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
323 .WillRepeatedly(Return(destination_dir_));
324 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
325 SHORTCUT_CREATION_AUTOMATED, ShellIntegration::ShortcutLocations()));
326
327 base::FilePath plist_path =
328 shim_path_.Append("Contents").Append("Info.plist");
329 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile:
330 base::mac::FilePathToNSString(plist_path)];
331 NSArray* file_handlers =
332 [plist objectForKey:app_mode::kCFBundleDocumentTypesKey];
333
334 NSDictionary* file_handler_0 = [file_handlers objectAtIndex:0];
335 EXPECT_NSEQ(app_mode::kBundleTypeRoleViewer,
336 [file_handler_0 objectForKey:app_mode::kCFBundleTypeRoleKey]);
337 NSArray* file_handler_0_extensions =
338 [file_handler_0 objectForKey:app_mode::kCFBundleTypeExtensionsKey];
339 EXPECT_TRUE([file_handler_0_extensions containsObject:@"ext0"]);
340 EXPECT_TRUE([file_handler_0_extensions containsObject:@"ext1"]);
341 NSArray* file_handler_0_types =
342 [file_handler_0 objectForKey:app_mode::kCFBundleTypeMIMETypesKey];
343 EXPECT_TRUE([file_handler_0_types containsObject:@"type0"]);
344 EXPECT_TRUE([file_handler_0_types containsObject:@"type1"]);
345
346 NSDictionary* file_handler_1 = [file_handlers objectAtIndex:1];
347 EXPECT_NSEQ(app_mode::kBundleTypeRoleViewer,
348 [file_handler_1 objectForKey:app_mode::kCFBundleTypeRoleKey]);
349 NSArray* file_handler_1_extensions =
350 [file_handler_1 objectForKey:app_mode::kCFBundleTypeExtensionsKey];
351 EXPECT_TRUE([file_handler_1_extensions containsObject:@"ext2"]);
352 NSArray* file_handler_1_types =
353 [file_handler_1 objectForKey:app_mode::kCFBundleTypeMIMETypesKey];
354 EXPECT_TRUE([file_handler_1_types containsObject:@"type2"]);
355 }
356
293 } // namespace web_app 357 } // namespace web_app
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698