Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: chrome/browser/web_applications/web_app_mac_unittest.mm

Issue 9362001: Unit tests for publishing app shortcuts on Mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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&));
Robert Sesek 2012/02/13 21:47:19 This isn't mocking the right thing. DestinationPat
sail 2012/02/13 23:26:42 Done. Fixed. I didn't run the test after the last
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 .WillRepeatedly(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]);
63
64 // Make sure all values in the plist are actually filled in.
65 for (NSString* value in [plist allValues])
66 EXPECT_FALSE([value hasPrefix:@"@APP_"]);
67 }
68
69 TEST(WebAppShortcutCreatorTest, CreateFailure) {
70 NiceMock<WebAppShortcutCreatorMock> shortcut_creator(GetShortcutInfo());
71 EXPECT_CALL(shortcut_creator, GetDstPath(_))
72 .WillRepeatedly(Return(FilePath("/non-existant/path/")));
73 EXPECT_FALSE(shortcut_creator.CreateShortcut());
74 }
75
76 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698