OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "apps/app_shim/app_shim_host_mac.h" | 5 #include "apps/app_shim/app_shim_host_mac.h" |
6 | 6 |
7 #include "apps/app_shim/app_shim_messages.h" | 7 #include "apps/app_shim/app_shim_messages.h" |
8 #include "base/memory/scoped_vector.h" | 8 #include "base/memory/scoped_vector.h" |
9 #include "chrome/test/base/testing_profile.h" | 9 #include "chrome/test/base/testing_profile.h" |
10 #include "ipc/ipc_message.h" | 10 #include "ipc/ipc_message.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 return app_id(); | 35 return app_id(); |
36 } | 36 } |
37 | 37 |
38 const Profile* GetProfile() const { | 38 const Profile* GetProfile() const { |
39 return profile(); | 39 return profile(); |
40 } | 40 } |
41 | 41 |
42 protected: | 42 protected: |
43 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir) | 43 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir) |
44 OVERRIDE; | 44 OVERRIDE; |
45 virtual bool LaunchApp(Profile* profile) OVERRIDE; | |
46 virtual bool Send(IPC::Message* message) OVERRIDE; | 45 virtual bool Send(IPC::Message* message) OVERRIDE; |
47 | 46 |
48 private: | 47 private: |
49 Profile* test_profile_; | 48 Profile* test_profile_; |
50 bool fails_profile_; | 49 bool fails_profile_; |
51 bool fails_launch_; | 50 bool fails_launch_; |
52 | 51 |
53 ScopedVector<IPC::Message> sent_messages_; | 52 ScopedVector<IPC::Message> sent_messages_; |
54 | 53 |
55 DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost); | 54 DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost); |
(...skipping 14 matching lines...) Expand all Loading... |
70 bool TestingAppShimHost::Send(IPC::Message* message) { | 69 bool TestingAppShimHost::Send(IPC::Message* message) { |
71 sent_messages_.push_back(message); | 70 sent_messages_.push_back(message); |
72 return true; | 71 return true; |
73 } | 72 } |
74 | 73 |
75 Profile* TestingAppShimHost::FetchProfileForDirectory( | 74 Profile* TestingAppShimHost::FetchProfileForDirectory( |
76 const std::string& profile_dir) { | 75 const std::string& profile_dir) { |
77 return fails_profile_ ? NULL : test_profile_; | 76 return fails_profile_ ? NULL : test_profile_; |
78 } | 77 } |
79 | 78 |
80 bool TestingAppShimHost::LaunchApp(Profile* profile) { | |
81 return !fails_launch_; | |
82 } | |
83 | |
84 class AppShimHostTest : public testing::Test, | 79 class AppShimHostTest : public testing::Test, |
85 public apps::AppShimHandler { | 80 public apps::AppShimHandler { |
86 public: | 81 public: |
87 AppShimHostTest() : launch_count_(0), close_count_(0), focus_count_(0) {} | 82 AppShimHostTest() : launch_count_(0), close_count_(0), focus_count_(0) {} |
88 | 83 |
89 TestingAppShimHost* host() { return host_.get(); } | 84 TestingAppShimHost* host() { return host_.get(); } |
90 TestingProfile* profile() { return profile_.get(); } | 85 TestingProfile* profile() { return profile_.get(); } |
91 | 86 |
92 bool LaunchWasSuccessful() { | 87 bool LaunchWasSuccessful() { |
93 EXPECT_EQ(1u, host()->sent_messages().size()); | 88 EXPECT_EQ(1u, host()->sent_messages().size()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 scoped_ptr<TestingProfile> profile_; | 120 scoped_ptr<TestingProfile> profile_; |
126 | 121 |
127 DISALLOW_COPY_AND_ASSIGN(AppShimHostTest); | 122 DISALLOW_COPY_AND_ASSIGN(AppShimHostTest); |
128 }; | 123 }; |
129 | 124 |
130 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 125 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
131 const char kTestProfileDir[] = "Default"; | 126 const char kTestProfileDir[] = "Default"; |
132 | 127 |
133 } // namespace | 128 } // namespace |
134 | 129 |
135 TEST_F(AppShimHostTest, TestLaunchApp) { | |
136 host()->ReceiveMessage( | |
137 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); | |
138 ASSERT_EQ(kTestAppId, host()->GetAppId()); | |
139 ASSERT_EQ(profile(), host()->GetProfile()); | |
140 ASSERT_TRUE(LaunchWasSuccessful()); | |
141 } | |
142 | |
143 TEST_F(AppShimHostTest, TestLaunchAppWithHandler) { | 130 TEST_F(AppShimHostTest, TestLaunchAppWithHandler) { |
144 apps::AppShimHandler::RegisterHandler(kTestAppId, this); | 131 apps::AppShimHandler::RegisterHandler(kTestAppId, this); |
145 EXPECT_TRUE(host()->ReceiveMessage( | 132 EXPECT_TRUE(host()->ReceiveMessage( |
146 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId))); | 133 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId))); |
147 EXPECT_EQ(kTestAppId, host()->GetAppId()); | 134 EXPECT_EQ(kTestAppId, host()->GetAppId()); |
148 EXPECT_TRUE(LaunchWasSuccessful()); | 135 EXPECT_TRUE(LaunchWasSuccessful()); |
149 EXPECT_EQ(1, launch_count_); | 136 EXPECT_EQ(1, launch_count_); |
150 EXPECT_EQ(0, focus_count_); | 137 EXPECT_EQ(0, focus_count_); |
151 EXPECT_EQ(0, close_count_); | 138 EXPECT_EQ(0, close_count_); |
152 | 139 |
(...skipping 11 matching lines...) Expand all Loading... |
164 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); | 151 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); |
165 ASSERT_FALSE(LaunchWasSuccessful()); | 152 ASSERT_FALSE(LaunchWasSuccessful()); |
166 } | 153 } |
167 | 154 |
168 TEST_F(AppShimHostTest, TestFailLaunch) { | 155 TEST_F(AppShimHostTest, TestFailLaunch) { |
169 host()->set_fails_launch(true); | 156 host()->set_fails_launch(true); |
170 host()->ReceiveMessage( | 157 host()->ReceiveMessage( |
171 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); | 158 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); |
172 ASSERT_FALSE(LaunchWasSuccessful()); | 159 ASSERT_FALSE(LaunchWasSuccessful()); |
173 } | 160 } |
OLD | NEW |