| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #import <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "apps/app_shim/app_shim_handler_mac.h" | 8 #include "apps/app_shim/app_shim_handler_mac.h" |
| 9 #include "apps/app_shim/app_shim_host_manager_mac.h" | 9 #include "apps/app_shim/app_shim_host_manager_mac.h" |
| 10 #include "apps/app_shim/extension_app_shim_handler_mac.h" | 10 #include "apps/app_shim/extension_app_shim_handler_mac.h" |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 | 219 |
| 220 @end | 220 @end |
| 221 | 221 |
| 222 namespace apps { | 222 namespace apps { |
| 223 | 223 |
| 224 // Shims require static libraries http://crbug.com/386024. | 224 // Shims require static libraries http://crbug.com/386024. |
| 225 #if defined(COMPONENT_BUILD) | 225 #if defined(COMPONENT_BUILD) |
| 226 #define MAYBE_Launch DISABLED_Launch | 226 #define MAYBE_Launch DISABLED_Launch |
| 227 #define MAYBE_RebuildShim DISABLED_RebuildShim | 227 #define MAYBE_RebuildShim DISABLED_RebuildShim |
| 228 #else | 228 #else |
| 229 // Launch is flaky http://crbug.com/415422. | 229 #define MAYBE_Launch Launch |
| 230 #define MAYBE_Launch DISABLED_Launch | |
| 231 #define MAYBE_RebuildShim RebuildShim | 230 #define MAYBE_RebuildShim RebuildShim |
| 232 #endif | 231 #endif |
| 233 | 232 |
| 234 // Test that launching the shim for an app starts the app, and vice versa. | 233 // Test that launching the shim for an app starts the app, and vice versa. |
| 235 // These two cases are combined because the time to run the test is dominated | 234 // These two cases are combined because the time to run the test is dominated |
| 236 // by loading the extension and creating the shim. | 235 // by loading the extension and creating the shim. |
| 237 IN_PROC_BROWSER_TEST_F(AppShimInteractiveTest, MAYBE_Launch) { | 236 IN_PROC_BROWSER_TEST_F(AppShimInteractiveTest, MAYBE_Launch) { |
| 238 // Install the app. | 237 // Install the app. |
| 239 const extensions::Extension* app = InstallPlatformApp("minimal"); | 238 const extensions::Extension* app = InstallPlatformApp("minimal"); |
| 240 | 239 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 251 // attempting to launch it. Since all of the file operations are done in the | 250 // attempting to launch it. Since all of the file operations are done in the |
| 252 // same event on the FILE thread, everything will be done by the time the | 251 // same event on the FILE thread, everything will be done by the time the |
| 253 // watcher's callback is executed. | 252 // watcher's callback is executed. |
| 254 scoped_refptr<WindowedFilePathWatcher> file_watcher = | 253 scoped_refptr<WindowedFilePathWatcher> file_watcher = |
| 255 new WindowedFilePathWatcher(shim_path); | 254 new WindowedFilePathWatcher(shim_path); |
| 256 web_app::UpdateAllShortcuts(base::string16(), profile(), app); | 255 web_app::UpdateAllShortcuts(base::string16(), profile(), app); |
| 257 file_watcher->Wait(); | 256 file_watcher->Wait(); |
| 258 ASSERT_TRUE(base::PathExists(shim_path)); | 257 ASSERT_TRUE(base::PathExists(shim_path)); |
| 259 NSString* bundle_id = GetBundleID(shim_path); | 258 NSString* bundle_id = GetBundleID(shim_path); |
| 260 | 259 |
| 261 // Case 1: Launch the shim, it should start the app. | 260 // Case 1: Launch the app, it should start the shim. |
| 262 { | |
| 263 ExtensionTestMessageListener launched_listener("Launched", false); | |
| 264 CommandLine shim_cmdline(CommandLine::NO_PROGRAM); | |
| 265 shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest); | |
| 266 ProcessSerialNumber shim_psn; | |
| 267 ASSERT_TRUE(base::mac::OpenApplicationWithPath( | |
| 268 shim_path, shim_cmdline, kLSLaunchDefaults, &shim_psn)); | |
| 269 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | |
| 270 | |
| 271 ASSERT_TRUE(GetFirstAppWindow()); | |
| 272 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); | |
| 273 | |
| 274 // If the window is closed, the shim should quit. | |
| 275 pid_t shim_pid; | |
| 276 EXPECT_EQ(noErr, GetProcessPID(&shim_psn, &shim_pid)); | |
| 277 GetFirstAppWindow()->GetBaseWindow()->Close(); | |
| 278 ASSERT_TRUE( | |
| 279 base::WaitForSingleProcess(shim_pid, TestTimeouts::action_timeout())); | |
| 280 | |
| 281 EXPECT_FALSE(GetFirstAppWindow()); | |
| 282 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); | |
| 283 } | |
| 284 | |
| 285 // Case 2: Launch the app, it should start the shim. | |
| 286 { | 261 { |
| 287 base::scoped_nsobject<WindowedNSNotificationObserver> ns_observer; | 262 base::scoped_nsobject<WindowedNSNotificationObserver> ns_observer; |
| 288 ns_observer.reset([[WindowedNSNotificationObserver alloc] | 263 ns_observer.reset([[WindowedNSNotificationObserver alloc] |
| 289 initForNotification:NSWorkspaceDidLaunchApplicationNotification | 264 initForNotification:NSWorkspaceDidLaunchApplicationNotification |
| 290 andBundleId:bundle_id]); | 265 andBundleId:bundle_id]); |
| 291 WindowedAppShimLaunchObserver observer(app->id()); | 266 WindowedAppShimLaunchObserver observer(app->id()); |
| 292 LaunchPlatformApp(app); | 267 LaunchPlatformApp(app); |
| 293 [ns_observer wait]; | 268 [ns_observer wait]; |
| 294 observer.Wait(); | 269 observer.Wait(); |
| 295 | 270 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 308 ns_observer.reset([[WindowedNSNotificationObserver alloc] | 283 ns_observer.reset([[WindowedNSNotificationObserver alloc] |
| 309 initForNotification:NSWorkspaceDidTerminateApplicationNotification | 284 initForNotification:NSWorkspaceDidTerminateApplicationNotification |
| 310 andBundleId:bundle_id]); | 285 andBundleId:bundle_id]); |
| 311 [base::mac::ObjCCastStrict<NSRunningApplication>( | 286 [base::mac::ObjCCastStrict<NSRunningApplication>( |
| 312 [running_shim objectAtIndex:0]) terminate]; | 287 [running_shim objectAtIndex:0]) terminate]; |
| 313 [ns_observer wait]; | 288 [ns_observer wait]; |
| 314 | 289 |
| 315 EXPECT_FALSE(GetFirstAppWindow()); | 290 EXPECT_FALSE(GetFirstAppWindow()); |
| 316 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); | 291 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
| 317 } | 292 } |
| 293 |
| 294 // Case 2: Launch the shim, it should start the app. |
| 295 { |
| 296 ExtensionTestMessageListener launched_listener("Launched", false); |
| 297 CommandLine shim_cmdline(CommandLine::NO_PROGRAM); |
| 298 shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest); |
| 299 ProcessSerialNumber shim_psn; |
| 300 ASSERT_TRUE(base::mac::OpenApplicationWithPath( |
| 301 shim_path, shim_cmdline, kLSLaunchDefaults, &shim_psn)); |
| 302 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 303 |
| 304 ASSERT_TRUE(GetFirstAppWindow()); |
| 305 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); |
| 306 |
| 307 // If the window is closed, the shim should quit. |
| 308 pid_t shim_pid; |
| 309 EXPECT_EQ(noErr, GetProcessPID(&shim_psn, &shim_pid)); |
| 310 GetFirstAppWindow()->GetBaseWindow()->Close(); |
| 311 ASSERT_TRUE( |
| 312 base::WaitForSingleProcess(shim_pid, TestTimeouts::action_timeout())); |
| 313 |
| 314 EXPECT_FALSE(GetFirstAppWindow()); |
| 315 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
| 316 } |
| 318 } | 317 } |
| 319 | 318 |
| 320 #if defined(ARCH_CPU_64_BITS) | 319 #if defined(ARCH_CPU_64_BITS) |
| 321 | 320 |
| 322 // Tests that a 32 bit shim attempting to launch 64 bit Chrome will eventually | 321 // Tests that a 32 bit shim attempting to launch 64 bit Chrome will eventually |
| 323 // be rebuilt. | 322 // be rebuilt. |
| 324 IN_PROC_BROWSER_TEST_F(AppShimInteractiveTest, MAYBE_RebuildShim) { | 323 IN_PROC_BROWSER_TEST_F(AppShimInteractiveTest, MAYBE_RebuildShim) { |
| 325 // Get the 32 bit shim. | 324 // Get the 32 bit shim. |
| 326 base::FilePath test_data_dir; | 325 base::FilePath test_data_dir; |
| 327 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 326 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 // the shim is rebuilt. | 398 // the shim is rebuilt. |
| 400 WindowedAppShimLaunchObserver(app->id()).Wait(); | 399 WindowedAppShimLaunchObserver(app->id()).Wait(); |
| 401 | 400 |
| 402 EXPECT_TRUE(GetFirstAppWindow()); | 401 EXPECT_TRUE(GetFirstAppWindow()); |
| 403 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); | 402 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); |
| 404 } | 403 } |
| 405 | 404 |
| 406 #endif // defined(ARCH_CPU_64_BITS) | 405 #endif // defined(ARCH_CPU_64_BITS) |
| 407 | 406 |
| 408 } // namespace apps | 407 } // namespace apps |
| OLD | NEW |