Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/web_applications/web_app_mac.h" | |
| 6 | |
| 7 #include "base/file_util.h" | |
| 8 #include "base/mac/foundation_util.h" | |
| 9 #include "base/scoped_temp_dir.h" | |
| 10 #include "base/sys_string_conversions.h" | |
| 11 #include "base/utf_string_conversions.h" | |
| 12 #include "chrome/common/mac/app_mode_common.h" | |
| 13 #include "testing/gmock/include/gmock/gmock.h" | |
| 14 #include "testing/gtest/include/gtest/gtest.h" | |
| 15 #import "testing/gtest_mac.h" | |
| 16 | |
| 17 using ::testing::_; | |
| 18 using ::testing::Return; | |
| 19 using ::testing::NiceMock; | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { | |
| 24 public: | |
| 25 explicit WebAppShortcutCreatorMock( | |
| 26 const ShellIntegration::ShortcutInfo& shortcut_info) | |
| 27 : WebAppShortcutCreator(shortcut_info) { | |
| 28 } | |
| 29 | |
| 30 MOCK_CONST_METHOD1(GetDstPath, FilePath(const FilePath&)); | |
| 31 }; | |
| 32 | |
| 33 ShellIntegration::ShortcutInfo GetShortcutInfo() { | |
| 34 ShellIntegration::ShortcutInfo info; | |
| 35 info.extension_id = "extension_id"; | |
| 36 info.title = ASCIIToUTF16("Shortcut Title"); | |
| 37 info.url = GURL("http://example.com/"); | |
| 38 return info; | |
| 39 } | |
| 40 | |
| 41 // This test currently fails because the Mac app loader isn't built yet. | |
| 42 TEST(WebAppShortcutCreatorTest, FAILS_CreateShortcut) { | |
| 43 ScopedTempDir scoped_temp_dir; | |
| 44 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | |
| 45 FilePath dst_path = scoped_temp_dir.path().Append("a.app"); | |
| 46 | |
| 47 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); | |
| 48 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); | |
| 49 EXPECT_CALL(shortcut_creator, GetDstPath(_)) | |
| 50 .WillOnce(Return(dst_path)); | |
| 51 EXPECT_TRUE(shortcut_creator.CreateShortcut()); | |
| 52 EXPECT_TRUE(file_util::PathExists(dst_path)); | |
| 53 | |
| 54 FilePath plist_path = dst_path.Append("Contents").Append("Info.plist"); | |
| 55 NSDictionary* plist = [NSDictionary dictionaryWithContentsOfFile: | |
| 56 base::mac::FilePathToNSString(plist_path)]; | |
| 57 EXPECT_NSEQ(base::SysUTF8ToNSString(info.extension_id), | |
| 58 [plist objectForKey:app_mode::kCrAppModeShortcutIDKey]); | |
| 59 EXPECT_NSEQ(base::SysUTF16ToNSString(info.title), | |
| 60 [plist objectForKey:app_mode::kCrAppModeShortcutNameKey]); | |
| 61 EXPECT_NSEQ(base::SysUTF8ToNSString(info.url.spec()), | |
| 62 [plist objectForKey:app_mode::kCrAppModeShortcutURLKey]); | |
|
jeremy
2012/02/08 09:14:51
Would be good to test that the function that needs
sail
2012/02/09 23:04:39
I added a TODO for this. Currently there are a cou
| |
| 63 } | |
| 64 | |
| 65 TEST(WebAppShortcutCreatorTest, CreateFailure) { | |
| 66 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); | |
| 67 EXPECT_CALL(shortcut_creator, GetDstPath(_)) | |
| 68 .WillOnce(Return(FilePath("/non-existant/path/"))); | |
| 69 EXPECT_FALSE(shortcut_creator.CreateShortcut()); | |
| 70 } | |
| 71 | |
| 72 } // namespace | |
| OLD | NEW |