| 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/extension_app_shim_handler_mac.h" | 5 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "apps/app_shim/app_shim_host_mac.h" | 9 #include "apps/app_shim/app_shim_host_mac.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "chrome/browser/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/test/base/testing_profile.h" | 12 #include "chrome/test/base/testing_profile.h" |
| 13 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 14 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
| 15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 | 17 |
| 18 namespace apps { | 18 namespace apps { |
| 19 | 19 |
| 20 using extensions::Extension; | 20 using extensions::Extension; |
| 21 typedef ShellWindowRegistry::ShellWindowList ShellWindowList; | 21 typedef ShellWindowRegistry::ShellWindowList ShellWindowList; |
| 22 | 22 |
| 23 using ::testing::_; | 23 using ::testing::_; |
| 24 using ::testing::Invoke; | 24 using ::testing::Invoke; |
| 25 using ::testing::Return; | 25 using ::testing::Return; |
| 26 using ::testing::WithArgs; |
| 26 | 27 |
| 27 class MockDelegate : public ExtensionAppShimHandler::Delegate { | 28 class MockDelegate : public ExtensionAppShimHandler::Delegate { |
| 28 public: | 29 public: |
| 29 virtual ~MockDelegate() {} | 30 virtual ~MockDelegate() {} |
| 30 | 31 |
| 31 MOCK_METHOD1(ProfileExistsForPath, bool(const base::FilePath&)); | 32 MOCK_METHOD1(ProfileExistsForPath, bool(const base::FilePath&)); |
| 32 MOCK_METHOD1(ProfileForPath, Profile*(const base::FilePath&)); | 33 MOCK_METHOD1(ProfileForPath, Profile*(const base::FilePath&)); |
| 33 MOCK_METHOD2(LoadProfileAsync, | 34 MOCK_METHOD2(LoadProfileAsync, |
| 34 void(const base::FilePath&, | 35 void(const base::FilePath&, |
| 35 base::Callback<void(Profile*)>)); | 36 base::Callback<void(Profile*)>)); |
| 36 | 37 |
| 37 MOCK_METHOD2(GetWindows, ShellWindowList(Profile*, const std::string&)); | 38 MOCK_METHOD2(GetWindows, ShellWindowList(Profile*, const std::string&)); |
| 38 | 39 |
| 39 MOCK_METHOD2(GetAppExtension, const Extension*(Profile*, const std::string&)); | 40 MOCK_METHOD2(GetAppExtension, const Extension*(Profile*, const std::string&)); |
| 41 MOCK_METHOD3(EnableExtension, void(Profile*, |
| 42 const std::string&, |
| 43 const base::Callback<void()>&)); |
| 40 MOCK_METHOD3(LaunchApp, | 44 MOCK_METHOD3(LaunchApp, |
| 41 void(Profile*, | 45 void(Profile*, |
| 42 const Extension*, | 46 const Extension*, |
| 43 const std::vector<base::FilePath>&)); | 47 const std::vector<base::FilePath>&)); |
| 44 MOCK_METHOD2(LaunchShim, void(Profile*, const Extension*)); | 48 MOCK_METHOD2(LaunchShim, void(Profile*, const Extension*)); |
| 45 | 49 |
| 46 MOCK_METHOD0(MaybeTerminate, void()); | 50 MOCK_METHOD0(MaybeTerminate, void()); |
| 47 | 51 |
| 48 void CaptureLoadProfileCallback( | 52 void CaptureLoadProfileCallback( |
| 49 const base::FilePath& path, | 53 const base::FilePath& path, |
| 50 base::Callback<void(Profile*)> callback) { | 54 base::Callback<void(Profile*)> callback) { |
| 51 callbacks_[path] = callback; | 55 callbacks_[path] = callback; |
| 52 } | 56 } |
| 53 | 57 |
| 54 bool RunLoadProfileCallback( | 58 bool RunLoadProfileCallback( |
| 55 const base::FilePath& path, | 59 const base::FilePath& path, |
| 56 Profile* profile) { | 60 Profile* profile) { |
| 57 callbacks_[path].Run(profile); | 61 callbacks_[path].Run(profile); |
| 58 return callbacks_.erase(path); | 62 return callbacks_.erase(path); |
| 59 } | 63 } |
| 60 | 64 |
| 65 void RunCallback(const base::Callback<void()>& callback) { |
| 66 callback.Run(); |
| 67 } |
| 68 |
| 61 private: | 69 private: |
| 62 std::map<base::FilePath, | 70 std::map<base::FilePath, |
| 63 base::Callback<void(Profile*)> > callbacks_; | 71 base::Callback<void(Profile*)> > callbacks_; |
| 64 }; | 72 }; |
| 65 | 73 |
| 66 class TestingExtensionAppShimHandler : public ExtensionAppShimHandler { | 74 class TestingExtensionAppShimHandler : public ExtensionAppShimHandler { |
| 67 public: | 75 public: |
| 68 TestingExtensionAppShimHandler(Delegate* delegate) { | 76 TestingExtensionAppShimHandler(Delegate* delegate) { |
| 69 set_delegate(delegate); | 77 set_delegate(delegate); |
| 70 } | 78 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 FakeHost host_ab_; | 210 FakeHost host_ab_; |
| 203 FakeHost host_bb_; | 211 FakeHost host_bb_; |
| 204 FakeHost host_aa_duplicate_; | 212 FakeHost host_aa_duplicate_; |
| 205 scoped_refptr<Extension> extension_a_; | 213 scoped_refptr<Extension> extension_a_; |
| 206 scoped_refptr<Extension> extension_b_; | 214 scoped_refptr<Extension> extension_b_; |
| 207 | 215 |
| 208 private: | 216 private: |
| 209 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandlerTest); | 217 DISALLOW_COPY_AND_ASSIGN(ExtensionAppShimHandlerTest); |
| 210 }; | 218 }; |
| 211 | 219 |
| 212 TEST_F(ExtensionAppShimHandlerTest, LaunchFailure) { | 220 TEST_F(ExtensionAppShimHandlerTest, LaunchProfileNotFound) { |
| 213 // Bad profile path. | 221 // Bad profile path. |
| 214 EXPECT_CALL(*delegate_, ProfileExistsForPath(profile_path_a_)) | 222 EXPECT_CALL(*delegate_, ProfileExistsForPath(profile_path_a_)) |
| 215 .WillOnce(Return(false)) | 223 .WillOnce(Return(false)) |
| 216 .WillRepeatedly(Return(true)); | 224 .WillRepeatedly(Return(true)); |
| 217 EXPECT_CALL(host_aa_, OnAppLaunchComplete(APP_SHIM_LAUNCH_PROFILE_NOT_FOUND)); | 225 EXPECT_CALL(host_aa_, OnAppLaunchComplete(APP_SHIM_LAUNCH_PROFILE_NOT_FOUND)); |
| 218 NormalLaunch(&host_aa_); | 226 NormalLaunch(&host_aa_); |
| 227 } |
| 219 | 228 |
| 229 TEST_F(ExtensionAppShimHandlerTest, LaunchAppNotFound) { |
| 230 // App not found. |
| 231 EXPECT_CALL(*delegate_, GetAppExtension(&profile_a_, kTestAppIdA)) |
| 232 .WillRepeatedly(Return(static_cast<const Extension*>(NULL))); |
| 233 EXPECT_CALL(*delegate_, EnableExtension(&profile_a_, kTestAppIdA, _)) |
| 234 .WillOnce(WithArgs<2>(Invoke(delegate_, &MockDelegate::RunCallback))); |
| 235 EXPECT_CALL(host_aa_, OnAppLaunchComplete(APP_SHIM_LAUNCH_APP_NOT_FOUND)); |
| 236 NormalLaunch(&host_aa_); |
| 237 } |
| 238 |
| 239 TEST_F(ExtensionAppShimHandlerTest, LaunchAppNotEnabled) { |
| 220 // App not found. | 240 // App not found. |
| 221 EXPECT_CALL(*delegate_, GetAppExtension(&profile_a_, kTestAppIdA)) | 241 EXPECT_CALL(*delegate_, GetAppExtension(&profile_a_, kTestAppIdA)) |
| 222 .WillOnce(Return(static_cast<const Extension*>(NULL))) | 242 .WillOnce(Return(static_cast<const Extension*>(NULL))) |
| 223 .WillRepeatedly(Return(extension_a_.get())); | 243 .WillRepeatedly(Return(extension_a_.get())); |
| 224 EXPECT_CALL(host_aa_, OnAppLaunchComplete(APP_SHIM_LAUNCH_APP_NOT_FOUND)); | 244 EXPECT_CALL(*delegate_, EnableExtension(&profile_a_, kTestAppIdA, _)) |
| 245 .WillOnce(WithArgs<2>(Invoke(delegate_, &MockDelegate::RunCallback))); |
| 225 NormalLaunch(&host_aa_); | 246 NormalLaunch(&host_aa_); |
| 226 } | 247 } |
| 227 | 248 |
| 228 TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) { | 249 TEST_F(ExtensionAppShimHandlerTest, LaunchAndCloseShim) { |
| 229 // Normal startup. | 250 // Normal startup. |
| 230 NormalLaunch(&host_aa_); | 251 NormalLaunch(&host_aa_); |
| 231 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA)); | 252 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA)); |
| 232 | 253 |
| 233 NormalLaunch(&host_ab_); | 254 NormalLaunch(&host_ab_); |
| 234 EXPECT_EQ(&host_ab_, handler_->FindHost(&profile_a_, kTestAppIdB)); | 255 EXPECT_EQ(&host_ab_, handler_->FindHost(&profile_a_, kTestAppIdB)); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 .WillRepeatedly(Return(&profile_a_)); | 387 .WillRepeatedly(Return(&profile_a_)); |
| 367 EXPECT_CALL(*delegate_, LoadProfileAsync(profile_path_a_, _)) | 388 EXPECT_CALL(*delegate_, LoadProfileAsync(profile_path_a_, _)) |
| 368 .WillOnce(Invoke(delegate_, &MockDelegate::CaptureLoadProfileCallback)); | 389 .WillOnce(Invoke(delegate_, &MockDelegate::CaptureLoadProfileCallback)); |
| 369 NormalLaunch(&host_aa_); | 390 NormalLaunch(&host_aa_); |
| 370 EXPECT_FALSE(handler_->FindHost(&profile_a_, kTestAppIdA)); | 391 EXPECT_FALSE(handler_->FindHost(&profile_a_, kTestAppIdA)); |
| 371 delegate_->RunLoadProfileCallback(profile_path_a_, &profile_a_); | 392 delegate_->RunLoadProfileCallback(profile_path_a_, &profile_a_); |
| 372 EXPECT_TRUE(handler_->FindHost(&profile_a_, kTestAppIdA)); | 393 EXPECT_TRUE(handler_->FindHost(&profile_a_, kTestAppIdA)); |
| 373 } | 394 } |
| 374 | 395 |
| 375 } // namespace apps | 396 } // namespace apps |
| OLD | NEW |