Chromium Code Reviews| Index: apps/app_shim/app_shim_interactive_uitest_mac.mm |
| diff --git a/apps/app_shim/app_shim_interactive_uitest_mac.mm b/apps/app_shim/app_shim_interactive_uitest_mac.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e84e68472cad700aafe721f2820f8268ce38659d |
| --- /dev/null |
| +++ b/apps/app_shim/app_shim_interactive_uitest_mac.mm |
| @@ -0,0 +1,130 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
|
tapted
2014/06/03 07:32:39
nit: 2013 -> 2014
jackhou1
2014/06/04 06:55:40
Done.
|
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// General end-to-end test for app shims. |
|
tapted
2014/06/03 07:32:39
nit: maybe move this down to the class declaration
jackhou1
2014/06/04 06:55:40
Done.
|
| + |
| +#import <Cocoa/Cocoa.h> |
| +#include <vector> |
| + |
| +#include "apps/app_shim/app_shim_host_manager_mac.h" |
| +#include "apps/app_shim/extension_app_shim_handler_mac.h" |
| +#include "apps/switches.h" |
| +#include "apps/ui/native_app_window.h" |
| +#include "base/auto_reset.h" |
| +#include "base/mac/foundation_util.h" |
| +#include "base/mac/launch_services_util.h" |
| +#include "base/path_service.h" |
| +#include "base/process/launch.h" |
| +#include "base/strings/sys_string_conversions.h" |
| +#include "base/test/test_timeouts.h" |
| +#include "chrome/browser/apps/app_browsertest_util.h" |
| +#include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/extensions/extension_test_message_listener.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/web_applications/web_app_mac.h" |
| +#include "chrome/common/chrome_paths.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "chrome/common/mac/app_mode_common.h" |
| +#include "chrome/test/base/interactive_test_utils.h" |
|
tapted
2014/06/03 07:32:39
did you end up using anything in here?
jackhou1
2014/06/04 06:55:40
Nope.
|
| +#include "content/public/test/test_utils.h" |
| +#include "extensions/browser/extension_registry.h" |
| +#include "ui/events/test/cocoa_test_event_utils.h" |
|
tapted
2014/06/03 07:32:39
nit: import this one - the rest are agnostic I thi
jackhou1
2014/06/04 06:55:40
Done.
|
| + |
| +using extensions::PlatformAppBrowserTest; |
| + |
| +namespace apps { |
| + |
| +namespace { |
| + |
| +class AppShimInteractiveTest : public PlatformAppBrowserTest { |
| + protected: |
| + AppShimInteractiveTest() |
| + : auto_reset_(&g_app_shims_enable_internal_for_test, true) {} |
| + |
| + // Temporarily enable app shims. |
| + base::AutoReset<bool> auto_reset_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AppShimInteractiveTest); |
| +}; |
| + |
| +NSString* GetBundleID(const base::FilePath& shim_path) { |
| + NSString* plist_path = base::mac::FilePathToNSString( |
| + shim_path.Append("Contents").Append("Info.plist")); |
| + return [[NSMutableDictionary dictionaryWithContentsOfFile:plist_path] |
| + objectForKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)]; |
| +} |
| + |
| +bool HasAppShimHost(Profile* profile, const std::string& app_id) { |
| + return g_browser_process->platform_part()->app_shim_host_manager()-> |
| + extension_app_shim_handler()->FindHost(profile, app_id); |
| +} |
| + |
| +} // namespace |
| + |
| +// Test that launching the shim for an app starts the app, and vice versa. |
| +// These two cases are combined because the time to run the test is dominated |
| +// by loading the extension and creating the shim. |
| +IN_PROC_BROWSER_TEST_F(AppShimInteractiveTest, Launch) { |
| + // Create the internal app shim. |
| + const extensions::Extension* app = InstallPlatformApp("minimal"); |
| + |
| + web_app::WebAppShortcutCreator shortcut_creator( |
|
tapted
2014/06/03 07:32:39
nit: perhaps a comment: ~use the shortcut creator
jackhou1
2014/06/04 06:55:40
This WebAppShortcutCreator is only used to get the
|
| + web_app::GetWebAppDataDirectory(profile()->GetPath(), app->id(), GURL()), |
| + web_app::ShortcutInfoForExtensionAndProfile(app, profile()), |
| + extensions::FileHandlersInfo()); |
| + base::FilePath shim_path = shortcut_creator.GetInternalShortcutPath(); |
| + |
| + EXPECT_FALSE(base::PathExists(shim_path)); |
| + web_app::UpdateAllShortcuts(base::string16(), profile(), app); |
| + // Setting the bundle id to the internal bundle id is the last thing done to |
| + // the shim. We must wait for this to complete otherwise the shim may not |
| + // launch. |
| + NSString* bundle_id = GetBundleID(shim_path); |
| + while (![bundle_id hasSuffix:@"-internal"]) { |
| + content::RunAllPendingInMessageLoop(); |
|
tapted
2014/06/03 07:32:39
I think this will spin on the CPU, which isn't nic
jackhou1
2014/06/04 06:55:40
I do actually call web_app::UpdateAllShortcuts (ra
|
| + bundle_id = GetBundleID(shim_path); |
| + } |
| + |
| + // Case 1: Launch the shim, it should start the app. |
| + ExtensionTestMessageListener launched_listener("Launched", false); |
| + CommandLine shim_cmdline(CommandLine::NO_PROGRAM); |
| + shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest); |
| + ProcessSerialNumber shim_psn; |
| + ASSERT_TRUE(base::mac::OpenApplicationWithPath( |
| + shim_path, shim_cmdline, kLSLaunchDefaults, &shim_psn)); |
| + ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| + |
| + EXPECT_TRUE(HasAppShimHost(profile(), app->id())); |
| + |
| + // If the window is closed, the shim should quit. |
| + pid_t shim_pid; |
| + EXPECT_EQ(noErr, GetProcessPID(&shim_psn, &shim_pid)); |
| + GetFirstAppWindow()->GetBaseWindow()->Close(); |
| + ASSERT_TRUE(base::WaitForSingleProcess( |
| + shim_pid, TestTimeouts::action_timeout())); |
| + |
| + EXPECT_FALSE(HasAppShimHost(profile(), app->id())); |
| + |
| + // Case 2: Launch the app, it should start the shim. |
| + LaunchPlatformApp(app); |
| + while (!HasAppShimHost(profile(), app->id())) |
| + content::RunAllPendingInMessageLoop(); |
|
tapted
2014/06/03 07:32:39
Same thing here - you can't spin the UI thread lik
jackhou1
2014/06/04 06:55:40
The shim is not launched until after the app start
|
| + |
| + // Quitting the shim eventually closes the app. |
| + NSArray* running_shim = [NSRunningApplication |
| + runningApplicationsWithBundleIdentifier:bundle_id]; |
| + if ([running_shim count] > 0) { |
| + [base::mac::ObjCCastStrict<NSRunningApplication>( |
| + [running_shim objectAtIndex:0]) terminate]; |
| + } |
| + |
| + while ([[NSRunningApplication |
| + runningApplicationsWithBundleIdentifier:bundle_id] count]) { |
| + content::RunAllPendingInMessageLoop(); |
|
tapted
2014/06/03 07:32:39
For this one, you could create a scoped_nsobject c
jackhou1
2014/06/04 06:55:40
Done.
|
| + } |
| + |
| + EXPECT_FALSE(GetFirstAppWindow()); |
| +} |
| + |
| +} // namespace apps |