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

Side by Side Diff: apps/app_shim/app_shim_host_mac_unittest.cc

Issue 15269003: Refactor extension handling code from AppShimHost into ExtensionAppShimHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and rebase Created 7 years, 6 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
« no previous file with comments | « apps/app_shim/app_shim_host_mac.cc ('k') | apps/app_shim/app_shim_host_manager_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/basictypes.h"
8 #include "base/memory/scoped_vector.h" 9 #include "base/memory/scoped_vector.h"
9 #include "chrome/test/base/testing_profile.h" 10 #include "chrome/test/base/testing_profile.h"
10 #include "ipc/ipc_message.h" 11 #include "ipc/ipc_message.h"
11 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
12 13
13 namespace { 14 namespace {
14 15
15 class TestingAppShimHost : public AppShimHost { 16 class TestingAppShimHost : public AppShimHost {
16 public: 17 public:
17 explicit TestingAppShimHost(Profile* profile); 18 explicit TestingAppShimHost(Profile* profile);
18 virtual ~TestingAppShimHost() {} 19 virtual ~TestingAppShimHost() {}
19 20
20 bool ReceiveMessage(IPC::Message* message); 21 bool ReceiveMessage(IPC::Message* message);
21 22
22 const std::vector<IPC::Message*>& sent_messages() { 23 const std::vector<IPC::Message*>& sent_messages() {
23 return sent_messages_.get(); 24 return sent_messages_.get();
24 } 25 }
25 26
26 void set_fails_profile(bool fails_profile) { 27 void set_fails_profile(bool fails_profile) {
27 fails_profile_ = fails_profile; 28 fails_profile_ = fails_profile;
28 } 29 }
29 30
30 void set_fails_launch(bool fails_launch) { 31 void set_fails_launch(bool fails_launch) {
31 fails_launch_ = fails_launch; 32 fails_launch_ = fails_launch;
32 } 33 }
33 34
34 const std::string& GetAppId() const {
35 return app_id();
36 }
37
38 const Profile* GetProfile() const {
39 return profile();
40 }
41
42 protected: 35 protected:
43 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir) 36 virtual Profile* FetchProfileForDirectory(const std::string& profile_dir)
44 OVERRIDE; 37 OVERRIDE;
45 virtual bool LaunchApp(Profile* profile) OVERRIDE;
46 virtual bool Send(IPC::Message* message) OVERRIDE; 38 virtual bool Send(IPC::Message* message) OVERRIDE;
47 39
48 private: 40 private:
49 Profile* test_profile_; 41 Profile* test_profile_;
50 bool fails_profile_; 42 bool fails_profile_;
51 bool fails_launch_; 43 bool fails_launch_;
52 44
53 ScopedVector<IPC::Message> sent_messages_; 45 ScopedVector<IPC::Message> sent_messages_;
54 46
55 DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost); 47 DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost);
(...skipping 14 matching lines...) Expand all
70 bool TestingAppShimHost::Send(IPC::Message* message) { 62 bool TestingAppShimHost::Send(IPC::Message* message) {
71 sent_messages_.push_back(message); 63 sent_messages_.push_back(message);
72 return true; 64 return true;
73 } 65 }
74 66
75 Profile* TestingAppShimHost::FetchProfileForDirectory( 67 Profile* TestingAppShimHost::FetchProfileForDirectory(
76 const std::string& profile_dir) { 68 const std::string& profile_dir) {
77 return fails_profile_ ? NULL : test_profile_; 69 return fails_profile_ ? NULL : test_profile_;
78 } 70 }
79 71
80 bool TestingAppShimHost::LaunchApp(Profile* profile) {
81 return !fails_launch_;
82 }
83
84 class AppShimHostTest : public testing::Test, 72 class AppShimHostTest : public testing::Test,
85 public apps::AppShimHandler { 73 public apps::AppShimHandler {
86 public: 74 public:
87 AppShimHostTest() : launch_count_(0), close_count_(0), focus_count_(0) {} 75 AppShimHostTest() : launch_count_(0), close_count_(0), focus_count_(0) {}
88 76
89 TestingAppShimHost* host() { return host_.get(); } 77 TestingAppShimHost* host() { return host_.get(); }
90 TestingProfile* profile() { return profile_.get(); } 78 TestingProfile* profile() { return profile_.get(); }
91 79
92 bool LaunchWasSuccessful() { 80 bool LaunchWasSuccessful() {
93 EXPECT_EQ(1u, host()->sent_messages().size()); 81 EXPECT_EQ(1u, host()->sent_messages().size());
(...skipping 16 matching lines...) Expand all
110 98
111 virtual void OnShimClose(Host* host) OVERRIDE { ++close_count_; } 99 virtual void OnShimClose(Host* host) OVERRIDE { ++close_count_; }
112 virtual void OnShimFocus(Host* host) OVERRIDE { ++focus_count_; } 100 virtual void OnShimFocus(Host* host) OVERRIDE { ++focus_count_; }
113 101
114 int launch_count_; 102 int launch_count_;
115 int close_count_; 103 int close_count_;
116 int focus_count_; 104 int focus_count_;
117 105
118 private: 106 private:
119 virtual void SetUp() OVERRIDE { 107 virtual void SetUp() OVERRIDE {
108 testing::Test::SetUp();
120 profile_.reset(new TestingProfile); 109 profile_.reset(new TestingProfile);
121 host_.reset(new TestingAppShimHost(profile())); 110 host_.reset(new TestingAppShimHost(profile()));
122 } 111 }
123 112
124 scoped_ptr<TestingAppShimHost> host_; 113 scoped_ptr<TestingAppShimHost> host_;
125 scoped_ptr<TestingProfile> profile_; 114 scoped_ptr<TestingProfile> profile_;
126 115
127 DISALLOW_COPY_AND_ASSIGN(AppShimHostTest); 116 DISALLOW_COPY_AND_ASSIGN(AppShimHostTest);
128 }; 117 };
129 118
130 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; 119 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
131 const char kTestProfileDir[] = "Default"; 120 const char kTestProfileDir[] = "Default";
132 121
133 } // namespace 122 } // namespace
134 123
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) { 124 TEST_F(AppShimHostTest, TestLaunchAppWithHandler) {
144 apps::AppShimHandler::RegisterHandler(kTestAppId, this); 125 apps::AppShimHandler::RegisterHandler(kTestAppId, this);
145 EXPECT_TRUE(host()->ReceiveMessage( 126 EXPECT_TRUE(host()->ReceiveMessage(
146 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId))); 127 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)));
147 EXPECT_EQ(kTestAppId, host()->GetAppId()); 128 EXPECT_EQ(kTestAppId,
129 implicit_cast<apps::AppShimHandler::Host*>(host())->GetAppId());
148 EXPECT_TRUE(LaunchWasSuccessful()); 130 EXPECT_TRUE(LaunchWasSuccessful());
149 EXPECT_EQ(1, launch_count_); 131 EXPECT_EQ(1, launch_count_);
150 EXPECT_EQ(0, focus_count_); 132 EXPECT_EQ(0, focus_count_);
151 EXPECT_EQ(0, close_count_); 133 EXPECT_EQ(0, close_count_);
152 134
153 EXPECT_TRUE(host()->ReceiveMessage(new AppShimHostMsg_FocusApp())); 135 EXPECT_TRUE(host()->ReceiveMessage(new AppShimHostMsg_FocusApp()));
154 EXPECT_EQ(1, focus_count_); 136 EXPECT_EQ(1, focus_count_);
155 137
156 SimulateDisconnect(); 138 SimulateDisconnect();
157 EXPECT_EQ(1, close_count_); 139 EXPECT_EQ(1, close_count_);
158 apps::AppShimHandler::RemoveHandler(kTestAppId); 140 apps::AppShimHandler::RemoveHandler(kTestAppId);
159 } 141 }
160 142
161 TEST_F(AppShimHostTest, TestFailProfile) { 143 TEST_F(AppShimHostTest, TestFailProfile) {
162 host()->set_fails_profile(true); 144 host()->set_fails_profile(true);
163 host()->ReceiveMessage( 145 host()->ReceiveMessage(
164 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); 146 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId));
165 ASSERT_FALSE(LaunchWasSuccessful()); 147 ASSERT_FALSE(LaunchWasSuccessful());
166 } 148 }
167 149
168 TEST_F(AppShimHostTest, TestFailLaunch) { 150 TEST_F(AppShimHostTest, TestFailLaunch) {
169 host()->set_fails_launch(true); 151 host()->set_fails_launch(true);
170 host()->ReceiveMessage( 152 host()->ReceiveMessage(
171 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); 153 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId));
172 ASSERT_FALSE(LaunchWasSuccessful()); 154 ASSERT_FALSE(LaunchWasSuccessful());
173 } 155 }
OLDNEW
« no previous file with comments | « apps/app_shim/app_shim_host_mac.cc ('k') | apps/app_shim/app_shim_host_manager_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698