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

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: Missed a comma. Created 6 years, 7 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') | chrome/common/chrome_switches.h » ('j') | 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 #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(const base::FilePath& app_data_dir,
41 const web_app::ShortcutInfo& shortcut_info)
42 : WebAppShortcutCreator(app_data_dir,
43 shortcut_info,
44 extensions::FileHandlersInfo()) {}
45
46 WebAppShortcutCreatorMock(
39 const base::FilePath& app_data_dir, 47 const base::FilePath& app_data_dir,
40 const web_app::ShortcutInfo& shortcut_info) 48 const web_app::ShortcutInfo& shortcut_info,
41 : WebAppShortcutCreator(app_data_dir, 49 const extensions::FileHandlersInfo& file_handlers_info)
42 shortcut_info) { 50 : WebAppShortcutCreator(app_data_dir, shortcut_info, file_handlers_info) {
43 } 51 }
44 52
45 MOCK_CONST_METHOD0(GetApplicationsDirname, base::FilePath()); 53 MOCK_CONST_METHOD0(GetApplicationsDirname, base::FilePath());
46 MOCK_CONST_METHOD1(GetAppBundleById, 54 MOCK_CONST_METHOD1(GetAppBundleById,
47 base::FilePath(const std::string& bundle_id)); 55 base::FilePath(const std::string& bundle_id));
48 MOCK_CONST_METHOD0(RevealAppShimInFinder, void()); 56 MOCK_CONST_METHOD0(RevealAppShimInFinder, void());
49 57
50 private: 58 private:
51 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorMock); 59 DISALLOW_COPY_AND_ASSIGN(WebAppShortcutCreatorMock);
52 }; 60 };
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()) 291 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder())
284 .Times(0); 292 .Times(0);
285 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 293 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
286 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations())); 294 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
287 295
288 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder()); 296 EXPECT_CALL(shortcut_creator, RevealAppShimInFinder());
289 EXPECT_TRUE(shortcut_creator.CreateShortcuts( 297 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
290 SHORTCUT_CREATION_BY_USER, web_app::ShortcutLocations())); 298 SHORTCUT_CREATION_BY_USER, web_app::ShortcutLocations()));
291 } 299 }
292 300
301 TEST_F(WebAppShortcutCreatorTest, FileHandlers) {
302 CommandLine::ForCurrentProcess()->AppendSwitch(
303 switches::kEnableAppsFileAssociations);
304 extensions::FileHandlersInfo file_handlers_info;
305 extensions::FileHandlerInfo handler_0;
306 handler_0.extensions.insert("ext0");
307 handler_0.extensions.insert("ext1");
308 handler_0.types.insert("type0");
309 handler_0.types.insert("type1");
310 file_handlers_info.handlers.push_back(handler_0);
311 extensions::FileHandlerInfo handler_1;
312 handler_1.extensions.insert("ext2");
313 handler_1.types.insert("type2");
314 file_handlers_info.handlers.push_back(handler_1);
315
316 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(
317 app_data_dir_, info_, file_handlers_info);
318 EXPECT_CALL(shortcut_creator, GetApplicationsDirname())
319 .WillRepeatedly(Return(destination_dir_));
320 EXPECT_TRUE(shortcut_creator.CreateShortcuts(
321 SHORTCUT_CREATION_AUTOMATED, web_app::ShortcutLocations()));
322
323 base::FilePath plist_path =
324 shim_path_.Append("Contents").Append("Info.plist");
325 NSDictionary* plist = [NSDictionary
326 dictionaryWithContentsOfFile:base::mac::FilePathToNSString(plist_path)];
327 NSArray* file_handlers =
328 [plist objectForKey:app_mode::kCFBundleDocumentTypesKey];
329
330 NSDictionary* file_handler_0 = [file_handlers objectAtIndex:0];
331 EXPECT_NSEQ(app_mode::kBundleTypeRoleViewer,
332 [file_handler_0 objectForKey:app_mode::kCFBundleTypeRoleKey]);
333 NSArray* file_handler_0_extensions =
334 [file_handler_0 objectForKey:app_mode::kCFBundleTypeExtensionsKey];
335 EXPECT_TRUE([file_handler_0_extensions containsObject:@"ext0"]);
336 EXPECT_TRUE([file_handler_0_extensions containsObject:@"ext1"]);
337 NSArray* file_handler_0_types =
338 [file_handler_0 objectForKey:app_mode::kCFBundleTypeMIMETypesKey];
339 EXPECT_TRUE([file_handler_0_types containsObject:@"type0"]);
340 EXPECT_TRUE([file_handler_0_types containsObject:@"type1"]);
341
342 NSDictionary* file_handler_1 = [file_handlers objectAtIndex:1];
343 EXPECT_NSEQ(app_mode::kBundleTypeRoleViewer,
344 [file_handler_1 objectForKey:app_mode::kCFBundleTypeRoleKey]);
345 NSArray* file_handler_1_extensions =
346 [file_handler_1 objectForKey:app_mode::kCFBundleTypeExtensionsKey];
347 EXPECT_TRUE([file_handler_1_extensions containsObject:@"ext2"]);
348 NSArray* file_handler_1_types =
349 [file_handler_1 objectForKey:app_mode::kCFBundleTypeMIMETypesKey];
350 EXPECT_TRUE([file_handler_1_types containsObject:@"type2"]);
351 }
352
293 } // namespace web_app 353 } // namespace web_app
OLDNEW
« no previous file with comments | « chrome/browser/web_applications/web_app_mac.mm ('k') | chrome/common/chrome_switches.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698