| 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 #include "chrome/browser/web_applications/web_app_mac.h" | 5 #import "chrome/browser/web_applications/web_app_mac.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
| 9 #include "base/scoped_temp_dir.h" | 9 #include "base/scoped_temp_dir.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/common/mac/app_mode_common.h" | 12 #include "chrome/common/mac/app_mode_common.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #import "testing/gtest_mac.h" | 15 #import "testing/gtest_mac.h" |
| 16 | 16 |
| 17 using ::testing::_; | 17 using ::testing::_; |
| 18 using ::testing::Return; | 18 using ::testing::Return; |
| 19 using ::testing::NiceMock; | 19 using ::testing::NiceMock; |
| 20 | 20 |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { | 23 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { |
| 24 public: | 24 public: |
| 25 explicit WebAppShortcutCreatorMock( | 25 explicit WebAppShortcutCreatorMock( |
| 26 const ShellIntegration::ShortcutInfo& shortcut_info) | 26 const ShellIntegration::ShortcutInfo& shortcut_info) |
| 27 : WebAppShortcutCreator(shortcut_info) { | 27 : WebAppShortcutCreator(shortcut_info, |
| 28 UTF8ToUTF16("fake.cfbundleidentifier")) { |
| 28 } | 29 } |
| 29 | 30 |
| 30 MOCK_CONST_METHOD1(GetDestinationPath, FilePath(const FilePath&)); | 31 MOCK_CONST_METHOD1(GetDestinationPath, FilePath(const FilePath&)); |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 ShellIntegration::ShortcutInfo GetShortcutInfo() { | 34 ShellIntegration::ShortcutInfo GetShortcutInfo() { |
| 34 ShellIntegration::ShortcutInfo info; | 35 ShellIntegration::ShortcutInfo info; |
| 35 info.extension_id = "extension_id"; | 36 info.extension_id = "extension_id"; |
| 36 info.title = ASCIIToUTF16("Shortcut Title"); | 37 info.title = ASCIIToUTF16("Shortcut Title"); |
| 37 info.url = GURL("http://example.com/"); | 38 info.url = GURL("http://example.com/"); |
| 38 return info; | 39 return info; |
| 39 } | 40 } |
| 40 | 41 |
| 41 // This test currently fails because the Mac app loader isn't built yet. | 42 // This test is disabled for the following reasons: |
| 42 TEST(WebAppShortcutCreatorTest, FAILS_CreateShortcut) { | 43 // * The plist still isn't filled in correctly. |
| 44 // * WebAppShortcutCreator::CreateShortcut() opens a Finder window which it |
| 45 // shouldn't be doing when run from a unit test. |
| 46 TEST(WebAppShortcutCreatorTest, DISABLED_CreateShortcut) { |
| 43 ScopedTempDir scoped_temp_dir; | 47 ScopedTempDir scoped_temp_dir; |
| 44 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | 48 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 45 FilePath dst_path = scoped_temp_dir.path().Append("a.app"); | 49 FilePath dst_path = scoped_temp_dir.path().Append("a.app"); |
| 46 | 50 |
| 47 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); | 51 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
| 48 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); | 52 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); |
| 49 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) | 53 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) |
| 50 .WillRepeatedly(Return(dst_path)); | 54 .WillRepeatedly(Return(dst_path)); |
| 51 EXPECT_TRUE(shortcut_creator.CreateShortcut()); | 55 EXPECT_TRUE(shortcut_creator.CreateShortcut()); |
| 52 EXPECT_TRUE(file_util::PathExists(dst_path)); | 56 EXPECT_TRUE(file_util::PathExists(dst_path)); |
| 53 | 57 |
| 54 FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); | 58 FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); |
| 55 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: | 59 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: |
| 56 base::mac::FilePathToNSString(plist_path)]; | 60 base::mac::FilePathToNSString(plist_path)]; |
| 57 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), | 61 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), |
| 58 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); | 62 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); |
| 59 EXPECT_NSEQ(base::SysUTF16ToNSString(info.title), | 63 EXPECT_NSEQ(base::SysUTF16ToNSString(info.title), |
| 60 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); | 64 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); |
| 61 EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()), | 65 EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()), |
| 62 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); | 66 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); |
| 63 | 67 |
| 64 // Make sure all values in the plist are actually filled in. | 68 // Make sure all values in the plist are actually filled in. |
| 65 for (NSString* value in [plist allValues]) | 69 for (id key in plist) { |
| 66 EXPECT_FALSE([value hasPrefix:@"@APP_"]); | 70 id value = [plist valueForKey:key]; |
| 71 if (!base::mac::ObjCCast<NSString>(value)) |
| 72 continue; |
| 73 |
| 74 EXPECT_EQ([value rangeOfString:@"@APP_"].location, NSNotFound) |
| 75 << [key UTF8String] << ":" << [value UTF8String]; |
| 76 } |
| 67 } | 77 } |
| 68 | 78 |
| 69 TEST(WebAppShortcutCreatorTest, CreateFailure) { | 79 TEST(WebAppShortcutCreatorTest, CreateFailure) { |
| 70 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); | 80 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); |
| 71 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) | 81 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) |
| 72 .WillRepeatedly(Return(FilePath("/non-existant/path/"))); | 82 .WillRepeatedly(Return(FilePath("/non-existant/path/"))); |
| 73 EXPECT_FALSE(shortcut_creator.CreateShortcut()); | 83 EXPECT_FALSE(shortcut_creator.CreateShortcut()); |
| 74 } | 84 } |
| 75 | 85 |
| 76 } // namespace | 86 } // namespace |
| OLD | NEW |