| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/apps/app_browsertest_util.h" | 5 #include "chrome/browser/apps/app_browsertest_util.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 9 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
| 10 #include "chrome/browser/extensions/extension_function_test_utils.h" | 10 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 11 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 11 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/extensions/app_launch_params.h" | 13 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 14 #include "chrome/browser/ui/extensions/application_launch.h" | 14 #include "chrome/browser/ui/extensions/application_launch.h" |
| 15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
| 17 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 18 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
| 19 #include "extensions/browser/app_window/app_window_contents.h" | 19 #include "extensions/browser/app_window/app_window_contents.h" |
| 20 #include "extensions/browser/app_window/app_window_registry.h" | 20 #include "extensions/browser/app_window/app_window_registry.h" |
| 21 #include "extensions/browser/app_window/native_app_window.h" | 21 #include "extensions/browser/app_window/native_app_window.h" |
| 22 #include "extensions/browser/process_manager.h" | 22 #include "extensions/browser/process_manager.h" |
| 23 #include "extensions/common/constants.h" | 23 #include "extensions/common/constants.h" |
| 24 #include "extensions/common/switches.h" | 24 #include "extensions/common/switches.h" |
| 25 #include "extensions/test/extension_test_message_listener.h" | 25 #include "extensions/test/extension_test_message_listener.h" |
| 26 | 26 |
| 27 #if defined(OS_CHROMEOS) |
| 28 #include "chrome/browser/media/router/media_routes_observer.h" |
| 29 #include "chrome/browser/ui/ash/cast_config_client_media_router.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #endif |
| 32 |
| 27 using content::WebContents; | 33 using content::WebContents; |
| 28 | 34 |
| 29 namespace { | 35 namespace { |
| 30 | 36 |
| 31 const char kAppWindowTestApp[] = "app_window/generic"; | 37 const char kAppWindowTestApp[] = "app_window/generic"; |
| 32 | 38 |
| 33 } // namespace | 39 } // namespace |
| 34 | 40 |
| 35 namespace utils = extension_function_test_utils; | 41 namespace utils = extension_function_test_utils; |
| 36 | 42 |
| 37 namespace extensions { | 43 namespace extensions { |
| 38 | 44 |
| 39 PlatformAppBrowserTest::PlatformAppBrowserTest() { | 45 PlatformAppBrowserTest::PlatformAppBrowserTest() { |
| 40 ChromeAppDelegate::DisableExternalOpenForTesting(); | 46 ChromeAppDelegate::DisableExternalOpenForTesting(); |
| 41 } | 47 } |
| 42 | 48 |
| 43 void PlatformAppBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { | 49 void PlatformAppBrowserTest::SetUpCommandLine(base::CommandLine* command_line) { |
| 44 // Skips ExtensionApiTest::SetUpCommandLine. | 50 // Skips ExtensionApiTest::SetUpCommandLine. |
| 45 ExtensionBrowserTest::SetUpCommandLine(command_line); | 51 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 46 | 52 |
| 47 // Make event pages get suspended quicker. | 53 // Make event pages get suspended quicker. |
| 48 ProcessManager::SetEventPageIdleTimeForTesting(1000); | 54 ProcessManager::SetEventPageIdleTimeForTesting(1000); |
| 49 ProcessManager::SetEventPageSuspendingTimeForTesting(1000); | 55 ProcessManager::SetEventPageSuspendingTimeForTesting(1000); |
| 50 } | 56 } |
| 51 | 57 |
| 58 void PlatformAppBrowserTest::SetUpInProcessBrowserTestFixture() { |
| 59 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 60 #if defined(OS_CHROMEOS) |
| 61 // Mock the Media Router in extension api tests. Several of the |
| 62 // PlatformAppBrowserTest suites call RunAllPendingInMessageLoop() when there |
| 63 // are mojo messages that will call back into Profile creation through the |
| 64 // media router. |
| 65 ON_CALL(media_router_, RegisterMediaSinksObserver(testing::_)) |
| 66 .WillByDefault(testing::Return(true)); |
| 67 |
| 68 CastConfigClientMediaRouter::SetMediaRouterForTest(&media_router_); |
| 69 #endif |
| 70 } |
| 71 |
| 72 void PlatformAppBrowserTest::TearDownInProcessBrowserTestFixture() { |
| 73 ExtensionApiTest::TearDownInProcessBrowserTestFixture(); |
| 74 #if defined(OS_CHROMEOS) |
| 75 CastConfigClientMediaRouter::SetMediaRouterForTest(nullptr); |
| 76 #endif |
| 77 } |
| 78 |
| 52 // static | 79 // static |
| 53 AppWindow* PlatformAppBrowserTest::GetFirstAppWindowForBrowser( | 80 AppWindow* PlatformAppBrowserTest::GetFirstAppWindowForBrowser( |
| 54 Browser* browser) { | 81 Browser* browser) { |
| 55 AppWindowRegistry* app_registry = AppWindowRegistry::Get(browser->profile()); | 82 AppWindowRegistry* app_registry = AppWindowRegistry::Get(browser->profile()); |
| 56 const AppWindowRegistry::AppWindowList& app_windows = | 83 const AppWindowRegistry::AppWindowList& app_windows = |
| 57 app_registry->app_windows(); | 84 app_registry->app_windows(); |
| 58 | 85 |
| 59 AppWindowRegistry::const_iterator iter = app_windows.begin(); | 86 AppWindowRegistry::const_iterator iter = app_windows.begin(); |
| 60 if (iter != app_windows.end()) | 87 if (iter != app_windows.end()) |
| 61 return *iter; | 88 return *iter; |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 return app_window; | 285 return app_window; |
| 259 } | 286 } |
| 260 | 287 |
| 261 void ExperimentalPlatformAppBrowserTest::SetUpCommandLine( | 288 void ExperimentalPlatformAppBrowserTest::SetUpCommandLine( |
| 262 base::CommandLine* command_line) { | 289 base::CommandLine* command_line) { |
| 263 PlatformAppBrowserTest::SetUpCommandLine(command_line); | 290 PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 264 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 291 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 265 } | 292 } |
| 266 | 293 |
| 267 } // namespace extensions | 294 } // namespace extensions |
| OLD | NEW |