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 AppWindowRegistry::AppWindowList AppWindowList; |
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 using ::testing::WithArgs; |
27 | 27 |
28 class MockDelegate : public ExtensionAppShimHandler::Delegate { | 28 class MockDelegate : public ExtensionAppShimHandler::Delegate { |
29 public: | 29 public: |
30 virtual ~MockDelegate() {} | 30 virtual ~MockDelegate() {} |
31 | 31 |
32 MOCK_METHOD1(ProfileExistsForPath, bool(const base::FilePath&)); | 32 MOCK_METHOD1(ProfileExistsForPath, bool(const base::FilePath&)); |
33 MOCK_METHOD1(ProfileForPath, Profile*(const base::FilePath&)); | 33 MOCK_METHOD1(ProfileForPath, Profile*(const base::FilePath&)); |
34 MOCK_METHOD2(LoadProfileAsync, | 34 MOCK_METHOD2(LoadProfileAsync, |
35 void(const base::FilePath&, | 35 void(const base::FilePath&, |
36 base::Callback<void(Profile*)>)); | 36 base::Callback<void(Profile*)>)); |
37 | 37 |
38 MOCK_METHOD2(GetWindows, ShellWindowList(Profile*, const std::string&)); | 38 MOCK_METHOD2(GetWindows, AppWindowList(Profile*, const std::string&)); |
39 | 39 |
40 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*, | 41 MOCK_METHOD3(EnableExtension, void(Profile*, |
42 const std::string&, | 42 const std::string&, |
43 const base::Callback<void()>&)); | 43 const base::Callback<void()>&)); |
44 MOCK_METHOD3(LaunchApp, | 44 MOCK_METHOD3(LaunchApp, |
45 void(Profile*, | 45 void(Profile*, |
46 const Extension*, | 46 const Extension*, |
47 const std::vector<base::FilePath>&)); | 47 const std::vector<base::FilePath>&)); |
48 MOCK_METHOD2(LaunchShim, void(Profile*, const Extension*)); | 48 MOCK_METHOD2(LaunchShim, void(Profile*, const Extension*)); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 .WillRepeatedly(Return(true)); | 168 .WillRepeatedly(Return(true)); |
169 EXPECT_CALL(*delegate_, ProfileForPath(profile_path_a_)) | 169 EXPECT_CALL(*delegate_, ProfileForPath(profile_path_a_)) |
170 .WillRepeatedly(Return(&profile_a_)); | 170 .WillRepeatedly(Return(&profile_a_)); |
171 EXPECT_CALL(*delegate_, ProfileExistsForPath(profile_path_b_)) | 171 EXPECT_CALL(*delegate_, ProfileExistsForPath(profile_path_b_)) |
172 .WillRepeatedly(Return(true)); | 172 .WillRepeatedly(Return(true)); |
173 EXPECT_CALL(*delegate_, ProfileForPath(profile_path_b_)) | 173 EXPECT_CALL(*delegate_, ProfileForPath(profile_path_b_)) |
174 .WillRepeatedly(Return(&profile_b_)); | 174 .WillRepeatedly(Return(&profile_b_)); |
175 | 175 |
176 // In most tests, we don't care about the result of GetWindows, it just | 176 // In most tests, we don't care about the result of GetWindows, it just |
177 // needs to be non-empty. | 177 // needs to be non-empty. |
178 ShellWindowList shell_window_list; | 178 AppWindowList app_window_list; |
179 shell_window_list.push_back(static_cast<ShellWindow*>(NULL)); | 179 app_window_list.push_back(static_cast<AppWindow*>(NULL)); |
180 EXPECT_CALL(*delegate_, GetWindows(_, _)) | 180 EXPECT_CALL(*delegate_, GetWindows(_, _)) |
181 .WillRepeatedly(Return(shell_window_list)); | 181 .WillRepeatedly(Return(app_window_list)); |
182 | 182 |
183 EXPECT_CALL(*delegate_, GetAppExtension(_, kTestAppIdA)) | 183 EXPECT_CALL(*delegate_, GetAppExtension(_, kTestAppIdA)) |
184 .WillRepeatedly(Return(extension_a_.get())); | 184 .WillRepeatedly(Return(extension_a_.get())); |
185 EXPECT_CALL(*delegate_, GetAppExtension(_, kTestAppIdB)) | 185 EXPECT_CALL(*delegate_, GetAppExtension(_, kTestAppIdB)) |
186 .WillRepeatedly(Return(extension_b_.get())); | 186 .WillRepeatedly(Return(extension_b_.get())); |
187 EXPECT_CALL(*delegate_, LaunchApp(_, _, _)) | 187 EXPECT_CALL(*delegate_, LaunchApp(_, _, _)) |
188 .WillRepeatedly(Return()); | 188 .WillRepeatedly(Return()); |
189 } | 189 } |
190 | 190 |
191 void NormalLaunch(AppShimHandler::Host* host) { | 191 void NormalLaunch(AppShimHandler::Host* host) { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 295 |
296 // Normal shim launch adds an entry in the map. | 296 // Normal shim launch adds an entry in the map. |
297 // App should not be launched here, but return success to the shim. | 297 // App should not be launched here, but return success to the shim. |
298 EXPECT_CALL(*delegate_, | 298 EXPECT_CALL(*delegate_, |
299 LaunchApp(&profile_a_, extension_a_.get(), _)) | 299 LaunchApp(&profile_a_, extension_a_.get(), _)) |
300 .Times(0); | 300 .Times(0); |
301 EXPECT_CALL(host_aa_, OnAppLaunchComplete(APP_SHIM_LAUNCH_SUCCESS)); | 301 EXPECT_CALL(host_aa_, OnAppLaunchComplete(APP_SHIM_LAUNCH_SUCCESS)); |
302 RegisterOnlyLaunch(&host_aa_); | 302 RegisterOnlyLaunch(&host_aa_); |
303 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA)); | 303 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA)); |
304 | 304 |
305 // Return no shell windows for OnShimFocus and OnShimQuit. | 305 // Return no app windows for OnShimFocus and OnShimQuit. |
306 ShellWindowList shell_window_list; | 306 AppWindowList app_window_list; |
307 EXPECT_CALL(*delegate_, GetWindows(&profile_a_, kTestAppIdA)) | 307 EXPECT_CALL(*delegate_, GetWindows(&profile_a_, kTestAppIdA)) |
308 .WillRepeatedly(Return(shell_window_list)); | 308 .WillRepeatedly(Return(app_window_list)); |
309 | 309 |
310 // Non-reopen focus does nothing. | 310 // Non-reopen focus does nothing. |
311 EXPECT_CALL(*handler_, OnShimFocus(&host_aa_, APP_SHIM_FOCUS_NORMAL, _)) | 311 EXPECT_CALL(*handler_, OnShimFocus(&host_aa_, APP_SHIM_FOCUS_NORMAL, _)) |
312 .WillOnce(Invoke(handler_.get(), | 312 .WillOnce(Invoke(handler_.get(), |
313 &TestingExtensionAppShimHandler::RealOnShimFocus)); | 313 &TestingExtensionAppShimHandler::RealOnShimFocus)); |
314 EXPECT_CALL(*delegate_, | 314 EXPECT_CALL(*delegate_, |
315 LaunchApp(&profile_a_, extension_a_.get(), _)) | 315 LaunchApp(&profile_a_, extension_a_.get(), _)) |
316 .Times(0); | 316 .Times(0); |
317 handler_->OnShimFocus(&host_aa_, | 317 handler_->OnShimFocus(&host_aa_, |
318 APP_SHIM_FOCUS_NORMAL, | 318 APP_SHIM_FOCUS_NORMAL, |
(...skipping 25 matching lines...) Expand all Loading... |
344 // Launch shims, adding entries in the map. | 344 // Launch shims, adding entries in the map. |
345 EXPECT_CALL(host_aa_, OnAppLaunchComplete(APP_SHIM_LAUNCH_SUCCESS)); | 345 EXPECT_CALL(host_aa_, OnAppLaunchComplete(APP_SHIM_LAUNCH_SUCCESS)); |
346 RegisterOnlyLaunch(&host_aa_); | 346 RegisterOnlyLaunch(&host_aa_); |
347 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA)); | 347 EXPECT_EQ(&host_aa_, handler_->FindHost(&profile_a_, kTestAppIdA)); |
348 | 348 |
349 EXPECT_CALL(host_ab_, OnAppLaunchComplete(APP_SHIM_LAUNCH_SUCCESS)); | 349 EXPECT_CALL(host_ab_, OnAppLaunchComplete(APP_SHIM_LAUNCH_SUCCESS)); |
350 RegisterOnlyLaunch(&host_ab_); | 350 RegisterOnlyLaunch(&host_ab_); |
351 EXPECT_EQ(&host_ab_, handler_->FindHost(&profile_a_, kTestAppIdB)); | 351 EXPECT_EQ(&host_ab_, handler_->FindHost(&profile_a_, kTestAppIdB)); |
352 | 352 |
353 // Return empty window list. | 353 // Return empty window list. |
354 ShellWindowList shell_window_list; | 354 AppWindowList app_window_list; |
355 EXPECT_CALL(*delegate_, GetWindows(_, _)) | 355 EXPECT_CALL(*delegate_, GetWindows(_, _)) |
356 .WillRepeatedly(Return(shell_window_list)); | 356 .WillRepeatedly(Return(app_window_list)); |
357 | 357 |
358 // Quitting when there's another shim should not terminate. | 358 // Quitting when there's another shim should not terminate. |
359 EXPECT_CALL(*delegate_, MaybeTerminate()) | 359 EXPECT_CALL(*delegate_, MaybeTerminate()) |
360 .Times(0); | 360 .Times(0); |
361 handler_->OnAppDeactivated(&profile_a_, kTestAppIdA); | 361 handler_->OnAppDeactivated(&profile_a_, kTestAppIdA); |
362 | 362 |
363 // Quitting when it's the last shim should terminate. | 363 // Quitting when it's the last shim should terminate. |
364 EXPECT_CALL(*delegate_, MaybeTerminate()); | 364 EXPECT_CALL(*delegate_, MaybeTerminate()); |
365 handler_->OnAppDeactivated(&profile_a_, kTestAppIdB); | 365 handler_->OnAppDeactivated(&profile_a_, kTestAppIdB); |
366 } | 366 } |
(...skipping 20 matching lines...) Expand all Loading... |
387 .WillRepeatedly(Return(&profile_a_)); | 387 .WillRepeatedly(Return(&profile_a_)); |
388 EXPECT_CALL(*delegate_, LoadProfileAsync(profile_path_a_, _)) | 388 EXPECT_CALL(*delegate_, LoadProfileAsync(profile_path_a_, _)) |
389 .WillOnce(Invoke(delegate_, &MockDelegate::CaptureLoadProfileCallback)); | 389 .WillOnce(Invoke(delegate_, &MockDelegate::CaptureLoadProfileCallback)); |
390 NormalLaunch(&host_aa_); | 390 NormalLaunch(&host_aa_); |
391 EXPECT_FALSE(handler_->FindHost(&profile_a_, kTestAppIdA)); | 391 EXPECT_FALSE(handler_->FindHost(&profile_a_, kTestAppIdA)); |
392 delegate_->RunLoadProfileCallback(profile_path_a_, &profile_a_); | 392 delegate_->RunLoadProfileCallback(profile_path_a_, &profile_a_); |
393 EXPECT_TRUE(handler_->FindHost(&profile_a_, kTestAppIdA)); | 393 EXPECT_TRUE(handler_->FindHost(&profile_a_, kTestAppIdA)); |
394 } | 394 } |
395 | 395 |
396 } // namespace apps | 396 } // namespace apps |
OLD | NEW |