| 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 #include "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 FilePath& web_app_path, |
| 26 const ShellIntegration::ShortcutInfo& shortcut_info) | 27 const ShellIntegration::ShortcutInfo& shortcut_info) |
| 27 : WebAppShortcutCreator(shortcut_info) { | 28 : WebAppShortcutCreator(web_app_path, shortcut_info) { |
| 28 } | 29 } |
| 29 | 30 |
| 30 MOCK_CONST_METHOD1(GetDstPath, FilePath(const FilePath&)); | 31 MOCK_CONST_METHOD1(GetDstPath, 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 currently fails because the Mac app loader isn't built yet. |
| 42 TEST(WebAppShortcutCreatorTest, FAILS_CreateShortcut) { | 43 TEST(WebAppShortcutCreatorTest, FAILS_CreateShortcut) { |
| 43 ScopedTempDir scoped_temp_dir; | 44 ScopedTempDir scoped_temp_dir; |
| 44 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | 45 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 45 FilePath dst_path = scoped_temp_dir.path().Append("a.app"); | 46 FilePath dst_path = scoped_temp_dir.path().Append("a.app"); |
| 46 | 47 |
| 47 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); | 48 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
| 48 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); | 49 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(FilePath(), info); |
| 49 EXPECT_CALL(shortcut_creator, GetDstPath(_)) | 50 EXPECT_CALL(shortcut_creator, GetDstPath(_)) |
| 50 .WillRepeatedly(Return(dst_path)); | 51 .WillRepeatedly(Return(dst_path)); |
| 51 EXPECT_TRUE(shortcut_creator.CreateShortcut()); | 52 EXPECT_TRUE(shortcut_creator.CreateShortcut()); |
| 52 EXPECT_TRUE(file_util::PathExists(dst_path)); | 53 EXPECT_TRUE(file_util::PathExists(dst_path)); |
| 53 | 54 |
| 54 FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); | 55 FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); |
| 55 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: | 56 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: |
| 56 base::mac::FilePathToNSString(plist_path)]; | 57 base::mac::FilePathToNSString(plist_path)]; |
| 57 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), | 58 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), |
| 58 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); | 59 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); |
| 59 EXPECT_NSEQ(base::SysUTF16ToNSString(info.title), | 60 EXPECT_NSEQ(base::SysUTF16ToNSString(info.title), |
| 60 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); | 61 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); |
| 61 EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()), | 62 EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()), |
| 62 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); | 63 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); |
| 63 | 64 |
| 64 // TODO(sail): Make sure all values in the plist are actually filled in. | 65 // TODO(sail): Make sure all values in the plist are actually filled in. |
| 65 // For example, scan all values and verify that none of them are of the | 66 // For example, scan all values and verify that none of them are of the |
| 66 // for "@APP_*@". | 67 // for "@APP_*@". |
| 67 } | 68 } |
| 68 | 69 |
| 69 TEST(WebAppShortcutCreatorTest, CreateFailure) { | 70 TEST(WebAppShortcutCreatorTest, CreateFailure) { |
| 70 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); | 71 NiceMock<WebAppShortcutCreatorMock> shortcut_creator( |
| 72 FilePath(), GetShortcutInfo()); |
| 71 EXPECT_CALL(shortcut_creator, GetDstPath(_)) | 73 EXPECT_CALL(shortcut_creator, GetDstPath(_)) |
| 72 .WillRepeatedly(Return(FilePath("/non-existant/path/"))); | 74 .WillRepeatedly(Return(FilePath("/non-existant/path/"))); |
| 73 EXPECT_FALSE(shortcut_creator.CreateShortcut()); | 75 EXPECT_FALSE(shortcut_creator.CreateShortcut()); |
| 74 } | 76 } |
| 75 | 77 |
| 76 } // namespace | 78 } // namespace |
| OLD | NEW |