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/app/chrome_command_ids.h" | 6 #include "chrome/app/chrome_command_ids.h" |
7 #include "chrome/browser/extensions/extension_browsertest.h" | 7 #include "chrome/browser/extensions/extension_browsertest.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_test_message_listener.h" | 9 #include "chrome/browser/extensions/extension_test_message_listener.h" |
10 #include "chrome/browser/extensions/lazy_background_page_test_util.h" | 10 #include "chrome/browser/extensions/lazy_background_page_test_util.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 return i->get(); | 142 return i->get(); |
143 } | 143 } |
144 } | 144 } |
145 return NULL; | 145 return NULL; |
146 } | 146 } |
147 | 147 |
148 // This gets all the items that any extension has registered for possible | 148 // This gets all the items that any extension has registered for possible |
149 // inclusion in context menus. | 149 // inclusion in context menus. |
150 MenuItem::List GetItems() { | 150 MenuItem::List GetItems() { |
151 MenuItem::List result; | 151 MenuItem::List result; |
152 std::set<std::string> extension_ids = menu_manager()->ExtensionIds(); | 152 std::set<MenuItem::ExtensionKey> extension_ids = |
153 std::set<std::string>::iterator i; | 153 menu_manager()->ExtensionIds(); |
| 154 std::set<MenuItem::ExtensionKey>::iterator i; |
154 for (i = extension_ids.begin(); i != extension_ids.end(); ++i) { | 155 for (i = extension_ids.begin(); i != extension_ids.end(); ++i) { |
155 const MenuItem::List* list = menu_manager()->MenuItems(*i); | 156 const MenuItem::List* list = menu_manager()->MenuItems(*i); |
156 result.insert(result.end(), list->begin(), list->end()); | 157 result.insert(result.end(), list->begin(), list->end()); |
157 } | 158 } |
158 return result; | 159 return result; |
159 } | 160 } |
160 | 161 |
161 // This creates a test menu for a page with |page_url| and |link_url|, looks | 162 // This creates a test menu for a page with |page_url| and |link_url|, looks |
162 // for an extension item with the given |label|, and returns true if the item | 163 // for an extension item with the given |label|, and returns true if the item |
163 // was found. | 164 // was found. |
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 // Test that menu items appear while the page is unloaded. | 628 // Test that menu items appear while the page is unloaded. |
628 ASSERT_TRUE(MenuHasItemWithLabel( | 629 ASSERT_TRUE(MenuHasItemWithLabel( |
629 about_blank, GURL(), GURL(), std::string("Item 1"))); | 630 about_blank, GURL(), GURL(), std::string("Item 1"))); |
630 ASSERT_TRUE(MenuHasItemWithLabel( | 631 ASSERT_TRUE(MenuHasItemWithLabel( |
631 about_blank, GURL(), GURL(), std::string("Checkbox 1"))); | 632 about_blank, GURL(), GURL(), std::string("Checkbox 1"))); |
632 | 633 |
633 // Test that checked menu items retain their checkedness. | 634 // Test that checked menu items retain their checkedness. |
634 LazyBackgroundObserver checkbox_checked; | 635 LazyBackgroundObserver checkbox_checked; |
635 scoped_ptr<TestRenderViewContextMenu> menu( | 636 scoped_ptr<TestRenderViewContextMenu> menu( |
636 CreateMenu(browser(), about_blank, GURL(), GURL())); | 637 CreateMenu(browser(), about_blank, GURL(), GURL())); |
637 MenuItem::Id id(false, extension->id()); | 638 MenuItem::Id id(false, MenuItem::ExtensionKey(extension->id())); |
638 id.string_uid = "checkbox1"; | 639 id.string_uid = "checkbox1"; |
639 int command_id = -1; | 640 int command_id = -1; |
640 ASSERT_TRUE(FindCommandId(menu.get(), id, &command_id)); | 641 ASSERT_TRUE(FindCommandId(menu.get(), id, &command_id)); |
641 EXPECT_FALSE(menu->IsCommandIdChecked(command_id)); | 642 EXPECT_FALSE(menu->IsCommandIdChecked(command_id)); |
642 | 643 |
643 // Executing the checkbox also fires the onClicked event. | 644 // Executing the checkbox also fires the onClicked event. |
644 ExtensionTestMessageListener listener("onClicked fired for checkbox1", false); | 645 ExtensionTestMessageListener listener("onClicked fired for checkbox1", false); |
645 menu->ExecuteCommand(command_id, 0); | 646 menu->ExecuteCommand(command_id, 0); |
646 checkbox_checked.WaitUntilClosed(); | 647 checkbox_checked.WaitUntilClosed(); |
647 | 648 |
(...skipping 12 matching lines...) Expand all Loading... |
660 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito")); | 661 ASSERT_TRUE(LoadContextMenuExtensionIncognito("incognito")); |
661 | 662 |
662 // Wait for the extension's processes to tell us they've created an item. | 663 // Wait for the extension's processes to tell us they've created an item. |
663 ASSERT_TRUE(created.WaitUntilSatisfied()); | 664 ASSERT_TRUE(created.WaitUntilSatisfied()); |
664 ASSERT_TRUE(created_incognito.WaitUntilSatisfied()); | 665 ASSERT_TRUE(created_incognito.WaitUntilSatisfied()); |
665 ASSERT_EQ(2u, GetItems().size()); | 666 ASSERT_EQ(2u, GetItems().size()); |
666 | 667 |
667 browser()->profile()->DestroyOffTheRecordProfile(); | 668 browser()->profile()->DestroyOffTheRecordProfile(); |
668 ASSERT_EQ(1u, GetItems().size()); | 669 ASSERT_EQ(1u, GetItems().size()); |
669 } | 670 } |
OLD | NEW |