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 |
| 227 const extensions::Extension* extension = |
| 228 LoadContextMenuExtension("onclick_null"); |
| 229 ASSERT_TRUE(extension); |
| 230 |
| 231 // Wait till item has been created and updated. |
| 232 ASSERT_TRUE(listener_update1.WaitUntilSatisfied()); |
| 233 |
| 234 GURL page_url("http://www.google.com"); |
| 235 |
| 236 // Create and build our test context menu. |
| 237 scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create( |
| 238 GetWebContents(), page_url, GURL(), GURL())); |
| 239 |
| 240 // Look for the extension item in the menu, and execute it. |
| 241 MenuItem::Id id(false, MenuItem::ExtensionKey(extension->id())); |
| 242 id.string_uid = "id1"; |
| 243 int command_id = -1; |
| 244 ASSERT_TRUE(FindCommandId(menu.get(), id, &command_id)); |
| 245 menu->ExecuteCommand(command_id, 0); |
| 246 |
| 247 // Let the test proceed. |
| 248 listener_update1.Reply(""); |
| 249 |
| 250 // Wait until the second context menu has been set up. |
| 251 ASSERT_TRUE(listener_update2.WaitUntilSatisfied()); |
| 252 |
| 253 // Rebuild the context menu and click on the second extension item. |
| 254 menu.reset(TestRenderViewContextMenu::Create(GetWebContents(), page_url, |
| 255 GURL(), GURL())); |
| 256 id.string_uid = "id2"; |
| 257 ASSERT_TRUE(FindCommandId(menu.get(), id, &command_id)); |
| 258 menu->ExecuteCommand(command_id, 0); |
| 259 ASSERT_TRUE(listener_done.WaitUntilSatisfied()); |
| 260 |
| 261 // Upon completion, the replaced onclick callbacks should not have fired. |
| 262 ASSERT_FALSE(listener_error1.was_satisfied()); |
| 263 ASSERT_FALSE(listener_error2.was_satisfied()); |
| 264 } |
| 265 |
218 // Tests that setting "documentUrlPatterns" for an item properly restricts | 266 // Tests that setting "documentUrlPatterns" for an item properly restricts |
219 // those items to matching pages. | 267 // those items to matching pages. |
220 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Patterns) { | 268 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Patterns) { |
221 ExtensionTestMessageListener listener("created items", false); | 269 ExtensionTestMessageListener listener("created items", false); |
222 | 270 |
223 ASSERT_TRUE(LoadContextMenuExtension("patterns")); | 271 ASSERT_TRUE(LoadContextMenuExtension("patterns")); |
224 | 272 |
225 // Wait for the js test code to create its two items with patterns. | 273 // Wait for the js test code to create its two items with patterns. |
226 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 274 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
227 | 275 |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
605 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito")); | 653 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito")); |
606 | 654 |
607 // Wait for the extension's processes to tell us they've created an item. | 655 // Wait for the extension's processes to tell us they've created an item. |
608 ASSERT_TRUE(created.WaitUntilSatisfied()); | 656 ASSERT_TRUE(created.WaitUntilSatisfied()); |
609 ASSERT_TRUE(created_incognito.WaitUntilSatisfied()); | 657 ASSERT_TRUE(created_incognito.WaitUntilSatisfied()); |
610 ASSERT_EQ(2u, GetItems().size()); | 658 ASSERT_EQ(2u, GetItems().size()); |
611 | 659 |
612 browser()->profile()->DestroyOffTheRecordProfile(); | 660 browser()->profile()->DestroyOffTheRecordProfile(); |
613 ASSERT_EQ(1u, GetItems().size()); | 661 ASSERT_EQ(1u, GetItems().size()); |
614 } | 662 } |
OLD | NEW |