| 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 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 const std::vector<IPC::Message*>& sent_messages() { | 23 const std::vector<IPC::Message*>& sent_messages() { |
| 24 return sent_messages_.get(); | 24 return sent_messages_.get(); |
| 25 } | 25 } |
| 26 | 26 |
| 27 void set_fails_profile(bool fails_profile) { | 27 void set_fails_profile(bool fails_profile) { |
| 28 fails_profile_ = fails_profile; | 28 fails_profile_ = fails_profile; |
| 29 } | 29 } |
| 30 | 30 |
| 31 protected: | 31 protected: |
| 32 virtual Profile* FetchProfileForDirectory(const base::FilePath& profile_dir) | 32 virtual void LoadProfile(const base::FilePath& profile_dir, |
| 33 OVERRIDE; | 33 base::Callback<void(Profile*)> callback) OVERRIDE; |
| 34 |
| 34 virtual bool Send(IPC::Message* message) OVERRIDE; | 35 virtual bool Send(IPC::Message* message) OVERRIDE; |
| 35 | 36 |
| 36 private: | 37 private: |
| 37 Profile* test_profile_; | 38 Profile* test_profile_; |
| 38 bool fails_profile_; | 39 bool fails_profile_; |
| 39 | 40 |
| 40 ScopedVector<IPC::Message> sent_messages_; | 41 ScopedVector<IPC::Message> sent_messages_; |
| 41 | 42 |
| 42 DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost); | 43 DISALLOW_COPY_AND_ASSIGN(TestingAppShimHost); |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 TestingAppShimHost::TestingAppShimHost(Profile* profile) | 46 TestingAppShimHost::TestingAppShimHost(Profile* profile) |
| 46 : test_profile_(profile), | 47 : test_profile_(profile), |
| 47 fails_profile_(false) { | 48 fails_profile_(false) { |
| 48 } | 49 } |
| 49 | 50 |
| 50 bool TestingAppShimHost::ReceiveMessage(IPC::Message* message) { | 51 bool TestingAppShimHost::ReceiveMessage(IPC::Message* message) { |
| 51 bool handled = OnMessageReceived(*message); | 52 bool handled = OnMessageReceived(*message); |
| 52 delete message; | 53 delete message; |
| 53 return handled; | 54 return handled; |
| 54 } | 55 } |
| 55 | 56 |
| 56 bool TestingAppShimHost::Send(IPC::Message* message) { | 57 bool TestingAppShimHost::Send(IPC::Message* message) { |
| 57 sent_messages_.push_back(message); | 58 sent_messages_.push_back(message); |
| 58 return true; | 59 return true; |
| 59 } | 60 } |
| 60 | 61 |
| 61 Profile* TestingAppShimHost::FetchProfileForDirectory( | 62 void TestingAppShimHost::LoadProfile(const base::FilePath& profile_dir, |
| 62 const base::FilePath& profile_dir) { | 63 base::Callback<void(Profile*)> callback) { |
| 63 return fails_profile_ ? NULL : test_profile_; | 64 callback.Run(test_profile_); |
| 64 } | 65 } |
| 65 | 66 |
| 66 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; | 67 const char kTestAppId[] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; |
| 67 const char kTestProfileDir[] = "Default"; | 68 const char kTestProfileDir[] = "Default"; |
| 68 | 69 |
| 69 class AppShimHostTest : public testing::Test, | 70 class AppShimHostTest : public testing::Test, |
| 70 public apps::AppShimHandler { | 71 public apps::AppShimHandler { |
| 71 public: | 72 public: |
| 72 AppShimHostTest() : fail_launch_(false), | 73 AppShimHostTest() : fail_launch_(false), |
| 73 launch_count_(0), | 74 launch_count_(0), |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 ASSERT_FALSE(LaunchWasSuccessful()); | 177 ASSERT_FALSE(LaunchWasSuccessful()); |
| 177 } | 178 } |
| 178 | 179 |
| 179 TEST_F(AppShimHostTest, TestFailLaunch) { | 180 TEST_F(AppShimHostTest, TestFailLaunch) { |
| 180 apps::AppShimHandler::RegisterHandler(kTestAppId, this); | 181 apps::AppShimHandler::RegisterHandler(kTestAppId, this); |
| 181 fail_launch_ = true; | 182 fail_launch_ = true; |
| 182 LaunchApp(true); | 183 LaunchApp(true); |
| 183 ASSERT_FALSE(LaunchWasSuccessful()); | 184 ASSERT_FALSE(LaunchWasSuccessful()); |
| 184 apps::AppShimHandler::RemoveHandler(kTestAppId); | 185 apps::AppShimHandler::RemoveHandler(kTestAppId); |
| 185 } | 186 } |
| OLD | NEW |