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 pid_t shim_pid = -1; |
334 ASSERT_TRUE(base::mac::OpenApplicationWithPath( | 334 ASSERT_TRUE(base::mac::OpenApplicationWithPath( |
335 shim_path_, shim_cmdline, kLSLaunchDefaults, &shim_psn)); | 335 shim_path_, shim_cmdline, NSWorkspaceLaunchDefault, &shim_pid)); |
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); | 345 base::Process shim_process(shim_pid); |
348 int exit_code; | 346 int exit_code; |
349 ASSERT_TRUE(shim_process.WaitForExitWithTimeout( | 347 ASSERT_TRUE(shim_process.WaitForExitWithTimeout( |
350 TestTimeouts::action_timeout(), &exit_code)); | 348 TestTimeouts::action_timeout(), &exit_code)); |
351 | 349 |
352 EXPECT_FALSE(GetFirstHostedAppWindow()); | 350 EXPECT_FALSE(GetFirstHostedAppWindow()); |
353 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); | 351 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 | 393 |
396 EXPECT_FALSE(GetFirstAppWindow()); | 394 EXPECT_FALSE(GetFirstAppWindow()); |
397 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); | 395 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
398 } | 396 } |
399 | 397 |
400 // Case 2: Launch the shim, it should start the app. | 398 // Case 2: Launch the shim, it should start the app. |
401 { | 399 { |
402 ExtensionTestMessageListener launched_listener("Launched", false); | 400 ExtensionTestMessageListener launched_listener("Launched", false); |
403 base::CommandLine shim_cmdline(base::CommandLine::NO_PROGRAM); | 401 base::CommandLine shim_cmdline(base::CommandLine::NO_PROGRAM); |
404 shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest); | 402 shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest); |
405 ProcessSerialNumber shim_psn; | 403 pid_t shim_pid = -1; |
406 ASSERT_TRUE(base::mac::OpenApplicationWithPath( | 404 ASSERT_TRUE(base::mac::OpenApplicationWithPath( |
407 shim_path_, shim_cmdline, kLSLaunchDefaults, &shim_psn)); | 405 shim_path_, shim_cmdline, NSWorkspaceLaunchDefault, &shim_pid)); |
408 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 406 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
409 | 407 |
410 ASSERT_TRUE(GetFirstAppWindow()); | 408 ASSERT_TRUE(GetFirstAppWindow()); |
411 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); | 409 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); |
412 | 410 |
413 // If the window is closed, the shim should quit. | 411 // 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(); | 412 GetFirstAppWindow()->GetBaseWindow()->Close(); |
417 base::Process shim_process(shim_pid); | 413 base::Process shim_process(shim_pid); |
418 int exit_code; | 414 int exit_code; |
419 ASSERT_TRUE(shim_process.WaitForExitWithTimeout( | 415 ASSERT_TRUE(shim_process.WaitForExitWithTimeout( |
420 TestTimeouts::action_timeout(), &exit_code)); | 416 TestTimeouts::action_timeout(), &exit_code)); |
421 | 417 |
422 EXPECT_FALSE(GetFirstAppWindow()); | 418 EXPECT_FALSE(GetFirstAppWindow()); |
423 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); | 419 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
424 } | 420 } |
425 } | 421 } |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
604 // (1) The shim will fail and instead launch Chrome with --app-id so that the | 600 // (1) The shim will fail and instead launch Chrome with --app-id so that the |
605 // app starts. | 601 // app starts. |
606 // (2) Chrome launches the shim in response to an app starting, this time the | 602 // (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 | 603 // shim launches Chrome with --app-shim-error, which causes Chrome to |
608 // rebuild the shim. | 604 // rebuild the shim. |
609 // (3) After rebuilding, Chrome again launches the shim and expects it to | 605 // (3) After rebuilding, Chrome again launches the shim and expects it to |
610 // behave normally. | 606 // behave normally. |
611 ExtensionTestMessageListener launched_listener("Launched", false); | 607 ExtensionTestMessageListener launched_listener("Launched", false); |
612 base::CommandLine shim_cmdline(base::CommandLine::NO_PROGRAM); | 608 base::CommandLine shim_cmdline(base::CommandLine::NO_PROGRAM); |
613 ASSERT_TRUE(base::mac::OpenApplicationWithPath( | 609 ASSERT_TRUE(base::mac::OpenApplicationWithPath( |
614 shim_path, shim_cmdline, kLSLaunchDefaults, NULL)); | 610 shim_path, shim_cmdline, NSWorkspaceLaunchDefault, nullptr)); |
615 | 611 |
616 // Wait for the app to start (1). At this point there is no shim host. | 612 // Wait for the app to start (1). At this point there is no shim host. |
617 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 613 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
618 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); | 614 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
619 | 615 |
620 // Wait for the rebuilt shim to connect (3). This does not race with the app | 616 // 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 | 617 // 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 | 618 // starts. Then Chrome must handle --app-shim-error on the UI thread before |
623 // the shim is rebuilt. | 619 // the shim is rebuilt. |
624 WindowedAppShimLaunchObserver(app->id()).Wait(); | 620 WindowedAppShimLaunchObserver(app->id()).Wait(); |
625 | 621 |
626 EXPECT_TRUE(GetFirstAppWindow()); | 622 EXPECT_TRUE(GetFirstAppWindow()); |
627 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); | 623 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); |
628 } | 624 } |
629 | 625 |
630 #endif // defined(ARCH_CPU_64_BITS) | 626 #endif // defined(ARCH_CPU_64_BITS) |
631 | 627 |
632 } // namespace apps | 628 } // namespace apps |
OLD | NEW |