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

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: Add test. Rebase on 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
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 // Tests that a 32 bit shim attempting to launch 64 bit Chrome will eventually
302 // be rebuilt.
303 IN_PROC_BROWSER_TEST_F(AppShimInteractiveTest, RebuildShim) {
304 // Get the 32 bit shim.
305 base::FilePath test_data_dir;
306 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir);
307 base::FilePath shim_path_32 =
tapted 2014/06/11 03:32:43 Should this actually try to pick a shim that is th
jackhou1 2014/06/13 09:47:48 Oh yeah, I forgot to ifdef this out. I don't think
308 test_data_dir.Append("app_shim").Append("app_shim_32_bit");
309 EXPECT_TRUE(base::PathExists(shim_path_32));
310
311 // Install test app.
312 const extensions::Extension* app = InstallPlatformApp("minimal");
313
314 // Use WebAppShortcutCreator to create a 64 bit shim.
315 web_app::WebAppShortcutCreator shortcut_creator(
316 web_app::GetWebAppDataDirectory(profile()->GetPath(), app->id(), GURL()),
317 web_app::ShortcutInfoForExtensionAndProfile(app, profile()),
318 extensions::FileHandlersInfo());
319 shortcut_creator.UpdateShortcuts();
320 base::FilePath shim_path = shortcut_creator.GetInternalShortcutPath();
321 NSMutableDictionary* plist_64 = [NSMutableDictionary
322 dictionaryWithContentsOfFile:base::mac::FilePathToNSString(
323 shim_path.Append("Contents").Append("Info.plist"))];
324
325 // Copy 32 bit shim to where it's expected to be.
326 // CopyDirectory doesn't seem to work when copying and renaming in one go.
327 ASSERT_TRUE(base::DeleteFile(shim_path, true));
328 ASSERT_TRUE(base::PathExists(shim_path.DirName()));
329 ASSERT_TRUE(base::CopyDirectory(shim_path_32, shim_path.DirName(), true));
330 ASSERT_TRUE(base::Move(shim_path.DirName().Append(shim_path_32.BaseName()),
331 shim_path));
332 ASSERT_TRUE(base::PathExists(
333 shim_path.Append("Contents").Append("MacOS").Append("app_mode_loader")));
334
335 // Fix up the plist so that it matches the installed test app.
336 NSString* plist_path = base::mac::FilePathToNSString(
337 shim_path.Append("Contents").Append("Info.plist"));
338 NSMutableDictionary* plist =
339 [NSMutableDictionary dictionaryWithContentsOfFile:plist_path];
340
341 NSArray* keys_to_copy = @[
342 base::mac::CFToNSCast(kCFBundleIdentifierKey),
343 base::mac::CFToNSCast(kCFBundleNameKey),
344 app_mode::kCrAppModeShortcutIDKey,
345 app_mode::kCrAppModeUserDataDirKey
346 ];
347 for (NSString* key in keys_to_copy) {
348 [plist setObject:[plist_64 objectForKey:key]
349 forKey:key];
350 }
351 [plist writeToFile:plist_path
352 atomically:YES];
353
354 base::mac::RemoveQuarantineAttribute(shim_path);
355
356 // Launch the shim, it should start the app and ultimately connect over IPC.
357 // This actually happens in multiple launches of the shim. The first time the
358 // shim will fail and instead launch Chrome with --app-id so that the app
359 // starts. The second time is when Chrome launches the shim in response to an
360 // app starting, this time the shim launches Chrome with --app-shim-error,
361 // which causes Chrome to rebuild the shim. Finally, after rebuilding, Chrome
362 // again launches the shim and expects it to behave normally.
363 ExtensionTestMessageListener launched_listener("Launched", false);
364 WindowedAppShimLaunchObserver observer(app->id());
365
366 CommandLine shim_cmdline(CommandLine::NO_PROGRAM);
367 ASSERT_TRUE(base::mac::OpenApplicationWithPath(
368 shim_path, shim_cmdline, kLSLaunchDefaults, NULL));
369
370 ASSERT_TRUE(launched_listener.WaitUntilSatisfied());
371 observer.Wait();
372
373 EXPECT_TRUE(GetFirstAppWindow());
374 EXPECT_TRUE(HasAppShimHost(profile(), app->id()));
tapted 2014/06/11 03:32:43 Is there a non-flaky way to do an EXPECT_FALSE ver
jackhou1 2014/06/13 09:47:49 It should be non-flaky to do those waits sequentia
375 }
376
300 } // namespace apps 377 } // namespace apps
OLDNEW
« no previous file with comments | « no previous file | chrome/app/app_mode_loader_mac.mm » ('j') | chrome/test/data/app_shim/app_shim_32_bit/Contents/PkgInfo » ('J')

Powered by Google App Engine
This is Rietveld 408576698