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 13 matching lines...) Expand all Loading... | |
24 } | 24 } |
25 | 25 |
26 void set_fails_profile(bool fails_profile) { | 26 void set_fails_profile(bool fails_profile) { |
27 fails_profile_ = fails_profile; | 27 fails_profile_ = fails_profile; |
28 } | 28 } |
29 | 29 |
30 void set_fails_launch(bool fails_launch) { | 30 void set_fails_launch(bool fails_launch) { |
31 fails_launch_ = fails_launch; | 31 fails_launch_ = fails_launch; |
32 } | 32 } |
33 | 33 |
34 const std::string& GetAppId() const { | |
35 return app_id(); | |
36 } | |
37 | |
38 const Profile* GetProfile() const { | |
39 return profile(); | |
40 } | |
41 | |
42 protected: | 34 protected: |
43 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir) | 35 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir) |
44 OVERRIDE; | 36 OVERRIDE; |
45 virtual bool LaunchApp(Profile* profile) OVERRIDE; | |
46 virtual bool Send(IPC::Message* message) OVERRIDE; | 37 virtual bool Send(IPC::Message* message) OVERRIDE; |
47 | 38 |
48 private: | 39 private: |
49 Profile* test_profile_; | 40 Profile* test_profile_; |
50 bool fails_profile_; | 41 bool fails_profile_; |
51 bool fails_launch_; | 42 bool fails_launch_; |
52 | 43 |
53 ScopedVector<IPC::Message> sent_messages_; | 44 ScopedVector<IPC::Message> sent_messages_; |
54 | 45 |
55 DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost); | 46 DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost); |
(...skipping 14 matching lines...) Expand all Loading... | |
70 bool TestingAppShimHost::Send(IPC::Message* message) { | 61 bool TestingAppShimHost::Send(IPC::Message* message) { |
71 sent_messages_.push_back(message); | 62 sent_messages_.push_back(message); |
72 return true; | 63 return true; |
73 } | 64 } |
74 | 65 |
75 Profile* TestingAppShimHost::FetchProfileForDirectory( | 66 Profile* TestingAppShimHost::FetchProfileForDirectory( |
76 const std::string& profile_dir) { | 67 const std::string& profile_dir) { |
77 return fails_profile_ ? NULL : test_profile_; | 68 return fails_profile_ ? NULL : test_profile_; |
78 } | 69 } |
79 | 70 |
80 bool TestingAppShimHost::LaunchApp(Profile* profile) { | |
81 return !fails_launch_; | |
82 } | |
83 | |
84 class AppShimHostTest : public testing::Test, | 71 class AppShimHostTest : public testing::Test, |
85 public apps::AppShimHandler { | 72 public apps::AppShimHandler { |
86 public: | 73 public: |
87 AppShimHostTest() : launch_count_(0), close_count_(0), focus_count_(0) {} | 74 AppShimHostTest() : launch_count_(0), close_count_(0), focus_count_(0) {} |
88 | 75 |
89 TestingAppShimHost* host() { return host_.get(); } | 76 TestingAppShimHost* host() { return host_.get(); } |
90 TestingProfile* profile() { return profile_.get(); } | 77 TestingProfile* profile() { return profile_.get(); } |
91 | 78 |
92 bool LaunchWasSuccessful() { | 79 bool LaunchWasSuccessful() { |
93 EXPECT_EQ(1u, host()->sent_messages().size()); | 80 EXPECT_EQ(1u, host()->sent_messages().size()); |
(...skipping 16 matching lines...) Expand all Loading... | |
110 | 97 |
111 virtual void OnShimClose(Host* host) OVERRIDE { ++close_count_; } | 98 virtual void OnShimClose(Host* host) OVERRIDE { ++close_count_; } |
112 virtual void OnShimFocus(Host* host) OVERRIDE { ++focus_count_; } | 99 virtual void OnShimFocus(Host* host) OVERRIDE { ++focus_count_; } |
113 | 100 |
114 int launch_count_; | 101 int launch_count_; |
115 int close_count_; | 102 int close_count_; |
116 int focus_count_; | 103 int focus_count_; |
117 | 104 |
118 private: | 105 private: |
119 virtual void SetUp() OVERRIDE { | 106 virtual void SetUp() OVERRIDE { |
107 testing::Test::SetUp(); | |
120 profile_.reset(new TestingProfile); | 108 profile_.reset(new TestingProfile); |
121 host_.reset(new TestingAppShimHost(profile())); | 109 host_.reset(new TestingAppShimHost(profile())); |
122 } | 110 } |
123 | 111 |
124 scoped_ptr<TestingAppShimHost> host_; | 112 scoped_ptr<TestingAppShimHost> host_; |
125 scoped_ptr<TestingProfile> profile_; | 113 scoped_ptr<TestingProfile> profile_; |
126 | 114 |
127 DISALLOW_COPY_AND_ASSIGN(AppShimHostTest); | 115 DISALLOW_COPY_AND_ASSIGN(AppShimHostTest); |
128 }; | 116 }; |
129 | 117 |
130 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 118 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
131 const char kTestProfileDir[] = "Default"; | 119 const char kTestProfileDir[] = "Default"; |
132 | 120 |
133 } // namespace | 121 } // namespace |
134 | 122 |
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) { | 123 TEST_F(AppShimHostTest, TestLaunchAppWithHandler) { |
144 apps::AppShimHandler::RegisterHandler(kTestAppId, this); | 124 apps::AppShimHandler::RegisterHandler(kTestAppId, this); |
145 EXPECT_TRUE(host()->ReceiveMessage( | 125 EXPECT_TRUE(host()->ReceiveMessage( |
146 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId))); | 126 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId))); |
147 EXPECT_EQ(kTestAppId, host()->GetAppId()); | 127 EXPECT_EQ(kTestAppId, |
128 static_cast<apps::AppShimHandler::Host*>(host())->GetAppId()); | |
tapted
2013/05/23 02:29:39
Does implicit_cast work? (defined in src/base/basi
jackhou1
2013/05/23 06:10:19
Done.
| |
148 EXPECT_TRUE(LaunchWasSuccessful()); | 129 EXPECT_TRUE(LaunchWasSuccessful()); |
149 EXPECT_EQ(1, launch_count_); | 130 EXPECT_EQ(1, launch_count_); |
150 EXPECT_EQ(0, focus_count_); | 131 EXPECT_EQ(0, focus_count_); |
151 EXPECT_EQ(0, close_count_); | 132 EXPECT_EQ(0, close_count_); |
152 | 133 |
153 EXPECT_TRUE(host()->ReceiveMessage(new AppShimHostMsg_FocusApp())); | 134 EXPECT_TRUE(host()->ReceiveMessage(new AppShimHostMsg_FocusApp())); |
154 EXPECT_EQ(1, focus_count_); | 135 EXPECT_EQ(1, focus_count_); |
155 | 136 |
156 SimulateDisconnect(); | 137 SimulateDisconnect(); |
157 EXPECT_EQ(1, close_count_); | 138 EXPECT_EQ(1, close_count_); |
158 apps::AppShimHandler::RemoveHandler(kTestAppId); | 139 apps::AppShimHandler::RemoveHandler(kTestAppId); |
159 } | 140 } |
160 | 141 |
161 TEST_F(AppShimHostTest, TestFailProfile) { | 142 TEST_F(AppShimHostTest, TestFailProfile) { |
162 host()->set_fails_profile(true); | 143 host()->set_fails_profile(true); |
163 host()->ReceiveMessage( | 144 host()->ReceiveMessage( |
164 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); | 145 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); |
165 ASSERT_FALSE(LaunchWasSuccessful()); | 146 ASSERT_FALSE(LaunchWasSuccessful()); |
166 } | 147 } |
167 | 148 |
168 TEST_F(AppShimHostTest, TestFailLaunch) { | 149 TEST_F(AppShimHostTest, TestFailLaunch) { |
169 host()->set_fails_launch(true); | 150 host()->set_fails_launch(true); |
170 host()->ReceiveMessage( | 151 host()->ReceiveMessage( |
171 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); | 152 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); |
172 ASSERT_FALSE(LaunchWasSuccessful()); | 153 ASSERT_FALSE(LaunchWasSuccessful()); |
173 } | 154 } |
OLD | NEW |