Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: apps/app_shim/app_shim_interactive_uitest_mac.mm

Issue 316493002: [Mac] Add interactive App Shim test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // 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.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // 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.
6
7 #import <Cocoa/Cocoa.h>
8 #include <vector>
9
10 #include "apps/app_shim/app_shim_host_manager_mac.h"
11 #include "apps/app_shim/extension_app_shim_handler_mac.h"
12 #include "apps/switches.h"
13 #include "apps/ui/native_app_window.h"
14 #include "base/auto_reset.h"
15 #include "base/mac/foundation_util.h"
16 #include "base/mac/launch_services_util.h"
17 #include "base/path_service.h"
18 #include "base/process/launch.h"
19 #include "base/strings/sys_string_conversions.h"
20 #include "base/test/test_timeouts.h"
21 #include "chrome/browser/apps/app_browsertest_util.h"
22 #include "chrome/browser/browser_process.h"
23 #include "chrome/browser/extensions/extension_test_message_listener.h"
24 #include "chrome/browser/profiles/profile.h"
25 #include "chrome/browser/web_applications/web_app_mac.h"
26 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/chrome_switches.h"
28 #include "chrome/common/mac/app_mode_common.h"
29 #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.
30 #include "content/public/test/test_utils.h"
31 #include "extensions/browser/extension_registry.h"
32 #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.
33
34 using extensions::PlatformAppBrowserTest;
35
36 namespace apps {
37
38 namespace {
39
40 class AppShimInteractiveTest : public PlatformAppBrowserTest {
41 protected:
42 AppShimInteractiveTest()
43 : auto_reset_(&g_app_shims_enable_internal_for_test, true) {}
44
45 // Temporarily enable app shims.
46 base::AutoReset<bool> auto_reset_;
47
48 DISALLOW_COPY_AND_ASSIGN(AppShimInteractiveTest);
49 };
50
51 NSString* GetBundleID(const base::FilePath& shim_path) {
52 NSString* plist_path = base::mac::FilePathToNSString(
53 shim_path.Append("Contents").Append("Info.plist"));
54 return [[NSMutableDictionary dictionaryWithContentsOfFile:plist_path]
55 objectForKey:base::mac::CFToNSCast(kCFBundleIdentifierKey)];
56 }
57
58 bool HasAppShimHost(Profile* profile, const std::string& app_id) {
59 return g_browser_process->platform_part()->app_shim_host_manager()->
60 extension_app_shim_handler()->FindHost(profile, app_id);
61 }
62
63 } // namespace
64
65 // Test that launching the shim for an app starts the app, and vice versa.
66 // These two cases are combined because the time to run the test is dominated
67 // by loading the extension and creating the shim.
68 IN_PROC_BROWSER_TEST_F(AppShimInteractiveTest, Launch) {
69 // Create the internal app shim.
70 const extensions::Extension* app = InstallPlatformApp("minimal");
71
72 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
73 web_app::GetWebAppDataDirectory(profile()->GetPath(), app->id(), GURL()),
74 web_app::ShortcutInfoForExtensionAndProfile(app, profile()),
75 extensions::FileHandlersInfo());
76 base::FilePath shim_path = shortcut_creator.GetInternalShortcutPath();
77
78 EXPECT_FALSE(base::PathExists(shim_path));
79 web_app::UpdateAllShortcuts(base::string16(), profile(), app);
80 // Setting the bundle id to the internal bundle id is the last thing done to
81 // the shim. We must wait for this to complete otherwise the shim may not
82 // launch.
83 NSString* bundle_id = GetBundleID(shim_path);
84 while (![bundle_id hasSuffix:@"-internal"]) {
85 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
86 bundle_id = GetBundleID(shim_path);
87 }
88
89 // Case 1: Launch the shim, it should start the app.
90 ExtensionTestMessageListener launched_listener("Launched", false);
91 CommandLine shim_cmdline(CommandLine::NO_PROGRAM);
92 shim_cmdline.AppendSwitch(app_mode::kLaunchedForTest);
93 ProcessSerialNumber shim_psn;
94 ASSERT_TRUE(base::mac::OpenApplicationWithPath(
95 shim_path, shim_cmdline, kLSLaunchDefaults, &shim_psn));
96 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
97
98 EXPECT_TRUE(HasAppShimHost(profile(), app->id()));
99
100 // If the window is closed, the shim should quit.
101 pid_t shim_pid;
102 EXPECT_EQ(noErr, GetProcessPID(&shim_psn, &shim_pid));
103 GetFirstAppWindow()->GetBaseWindow()->Close();
104 ASSERT_TRUE(base::WaitForSingleProcess(
105 shim_pid, TestTimeouts::action_timeout()));
106
107 EXPECT_FALSE(HasAppShimHost(profile(), app->id()));
108
109 // Case 2: Launch the app, it should start the shim.
110 LaunchPlatformApp(app);
111 while (!HasAppShimHost(profile(), app->id()))
112 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
113
114 // Quitting the shim eventually closes the app.
115 NSArray* running_shim = [NSRunningApplication
116 runningApplicationsWithBundleIdentifier:bundle_id];
117 if ([running_shim count] > 0) {
118 [base::mac::ObjCCastStrict<NSRunningApplication>(
119 [running_shim objectAtIndex:0]) terminate];
120 }
121
122 while ([[NSRunningApplication
123 runningApplicationsWithBundleIdentifier:bundle_id] count]) {
124 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.
125 }
126
127 EXPECT_FALSE(GetFirstAppWindow());
128 }
129
130 } // namespace apps
OLDNEW
« no previous file with comments | « no previous file | apps/app_shim/chrome_main_app_mode_mac.mm » ('j') | chrome/browser/web_applications/web_app_mac.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698