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/shell_window_registry.h" | 8 #include "apps/app_window_registry.h" |
9 #include "apps/ui/native_app_window.h" | 9 #include "apps/ui/native_app_window.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
12 #include "chrome/browser/extensions/api/tabs/tabs_api.h" | 12 #include "chrome/browser/extensions/api/tabs/tabs_api.h" |
13 #include "chrome/browser/extensions/extension_function_test_utils.h" | 13 #include "chrome/browser/extensions/extension_function_test_utils.h" |
14 #include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" | 14 #include "chrome/browser/ui/apps/chrome_shell_window_delegate.h" |
15 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
16 #include "chrome/browser/ui/extensions/application_launch.h" | 16 #include "chrome/browser/ui/extensions/application_launch.h" |
17 #include "content/public/browser/notification_service.h" | 17 #include "content/public/browser/notification_service.h" |
18 #include "content/public/test/browser_test_utils.h" | 18 #include "content/public/test/browser_test_utils.h" |
19 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
20 #include "extensions/common/switches.h" | 20 #include "extensions/common/switches.h" |
21 | 21 |
22 using apps::ShellWindow; | 22 using apps::AppWindow; |
23 using apps::ShellWindowRegistry; | 23 using apps::AppWindowRegistry; |
24 using content::WebContents; | 24 using content::WebContents; |
25 | 25 |
26 namespace utils = extension_function_test_utils; | 26 namespace utils = extension_function_test_utils; |
27 | 27 |
28 namespace extensions { | 28 namespace extensions { |
29 | 29 |
30 PlatformAppBrowserTest::PlatformAppBrowserTest() { | 30 PlatformAppBrowserTest::PlatformAppBrowserTest() { |
31 ChromeShellWindowDelegate::DisableExternalOpenForTesting(); | 31 ChromeShellWindowDelegate::DisableExternalOpenForTesting(); |
32 } | 32 } |
33 | 33 |
34 void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) { | 34 void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) { |
35 // Skips ExtensionApiTest::SetUpCommandLine. | 35 // Skips ExtensionApiTest::SetUpCommandLine. |
36 ExtensionBrowserTest::SetUpCommandLine(command_line); | 36 ExtensionBrowserTest::SetUpCommandLine(command_line); |
37 | 37 |
38 // Make event pages get suspended quicker. | 38 // Make event pages get suspended quicker. |
39 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1000"); | 39 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1000"); |
40 command_line->AppendSwitchASCII(switches::kEventPageSuspendingTime, "1000"); | 40 command_line->AppendSwitchASCII(switches::kEventPageSuspendingTime, "1000"); |
41 } | 41 } |
42 | 42 |
43 // static | 43 // static |
44 ShellWindow* PlatformAppBrowserTest::GetFirstShellWindowForBrowser( | 44 AppWindow* PlatformAppBrowserTest::GetFirstAppWindowForBrowser( |
45 Browser* browser) { | 45 Browser* browser) { |
46 ShellWindowRegistry* app_registry = | 46 AppWindowRegistry* app_registry = AppWindowRegistry::Get(browser->profile()); |
47 ShellWindowRegistry::Get(browser->profile()); | 47 const AppWindowRegistry::AppWindowList& app_windows = |
48 const ShellWindowRegistry::ShellWindowList& shell_windows = | 48 app_registry->app_windows(); |
49 app_registry->shell_windows(); | |
50 | 49 |
51 ShellWindowRegistry::const_iterator iter = shell_windows.begin(); | 50 AppWindowRegistry::const_iterator iter = app_windows.begin(); |
52 if (iter != shell_windows.end()) | 51 if (iter != app_windows.end()) |
53 return *iter; | 52 return *iter; |
54 | 53 |
55 return NULL; | 54 return NULL; |
56 } | 55 } |
57 | 56 |
58 const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp( | 57 const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp( |
59 const char* name) { | 58 const char* name) { |
60 content::WindowedNotificationObserver app_loaded_observer( | 59 content::WindowedNotificationObserver app_loaded_observer( |
61 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | 60 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
62 content::NotificationService::AllSources()); | 61 content::NotificationService::AllSources()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 app_loaded_observer.Wait(); | 93 app_loaded_observer.Wait(); |
95 | 94 |
96 return extension; | 95 return extension; |
97 } | 96 } |
98 | 97 |
99 void PlatformAppBrowserTest::LaunchPlatformApp(const Extension* extension) { | 98 void PlatformAppBrowserTest::LaunchPlatformApp(const Extension* extension) { |
100 OpenApplication(AppLaunchParams( | 99 OpenApplication(AppLaunchParams( |
101 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); | 100 browser()->profile(), extension, LAUNCH_CONTAINER_NONE, NEW_WINDOW)); |
102 } | 101 } |
103 | 102 |
104 WebContents* PlatformAppBrowserTest::GetFirstShellWindowWebContents() { | 103 WebContents* PlatformAppBrowserTest::GetFirstAppWindowWebContents() { |
105 ShellWindow* window = GetFirstShellWindow(); | 104 AppWindow* window = GetFirstAppWindow(); |
106 if (window) | 105 if (window) |
107 return window->web_contents(); | 106 return window->web_contents(); |
108 | 107 |
109 return NULL; | 108 return NULL; |
110 } | 109 } |
111 | 110 |
112 ShellWindow* PlatformAppBrowserTest::GetFirstShellWindow() { | 111 AppWindow* PlatformAppBrowserTest::GetFirstAppWindow() { |
113 return GetFirstShellWindowForBrowser(browser()); | 112 return GetFirstAppWindowForBrowser(browser()); |
114 } | 113 } |
115 | 114 |
116 apps::ShellWindow* PlatformAppBrowserTest::GetFirstShellWindowForApp( | 115 apps::AppWindow* PlatformAppBrowserTest::GetFirstAppWindowForApp( |
117 const std::string& app_id) { | 116 const std::string& app_id) { |
118 ShellWindowRegistry* app_registry = | 117 AppWindowRegistry* app_registry = |
119 ShellWindowRegistry::Get(browser()->profile()); | 118 AppWindowRegistry::Get(browser()->profile()); |
120 const ShellWindowRegistry::ShellWindowList& shell_windows = | 119 const AppWindowRegistry::AppWindowList& app_windows = |
121 app_registry->GetShellWindowsForApp(app_id); | 120 app_registry->GetAppWindowsForApp(app_id); |
122 | 121 |
123 ShellWindowRegistry::const_iterator iter = shell_windows.begin(); | 122 AppWindowRegistry::const_iterator iter = app_windows.begin(); |
124 if (iter != shell_windows.end()) | 123 if (iter != app_windows.end()) |
125 return *iter; | 124 return *iter; |
126 | 125 |
127 return NULL; | 126 return NULL; |
128 } | 127 } |
129 | 128 |
130 size_t PlatformAppBrowserTest::RunGetWindowsFunctionForExtension( | 129 size_t PlatformAppBrowserTest::RunGetWindowsFunctionForExtension( |
131 const Extension* extension) { | 130 const Extension* extension) { |
132 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); | 131 scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction(); |
133 function->set_extension(extension); | 132 function->set_extension(extension); |
134 scoped_ptr<base::ListValue> result(utils::ToList( | 133 scoped_ptr<base::ListValue> result(utils::ToList( |
135 utils::RunFunctionAndReturnSingleResult(function.get(), | 134 utils::RunFunctionAndReturnSingleResult(function.get(), |
136 "[]", | 135 "[]", |
137 browser()))); | 136 browser()))); |
138 return result->GetSize(); | 137 return result->GetSize(); |
139 } | 138 } |
140 | 139 |
141 bool PlatformAppBrowserTest::RunGetWindowFunctionForExtension( | 140 bool PlatformAppBrowserTest::RunGetWindowFunctionForExtension( |
142 int window_id, | 141 int window_id, |
143 const Extension* extension) { | 142 const Extension* extension) { |
144 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction(); | 143 scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction(); |
145 function->set_extension(extension); | 144 function->set_extension(extension); |
146 utils::RunFunction( | 145 utils::RunFunction( |
147 function.get(), | 146 function.get(), |
148 base::StringPrintf("[%u]", window_id), | 147 base::StringPrintf("[%u]", window_id), |
149 browser(), | 148 browser(), |
150 utils::NONE); | 149 utils::NONE); |
151 return function->GetResultList() != NULL; | 150 return function->GetResultList() != NULL; |
152 } | 151 } |
153 | 152 |
154 size_t PlatformAppBrowserTest::GetShellWindowCount() { | 153 size_t PlatformAppBrowserTest::GetAppWindowCount() { |
155 return ShellWindowRegistry::Get(browser()->profile())-> | 154 return AppWindowRegistry::Get(browser()->profile())->app_windows().size(); |
156 shell_windows().size(); | |
157 } | 155 } |
158 | 156 |
159 size_t PlatformAppBrowserTest::GetShellWindowCountForApp( | 157 size_t PlatformAppBrowserTest::GetAppWindowCountForApp( |
160 const std::string& app_id) { | 158 const std::string& app_id) { |
161 return ShellWindowRegistry::Get(browser()->profile())-> | 159 return AppWindowRegistry::Get(browser()->profile()) |
162 GetShellWindowsForApp(app_id).size(); | 160 ->GetAppWindowsForApp(app_id) |
| 161 .size(); |
163 } | 162 } |
164 | 163 |
165 void PlatformAppBrowserTest::ClearCommandLineArgs() { | 164 void PlatformAppBrowserTest::ClearCommandLineArgs() { |
166 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 165 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
167 CommandLine::StringVector args = command_line->GetArgs(); | 166 CommandLine::StringVector args = command_line->GetArgs(); |
168 CommandLine::StringVector argv = command_line->argv(); | 167 CommandLine::StringVector argv = command_line->argv(); |
169 for (size_t i = 0; i < args.size(); i++) | 168 for (size_t i = 0; i < args.size(); i++) |
170 argv.pop_back(); | 169 argv.pop_back(); |
171 command_line->InitFromArgv(argv); | 170 command_line->InitFromArgv(argv); |
172 } | 171 } |
173 | 172 |
174 void PlatformAppBrowserTest::SetCommandLineArg(const std::string& test_file) { | 173 void PlatformAppBrowserTest::SetCommandLineArg(const std::string& test_file) { |
175 ClearCommandLineArgs(); | 174 ClearCommandLineArgs(); |
176 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 175 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
177 base::FilePath test_doc(test_data_dir_.AppendASCII(test_file)); | 176 base::FilePath test_doc(test_data_dir_.AppendASCII(test_file)); |
178 test_doc = test_doc.NormalizePathSeparators(); | 177 test_doc = test_doc.NormalizePathSeparators(); |
179 command_line->AppendArgPath(test_doc); | 178 command_line->AppendArgPath(test_doc); |
180 } | 179 } |
181 | 180 |
182 ShellWindow* PlatformAppBrowserTest::CreateShellWindow( | 181 AppWindow* PlatformAppBrowserTest::CreateAppWindow(const Extension* extension) { |
183 const Extension* extension) { | 182 return CreateAppWindowFromParams(extension, AppWindow::CreateParams()); |
184 return CreateShellWindowFromParams(extension, ShellWindow::CreateParams()); | |
185 } | 183 } |
186 | 184 |
187 ShellWindow* PlatformAppBrowserTest::CreateShellWindowFromParams( | 185 AppWindow* PlatformAppBrowserTest::CreateAppWindowFromParams( |
188 const Extension* extension, const ShellWindow::CreateParams& params) { | 186 const Extension* extension, |
189 ShellWindow* window = new ShellWindow(browser()->profile(), | 187 const AppWindow::CreateParams& params) { |
190 new ChromeShellWindowDelegate(), | 188 AppWindow* window = new AppWindow( |
191 extension); | 189 browser()->profile(), new ChromeShellWindowDelegate(), extension); |
192 window->Init(GURL(std::string()), | 190 window->Init( |
193 new apps::AppWindowContents(window), | 191 GURL(std::string()), new apps::AppWindowContentsImpl(window), params); |
194 params); | |
195 return window; | 192 return window; |
196 } | 193 } |
197 | 194 |
198 void PlatformAppBrowserTest::CloseShellWindow(ShellWindow* window) { | 195 void PlatformAppBrowserTest::CloseAppWindow(AppWindow* window) { |
199 content::WebContentsDestroyedWatcher destroyed_watcher( | 196 content::WebContentsDestroyedWatcher destroyed_watcher( |
200 window->web_contents()); | 197 window->web_contents()); |
201 window->GetBaseWindow()->Close(); | 198 window->GetBaseWindow()->Close(); |
202 destroyed_watcher.Wait(); | 199 destroyed_watcher.Wait(); |
203 } | 200 } |
204 | 201 |
205 void PlatformAppBrowserTest::CallAdjustBoundsToBeVisibleOnScreenForShellWindow( | 202 void PlatformAppBrowserTest::CallAdjustBoundsToBeVisibleOnScreenForAppWindow( |
206 ShellWindow* window, | 203 AppWindow* window, |
207 const gfx::Rect& cached_bounds, | 204 const gfx::Rect& cached_bounds, |
208 const gfx::Rect& cached_screen_bounds, | 205 const gfx::Rect& cached_screen_bounds, |
209 const gfx::Rect& current_screen_bounds, | 206 const gfx::Rect& current_screen_bounds, |
210 const gfx::Size& minimum_size, | 207 const gfx::Size& minimum_size, |
211 gfx::Rect* bounds) { | 208 gfx::Rect* bounds) { |
212 window->AdjustBoundsToBeVisibleOnScreen(cached_bounds, | 209 window->AdjustBoundsToBeVisibleOnScreen(cached_bounds, |
213 cached_screen_bounds, | 210 cached_screen_bounds, |
214 current_screen_bounds, | 211 current_screen_bounds, |
215 minimum_size, | 212 minimum_size, |
216 bounds); | 213 bounds); |
217 } | 214 } |
218 | 215 |
219 void ExperimentalPlatformAppBrowserTest::SetUpCommandLine( | 216 void ExperimentalPlatformAppBrowserTest::SetUpCommandLine( |
220 CommandLine* command_line) { | 217 CommandLine* command_line) { |
221 PlatformAppBrowserTest::SetUpCommandLine(command_line); | 218 PlatformAppBrowserTest::SetUpCommandLine(command_line); |
222 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 219 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
223 } | 220 } |
224 | 221 |
225 } // namespace extensions | 222 } // namespace extensions |
OLD | NEW |