| 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 "apps/app_window_contents.h" | 7 #include "apps/app_window_contents.h" |
| 8 #include "apps/app_window_registry.h" | |
| 9 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 10 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
| 11 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 10 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
| 12 #include "chrome/browser/extensions/extension_function_test_utils.h" | 11 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 13 #include "chrome/browser/extensions/extension_test_message_listener.h" | 12 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 14 #include "chrome/browser/ui/apps/chrome_app_delegate.h" | 13 #include "chrome/browser/ui/apps/chrome_app_delegate.h" |
| 15 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/extensions/application_launch.h" | 15 #include "chrome/browser/ui/extensions/application_launch.h" |
| 17 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
| 18 #include "content/public/test/browser_test_utils.h" | 17 #include "content/public/test/browser_test_utils.h" |
| 19 #include "content/public/test/test_utils.h" | 18 #include "content/public/test/test_utils.h" |
| 19 #include "extensions/browser/app_window/app_window_registry.h" |
| 20 #include "extensions/browser/app_window/native_app_window.h" | 20 #include "extensions/browser/app_window/native_app_window.h" |
| 21 #include "extensions/common/switches.h" | 21 #include "extensions/common/switches.h" |
| 22 | 22 |
| 23 using apps::AppWindow; | |
| 24 using apps::AppWindowRegistry; | |
| 25 using content::WebContents; | 23 using content::WebContents; |
| 26 | 24 |
| 27 namespace { | 25 namespace { |
| 28 | 26 |
| 29 const char kAppWindowTestApp[] = "app_window/generic"; | 27 const char kAppWindowTestApp[] = "app_window/generic"; |
| 30 | 28 |
| 31 } // namespace | 29 } // namespace |
| 32 | 30 |
| 33 namespace utils = extension_function_test_utils; | 31 namespace utils = extension_function_test_utils; |
| 34 | 32 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 if (window) | 119 if (window) |
| 122 return window->web_contents(); | 120 return window->web_contents(); |
| 123 | 121 |
| 124 return NULL; | 122 return NULL; |
| 125 } | 123 } |
| 126 | 124 |
| 127 AppWindow* PlatformAppBrowserTest::GetFirstAppWindow() { | 125 AppWindow* PlatformAppBrowserTest::GetFirstAppWindow() { |
| 128 return GetFirstAppWindowForBrowser(browser()); | 126 return GetFirstAppWindowForBrowser(browser()); |
| 129 } | 127 } |
| 130 | 128 |
| 131 apps::AppWindow* PlatformAppBrowserTest::GetFirstAppWindowForApp( | 129 AppWindow* PlatformAppBrowserTest::GetFirstAppWindowForApp( |
| 132 const std::string& app_id) { | 130 const std::string& app_id) { |
| 133 AppWindowRegistry* app_registry = | 131 AppWindowRegistry* app_registry = |
| 134 AppWindowRegistry::Get(browser()->profile()); | 132 AppWindowRegistry::Get(browser()->profile()); |
| 135 const AppWindowRegistry::AppWindowList& app_windows = | 133 const AppWindowRegistry::AppWindowList& app_windows = |
| 136 app_registry->GetAppWindowsForApp(app_id); | 134 app_registry->GetAppWindowsForApp(app_id); |
| 137 | 135 |
| 138 AppWindowRegistry::const_iterator iter = app_windows.begin(); | 136 AppWindowRegistry::const_iterator iter = app_windows.begin(); |
| 139 if (iter != app_windows.end()) | 137 if (iter != app_windows.end()) |
| 140 return *iter; | 138 return *iter; |
| 141 | 139 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 const gfx::Rect& current_screen_bounds, | 220 const gfx::Rect& current_screen_bounds, |
| 223 const gfx::Size& minimum_size, | 221 const gfx::Size& minimum_size, |
| 224 gfx::Rect* bounds) { | 222 gfx::Rect* bounds) { |
| 225 window->AdjustBoundsToBeVisibleOnScreen(cached_bounds, | 223 window->AdjustBoundsToBeVisibleOnScreen(cached_bounds, |
| 226 cached_screen_bounds, | 224 cached_screen_bounds, |
| 227 current_screen_bounds, | 225 current_screen_bounds, |
| 228 minimum_size, | 226 minimum_size, |
| 229 bounds); | 227 bounds); |
| 230 } | 228 } |
| 231 | 229 |
| 232 apps::AppWindow* PlatformAppBrowserTest::CreateTestAppWindow( | 230 AppWindow* PlatformAppBrowserTest::CreateTestAppWindow( |
| 233 const std::string& window_create_options) { | 231 const std::string& window_create_options) { |
| 234 ExtensionTestMessageListener launched_listener("launched", true); | 232 ExtensionTestMessageListener launched_listener("launched", true); |
| 235 ExtensionTestMessageListener loaded_listener("window_loaded", false); | 233 ExtensionTestMessageListener loaded_listener("window_loaded", false); |
| 236 | 234 |
| 237 // Load and launch the test app. | 235 // Load and launch the test app. |
| 238 const Extension* extension = | 236 const Extension* extension = |
| 239 LoadAndLaunchPlatformApp(kAppWindowTestApp, &launched_listener); | 237 LoadAndLaunchPlatformApp(kAppWindowTestApp, &launched_listener); |
| 240 EXPECT_TRUE(extension); | 238 EXPECT_TRUE(extension); |
| 241 EXPECT_TRUE(launched_listener.WaitUntilSatisfied()); | 239 EXPECT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 242 | 240 |
| 243 // Send the options for window creation. | 241 // Send the options for window creation. |
| 244 launched_listener.Reply(window_create_options); | 242 launched_listener.Reply(window_create_options); |
| 245 | 243 |
| 246 // Wait for the window to be opened and loaded. | 244 // Wait for the window to be opened and loaded. |
| 247 EXPECT_TRUE(loaded_listener.WaitUntilSatisfied()); | 245 EXPECT_TRUE(loaded_listener.WaitUntilSatisfied()); |
| 248 | 246 |
| 249 EXPECT_EQ(1U, GetAppWindowCount()); | 247 EXPECT_EQ(1U, GetAppWindowCount()); |
| 250 AppWindow* app_window = GetFirstAppWindow(); | 248 AppWindow* app_window = GetFirstAppWindow(); |
| 251 return app_window; | 249 return app_window; |
| 252 } | 250 } |
| 253 | 251 |
| 254 void ExperimentalPlatformAppBrowserTest::SetUpCommandLine( | 252 void ExperimentalPlatformAppBrowserTest::SetUpCommandLine( |
| 255 CommandLine* command_line) { | 253 CommandLine* command_line) { |
| 256 PlatformAppBrowserTest::SetUpCommandLine(command_line); | 254 PlatformAppBrowserTest::SetUpCommandLine(command_line); |
| 257 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 255 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 258 } | 256 } |
| 259 | 257 |
| 260 } // namespace extensions | 258 } // namespace extensions |
| OLD | NEW |