| 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/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/memory/scoped_vector.h" | 9 #include "base/memory/scoped_vector.h" |
| 10 #include "chrome/test/base/testing_profile.h" | 10 #include "chrome/test/base/testing_profile.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 } | 65 } |
| 66 | 66 |
| 67 Profile* TestingAppShimHost::FetchProfileForDirectory( | 67 Profile* TestingAppShimHost::FetchProfileForDirectory( |
| 68 const std::string& profile_dir) { | 68 const std::string& profile_dir) { |
| 69 return fails_profile_ ? NULL : test_profile_; | 69 return fails_profile_ ? NULL : test_profile_; |
| 70 } | 70 } |
| 71 | 71 |
| 72 class AppShimHostTest : public testing::Test, | 72 class AppShimHostTest : public testing::Test, |
| 73 public apps::AppShimHandler { | 73 public apps::AppShimHandler { |
| 74 public: | 74 public: |
| 75 AppShimHostTest() : launch_count_(0), close_count_(0), focus_count_(0) {} | 75 AppShimHostTest() : launch_count_(0), |
| 76 close_count_(0), |
| 77 focus_count_(0), |
| 78 quit_count_(0) {} |
| 76 | 79 |
| 77 TestingAppShimHost* host() { return host_.get(); } | 80 TestingAppShimHost* host() { return host_.get(); } |
| 78 TestingProfile* profile() { return profile_.get(); } | 81 TestingProfile* profile() { return profile_.get(); } |
| 79 | 82 |
| 80 bool LaunchWasSuccessful() { | 83 bool LaunchWasSuccessful() { |
| 81 EXPECT_EQ(1u, host()->sent_messages().size()); | 84 EXPECT_EQ(1u, host()->sent_messages().size()); |
| 82 IPC::Message* message = host()->sent_messages()[0]; | 85 IPC::Message* message = host()->sent_messages()[0]; |
| 83 EXPECT_EQ(AppShimMsg_LaunchApp_Done::ID, message->type()); | 86 EXPECT_EQ(AppShimMsg_LaunchApp_Done::ID, message->type()); |
| 84 AppShimMsg_LaunchApp_Done::Param param; | 87 AppShimMsg_LaunchApp_Done::Param param; |
| 85 AppShimMsg_LaunchApp_Done::Read(message, ¶m); | 88 AppShimMsg_LaunchApp_Done::Read(message, ¶m); |
| 86 return param.a; | 89 return param.a; |
| 87 } | 90 } |
| 88 | 91 |
| 89 void SimulateDisconnect() { | 92 void SimulateDisconnect() { |
| 90 implicit_cast<IPC::Listener*>(host_.release())->OnChannelError(); | 93 implicit_cast<IPC::Listener*>(host_.release())->OnChannelError(); |
| 91 } | 94 } |
| 92 | 95 |
| 93 protected: | 96 protected: |
| 94 virtual bool OnShimLaunch(Host* host) OVERRIDE { | 97 virtual bool OnShimLaunch(Host* host) OVERRIDE { |
| 95 ++launch_count_; | 98 ++launch_count_; |
| 96 return true; | 99 return true; |
| 97 } | 100 } |
| 98 | 101 |
| 99 virtual void OnShimClose(Host* host) OVERRIDE { ++close_count_; } | 102 virtual void OnShimClose(Host* host) OVERRIDE { ++close_count_; } |
| 100 virtual void OnShimFocus(Host* host) OVERRIDE { ++focus_count_; } | 103 virtual void OnShimFocus(Host* host) OVERRIDE { ++focus_count_; } |
| 104 virtual void OnShimQuit(Host* host) OVERRIDE { ++quit_count_; } |
| 101 | 105 |
| 102 int launch_count_; | 106 int launch_count_; |
| 103 int close_count_; | 107 int close_count_; |
| 104 int focus_count_; | 108 int focus_count_; |
| 109 int quit_count_; |
| 105 | 110 |
| 106 private: | 111 private: |
| 107 virtual void SetUp() OVERRIDE { | 112 virtual void SetUp() OVERRIDE { |
| 108 testing::Test::SetUp(); | 113 testing::Test::SetUp(); |
| 109 profile_.reset(new TestingProfile); | 114 profile_.reset(new TestingProfile); |
| 110 host_.reset(new TestingAppShimHost(profile())); | 115 host_.reset(new TestingAppShimHost(profile())); |
| 111 } | 116 } |
| 112 | 117 |
| 113 scoped_ptr<TestingAppShimHost> host_; | 118 scoped_ptr<TestingAppShimHost> host_; |
| 114 scoped_ptr<TestingProfile> profile_; | 119 scoped_ptr<TestingProfile> profile_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 128 EXPECT_EQ(kTestAppId, | 133 EXPECT_EQ(kTestAppId, |
| 129 implicit_cast<apps::AppShimHandler::Host*>(host())->GetAppId()); | 134 implicit_cast<apps::AppShimHandler::Host*>(host())->GetAppId()); |
| 130 EXPECT_TRUE(LaunchWasSuccessful()); | 135 EXPECT_TRUE(LaunchWasSuccessful()); |
| 131 EXPECT_EQ(1, launch_count_); | 136 EXPECT_EQ(1, launch_count_); |
| 132 EXPECT_EQ(0, focus_count_); | 137 EXPECT_EQ(0, focus_count_); |
| 133 EXPECT_EQ(0, close_count_); | 138 EXPECT_EQ(0, close_count_); |
| 134 | 139 |
| 135 EXPECT_TRUE(host()->ReceiveMessage(new AppShimHostMsg_FocusApp())); | 140 EXPECT_TRUE(host()->ReceiveMessage(new AppShimHostMsg_FocusApp())); |
| 136 EXPECT_EQ(1, focus_count_); | 141 EXPECT_EQ(1, focus_count_); |
| 137 | 142 |
| 143 EXPECT_TRUE(host()->ReceiveMessage(new AppShimHostMsg_QuitApp())); |
| 144 EXPECT_EQ(1, quit_count_); |
| 145 |
| 138 SimulateDisconnect(); | 146 SimulateDisconnect(); |
| 139 EXPECT_EQ(1, close_count_); | 147 EXPECT_EQ(1, close_count_); |
| 140 apps::AppShimHandler::RemoveHandler(kTestAppId); | 148 apps::AppShimHandler::RemoveHandler(kTestAppId); |
| 141 } | 149 } |
| 142 | 150 |
| 143 TEST_F(AppShimHostTest, TestFailProfile) { | 151 TEST_F(AppShimHostTest, TestFailProfile) { |
| 144 host()->set_fails_profile(true); | 152 host()->set_fails_profile(true); |
| 145 host()->ReceiveMessage( | 153 host()->ReceiveMessage( |
| 146 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); | 154 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); |
| 147 ASSERT_FALSE(LaunchWasSuccessful()); | 155 ASSERT_FALSE(LaunchWasSuccessful()); |
| 148 } | 156 } |
| 149 | 157 |
| 150 TEST_F(AppShimHostTest, TestFailLaunch) { | 158 TEST_F(AppShimHostTest, TestFailLaunch) { |
| 151 host()->set_fails_launch(true); | 159 host()->set_fails_launch(true); |
| 152 host()->ReceiveMessage( | 160 host()->ReceiveMessage( |
| 153 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); | 161 new AppShimHostMsg_LaunchApp(kTestProfileDir, kTestAppId)); |
| 154 ASSERT_FALSE(LaunchWasSuccessful()); | 162 ASSERT_FALSE(LaunchWasSuccessful()); |
| 155 } | 163 } |
| OLD | NEW |