| Index: chrome/browser/extensions/extension_context_menu_browsertest.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/extension_context_menu_browsertest.cc (revision 158704)
|
| +++ chrome/browser/extensions/extension_context_menu_browsertest.cc (working copy)
|
| @@ -39,6 +39,36 @@
|
|
|
| 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.
|
| @@ -65,8 +95,17 @@
|
| return false;
|
| }
|
|
|
| - extensions::ContextMenuMatcher& extension_items() {
|
| - return extension_items_;
|
| + // 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;
|
| }
|
|
|
| protected:
|
| @@ -158,7 +197,7 @@
|
| const std::string& label) {
|
| scoped_ptr<TestRenderViewContextMenu> menu(
|
| CreateMenu(browser(), page_url, link_url, frame_url));
|
| - return MenuHasExtensionItemWithLabel(menu.get(), label);
|
| + return menu->HasExtensionItemWithLabel(label);
|
| }
|
|
|
| // This creates an extension that starts |enabled| and then switches to
|
| @@ -194,56 +233,6 @@
|
| 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.
|
| @@ -313,7 +302,7 @@
|
| ASSERT_TRUE(listener.WaitUntilSatisfied());
|
|
|
| // Make sure we have an item registered with a long title.
|
| - size_t limit = extensions::ContextMenuMatcher::kMaxExtensionItemTitleLength;
|
| + size_t limit = RenderViewContextMenu::kMaxExtensionItemTitleLength;
|
| MenuItem::List items = GetItems();
|
| ASSERT_EQ(1u, items.size());
|
| MenuItem* item = items.at(0);
|
| @@ -326,7 +315,7 @@
|
| CreateMenu(browser(), url, GURL(), GURL()));
|
|
|
| string16 label;
|
| - ASSERT_TRUE(GetItemLabel(menu.get(), item->id(), &label));
|
| + ASSERT_TRUE(menu->GetItemLabel(item->id(), &label));
|
| ASSERT_TRUE(label.size() <= limit);
|
| }
|
|
|
| @@ -591,7 +580,7 @@
|
| MenuItem::Id id(false, extension->id());
|
| id.string_uid = "checkbox1";
|
| int command_id = -1;
|
| - ASSERT_TRUE(FindCommandId(menu.get(), id, &command_id));
|
| + ASSERT_TRUE(menu->FindCommandId(id, &command_id));
|
| EXPECT_FALSE(menu->IsCommandIdChecked(command_id));
|
|
|
| // Executing the checkbox also fires the onClicked event.
|
|
|