| 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/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
| 7 #include "base/threading/platform_thread.h" | 7 #include "base/threading/platform_thread.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/automation/automation_util.h" | 10 #include "chrome/browser/automation/automation_util.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // The empty app doesn't add any context menu items, so its menu should | 162 // The empty app doesn't add any context menu items, so its menu should |
| 163 // only include the developer tools. | 163 // only include the developer tools. |
| 164 WebContents* web_contents = GetFirstShellWindowWebContents(); | 164 WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 165 ASSERT_TRUE(web_contents); | 165 ASSERT_TRUE(web_contents); |
| 166 WebKit::WebContextMenuData data; | 166 WebKit::WebContextMenuData data; |
| 167 content::ContextMenuParams params(data); | 167 content::ContextMenuParams params(data); |
| 168 scoped_ptr<PlatformAppContextMenu> menu; | 168 scoped_ptr<PlatformAppContextMenu> menu; |
| 169 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 169 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 170 menu->Init(); | 170 menu->Init(); |
| 171 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 171 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 172 ASSERT_TRUE( |
| 173 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
| 172 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); | 174 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 173 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 175 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 174 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 176 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 175 } | 177 } |
| 176 | 178 |
| 177 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { | 179 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenu) { |
| 178 ExtensionTestMessageListener launched_listener("Launched", false); | 180 ExtensionTestMessageListener launched_listener("Launched", false); |
| 179 LoadAndLaunchPlatformApp("context_menu"); | 181 LoadAndLaunchPlatformApp("context_menu"); |
| 180 | 182 |
| 181 // Wait for the extension to tell us it's initialized its context menus and | 183 // Wait for the extension to tell us it's initialized its context menus and |
| 182 // launched a window. | 184 // launched a window. |
| 183 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 185 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 184 | 186 |
| 185 // The context_menu app has two context menu items. These, along with a | 187 // The context_menu app has two context menu items. These, along with a |
| 186 // separator and the developer tools, is all that should be in the menu. | 188 // separator and the developer tools, is all that should be in the menu. |
| 187 WebContents* web_contents = GetFirstShellWindowWebContents(); | 189 WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 188 ASSERT_TRUE(web_contents); | 190 ASSERT_TRUE(web_contents); |
| 189 WebKit::WebContextMenuData data; | 191 WebKit::WebContextMenuData data; |
| 190 content::ContextMenuParams params(data); | 192 content::ContextMenuParams params(data); |
| 191 scoped_ptr<PlatformAppContextMenu> menu; | 193 scoped_ptr<PlatformAppContextMenu> menu; |
| 192 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 194 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 193 menu->Init(); | 195 menu->Init(); |
| 194 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 196 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 195 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); | 197 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
| 196 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 198 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 199 ASSERT_TRUE( |
| 200 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
| 197 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); | 201 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 198 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 202 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 199 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 203 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 200 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 204 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 201 } | 205 } |
| 202 | 206 |
| 207 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, InstalledAppWithContextMenu) { |
| 208 ExtensionTestMessageListener launched_listener("Launched", false); |
| 209 InstallAndLaunchPlatformApp("context_menu"); |
| 210 |
| 211 // Wait for the extension to tell us it's initialized its context menus and |
| 212 // launched a window. |
| 213 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 214 |
| 215 // The context_menu app has two context menu items. For an installed app |
| 216 // these are all that should be in the menu. |
| 217 WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 218 ASSERT_TRUE(web_contents); |
| 219 WebKit::WebContextMenuData data; |
| 220 content::ContextMenuParams params(data); |
| 221 scoped_ptr<PlatformAppContextMenu> menu; |
| 222 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 223 menu->Init(); |
| 224 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 225 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
| 226 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 227 ASSERT_FALSE( |
| 228 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
| 229 ASSERT_FALSE(menu->HasCommandWithId(IDC_RELOAD)); |
| 230 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 231 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 232 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 233 } |
| 234 |
| 203 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { | 235 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuTextField) { |
| 204 ExtensionTestMessageListener launched_listener("Launched", false); | 236 ExtensionTestMessageListener launched_listener("Launched", false); |
| 205 LoadAndLaunchPlatformApp("context_menu"); | 237 LoadAndLaunchPlatformApp("context_menu"); |
| 206 | 238 |
| 207 // Wait for the extension to tell us it's initialized its context menus and | 239 // Wait for the extension to tell us it's initialized its context menus and |
| 208 // launched a window. | 240 // launched a window. |
| 209 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 241 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 210 | 242 |
| 211 // The context_menu app has one context menu item. This, along with a | 243 // The context_menu app has one context menu item. This, along with a |
| 212 // separator and the developer tools, is all that should be in the menu. | 244 // separator and the developer tools, is all that should be in the menu. |
| 213 WebContents* web_contents = GetFirstShellWindowWebContents(); | 245 WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 214 ASSERT_TRUE(web_contents); | 246 ASSERT_TRUE(web_contents); |
| 215 WebKit::WebContextMenuData data; | 247 WebKit::WebContextMenuData data; |
| 216 content::ContextMenuParams params(data); | 248 content::ContextMenuParams params(data); |
| 217 params.is_editable = true; | 249 params.is_editable = true; |
| 218 scoped_ptr<PlatformAppContextMenu> menu; | 250 scoped_ptr<PlatformAppContextMenu> menu; |
| 219 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 251 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 220 menu->Init(); | 252 menu->Init(); |
| 221 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 253 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 222 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 254 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 255 ASSERT_TRUE( |
| 256 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
| 223 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); | 257 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 224 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 258 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 225 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 259 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 226 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 260 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 227 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 261 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 228 } | 262 } |
| 229 | 263 |
| 230 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { | 264 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuSelection) { |
| 231 ExtensionTestMessageListener launched_listener("Launched", false); | 265 ExtensionTestMessageListener launched_listener("Launched", false); |
| 232 LoadAndLaunchPlatformApp("context_menu"); | 266 LoadAndLaunchPlatformApp("context_menu"); |
| 233 | 267 |
| 234 // Wait for the extension to tell us it's initialized its context menus and | 268 // Wait for the extension to tell us it's initialized its context menus and |
| 235 // launched a window. | 269 // launched a window. |
| 236 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); | 270 ASSERT_TRUE(launched_listener.WaitUntilSatisfied()); |
| 237 | 271 |
| 238 // The context_menu app has one context menu item. This, along with a | 272 // The context_menu app has one context menu item. This, along with a |
| 239 // separator and the developer tools, is all that should be in the menu. | 273 // separator and the developer tools, is all that should be in the menu. |
| 240 WebContents* web_contents = GetFirstShellWindowWebContents(); | 274 WebContents* web_contents = GetFirstShellWindowWebContents(); |
| 241 ASSERT_TRUE(web_contents); | 275 ASSERT_TRUE(web_contents); |
| 242 WebKit::WebContextMenuData data; | 276 WebKit::WebContextMenuData data; |
| 243 content::ContextMenuParams params(data); | 277 content::ContextMenuParams params(data); |
| 244 params.selection_text = ASCIIToUTF16("Hello World"); | 278 params.selection_text = ASCIIToUTF16("Hello World"); |
| 245 scoped_ptr<PlatformAppContextMenu> menu; | 279 scoped_ptr<PlatformAppContextMenu> menu; |
| 246 menu.reset(new PlatformAppContextMenu(web_contents, params)); | 280 menu.reset(new PlatformAppContextMenu(web_contents, params)); |
| 247 menu->Init(); | 281 menu->Init(); |
| 248 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 282 ASSERT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 249 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 283 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 284 ASSERT_TRUE( |
| 285 menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE)); |
| 250 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); | 286 ASSERT_TRUE(menu->HasCommandWithId(IDC_RELOAD)); |
| 251 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 287 ASSERT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 252 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 288 ASSERT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 253 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 289 ASSERT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 254 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 290 ASSERT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 255 } | 291 } |
| 256 | 292 |
| 257 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { | 293 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, AppWithContextMenuClicked) { |
| 258 ExtensionTestMessageListener launched_listener("Launched", false); | 294 ExtensionTestMessageListener launched_listener("Launched", false); |
| 259 LoadAndLaunchPlatformApp("context_menu_click"); | 295 LoadAndLaunchPlatformApp("context_menu_click"); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 | 599 |
| 564 // Tell javascript to open a third window. | 600 // Tell javascript to open a third window. |
| 565 page3_listener.Reply("continue"); | 601 page3_listener.Reply("continue"); |
| 566 | 602 |
| 567 // Wait for javascript to verify that the third window got the restored size | 603 // Wait for javascript to verify that the third window got the restored size |
| 568 // and explicitly specified coordinates. | 604 // and explicitly specified coordinates. |
| 569 ASSERT_TRUE(done3_listener.WaitUntilSatisfied()); | 605 ASSERT_TRUE(done3_listener.WaitUntilSatisfied()); |
| 570 } | 606 } |
| 571 | 607 |
| 572 } // namespace extensions | 608 } // namespace extensions |
| OLD | NEW |