| 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 "chrome/browser/apps/app_shim/app_shim_host_mac.h" | 5 #include "chrome/browser/apps/app_shim/app_shim_host_mac.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <tuple> | 8 #include <tuple> |
| 8 #include <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/ptr_util.h" |
| 12 #include "chrome/common/mac/app_shim_messages.h" | 13 #include "chrome/common/mac/app_shim_messages.h" |
| 13 #include "ipc/ipc_message.h" | 14 #include "ipc/ipc_message.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| 18 class TestingAppShimHost : public AppShimHost { | 19 class TestingAppShimHost : public AppShimHost { |
| 19 public: | 20 public: |
| 20 TestingAppShimHost() {} | 21 TestingAppShimHost() {} |
| 21 ~TestingAppShimHost() override {} | 22 ~TestingAppShimHost() override {} |
| 22 | 23 |
| 23 bool ReceiveMessage(IPC::Message* message); | 24 bool ReceiveMessage(IPC::Message* message); |
| 24 | 25 |
| 25 const std::vector<IPC::Message*>& sent_messages() { | 26 const std::vector<std::unique_ptr<IPC::Message>>& sent_messages() { |
| 26 return sent_messages_.get(); | 27 return sent_messages_; |
| 27 } | 28 } |
| 28 | 29 |
| 29 protected: | 30 protected: |
| 30 bool Send(IPC::Message* message) override; | 31 bool Send(IPC::Message* message) override; |
| 31 | 32 |
| 32 private: | 33 private: |
| 33 ScopedVector<IPC::Message> sent_messages_; | 34 std::vector<std::unique_ptr<IPC::Message>> sent_messages_; |
| 34 | 35 |
| 35 DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost); | 36 DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost); |
| 36 }; | 37 }; |
| 37 | 38 |
| 38 bool TestingAppShimHost::ReceiveMessage(IPC::Message* message) { | 39 bool TestingAppShimHost::ReceiveMessage(IPC::Message* message) { |
| 39 bool handled = OnMessageReceived(*message); | 40 bool handled = OnMessageReceived(*message); |
| 40 delete message; | 41 delete message; |
| 41 return handled; | 42 return handled; |
| 42 } | 43 } |
| 43 | 44 |
| 44 bool TestingAppShimHost::Send(IPC::Message* message) { | 45 bool TestingAppShimHost::Send(IPC::Message* message) { |
| 45 sent_messages_.push_back(message); | 46 sent_messages_.push_back(base::WrapUnique(message)); |
| 46 return true; | 47 return true; |
| 47 } | 48 } |
| 48 | 49 |
| 49 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 50 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 50 const char kTestProfileDir[] = "Profile 1"; | 51 const char kTestProfileDir[] = "Profile 1"; |
| 51 | 52 |
| 52 class AppShimHostTest : public testing::Test, | 53 class AppShimHostTest : public testing::Test, |
| 53 public apps::AppShimHandler { | 54 public apps::AppShimHandler { |
| 54 public: | 55 public: |
| 55 AppShimHostTest() : launch_result_(apps::APP_SHIM_LAUNCH_SUCCESS), | 56 AppShimHostTest() : launch_result_(apps::APP_SHIM_LAUNCH_SUCCESS), |
| 56 launch_count_(0), | 57 launch_count_(0), |
| 57 launch_now_count_(0), | 58 launch_now_count_(0), |
| 58 close_count_(0), | 59 close_count_(0), |
| 59 focus_count_(0), | 60 focus_count_(0), |
| 60 quit_count_(0) {} | 61 quit_count_(0) {} |
| 61 | 62 |
| 62 TestingAppShimHost* host() { return host_.get(); } | 63 TestingAppShimHost* host() { return host_.get(); } |
| 63 | 64 |
| 64 void LaunchApp(apps::AppShimLaunchType launch_type) { | 65 void LaunchApp(apps::AppShimLaunchType launch_type) { |
| 65 EXPECT_TRUE(host()->ReceiveMessage( | 66 EXPECT_TRUE(host()->ReceiveMessage( |
| 66 new AppShimHostMsg_LaunchApp(base::FilePath(kTestProfileDir), | 67 new AppShimHostMsg_LaunchApp(base::FilePath(kTestProfileDir), |
| 67 kTestAppId, | 68 kTestAppId, |
| 68 launch_type, | 69 launch_type, |
| 69 std::vector<base::FilePath>()))); | 70 std::vector<base::FilePath>()))); |
| 70 } | 71 } |
| 71 | 72 |
| 72 apps::AppShimLaunchResult GetLaunchResult() { | 73 apps::AppShimLaunchResult GetLaunchResult() { |
| 73 EXPECT_EQ(1u, host()->sent_messages().size()); | 74 EXPECT_EQ(1u, host()->sent_messages().size()); |
| 74 IPC::Message* message = host()->sent_messages()[0]; | 75 IPC::Message* message = host()->sent_messages()[0].get(); |
| 75 EXPECT_EQ(AppShimMsg_LaunchApp_Done::ID, message->type()); | 76 EXPECT_EQ(AppShimMsg_LaunchApp_Done::ID, message->type()); |
| 76 AppShimMsg_LaunchApp_Done::Param param; | 77 AppShimMsg_LaunchApp_Done::Param param; |
| 77 AppShimMsg_LaunchApp_Done::Read(message, ¶m); | 78 AppShimMsg_LaunchApp_Done::Read(message, ¶m); |
| 78 return std::get<0>(param); | 79 return std::get<0>(param); |
| 79 } | 80 } |
| 80 | 81 |
| 81 void SimulateDisconnect() { | 82 void SimulateDisconnect() { |
| 82 static_cast<IPC::Listener*>(host_.release())->OnChannelError(); | 83 static_cast<IPC::Listener*>(host_.release())->OnChannelError(); |
| 83 } | 84 } |
| 84 | 85 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 apps::AppShimHandler::RemoveHandler(kTestAppId); | 168 apps::AppShimHandler::RemoveHandler(kTestAppId); |
| 168 } | 169 } |
| 169 | 170 |
| 170 TEST_F(AppShimHostTest, TestFailLaunch) { | 171 TEST_F(AppShimHostTest, TestFailLaunch) { |
| 171 apps::AppShimHandler::RegisterHandler(kTestAppId, this); | 172 apps::AppShimHandler::RegisterHandler(kTestAppId, this); |
| 172 launch_result_ = apps::APP_SHIM_LAUNCH_APP_NOT_FOUND; | 173 launch_result_ = apps::APP_SHIM_LAUNCH_APP_NOT_FOUND; |
| 173 LaunchApp(apps::APP_SHIM_LAUNCH_NORMAL); | 174 LaunchApp(apps::APP_SHIM_LAUNCH_NORMAL); |
| 174 EXPECT_EQ(apps::APP_SHIM_LAUNCH_APP_NOT_FOUND, GetLaunchResult()); | 175 EXPECT_EQ(apps::APP_SHIM_LAUNCH_APP_NOT_FOUND, GetLaunchResult()); |
| 175 apps::AppShimHandler::RemoveHandler(kTestAppId); | 176 apps::AppShimHandler::RemoveHandler(kTestAppId); |
| 176 } | 177 } |
| OLD | NEW |