| OLD | NEW |
| 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_lifetime_monitor_factory.h" | 8 #include "apps/app_lifetime_monitor_factory.h" |
| 9 #include "apps/switches.h" | 9 #include "apps/switches.h" |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/browser/ui/browser_list.h" | 28 #include "chrome/browser/ui/browser_list.h" |
| 29 #include "chrome/browser/ui/browser_window.h" | 29 #include "chrome/browser/ui/browser_window.h" |
| 30 #include "chrome/browser/web_applications/web_app_mac.h" | 30 #include "chrome/browser/web_applications/web_app_mac.h" |
| 31 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
| 32 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/mac/app_mode_common.h" | 33 #include "chrome/common/mac/app_mode_common.h" |
| 34 #include "content/public/test/test_utils.h" | 34 #include "content/public/test/test_utils.h" |
| 35 #include "extensions/browser/app_window/native_app_window.h" | 35 #include "extensions/browser/app_window/native_app_window.h" |
| 36 #include "extensions/browser/extension_prefs.h" | 36 #include "extensions/browser/extension_prefs.h" |
| 37 #include "extensions/test/extension_test_message_listener.h" | 37 #include "extensions/test/extension_test_message_listener.h" |
| 38 #import "ui/base/test/windowed_nsnotification_observer.h" |
| 38 #import "ui/events/test/cocoa_test_event_utils.h" | 39 #import "ui/events/test/cocoa_test_event_utils.h" |
| 39 | 40 |
| 40 namespace { | 41 namespace { |
| 41 | 42 |
| 42 // General end-to-end test for app shims. | 43 // General end-to-end test for app shims. |
| 43 class AppShimInteractiveTest : public extensions::PlatformAppBrowserTest { | 44 class AppShimInteractiveTest : public extensions::PlatformAppBrowserTest { |
| 44 protected: | 45 protected: |
| 45 AppShimInteractiveTest() | 46 AppShimInteractiveTest() |
| 46 : auto_reset_(&g_app_shims_allow_update_and_launch_in_tests, true) {} | 47 : auto_reset_(&g_app_shims_allow_update_and_launch_in_tests, true) {} |
| 47 | 48 |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 const extensions::Extension* extension = | 295 const extensions::Extension* extension = |
| 295 apps::ExtensionAppShimHandler::MaybeGetAppForBrowser(browser); | 296 apps::ExtensionAppShimHandler::MaybeGetAppForBrowser(browser); |
| 296 if (extension && extension->is_hosted_app()) | 297 if (extension && extension->is_hosted_app()) |
| 297 return browser; | 298 return browser; |
| 298 } | 299 } |
| 299 return nullptr; | 300 return nullptr; |
| 300 } | 301 } |
| 301 | 302 |
| 302 } // namespace | 303 } // namespace |
| 303 | 304 |
| 304 // Watches for NSNotifications from the shared workspace. | |
| 305 @interface WindowedNSNotificationObserver : NSObject { | |
| 306 @private | |
| 307 base::scoped_nsobject<NSString> bundleId_; | |
| 308 BOOL notificationReceived_; | |
| 309 scoped_ptr<base::RunLoop> runLoop_; | |
| 310 } | |
| 311 | |
| 312 - (id)initForNotification:(NSString*)name | |
| 313 andBundleId:(NSString*)bundleId; | |
| 314 - (void)observe:(NSNotification*)notification; | |
| 315 - (void)wait; | |
| 316 @end | |
| 317 | |
| 318 @implementation WindowedNSNotificationObserver | |
| 319 | |
| 320 - (id)initForNotification:(NSString*)name | |
| 321 andBundleId:(NSString*)bundleId { | |
| 322 if (self = [super init]) { | |
| 323 bundleId_.reset([[bundleId copy] retain]); | |
| 324 [[[NSWorkspace sharedWorkspace] notificationCenter] | |
| 325 addObserver:self | |
| 326 selector:@selector(observe:) | |
| 327 name:name | |
| 328 object:nil]; | |
| 329 } | |
| 330 return self; | |
| 331 } | |
| 332 | |
| 333 - (void)observe:(NSNotification*)notification { | |
| 334 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 335 | |
| 336 NSRunningApplication* application = | |
| 337 [[notification userInfo] objectForKey:NSWorkspaceApplicationKey]; | |
| 338 if (![[application bundleIdentifier] isEqualToString:bundleId_]) | |
| 339 return; | |
| 340 | |
| 341 [[[NSWorkspace sharedWorkspace] notificationCenter] removeObserver:self]; | |
| 342 notificationReceived_ = YES; | |
| 343 if (runLoop_.get()) | |
| 344 runLoop_->Quit(); | |
| 345 } | |
| 346 | |
| 347 - (void)wait { | |
| 348 if (notificationReceived_) | |
| 349 return; | |
| 350 | |
| 351 runLoop_.reset(new base::RunLoop); | |
| 352 runLoop_->Run(); | |
| 353 } | |
| 354 | |
| 355 @end | |
| 356 | |
| 357 namespace apps { | 305 namespace apps { |
| 358 | 306 |
| 359 // Shims require static libraries http://crbug.com/386024. | 307 // Shims require static libraries http://crbug.com/386024. |
| 360 #if defined(COMPONENT_BUILD) | 308 #if defined(COMPONENT_BUILD) |
| 361 #define MAYBE_Launch DISABLED_Launch | 309 #define MAYBE_Launch DISABLED_Launch |
| 362 #define MAYBE_HostedAppLaunch DISABLED_HostedAppLaunch | 310 #define MAYBE_HostedAppLaunch DISABLED_HostedAppLaunch |
| 363 #define MAYBE_ShowWindow DISABLED_ShowWindow | 311 #define MAYBE_ShowWindow DISABLED_ShowWindow |
| 364 #define MAYBE_RebuildShim DISABLED_RebuildShim | 312 #define MAYBE_RebuildShim DISABLED_RebuildShim |
| 365 #else | 313 #else |
| 366 #define MAYBE_Launch Launch | 314 #define MAYBE_Launch Launch |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 // the shim is rebuilt. | 665 // the shim is rebuilt. |
| 718 WindowedAppShimLaunchObserver(app->id()).Wait(); | 666 WindowedAppShimLaunchObserver(app->id()).Wait(); |
| 719 | 667 |
| 720 EXPECT_TRUE(GetFirstAppWindow()); | 668 EXPECT_TRUE(GetFirstAppWindow()); |
| 721 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); | 669 EXPECT_TRUE(HasAppShimHost(profile(), app->id())); |
| 722 } | 670 } |
| 723 | 671 |
| 724 #endif // defined(ARCH_CPU_64_BITS) | 672 #endif // defined(ARCH_CPU_64_BITS) |
| 725 | 673 |
| 726 } // namespace apps | 674 } // namespace apps |
| OLD | NEW |