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. | |
lazyboy
2015/02/26 00:39:47
// This test also tests that setting onclick handl
robwu
2015/02/26 09:33:46
Done.
| |
219 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, UpdateOnclick) { | |
220 ExtensionTestMessageListener listener_error1("onclick-unexpected", false); | |
lazyboy
2015/02/26 00:39:47
"onclick1-unexpected", let's append 1 in all place
robwu
2015/02/26 09:33:46
Done.
| |
221 ExtensionTestMessageListener listener_error2("onclick2-unexpected", false); | |
222 ExtensionTestMessageListener listener_update1("update1", true); | |
223 ExtensionTestMessageListener listener_update2("update2", false); | |
224 ExtensionTestMessageListener listener_done("onclick2", false); | |
225 ASSERT_TRUE(LoadContextMenuExtension("onclick_null")); | |
226 | |
227 // Wait till item has been created and updated. | |
228 ASSERT_TRUE(listener_update1.WaitUntilSatisfied()); | |
229 | |
230 GURL page_url("http://www.google.com"); | |
231 | |
232 // Create and build our test context menu. | |
233 scoped_ptr<TestRenderViewContextMenu> menu(TestRenderViewContextMenu::Create( | |
234 GetWebContents(), page_url, GURL(), GURL())); | |
235 | |
236 // Look for the extension item in the menu, and execute it. | |
237 int command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(0); | |
238 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id)); | |
239 menu->ExecuteCommand(command_id, 0); | |
240 | |
241 // Let the test proceed. | |
242 listener_update1.Reply(""); | |
243 | |
244 // Wait until the second context menu has been set up. | |
245 ASSERT_TRUE(listener_update2.WaitUntilSatisfied()); | |
246 | |
247 // Click on the second menu item. | |
248 command_id = ContextMenuMatcher::ConvertToExtensionsCustomCommandId(1); | |
249 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id)); | |
250 menu->ExecuteCommand(command_id, 0); | |
251 ASSERT_TRUE(listener_done.WaitUntilSatisfied()); | |
252 | |
253 // Upon completion, the replaced onclick callbacks should not have fired. | |
254 ASSERT_FALSE(listener_error1.was_satisfied()); | |
255 ASSERT_FALSE(listener_error2.was_satisfied()); | |
256 } | |
257 | |
218 // Tests that setting "documentUrlPatterns" for an item properly restricts | 258 // Tests that setting "documentUrlPatterns" for an item properly restricts |
219 // those items to matching pages. | 259 // those items to matching pages. |
220 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Patterns) { | 260 IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Patterns) { |
221 ExtensionTestMessageListener listener("created items", false); | 261 ExtensionTestMessageListener listener("created items", false); |
222 | 262 |
223 ASSERT_TRUE(LoadContextMenuExtension("patterns")); | 263 ASSERT_TRUE(LoadContextMenuExtension("patterns")); |
224 | 264 |
225 // Wait for the js test code to create its two items with patterns. | 265 // Wait for the js test code to create its two items with patterns. |
226 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 266 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
227 | 267 |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
605 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito")); | 645 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito")); |
606 | 646 |
607 // Wait for the extension's processes to tell us they've created an item. | 647 // Wait for the extension's processes to tell us they've created an item. |
608 ASSERT_TRUE(created.WaitUntilSatisfied()); | 648 ASSERT_TRUE(created.WaitUntilSatisfied()); |
609 ASSERT_TRUE(created_incognito.WaitUntilSatisfied()); | 649 ASSERT_TRUE(created_incognito.WaitUntilSatisfied()); |
610 ASSERT_EQ(2u, GetItems().size()); | 650 ASSERT_EQ(2u, GetItems().size()); |
611 | 651 |
612 browser()->profile()->DestroyOffTheRecordProfile(); | 652 browser()->profile()->DestroyOffTheRecordProfile(); |
613 ASSERT_EQ(1u, GetItems().size()); | 653 ASSERT_EQ(1u, GetItems().size()); |
614 } | 654 } |
OLD | NEW |