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

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

Issue 345493004: [Mac] App shim error test. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Sync and rebase 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
« no previous file with comments | « no previous file | chrome/test/data/app_shim/app_shim_32_bit.app.dSYM/Contents/Info.plist » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "apps/switches.h" 11 #include "apps/switches.h"
12 #include "apps/ui/native_app_window.h" 12 #include "apps/ui/native_app_window.h"
13 #include "base/auto_reset.h" 13 #include "base/auto_reset.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/files/file_path_watcher.h" 15 #include "base/files/file_path_watcher.h"
16 #include "base/mac/foundation_util.h" 16 #include "base/mac/foundation_util.h"
17 #include "base/mac/launch_services_util.h" 17 #include "base/mac/launch_services_util.h"
18 #include "base/mac/mac_util.h"
18 #include "base/mac/scoped_nsobject.h" 19 #include "base/mac/scoped_nsobject.h"
19 #include "base/path_service.h" 20 #include "base/path_service.h"
20 #include "base/process/launch.h" 21 #include "base/process/launch.h"
21 #include "base/strings/sys_string_conversions.h" 22 #include "base/strings/sys_string_conversions.h"
22 #include "base/test/test_timeouts.h" 23 #include "base/test/test_timeouts.h"
23 #include "chrome/browser/apps/app_browsertest_util.h" 24 #include "chrome/browser/apps/app_browsertest_util.h"
24 #include "chrome/browser/browser_process.h" 25 #include "chrome/browser/browser_process.h"
25 #include "chrome/browser/extensions/extension_test_message_listener.h" 26 #include "chrome/browser/extensions/extension_test_message_listener.h"
26 #include "chrome/browser/profiles/profile.h" 27 #include "chrome/browser/profiles/profile.h"
27 #include "chrome/browser/web_applications/web_app_mac.h" 28 #include "chrome/browser/web_applications/web_app_mac.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 runLoop_->Run(); 209 runLoop_->Run();
209 } 210 }
210 211
211 @end 212 @end
212 213
213 namespace apps { 214 namespace apps {
214 215
215 // Shims require static libraries http://crbug.com/386024. 216 // Shims require static libraries http://crbug.com/386024.
216 #if defined(COMPONENT_BUILD) 217 #if defined(COMPONENT_BUILD)
217 #define MAYBE_Launch DISABLED_Launch 218 #define MAYBE_Launch DISABLED_Launch
219 #define MAYBE_RebuildShim DISABLED_RebuildShim
218 #else 220 #else
219 #define MAYBE_Launch Launch 221 #define MAYBE_Launch Launch
222 #define MAYBE_RebuildShim RebuildShim
220 #endif 223 #endif
221 224
222 // Test that launching the shim for an app starts the app, and vice versa. 225 // Test that launching the shim for an app starts the app, and vice versa.
223 // These two cases are combined because the time to run the test is dominated 226 // These two cases are combined because the time to run the test is dominated
224 // by loading the extension and creating the shim. 227 // by loading the extension and creating the shim.
225 IN_PROC_BROWSER_TEST_F(AppShimInteractiveTest, MAYBE_Launch) { 228 IN_PROC_BROWSER_TEST_F(AppShimInteractiveTest, MAYBE_Launch) {
226 // Install the app. 229 // Install the app.
227 const extensions::Extension* app = InstallPlatformApp("minimal"); 230 const extensions::Extension* app = InstallPlatformApp("minimal");
228 231
229 // Use a WebAppShortcutCreator to get the path. 232 // Use a WebAppShortcutCreator to get the path.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 andBundleId:bundle_id]); 300 andBundleId:bundle_id]);
298 [base::mac::ObjCCastStrict<NSRunningApplication>( 301 [base::mac::ObjCCastStrict<NSRunningApplication>(
299 [running_shim objectAtIndex:0]) terminate]; 302 [running_shim objectAtIndex:0]) terminate];
300 [ns_observer wait]; 303 [ns_observer wait];
301 304
302 EXPECT_FALSE(GetFirstAppWindow()); 305 EXPECT_FALSE(GetFirstAppWindow());
303 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); 306 EXPECT_FALSE(HasAppShimHost(profile(), app->id()));
304 } 307 }
305 } 308 }
306 309
310 #if defined(ARCH_CPU_64_BITS)
311
312 // Tests that a 32 bit shim attempting to launch 64 bit Chrome will eventually
313 // be rebuilt.
314 IN_PROC_BROWSER_TEST_F(AppShimInteractiveTest, MAYBE_RebuildShim) {
315 // Get the 32 bit shim.
316 base::FilePath test_data_dir;
317 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
318 base::FilePath shim_path_32 =
319 test_data_dir.Append("app_shim").Append("app_shim_32_bit.app");
320 EXPECT_TRUE(base::PathExists(shim_path_32));
321
322 // Install test app.
323 const extensions::Extension* app = InstallPlatformApp("minimal");
324
325 // Use WebAppShortcutCreator to create a 64 bit shim.
326 web_app::WebAppShortcutCreator shortcut_creator(
327 web_app::GetWebAppDataDirectory(profile()->GetPath(), app->id(), GURL()),
328 web_app::ShortcutInfoForExtensionAndProfile(app, profile()),
329 extensions::FileHandlersInfo());
330 shortcut_creator.UpdateShortcuts();
331 base::FilePath shim_path = shortcut_creator.GetInternalShortcutPath();
332 NSMutableDictionary* plist_64 = [NSMutableDictionary
333 dictionaryWithContentsOfFile:base::mac::FilePathToNSString(
334 shim_path.Append("Contents").Append("Info.plist"))];
335
336 // Copy 32 bit shim to where it's expected to be.
337 // CopyDirectory doesn't seem to work when copying and renaming in one go.
338 ASSERT_TRUE(base::DeleteFile(shim_path, true));
339 ASSERT_TRUE(base::PathExists(shim_path.DirName()));
340 ASSERT_TRUE(base::CopyDirectory(shim_path_32, shim_path.DirName(), true));
341 ASSERT_TRUE(base::Move(shim_path.DirName().Append(shim_path_32.BaseName()),
342 shim_path));
343 ASSERT_TRUE(base::PathExists(
344 shim_path.Append("Contents").Append("MacOS").Append("app_mode_loader")));
345
346 // Fix up the plist so that it matches the installed test app.
347 NSString* plist_path = base::mac::FilePathToNSString(
348 shim_path.Append("Contents").Append("Info.plist"));
349 NSMutableDictionary* plist =
350 [NSMutableDictionary dictionaryWithContentsOfFile:plist_path];
351
352 NSArray* keys_to_copy = @[
353 base::mac::CFToNSCast(kCFBundleIdentifierKey),
354 base::mac::CFToNSCast(kCFBundleNameKey),
355 app_mode::kCrAppModeShortcutIDKey,
356 app_mode::kCrAppModeUserDataDirKey,
357 app_mode::kBrowserBundleIDKey
358 ];
359 for (NSString* key in keys_to_copy) {
360 [plist setObject:[plist_64 objectForKey:key]
361 forKey:key];
362 }
363 [plist writeToFile:plist_path
364 atomically:YES];
365
366 base::mac::RemoveQuarantineAttribute(shim_path);
367
368 // Launch the shim, it should start the app and ultimately connect over IPC.
369 // This actually happens in multiple launches of the shim:
370 // (1) The shim will fail and instead launch Chrome with --app-id so that the
371 // app starts.
372 // (2) Chrome launches the shim in response to an app starting, this time the
373 // shim launches Chrome with --app-shim-error, which causes Chrome to
374 // rebuild the shim.
375 // (3) After rebuilding, Chrome again launches the shim and expects it to
376 // behave normally.
377 ExtensionTestMessageListener launched_listener("Launched", false);
378 CommandLine shim_cmdline(CommandLine::NO_PROGRAM);
379 ASSERT_TRUE(base::mac::OpenApplicationWithPath(
380 shim_path, shim_cmdline, kLSLaunchDefaults, NULL));
381
382 // Wait for the app to start (1). At this point there is no shim host.
383 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
384 EXPECT_FALSE(HasAppShimHost(profile(), app->id()));
385
386 // Wait for the rebuilt shim to connect (3). This does not race with the app
387 // starting (1) because Chrome only launches the shim (2) after the app
388 // starts. Then Chrome must handle --app-shim-error on the UI thread before
389 // the shim is rebuilt.
390 WindowedAppShimLaunchObserver(app->id()).Wait();
391
392 EXPECT_TRUE(GetFirstAppWindow());
393 EXPECT_TRUE(HasAppShimHost(profile(), app->id()));
394 }
395
396 #endif // defined(ARCH_CPU_64_BITS)
397
307 } // namespace apps 398 } // namespace apps
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/app_shim/app_shim_32_bit.app.dSYM/Contents/Info.plist » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698