| 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 | 8 |
| 9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 using ::testing::_; | 23 using ::testing::_; |
| 24 using ::testing::Return; | 24 using ::testing::Return; |
| 25 using ::testing::NiceMock; | 25 using ::testing::NiceMock; |
| 26 | 26 |
| 27 namespace { | 27 namespace { |
| 28 | 28 |
| 29 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { | 29 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { |
| 30 public: | 30 public: |
| 31 explicit WebAppShortcutCreatorMock( | 31 explicit WebAppShortcutCreatorMock( |
| 32 const ShellIntegration::ShortcutInfo& shortcut_info) | 32 const ShellIntegration::ShortcutInfo& shortcut_info) |
| 33 : WebAppShortcutCreator(FilePath(), shortcut_info, | 33 : WebAppShortcutCreator(FilePath("/fake/path"), shortcut_info, |
| 34 UTF8ToUTF16("fake.cfbundleidentifier")) { | 34 UTF8ToUTF16("fake.cfbundleidentifier")) { |
| 35 } | 35 } |
| 36 | 36 |
| 37 MOCK_CONST_METHOD1(GetDestinationPath, FilePath(const FilePath&)); | 37 MOCK_CONST_METHOD1(GetDestinationPath, FilePath(const FilePath&)); |
| 38 MOCK_CONST_METHOD1(RevealGeneratedBundleInFinder, void(const FilePath&)); |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 ShellIntegration::ShortcutInfo GetShortcutInfo() { | 41 ShellIntegration::ShortcutInfo GetShortcutInfo() { |
| 41 ShellIntegration::ShortcutInfo info; | 42 ShellIntegration::ShortcutInfo info; |
| 42 info.extension_id = "extension_id"; | 43 info.extension_id = "extension_id"; |
| 44 info.extension_path = FilePath("/fake/extension/path"); |
| 43 info.title = ASCIIToUTF16("Shortcut Title"); | 45 info.title = ASCIIToUTF16("Shortcut Title"); |
| 44 info.url = GURL("http://example.com/"); | 46 info.url = GURL("http://example.com/"); |
| 45 return info; | 47 return info; |
| 46 } | 48 } |
| 47 | 49 |
| 48 } // namespace | 50 } // namespace |
| 49 | 51 |
| 50 namespace web_app { | 52 namespace web_app { |
| 51 | 53 |
| 52 // This test is disabled for the following reasons: | 54 // This test is disabled for the following reasons: |
| 53 // * The plist still isn't filled in correctly. | 55 // * The plist still isn't filled in correctly. |
| 54 // * WebAppShortcutCreator::CreateShortcut() opens a Finder window which it | 56 // * WebAppShortcutCreator::CreateShortcut() opens a Finder window which it |
| 55 // shouldn't be doing when run from a unit test. | 57 // shouldn't be doing when run from a unit test. |
| 56 TEST(WebAppShortcutCreatorTest, DISABLED_CreateShortcut) { | 58 TEST(WebAppShortcutCreatorTest, CreateShortcut) { |
| 57 ScopedTempDir scoped_temp_dir; | 59 ScopedTempDir scoped_temp_dir; |
| 58 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | 60 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 59 FilePath dst_path = scoped_temp_dir.path().Append("a.app"); | 61 FilePath dst_path = scoped_temp_dir.path().Append("a.app"); |
| 60 | 62 |
| 61 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); | 63 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
| 62 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); | 64 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); |
| 63 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) | 65 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) |
| 64 .WillRepeatedly(Return(dst_path)); | 66 .WillRepeatedly(Return(dst_path)); |
| 67 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); |
| 68 |
| 65 EXPECT_TRUE(shortcut_creator.CreateShortcut()); | 69 EXPECT_TRUE(shortcut_creator.CreateShortcut()); |
| 66 EXPECT_TRUE(file_util::PathExists(dst_path)); | 70 EXPECT_TRUE(file_util::PathExists(dst_path)); |
| 67 | 71 |
| 68 FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); | 72 FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); |
| 69 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: | 73 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: |
| 70 base::mac::FilePathToNSString(plist_path)]; | 74 base::mac::FilePathToNSString(plist_path)]; |
| 71 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), | 75 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), |
| 72 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); | 76 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); |
| 73 EXPECT_NSEQ(base::SysUTF16ToNSString(info.title), | 77 EXPECT_NSEQ(base::SysUTF16ToNSString(info.title), |
| 74 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); | 78 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); |
| 75 EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()), | 79 EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()), |
| 76 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); | 80 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); |
| 77 | 81 |
| 78 // Make sure all values in the plist are actually filled in. | 82 // Make sure all values in the plist are actually filled in. |
| 79 for (id key in plist) { | 83 for (id key in plist) { |
| 80 id value = [plist valueForKey:key]; | 84 id value = [plist valueForKey:key]; |
| 81 if (!base::mac::ObjCCast<NSString>(value)) | 85 if (!base::mac::ObjCCast<NSString>(value)) |
| 82 continue; | 86 continue; |
| 83 | 87 |
| 84 EXPECT_EQ([value rangeOfString:@"@APP_"].location, NSNotFound) | 88 EXPECT_EQ([value rangeOfString:@"@APP_"].location, NSNotFound) |
| 85 << [key UTF8String] << ":" << [value UTF8String]; | 89 << [key UTF8String] << ":" << [value UTF8String]; |
| 86 } | 90 } |
| 87 } | 91 } |
| 88 | 92 |
| 89 TEST(WebAppShortcutCreatorTest, DISABLED_CreateFailure) { | 93 TEST(WebAppShortcutCreatorTest, CreateFailure) { |
| 90 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); | 94 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); |
| 91 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) | 95 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) |
| 92 .WillRepeatedly(Return(FilePath("/non-existant/path/"))); | 96 .WillRepeatedly(Return(FilePath("/non-existant/path/"))); |
| 93 EXPECT_FALSE(shortcut_creator.CreateShortcut()); | 97 EXPECT_FALSE(shortcut_creator.CreateShortcut()); |
| 94 } | 98 } |
| 95 | 99 |
| 96 TEST(WebAppShortcutCreatorTest, UpdateIcon) { | 100 TEST(WebAppShortcutCreatorTest, UpdateIcon) { |
| 97 ScopedTempDir scoped_temp_dir; | 101 ScopedTempDir scoped_temp_dir; |
| 98 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | 102 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 99 FilePath dst_path = scoped_temp_dir.path(); | 103 FilePath dst_path = scoped_temp_dir.path(); |
| 100 | 104 |
| 101 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); | 105 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
| 102 info.favicon = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 106 info.favicon = *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 103 IDR_PRODUCT_LOGO_32).ToSkBitmap(); | 107 IDR_PRODUCT_LOGO_32).ToSkBitmap(); |
| 104 WebAppShortcutCreatorMock shortcut_creator(info); | 108 WebAppShortcutCreatorMock shortcut_creator(info); |
| 105 | 109 |
| 106 shortcut_creator.UpdateIcon(dst_path); | 110 shortcut_creator.UpdateIcon(dst_path); |
| 107 FilePath icon_path = | 111 FilePath icon_path = |
| 108 dst_path.Append("Contents").Append("Resources").Append("app.icns"); | 112 dst_path.Append("Contents").Append("Resources").Append("app.icns"); |
| 109 | 113 |
| 110 scoped_nsobject<NSImage> image([[NSImage alloc] initWithContentsOfFile: | 114 scoped_nsobject<NSImage> image([[NSImage alloc] initWithContentsOfFile: |
| 111 base::mac::FilePathToNSString(icon_path)]); | 115 base::mac::FilePathToNSString(icon_path)]); |
| 112 EXPECT_TRUE(image); | 116 EXPECT_TRUE(image); |
| 113 EXPECT_EQ(info.favicon.width(), [image size].width); | 117 EXPECT_EQ(info.favicon.width(), [image size].width); |
| 114 EXPECT_EQ(info.favicon.height(), [image size].height); | 118 EXPECT_EQ(info.favicon.height(), [image size].height); |
| 115 } | 119 } |
| 116 | 120 |
| 117 } // namespace web_app | 121 } // namespace web_app |
| OLD | NEW |