OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { | 144 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, EmptyContextMenu) { |
145 ExtensionTestMessageListener launched_listener("Launched", false); | 145 ExtensionTestMessageListener launched_listener("Launched", false); |
146 LoadAndLaunchPlatformApp("minimal"); | 146 LoadAndLaunchPlatformApp("minimal"); |
147 | 147 |
148 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 148 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
149 | 149 |
150 // The empty app doesn't add any context menu items, so its menu should | 150 // The empty app doesn't add any context menu items, so its menu should |
151 // only include the developer tools. | 151 // only include the developer tools. |
152 WebContents* web_contents = GetFirstShellWindowWebContents(); | 152 WebContents* web_contents = GetFirstShellWindowWebContents(); |
153 ASSERT_TRUE(web_contents); | 153 ASSERT_TRUE(web_contents); |
154 WebKit::WebContextMenuData data; | 154 content::ContextMenuParams params; |
155 content::ContextMenuParams params(data); | |
156 scoped_ptr<PlatformAppContextMenu> menu; | 155 scoped_ptr<PlatformAppContextMenu> menu; |
157 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 156 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
158 menu->Init(); | 157 menu->Init(); |
159 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 158 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
160 ASSERT_TRUE( | 159 ASSERT_TRUE( |
161 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 160 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
162 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 161 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
163 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 162 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
164 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 163 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
165 } | 164 } |
166 | 165 |
167 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { | 166 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { |
168 ExtensionTestMessageListener launched_listener("Launched", false); | 167 ExtensionTestMessageListener launched_listener("Launched", false); |
169 LoadAndLaunchPlatformApp("context_menu"); | 168 LoadAndLaunchPlatformApp("context_menu"); |
170 | 169 |
171 // Wait for the extension to tell us it's initialized its context menus and | 170 // Wait for the extension to tell us it's initialized its context menus and |
172 // launched a window. | 171 // launched a window. |
173 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 172 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
174 | 173 |
175 // The context_menu app has two context menu items. These, along with a | 174 // The context_menu app has two context menu items. These, along with a |
176 // separator and the developer tools, is all that should be in the menu. | 175 // separator and the developer tools, is all that should be in the menu. |
177 WebContents* web_contents = GetFirstShellWindowWebContents(); | 176 WebContents* web_contents = GetFirstShellWindowWebContents(); |
178 ASSERT_TRUE(web_contents); | 177 ASSERT_TRUE(web_contents); |
179 WebKit::WebContextMenuData data; | 178 content::ContextMenuParams params; |
180 content::ContextMenuParams params(data); | |
181 scoped_ptr<PlatformAppContextMenu> menu; | 179 scoped_ptr<PlatformAppContextMenu> menu; |
182 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 180 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
183 menu->Init(); | 181 menu->Init(); |
184 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 182 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
185 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); | 183 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
186 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 184 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
187 ASSERT_TRUE( | 185 ASSERT_TRUE( |
188 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 186 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
189 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 187 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
190 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 188 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
191 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 189 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
192 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 190 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
193 } | 191 } |
194 | 192 |
195 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { | 193 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { |
196 ExtensionTestMessageListener launched_listener("Launched", false); | 194 ExtensionTestMessageListener launched_listener("Launched", false); |
197 InstallAndLaunchPlatformApp("context_menu"); | 195 InstallAndLaunchPlatformApp("context_menu"); |
198 | 196 |
199 // Wait for the extension to tell us it's initialized its context menus and | 197 // Wait for the extension to tell us it's initialized its context menus and |
200 // launched a window. | 198 // launched a window. |
201 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 199 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
202 | 200 |
203 // The context_menu app has two context menu items. For an installed app | 201 // The context_menu app has two context menu items. For an installed app |
204 // these are all that should be in the menu. | 202 // these are all that should be in the menu. |
205 WebContents* web_contents = GetFirstShellWindowWebContents(); | 203 WebContents* web_contents = GetFirstShellWindowWebContents(); |
206 ASSERT_TRUE(web_contents); | 204 ASSERT_TRUE(web_contents); |
207 WebKit::WebContextMenuData data; | 205 content::ContextMenuParams params; |
208 content::ContextMenuParams params(data); | |
209 scoped_ptr<PlatformAppContextMenu> menu; | 206 scoped_ptr<PlatformAppContextMenu> menu; |
210 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 207 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
211 menu->Init(); | 208 menu->Init(); |
212 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 209 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
213 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); | 210 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
214 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 211 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
215 ASSERT_FALSE( | 212 ASSERT_FALSE( |
216 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 213 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
217 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 214 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
218 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 215 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
219 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 216 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
220 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 217 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
221 } | 218 } |
222 | 219 |
223 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { | 220 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { |
224 ExtensionTestMessageListener launched_listener("Launched", false); | 221 ExtensionTestMessageListener launched_listener("Launched", false); |
225 LoadAndLaunchPlatformApp("context_menu"); | 222 LoadAndLaunchPlatformApp("context_menu"); |
226 | 223 |
227 // Wait for the extension to tell us it's initialized its context menus and | 224 // Wait for the extension to tell us it's initialized its context menus and |
228 // launched a window. | 225 // launched a window. |
229 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 226 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
230 | 227 |
231 // The context_menu app has one context menu item. This, along with a | 228 // The context_menu app has one context menu item. This, along with a |
232 // separator and the developer tools, is all that should be in the menu. | 229 // separator and the developer tools, is all that should be in the menu. |
233 WebContents* web_contents = GetFirstShellWindowWebContents(); | 230 WebContents* web_contents = GetFirstShellWindowWebContents(); |
234 ASSERT_TRUE(web_contents); | 231 ASSERT_TRUE(web_contents); |
235 WebKit::WebContextMenuData data; | 232 content::ContextMenuParams params; |
236 content::ContextMenuParams params(data); | |
237 params.is_editable = true; | 233 params.is_editable = true; |
238 scoped_ptr<PlatformAppContextMenu> menu; | 234 scoped_ptr<PlatformAppContextMenu> menu; |
239 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 235 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
240 menu->Init(); | 236 menu->Init(); |
241 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 237 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
242 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 238 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
243 ASSERT_TRUE( | 239 ASSERT_TRUE( |
244 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 240 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
245 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 241 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
246 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 242 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
247 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 243 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
248 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 244 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
249 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 245 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
250 } | 246 } |
251 | 247 |
252 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { | 248 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { |
253 ExtensionTestMessageListener launched_listener("Launched", false); | 249 ExtensionTestMessageListener launched_listener("Launched", false); |
254 LoadAndLaunchPlatformApp("context_menu"); | 250 LoadAndLaunchPlatformApp("context_menu"); |
255 | 251 |
256 // Wait for the extension to tell us it's initialized its context menus and | 252 // Wait for the extension to tell us it's initialized its context menus and |
257 // launched a window. | 253 // launched a window. |
258 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 254 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
259 | 255 |
260 // The context_menu app has one context menu item. This, along with a | 256 // The context_menu app has one context menu item. This, along with a |
261 // separator and the developer tools, is all that should be in the menu. | 257 // separator and the developer tools, is all that should be in the menu. |
262 WebContents* web_contents = GetFirstShellWindowWebContents(); | 258 WebContents* web_contents = GetFirstShellWindowWebContents(); |
263 ASSERT_TRUE(web_contents); | 259 ASSERT_TRUE(web_contents); |
264 WebKit::WebContextMenuData data; | 260 content::ContextMenuParams params; |
265 content::ContextMenuParams params(data); | |
266 params.selection_text = ASCIIToUTF16("Hello World"); | 261 params.selection_text = ASCIIToUTF16("Hello World"); |
267 scoped_ptr<PlatformAppContextMenu> menu; | 262 scoped_ptr<PlatformAppContextMenu> menu; |
268 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 263 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
269 menu->Init(); | 264 menu->Init(); |
270 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 265 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
271 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 266 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
272 ASSERT_TRUE( | 267 ASSERT_TRUE( |
273 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); | 268 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
274 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); | 269 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP)); |
275 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 270 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
276 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 271 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
277 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 272 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
278 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 273 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
279 } | 274 } |
280 | 275 |
281 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { | 276 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { |
282 ExtensionTestMessageListener launched_listener("Launched", false); | 277 ExtensionTestMessageListener launched_listener("Launched", false); |
283 LoadAndLaunchPlatformApp("context_menu_click"); | 278 LoadAndLaunchPlatformApp("context_menu_click"); |
284 | 279 |
285 // Wait for the extension to tell us it's initialized its context menus and | 280 // Wait for the extension to tell us it's initialized its context menus and |
286 // launched a window. | 281 // launched a window. |
287 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 282 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
288 | 283 |
289 // Test that the menu item shows up | 284 // Test that the menu item shows up |
290 WebContents* web_contents = GetFirstShellWindowWebContents(); | 285 WebContents* web_contents = GetFirstShellWindowWebContents(); |
291 ASSERT_TRUE(web_contents); | 286 ASSERT_TRUE(web_contents); |
292 WebKit::WebContextMenuData data; | 287 content::ContextMenuParams params; |
293 content::ContextMenuParams params(data); | |
294 params.page_url = GURL("http://foo.bar"); | 288 params.page_url = GURL("http://foo.bar"); |
295 scoped_ptr<PlatformAppContextMenu> menu; | 289 scoped_ptr<PlatformAppContextMenu> menu; |
296 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 290 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
297 menu->Init(); | 291 menu->Init(); |
298 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 292 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
299 | 293 |
300 // Execute the menu item | 294 // Execute the menu item |
301 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", | 295 ExtensionTestMessageListener onclicked_listener("onClicked fired for id1", |
302 false); | 296 false); |
303 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST, 0); | 297 menu->ExecuteCommand(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST, 0); |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 | 980 |
987 while (!ContainsKey(opener_app_ids_, file_manager->id())) { | 981 while (!ContainsKey(opener_app_ids_, file_manager->id())) { |
988 content::RunAllPendingInMessageLoop(); | 982 content::RunAllPendingInMessageLoop(); |
989 } | 983 } |
990 } | 984 } |
991 | 985 |
992 #endif // defined(OS_CHROMEOS) | 986 #endif // defined(OS_CHROMEOS) |
993 | 987 |
994 | 988 |
995 } // namespace extensions | 989 } // namespace extensions |
OLD | NEW |