| Index: chrome/browser/extensions/extension_context_menu_browsertest.cc
|
| ===================================================================
|
| --- chrome/browser/extensions/extension_context_menu_browsertest.cc (revision 52866)
|
| +++ chrome/browser/extensions/extension_context_menu_browsertest.cc (working copy)
|
| @@ -27,6 +27,18 @@
|
|
|
| virtual ~TestRenderViewContextMenu() {}
|
|
|
| + bool HasExtensionItemWithTitle(std::string title) {
|
| + std::map<int, ExtensionMenuItem::Id>::iterator i;
|
| + for (i = extension_item_map_.begin(); i != extension_item_map_.end(); ++i) {
|
| + int id = i->first;
|
| + ExtensionMenuItem* item = GetExtensionMenuItem(id);
|
| + if (item && item->title() == title) {
|
| + return true;
|
| + }
|
| + }
|
| + return false;
|
| + }
|
| +
|
| protected:
|
| virtual bool GetAcceleratorForCommandId(int command_id,
|
| menus::Accelerator* accelerator) {
|
| @@ -36,30 +48,48 @@
|
| virtual void PlatformInit() {}
|
| };
|
|
|
| -IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, ContextMenusSimple) {
|
| - CommandLine::ForCurrentProcess()->AppendSwitch(
|
| - switches::kEnableExperimentalExtensionApis);
|
| - FilePath extension_dir = test_data_dir_.AppendASCII("context_menus");
|
| - ASSERT_TRUE(LoadExtension(extension_dir));
|
| +class ExtensionContextMenuBrowserTest : public ExtensionBrowserTest {
|
| + public:
|
| + // Helper to load an extension from context_menus/|subdirectory| in the
|
| + // extensions test data dir.
|
| + void LoadContextMenuExtension(std::string subdirectory) {
|
| + FilePath extension_dir =
|
| + test_data_dir_.AppendASCII("context_menus").AppendASCII(subdirectory);
|
| + ASSERT_TRUE(LoadExtension(extension_dir));
|
| + }
|
|
|
| + // This creates a test menu using |params|, looks for an extension item with
|
| + // the given |title|, and returns true if the item was found.
|
| + bool MenuHasItemWithTitle(const ContextMenuParams& params,
|
| + std::string title) {
|
| + TabContents* tab_contents = browser()->GetSelectedTabContents();
|
| + TestRenderViewContextMenu menu(tab_contents, params);
|
| + menu.Init();
|
| + return menu.HasExtensionItemWithTitle(title);
|
| + }
|
| +};
|
| +
|
| +// Returns a new ContextMenuParams initialized with reasonable default values.
|
| +ContextMenuParams* CreateParams() {
|
| + WebContextMenuData data;
|
| + ContextMenuParams* params = new ContextMenuParams(data);
|
| + return params;
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Simple) {
|
| + LoadContextMenuExtension("simple");
|
| +
|
| // The extension's background page will create a context menu item and then
|
| // cause a navigation on success - we wait for that here.
|
| ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 1));
|
|
|
| // Initialize the data we need to create a context menu.
|
| TabContents* tab_contents = browser()->GetSelectedTabContents();
|
| - ContextMenuParams params;
|
| - params.media_type = WebContextMenuData::MediaTypeNone;
|
| - params.x = 0;
|
| - params.y = 0;
|
| - params.is_image_blocked = false;
|
| - params.frame_url = tab_contents->GetURL();
|
| - params.media_flags = 0;
|
| - params.spellcheck_enabled = false;
|
| - params.is_editable = false;
|
| + scoped_ptr<ContextMenuParams> params(CreateParams());
|
| + params->page_url = GURL("http://www.google.com");
|
|
|
| // Create and build our test context menu.
|
| - TestRenderViewContextMenu menu(tab_contents, params);
|
| + TestRenderViewContextMenu menu(tab_contents, *params);
|
| menu.Init();
|
|
|
| // Look for the extension item in the menu, and execute it.
|
| @@ -71,3 +101,22 @@
|
| // wait for that here.
|
| ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 1));
|
| }
|
| +
|
| +IN_PROC_BROWSER_TEST_F(ExtensionContextMenuBrowserTest, Patterns) {
|
| + // The js test code will create two items with patterns and then navigate a
|
| + // tab to tell us to proceed.
|
| + LoadContextMenuExtension("patterns");
|
| + ASSERT_TRUE(ui_test_utils::WaitForNavigationsInCurrentTab(browser(), 1));
|
| +
|
| + scoped_ptr<ContextMenuParams> params(CreateParams());
|
| +
|
| + // Check that a document url that should match the items' patterns appears.
|
| + params->frame_url = GURL("http://www.google.com");
|
| + ASSERT_TRUE(MenuHasItemWithTitle(*params, std::string("test_item1")));
|
| + ASSERT_TRUE(MenuHasItemWithTitle(*params, std::string("test_item2")));
|
| +
|
| + // Now check for a non-matching url.
|
| + params->frame_url = GURL("http://www.test.com");
|
| + ASSERT_FALSE(MenuHasItemWithTitle(*params, std::string("test_item1")));
|
| + ASSERT_FALSE(MenuHasItemWithTitle(*params, std::string("test_item2")));
|
| +}
|
|
|