| 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/files/scoped_temp_dir.h" |
| 10 #include "base/mac/foundation_util.h" | 11 #include "base/mac/foundation_util.h" |
| 11 #include "base/memory/scoped_nsobject.h" | 12 #include "base/memory/scoped_nsobject.h" |
| 12 #include "base/scoped_temp_dir.h" | |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/common/mac/app_mode_common.h" | 15 #include "chrome/common/mac/app_mode_common.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "third_party/skia/include/core/SkBitmap.h" | |
| 18 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #import "testing/gtest_mac.h" | 19 #import "testing/gtest_mac.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 22 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 23 | 23 |
| 24 using ::testing::_; | 24 using ::testing::_; |
| 25 using ::testing::Return; | 25 using ::testing::Return; |
| 26 using ::testing::NiceMock; | 26 using ::testing::NiceMock; |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { | 30 class WebAppShortcutCreatorMock : public web_app::WebAppShortcutCreator { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 50 | 50 |
| 51 } // namespace | 51 } // namespace |
| 52 | 52 |
| 53 namespace web_app { | 53 namespace web_app { |
| 54 | 54 |
| 55 // This test is disabled for the following reasons: | 55 // This test is disabled for the following reasons: |
| 56 // * The plist still isn't filled in correctly. | 56 // * The plist still isn't filled in correctly. |
| 57 // * WebAppShortcutCreator::CreateShortcut() opens a Finder window which it | 57 // * WebAppShortcutCreator::CreateShortcut() opens a Finder window which it |
| 58 // shouldn't be doing when run from a unit test. | 58 // shouldn't be doing when run from a unit test. |
| 59 TEST(WebAppShortcutCreatorTest, CreateShortcut) { | 59 TEST(WebAppShortcutCreatorTest, CreateShortcut) { |
| 60 ScopedTempDir scoped_temp_dir; | 60 base::ScopedTempDir scoped_temp_dir; |
| 61 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | 61 EXPECT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 62 FilePath dst_path = scoped_temp_dir.path().Append("a.app"); | 62 FilePath dst_path = scoped_temp_dir.path().Append("a.app"); |
| 63 | 63 |
| 64 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); | 64 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
| 65 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); | 65 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(info); |
| 66 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) | 66 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) |
| 67 .WillRepeatedly(Return(dst_path)); | 67 .WillRepeatedly(Return(dst_path)); |
| 68 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); | 68 EXPECT_CALL(shortcut_creator, RevealGeneratedBundleInFinder(dst_path)); |
| 69 | 69 |
| 70 EXPECT_TRUE(shortcut_creator.CreateShortcut()); | 70 EXPECT_TRUE(shortcut_creator.CreateShortcut()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 92 } | 92 } |
| 93 | 93 |
| 94 TEST(WebAppShortcutCreatorTest, CreateFailure) { | 94 TEST(WebAppShortcutCreatorTest, CreateFailure) { |
| 95 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); | 95 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo()); |
| 96 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) | 96 EXPECT_CALL(shortcut_creator, GetDestinationPath(_)) |
| 97 .WillRepeatedly(Return(FilePath("/non-existant/path/"))); | 97 .WillRepeatedly(Return(FilePath("/non-existant/path/"))); |
| 98 EXPECT_FALSE(shortcut_creator.CreateShortcut()); | 98 EXPECT_FALSE(shortcut_creator.CreateShortcut()); |
| 99 } | 99 } |
| 100 | 100 |
| 101 TEST(WebAppShortcutCreatorTest, UpdateIcon) { | 101 TEST(WebAppShortcutCreatorTest, UpdateIcon) { |
| 102 ScopedTempDir scoped_temp_dir; | 102 base::ScopedTempDir scoped_temp_dir; |
| 103 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); | 103 ASSERT_TRUE(scoped_temp_dir.CreateUniqueTempDir()); |
| 104 FilePath dst_path = scoped_temp_dir.path(); | 104 FilePath dst_path = scoped_temp_dir.path(); |
| 105 | 105 |
| 106 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); | 106 ShellIntegration::ShortcutInfo info = GetShortcutInfo(); |
| 107 info.favicon = ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 107 info.favicon = ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
| 108 IDR_PRODUCT_LOGO_32); | 108 IDR_PRODUCT_LOGO_32); |
| 109 WebAppShortcutCreatorMock shortcut_creator(info); | 109 WebAppShortcutCreatorMock shortcut_creator(info); |
| 110 | 110 |
| 111 shortcut_creator.UpdateIcon(dst_path); | 111 shortcut_creator.UpdateIcon(dst_path); |
| 112 FilePath icon_path = | 112 FilePath icon_path = |
| 113 dst_path.Append("Contents").Append("Resources").Append("app.icns"); | 113 dst_path.Append("Contents").Append("Resources").Append("app.icns"); |
| 114 | 114 |
| 115 scoped_nsobject<NSImage> image([[NSImage alloc] initWithContentsOfFile: | 115 scoped_nsobject<NSImage> image([[NSImage alloc] initWithContentsOfFile: |
| 116 base::mac::FilePathToNSString(icon_path)]); | 116 base::mac::FilePathToNSString(icon_path)]); |
| 117 EXPECT_TRUE(image); | 117 EXPECT_TRUE(image); |
| 118 EXPECT_EQ(info.favicon.ToSkBitmap()->width(), [image size].width); | 118 EXPECT_EQ(info.favicon.ToSkBitmap()->width(), [image size].width); |
| 119 EXPECT_EQ(info.favicon.ToSkBitmap()->height(), [image size].height); | 119 EXPECT_EQ(info.favicon.ToSkBitmap()->height(), [image size].height); |
| 120 } | 120 } |
| 121 | 121 |
| 122 } // namespace web_app | 122 } // namespace web_app |
| OLD | NEW |