| 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_lifetime_monitor_factory.h" | 8 #include "apps/app_lifetime_monitor_factory.h" |
| 9 #include "apps/switches.h" | 9 #include "apps/switches.h" |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/mac/foundation_util.h" | 11 #include "base/mac/foundation_util.h" |
| 12 #include "base/mac/launch_services_util.h" | 12 #import "base/mac/launch_services_util.h" |
| 13 #include "base/mac/mac_util.h" | 13 #include "base/mac/mac_util.h" |
| 14 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/process/launch.h" | 17 #include "base/process/launch.h" |
| 18 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
| 19 #include "base/test/test_timeouts.h" | 19 #include "base/test/test_timeouts.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "chrome/browser/apps/app_browsertest_util.h" | 21 #include "chrome/browser/apps/app_browsertest_util.h" |
| 22 #include "chrome/browser/apps/app_shim/app_shim_handler_mac.h" | 22 #include "chrome/browser/apps/app_shim/app_shim_handler_mac.h" |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 | 323 |
| 324 EXPECT_FALSE(GetFirstHostedAppWindow()); | 324 EXPECT_FALSE(GetFirstHostedAppWindow()); |
| 325 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); | 325 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
| 326 } | 326 } |
| 327 | 327 |
| 328 // Case 2: Launch the shim, it should start the hosted app. | 328 // Case 2: Launch the shim, it should start the hosted app. |
| 329 { | 329 { |
| 330 HostedAppBrowserListObserver listener(app->id()); | 330 HostedAppBrowserListObserver listener(app->id()); |
| 331 base::CommandLine shim_cmdline(base::CommandLine::NO_PROGRAM); | 331 base::CommandLine shim_cmdline(base::CommandLine::NO_PROGRAM); |
| 332 shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest); | 332 shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest); |
| 333 ProcessSerialNumber shim_psn; | 333 base::Process shim_process = base::mac::OpenApplicationWithPath( |
| 334 ASSERT_TRUE(base::mac::OpenApplicationWithPath( | 334 shim_path_, shim_cmdline, NSWorkspaceLaunchDefault); |
| 335 shim_path_, shim_cmdline, kLSLaunchDefaults, &shim_psn)); | 335 ASSERT_TRUE(shim_process.IsValid()); |
| 336 listener.WaitUntilAdded(); | 336 listener.WaitUntilAdded(); |
| 337 | 337 |
| 338 ASSERT_TRUE(GetFirstHostedAppWindow()); | 338 ASSERT_TRUE(GetFirstHostedAppWindow()); |
| 339 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); | 339 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); |
| 340 | 340 |
| 341 // If the window is closed, the shim should quit. | 341 // If the window is closed, the shim should quit. |
| 342 pid_t shim_pid; | |
| 343 EXPECT_EQ(noErr, GetProcessPID(&shim_psn, &shim_pid)); | |
| 344 GetFirstHostedAppWindow()->window()->Close(); | 342 GetFirstHostedAppWindow()->window()->Close(); |
| 345 // Wait for the window to be closed. | 343 // Wait for the window to be closed. |
| 346 listener.WaitUntilRemoved(); | 344 listener.WaitUntilRemoved(); |
| 347 base::Process shim_process(shim_pid); | |
| 348 int exit_code; | 345 int exit_code; |
| 349 ASSERT_TRUE(shim_process.WaitForExitWithTimeout( | 346 ASSERT_TRUE(shim_process.WaitForExitWithTimeout( |
| 350 TestTimeouts::action_timeout(), &exit_code)); | 347 TestTimeouts::action_timeout(), &exit_code)); |
| 351 | 348 |
| 352 EXPECT_FALSE(GetFirstHostedAppWindow()); | 349 EXPECT_FALSE(GetFirstHostedAppWindow()); |
| 353 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); | 350 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
| 354 } | 351 } |
| 355 } | 352 } |
| 356 | 353 |
| 357 // Test that launching the shim for an app starts the app, and vice versa. | 354 // Test that launching the shim for an app starts the app, and vice versa. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 | 392 |
| 396 EXPECT_FALSE(GetFirstAppWindow()); | 393 EXPECT_FALSE(GetFirstAppWindow()); |
| 397 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); | 394 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
| 398 } | 395 } |
| 399 | 396 |
| 400 // Case 2: Launch the shim, it should start the app. | 397 // Case 2: Launch the shim, it should start the app. |
| 401 { | 398 { |
| 402 ExtensionTestMessageListener launched_listener("Launched", false); | 399 ExtensionTestMessageListener launched_listener("Launched", false); |
| 403 base::CommandLine shim_cmdline(base::CommandLine::NO_PROGRAM); | 400 base::CommandLine shim_cmdline(base::CommandLine::NO_PROGRAM); |
| 404 shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest); | 401 shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest); |
| 405 ProcessSerialNumber shim_psn; | 402 base::Process shim_process = base::mac::OpenApplicationWithPath( |
| 406 ASSERT_TRUE(base::mac::OpenApplicationWithPath( | 403 shim_path_, shim_cmdline, NSWorkspaceLaunchDefault); |
| 407 shim_path_, shim_cmdline, kLSLaunchDefaults, &shim_psn)); | 404 ASSERT_TRUE(shim_process.IsValid()); |
| 408 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 405 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 409 | 406 |
| 410 ASSERT_TRUE(GetFirstAppWindow()); | 407 ASSERT_TRUE(GetFirstAppWindow()); |
| 411 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); | 408 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); |
| 412 | 409 |
| 413 // If the window is closed, the shim should quit. | 410 // If the window is closed, the shim should quit. |
| 414 pid_t shim_pid; | |
| 415 EXPECT_EQ(noErr, GetProcessPID(&shim_psn, &shim_pid)); | |
| 416 GetFirstAppWindow()->GetBaseWindow()->Close(); | 411 GetFirstAppWindow()->GetBaseWindow()->Close(); |
| 417 base::Process shim_process(shim_pid); | |
| 418 int exit_code; | 412 int exit_code; |
| 419 ASSERT_TRUE(shim_process.WaitForExitWithTimeout( | 413 ASSERT_TRUE(shim_process.WaitForExitWithTimeout( |
| 420 TestTimeouts::action_timeout(), &exit_code)); | 414 TestTimeouts::action_timeout(), &exit_code)); |
| 421 | 415 |
| 422 EXPECT_FALSE(GetFirstAppWindow()); | 416 EXPECT_FALSE(GetFirstAppWindow()); |
| 423 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); | 417 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
| 424 } | 418 } |
| 425 } | 419 } |
| 426 | 420 |
| 427 // Test that the shim's lifetime depends on the visibility of windows. I.e. the | 421 // Test that the shim's lifetime depends on the visibility of windows. I.e. the |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 // This actually happens in multiple launches of the shim: | 597 // This actually happens in multiple launches of the shim: |
| 604 // (1) The shim will fail and instead launch Chrome with --app-id so that the | 598 // (1) The shim will fail and instead launch Chrome with --app-id so that the |
| 605 // app starts. | 599 // app starts. |
| 606 // (2) Chrome launches the shim in response to an app starting, this time the | 600 // (2) Chrome launches the shim in response to an app starting, this time the |
| 607 // shim launches Chrome with --app-shim-error, which causes Chrome to | 601 // shim launches Chrome with --app-shim-error, which causes Chrome to |
| 608 // rebuild the shim. | 602 // rebuild the shim. |
| 609 // (3) After rebuilding, Chrome again launches the shim and expects it to | 603 // (3) After rebuilding, Chrome again launches the shim and expects it to |
| 610 // behave normally. | 604 // behave normally. |
| 611 ExtensionTestMessageListener launched_listener("Launched", false); | 605 ExtensionTestMessageListener launched_listener("Launched", false); |
| 612 base::CommandLine shim_cmdline(base::CommandLine::NO_PROGRAM); | 606 base::CommandLine shim_cmdline(base::CommandLine::NO_PROGRAM); |
| 613 ASSERT_TRUE(base::mac::OpenApplicationWithPath( | 607 base::Process shim_process = base::mac::OpenApplicationWithPath( |
| 614 shim_path, shim_cmdline, kLSLaunchDefaults, NULL)); | 608 shim_path, shim_cmdline, NSWorkspaceLaunchDefault); |
| 609 ASSERT_TRUE(shim_process.IsValid()); |
| 615 | 610 |
| 616 // Wait for the app to start (1). At this point there is no shim host. | 611 // Wait for the app to start (1). At this point there is no shim host. |
| 617 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 612 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 618 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); | 613 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
| 619 | 614 |
| 620 // Wait for the rebuilt shim to connect (3). This does not race with the app | 615 // Wait for the rebuilt shim to connect (3). This does not race with the app |
| 621 // starting (1) because Chrome only launches the shim (2) after the app | 616 // starting (1) because Chrome only launches the shim (2) after the app |
| 622 // starts. Then Chrome must handle --app-shim-error on the UI thread before | 617 // starts. Then Chrome must handle --app-shim-error on the UI thread before |
| 623 // the shim is rebuilt. | 618 // the shim is rebuilt. |
| 624 WindowedAppShimLaunchObserver(app->id()).Wait(); | 619 WindowedAppShimLaunchObserver(app->id()).Wait(); |
| 625 | 620 |
| 626 EXPECT_TRUE(GetFirstAppWindow()); | 621 EXPECT_TRUE(GetFirstAppWindow()); |
| 627 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); | 622 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); |
| 628 } | 623 } |
| 629 | 624 |
| 630 #endif // defined(ARCH_CPU_64_BITS) | 625 #endif // defined(ARCH_CPU_64_BITS) |
| 631 | 626 |
| 632 } // namespace apps | 627 } // namespace apps |
| OLD | NEW |