| 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/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
| 6 #include "chrome/browser/extensions/extension_browsertest.h" | 6 #include "chrome/browser/extensions/extension_browsertest.h" |
| 7 #include "chrome/browser/extensions/lazy_background_page_test_util.h" | 7 #include "chrome/browser/extensions/lazy_background_page_test_util.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" | 9 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" | 10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 208 |
| 209 // Look for the extension item in the menu, and execute it. | 209 // Look for the extension item in the menu, and execute it. |
| 210 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0); | 210 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0); |
| 211 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id)); | 211 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id)); |
| 212 menu->ExecuteCommand(command_id, 0); | 212 menu->ExecuteCommand(command_id, 0); |
| 213 | 213 |
| 214 // Wait for the extension's script to tell us its onclick fired. | 214 // Wait for the extension's script to tell us its onclick fired. |
| 215 ASSERT_TRUE(listener2.WaitUntilSatisfied()); | 215 ASSERT_TRUE(listener2.WaitUntilSatisfied()); |
| 216 } | 216 } |
| 217 | 217 |
| 218 // Tests that previous onclick is not fired after updating the menu's onclick, |
| 219 // and whether setting onclick to null removes the handler. |
| 220 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, UpdateOnclick) { |
| 221 ExtensionTestMessageListener listener_error1("onclick1-unexpected", false); |
| 222 ExtensionTestMessageListener listener_error2("onclick2-unexpected", false); |
| 223 ExtensionTestMessageListener listener_update1("update1", true); |
| 224 ExtensionTestMessageListener listener_update2("update2", false); |
| 225 ExtensionTestMessageListener listener_done("onclick2", false); |
| 226 ASSERT_TRUE(LoadContextMenuExtension("onclick_null")); |
| 227 |
| 228 // Wait till item has been created and updated. |
| 229 ASSERT_TRUE(listener_update1.WaitUntilSatisfied()); |
| 230 |
| 231 GURL page_url("http://www.google.com"); |
| 232 |
| 233 // Create and build our test context menu. |
| 234 scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create( |
| 235 GetWebContents(), page_url, GURL(), GURL())); |
| 236 |
| 237 // Look for the extension item in the menu, and execute it. |
| 238 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0); |
| 239 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id)); |
| 240 menu->ExecuteCommand(command_id, 0); |
| 241 |
| 242 // Let the test proceed. |
| 243 listener_update1.Reply(""); |
| 244 |
| 245 // Wait until the second context menu has been set up. |
| 246 ASSERT_TRUE(listener_update2.WaitUntilSatisfied()); |
| 247 |
| 248 // Click on the second menu item. |
| 249 command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(1); |
| 250 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id)); |
| 251 menu->ExecuteCommand(command_id, 0); |
| 252 ASSERT_TRUE(listener_done.WaitUntilSatisfied()); |
| 253 |
| 254 // Upon completion, the replaced onclick callbacks should not have fired. |
| 255 ASSERT_FALSE(listener_error1.was_satisfied()); |
| 256 ASSERT_FALSE(listener_error2.was_satisfied()); |
| 257 } |
| 258 |
| 218 // Tests that setting "documentUrlPatterns" for an item properly restricts | 259 // Tests that setting "documentUrlPatterns" for an item properly restricts |
| 219 // those items to matching pages. | 260 // those items to matching pages. |
| 220 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Patterns) { | 261 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Patterns) { |
| 221 ExtensionTestMessageListener listener("created items", false); | 262 ExtensionTestMessageListener listener("created items", false); |
| 222 | 263 |
| 223 ASSERT_TRUE(LoadContextMenuExtension("patterns")); | 264 ASSERT_TRUE(LoadContextMenuExtension("patterns")); |
| 224 | 265 |
| 225 // Wait for the js test code to create its two items with patterns. | 266 // Wait for the js test code to create its two items with patterns. |
| 226 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 267 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 227 | 268 |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito")); | 646 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito")); |
| 606 | 647 |
| 607 // Wait for the extension's processes to tell us they've created an item. | 648 // Wait for the extension's processes to tell us they've created an item. |
| 608 ASSERT_TRUE(created.WaitUntilSatisfied()); | 649 ASSERT_TRUE(created.WaitUntilSatisfied()); |
| 609 ASSERT_TRUE(created_incognito.WaitUntilSatisfied()); | 650 ASSERT_TRUE(created_incognito.WaitUntilSatisfied()); |
| 610 ASSERT_EQ(2u, GetItems().size()); | 651 ASSERT_EQ(2u, GetItems().size()); |
| 611 | 652 |
| 612 browser()->profile()->DestroyOffTheRecordProfile(); | 653 browser()->profile()->DestroyOffTheRecordProfile(); |
| 613 ASSERT_EQ(1u, GetItems().size()); | 654 ASSERT_EQ(1u, GetItems().size()); |
| 614 } | 655 } |
| OLD | NEW |