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

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

Issue 265163006: [Mac] Rebuild app shims when they fail to dyload Chrome Framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to latest http://crrev.com/316493002 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/app/app_mode_loader_mac.mm » ('j') | chrome/app/app_mode_loader_mac.mm » ('J')
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 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 andBundleId:bundle_id]); 291 andBundleId:bundle_id]);
291 [base::mac::ObjCCastStrict<NSRunningApplication>( 292 [base::mac::ObjCCastStrict<NSRunningApplication>(
292 [running_shim objectAtIndex:0]) terminate]; 293 [running_shim objectAtIndex:0]) terminate];
293 [ns_observer wait]; 294 [ns_observer wait];
294 295
295 EXPECT_FALSE(GetFirstAppWindow()); 296 EXPECT_FALSE(GetFirstAppWindow());
296 EXPECT_FALSE(HasAppShimHost(profile(), app->id())); 297 EXPECT_FALSE(HasAppShimHost(profile(), app->id()));
297 } 298 }
298 } 299 }
299 300
301 #if defined(ARCH_CPU_64_BITS)
302
303 // Tests that a 32 bit shim attempting to launch 64 bit Chrome will eventually
304 // be rebuilt.
305 IN_PROC_BROWSER_TEST_F(AppShimInteractiveTest, RebuildShim) {
306 // Get the 32 bit shim.
307 base::FilePath test_data_dir;
308 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
309 base::FilePath shim_path_32 =
310 test_data_dir.Append("app_shim").Append("app_shim_32_bit.app");
311 EXPECT_TRUE(base::PathExists(shim_path_32));
312
313 // Install test app.
314 const extensions::Extension* app = InstallPlatformApp("minimal");
315
316 // Use WebAppShortcutCreator to create a 64 bit shim.
317 web_app::WebAppShortcutCreator shortcut_creator(
318 web_app::GetWebAppDataDirectory(profile()->GetPath(), app->id(), GURL()),
319 web_app::ShortcutInfoForExtensionAndProfile(app, profile()),
320 extensions::FileHandlersInfo());
321 shortcut_creator.UpdateShortcuts();
322 base::FilePath shim_path = shortcut_creator.GetInternalShortcutPath();
323 NSMutableDictionary* plist_64 = [NSMutableDictionary
324 dictionaryWithContentsOfFile:base::mac::FilePathToNSString(
325 shim_path.Append("Contents").Append("Info.plist"))];
326
327 // Copy 32 bit shim to where it's expected to be.
328 // CopyDirectory doesn't seem to work when copying and renaming in one go.
329 ASSERT_TRUE(base::DeleteFile(shim_path, true));
330 ASSERT_TRUE(base::PathExists(shim_path.DirName()));
331 ASSERT_TRUE(base::CopyDirectory(shim_path_32, shim_path.DirName(), true));
332 ASSERT_TRUE(base::Move(shim_path.DirName().Append(shim_path_32.BaseName()),
333 shim_path));
334 ASSERT_TRUE(base::PathExists(
335 shim_path.Append("Contents").Append("MacOS").Append("app_mode_loader")));
336
337 // Fix up the plist so that it matches the installed test app.
338 NSString* plist_path = base::mac::FilePathToNSString(
339 shim_path.Append("Contents").Append("Info.plist"));
340 NSMutableDictionary* plist =
341 [NSMutableDictionary dictionaryWithContentsOfFile:plist_path];
342
343 NSArray* keys_to_copy = @[
344 base::mac::CFToNSCast(kCFBundleIdentifierKey),
345 base::mac::CFToNSCast(kCFBundleNameKey),
346 app_mode::kCrAppModeShortcutIDKey,
347 app_mode::kCrAppModeUserDataDirKey,
348 app_mode::kBrowserBundleIDKey
349 ];
350 for (NSString* key in keys_to_copy) {
351 [plist setObject:[plist_64 objectForKey:key]
352 forKey:key];
353 }
354 [plist writeToFile:plist_path
355 atomically:YES];
356
357 base::mac::RemoveQuarantineAttribute(shim_path);
358
359 // Launch the shim, it should start the app and ultimately connect over IPC.
360 // This actually happens in multiple launches of the shim:
361 // (1) The shim will fail and instead launch Chrome with --app-id so that the
362 // app starts.
363 // (2) Chrome launches the shim in response to an app starting, this time the
364 // shim launches Chrome with --app-shim-error, which causes Chrome to
365 // rebuild the shim.
366 // (3) After rebuilding, Chrome again launches the shim and expects it to
367 // behave normally.
368 ExtensionTestMessageListener launched_listener("Launched", false);
369 CommandLine shim_cmdline(CommandLine::NO_PROGRAM);
370 ASSERT_TRUE(base::mac::OpenApplicationWithPath(
371 shim_path, shim_cmdline, kLSLaunchDefaults, NULL));
372
373 // Wait for the app to start (1). At this point there is no shim host.
374 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
375 EXPECT_FALSE(HasAppShimHost(profile(), app->id()));
376
377 // Wait for the rebuilt shim to connect (3). This does not race with the app
378 // starting (1) because Chrome only launches the shim (2) after the app
379 // starts. Then Chrome must handle --app-shim-error on the UI thread before
380 // the shim is rebuilt.
381 WindowedAppShimLaunchObserver(app->id()).Wait();
382
383 EXPECT_TRUE(GetFirstAppWindow());
384 EXPECT_TRUE(HasAppShimHost(profile(), app->id()));
385 }
386
387 #endif // defined(ARCH_CPU_64_BITS)
388
300 } // namespace apps 389 } // namespace apps
OLDNEW
« no previous file with comments | « no previous file | chrome/app/app_mode_loader_mac.mm » ('j') | chrome/app/app_mode_loader_mac.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698