| Index: chrome/browser/extensions/extension_context_menu_browsertest.cc
|
| diff --git a/chrome/browser/extensions/extension_context_menu_browsertest.cc b/chrome/browser/extensions/extension_context_menu_browsertest.cc
|
| index 442d2abf426238b644f1d704338a3ad76501f785..10bf72e70ecff230ab74a583cb9116e8aacb0282 100644
|
| --- a/chrome/browser/extensions/extension_context_menu_browsertest.cc
|
| +++ b/chrome/browser/extensions/extension_context_menu_browsertest.cc
|
| @@ -39,36 +39,6 @@ class TestRenderViewContextMenu : public RenderViewContextMenu {
|
|
|
| virtual ~TestRenderViewContextMenu() {}
|
|
|
| - bool HasExtensionItemWithLabel(const std::string& label) {
|
| - string16 label16 = UTF8ToUTF16(label);
|
| - std::map<int, MenuItem::Id>::iterator i;
|
| - for (i = extension_item_map_.begin(); i != extension_item_map_.end(); ++i) {
|
| - const MenuItem::Id& id = i->second;
|
| - string16 tmp_label;
|
| - EXPECT_TRUE(GetItemLabel(id, &tmp_label));
|
| - if (tmp_label == label16)
|
| - return true;
|
| - }
|
| - return false;
|
| - }
|
| -
|
| - // Looks in the menu for an extension item with |id|, and if it is found and
|
| - // has a label, that is put in |result| and we return true. Otherwise returns
|
| - // false.
|
| - bool GetItemLabel(const MenuItem::Id& id, string16* result) {
|
| - int command_id = 0;
|
| - if (!FindCommandId(id, &command_id))
|
| - return false;
|
| -
|
| - MenuModel* model = NULL;
|
| - int index = -1;
|
| - if (!GetMenuModelAndItemIndex(command_id, &model, &index)) {
|
| - return false;
|
| - }
|
| - *result = model->GetLabelAt(index);
|
| - return true;
|
| - }
|
| -
|
| // Searches for an menu item with |command_id|. If it's found, the return
|
| // value is true and the model and index where it appears in that model are
|
| // returned in |found_model| and |found_index|. Otherwise returns false.
|
| @@ -95,17 +65,8 @@ class TestRenderViewContextMenu : public RenderViewContextMenu {
|
| return false;
|
| }
|
|
|
| - // Given an extension menu item id, tries to find the corresponding command id
|
| - // in the menu.
|
| - bool FindCommandId(const MenuItem::Id& id, int* command_id) {
|
| - std::map<int, MenuItem::Id>::const_iterator i;
|
| - for (i = extension_item_map_.begin(); i != extension_item_map_.end(); ++i) {
|
| - if (i->second == id) {
|
| - *command_id = i->first;
|
| - return true;
|
| - }
|
| - }
|
| - return false;
|
| + extensions::ContextMenuMatcher& extension_items() {
|
| + return extension_items_;
|
| }
|
|
|
| protected:
|
| @@ -197,7 +158,7 @@ class ExtensionContextMenuBrowserTest : public ExtensionBrowserTest {
|
| const std::string& label) {
|
| scoped_ptr<TestRenderViewContextMenu> menu(
|
| CreateMenu(browser(), page_url, link_url, frame_url));
|
| - return menu->HasExtensionItemWithLabel(label);
|
| + return MenuHasExtensionItemWithLabel(menu.get(), label);
|
| }
|
|
|
| // This creates an extension that starts |enabled| and then switches to
|
| @@ -233,6 +194,56 @@ class ExtensionContextMenuBrowserTest : public ExtensionBrowserTest {
|
| ASSERT_TRUE(update.WaitUntilSatisfied());
|
| ASSERT_EQ(!enabled, menu->IsCommandIdEnabled(command_id));
|
| }
|
| +
|
| + bool MenuHasExtensionItemWithLabel(TestRenderViewContextMenu* menu,
|
| + const std::string& label) {
|
| + string16 label16 = UTF8ToUTF16(label);
|
| + std::map<int, MenuItem::Id>::iterator i;
|
| + for (i = menu->extension_items().extension_item_map_.begin();
|
| + i != menu->extension_items().extension_item_map_.end(); ++i) {
|
| + const MenuItem::Id& id = i->second;
|
| + string16 tmp_label;
|
| + EXPECT_TRUE(GetItemLabel(menu, id, &tmp_label));
|
| + if (tmp_label == label16)
|
| + return true;
|
| + }
|
| + return false;
|
| + }
|
| +
|
| + // Looks in the menu for an extension item with |id|, and if it is found and
|
| + // has a label, that is put in |result| and we return true. Otherwise returns
|
| + // false.
|
| + bool GetItemLabel(TestRenderViewContextMenu* menu,
|
| + const MenuItem::Id& id,
|
| + string16* result) {
|
| + int command_id = 0;
|
| + if (!FindCommandId(menu, id, &command_id))
|
| + return false;
|
| +
|
| + MenuModel* model = NULL;
|
| + int index = -1;
|
| + if (!menu->GetMenuModelAndItemIndex(command_id, &model, &index)) {
|
| + return false;
|
| + }
|
| + *result = model->GetLabelAt(index);
|
| + return true;
|
| + }
|
| +
|
| + // Given an extension menu item id, tries to find the corresponding command id
|
| + // in the menu.
|
| + bool FindCommandId(TestRenderViewContextMenu* menu,
|
| + const MenuItem::Id& id,
|
| + int* command_id) {
|
| + std::map<int, MenuItem::Id>::const_iterator i;
|
| + for (i = menu->extension_items().extension_item_map_.begin();
|
| + i != menu->extension_items().extension_item_map_.end(); ++i) {
|
| + if (i->second == id) {
|
| + *command_id = i->first;
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| + }
|
| };
|
|
|
| // Tests adding a simple context menu item.
|
| @@ -302,7 +313,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, LongTitle) {
|
| ASSERT_TRUE(listener.WaitUntilSatisfied());
|
|
|
| // Make sure we have an item registered with a long title.
|
| - size_t limit = RenderViewContextMenu::kMaxExtensionItemTitleLength;
|
| + size_t limit = extensions::ContextMenuMatcher::kMaxExtensionItemTitleLength;
|
| MenuItem::List items = GetItems();
|
| ASSERT_EQ(1u, items.size());
|
| MenuItem* item = items.at(0);
|
| @@ -315,7 +326,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, LongTitle) {
|
| CreateMenu(browser(), url, GURL(), GURL()));
|
|
|
| string16 label;
|
| - ASSERT_TRUE(menu->GetItemLabel(item->id(), &label));
|
| + ASSERT_TRUE(GetItemLabel(menu.get(), item->id(), &label));
|
| ASSERT_TRUE(label.size() <= limit);
|
| }
|
|
|
| @@ -580,7 +591,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserLazyTest, EventPage) {
|
| MenuItem::Id id(false, extension->id());
|
| id.string_uid = "checkbox1";
|
| int command_id = -1;
|
| - ASSERT_TRUE(menu->FindCommandId(id, &command_id));
|
| + ASSERT_TRUE(FindCommandId(menu.get(), id, &command_id));
|
| EXPECT_FALSE(menu->IsCommandIdChecked(command_id));
|
|
|
| // Executing the checkbox also fires the onClicked event.
|
|
|