| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/extensions/extension_browsertest.h" | 9 #include "chrome/browser/extensions/extension_browsertest.h" |
| 10 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 LoadExtension(test_data_dir_.AppendASCII("basic")); | 145 LoadExtension(test_data_dir_.AppendASCII("basic")); |
| 146 ASSERT_TRUE(listener.WaitUntilSatisfied()); | 146 ASSERT_TRUE(listener.WaitUntilSatisfied()); |
| 147 | 147 |
| 148 // There should only be one panel. | 148 // There should only be one panel. |
| 149 PanelManager* panel_manager = PanelManager::GetInstance(); | 149 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 150 EXPECT_EQ(1, panel_manager->num_panels()); | 150 EXPECT_EQ(1, panel_manager->num_panels()); |
| 151 Panel* panel = panel_manager->panels().front(); | 151 Panel* panel = panel_manager->panels().front(); |
| 152 content::WebContents* web_contents = panel->GetWebContents(); | 152 content::WebContents* web_contents = panel->GetWebContents(); |
| 153 ASSERT_TRUE(web_contents); | 153 ASSERT_TRUE(web_contents); |
| 154 | 154 |
| 155 WebKit::WebContextMenuData data; | |
| 156 | |
| 157 // Verify basic menu contents. The basic extension does not add any | 155 // Verify basic menu contents. The basic extension does not add any |
| 158 // context menu items so the panel's menu should include only the | 156 // context menu items so the panel's menu should include only the |
| 159 // developer tools. | 157 // developer tools. |
| 160 { | 158 { |
| 161 content::ContextMenuParams params(data); | 159 content::ContextMenuParams params; |
| 162 params.page_url = web_contents->GetURL(); | 160 params.page_url = web_contents->GetURL(); |
| 163 // Ensure context menu isn't swallowed by WebContentsDelegate (the panel). | 161 // Ensure context menu isn't swallowed by WebContentsDelegate (the panel). |
| 164 EXPECT_FALSE(web_contents->GetDelegate()->HandleContextMenu(params)); | 162 EXPECT_FALSE(web_contents->GetDelegate()->HandleContextMenu(params)); |
| 165 | 163 |
| 166 scoped_ptr<PanelContextMenu> menu( | 164 scoped_ptr<PanelContextMenu> menu( |
| 167 new PanelContextMenu(web_contents, params)); | 165 new PanelContextMenu(web_contents, params)); |
| 168 menu->Init(); | 166 menu->Init(); |
| 169 | 167 |
| 170 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 168 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 171 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 169 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 172 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_PASTE)); | 170 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_PASTE)); |
| 173 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 171 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 174 EXPECT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 172 EXPECT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 175 EXPECT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 173 EXPECT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 176 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | 174 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
| 177 } | 175 } |
| 178 | 176 |
| 179 // Verify expected menu contents for editable item. | 177 // Verify expected menu contents for editable item. |
| 180 { | 178 { |
| 181 content::ContextMenuParams params(data); | 179 content::ContextMenuParams params; |
| 182 params.is_editable = true; | 180 params.is_editable = true; |
| 183 params.page_url = web_contents->GetURL(); | 181 params.page_url = web_contents->GetURL(); |
| 184 // Ensure context menu isn't swallowed by WebContentsDelegate (the panel). | 182 // Ensure context menu isn't swallowed by WebContentsDelegate (the panel). |
| 185 EXPECT_FALSE(web_contents->GetDelegate()->HandleContextMenu(params)); | 183 EXPECT_FALSE(web_contents->GetDelegate()->HandleContextMenu(params)); |
| 186 | 184 |
| 187 scoped_ptr<PanelContextMenu> menu( | 185 scoped_ptr<PanelContextMenu> menu( |
| 188 new PanelContextMenu(web_contents, params)); | 186 new PanelContextMenu(web_contents, params)); |
| 189 menu->Init(); | 187 menu->Init(); |
| 190 | 188 |
| 191 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 189 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 192 EXPECT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 190 EXPECT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 193 EXPECT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_PASTE)); | 191 EXPECT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_PASTE)); |
| 194 EXPECT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 192 EXPECT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 195 EXPECT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 193 EXPECT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 196 EXPECT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 194 EXPECT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 197 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | 195 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
| 198 } | 196 } |
| 199 | 197 |
| 200 // Verify expected menu contents for text selection. | 198 // Verify expected menu contents for text selection. |
| 201 { | 199 { |
| 202 content::ContextMenuParams params(data); | 200 content::ContextMenuParams params; |
| 203 params.page_url = web_contents->GetURL(); | 201 params.page_url = web_contents->GetURL(); |
| 204 params.selection_text = ASCIIToUTF16("Select me"); | 202 params.selection_text = ASCIIToUTF16("Select me"); |
| 205 // Ensure context menu isn't swallowed by WebContentsDelegate (the panel). | 203 // Ensure context menu isn't swallowed by WebContentsDelegate (the panel). |
| 206 EXPECT_FALSE(web_contents->GetDelegate()->HandleContextMenu(params)); | 204 EXPECT_FALSE(web_contents->GetDelegate()->HandleContextMenu(params)); |
| 207 | 205 |
| 208 scoped_ptr<PanelContextMenu> menu( | 206 scoped_ptr<PanelContextMenu> menu( |
| 209 new PanelContextMenu(web_contents, params)); | 207 new PanelContextMenu(web_contents, params)); |
| 210 menu->Init(); | 208 menu->Init(); |
| 211 | 209 |
| 212 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 210 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 213 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 211 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 214 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_PASTE)); | 212 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_PASTE)); |
| 215 EXPECT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 213 EXPECT_TRUE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 216 EXPECT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 214 EXPECT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 217 EXPECT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 215 EXPECT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 218 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | 216 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
| 219 } | 217 } |
| 220 | 218 |
| 221 // Verify expected menu contexts for a link. | 219 // Verify expected menu contexts for a link. |
| 222 { | 220 { |
| 223 content::ContextMenuParams params(data); | 221 content::ContextMenuParams params; |
| 224 params.page_url = web_contents->GetURL(); | 222 params.page_url = web_contents->GetURL(); |
| 225 params.unfiltered_link_url = GURL("http://google.com/"); | 223 params.unfiltered_link_url = GURL("http://google.com/"); |
| 226 // Ensure context menu isn't swallowed by WebContentsDelegate (the panel). | 224 // Ensure context menu isn't swallowed by WebContentsDelegate (the panel). |
| 227 EXPECT_FALSE(web_contents->GetDelegate()->HandleContextMenu(params)); | 225 EXPECT_FALSE(web_contents->GetDelegate()->HandleContextMenu(params)); |
| 228 | 226 |
| 229 scoped_ptr<PanelContextMenu> menu( | 227 scoped_ptr<PanelContextMenu> menu( |
| 230 new PanelContextMenu(web_contents, params)); | 228 new PanelContextMenu(web_contents, params)); |
| 231 menu->Init(); | 229 menu->Init(); |
| 232 | 230 |
| 233 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 231 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 250 LoadExtension(test_data_dir_.AppendASCII("context_menu2")); | 248 LoadExtension(test_data_dir_.AppendASCII("context_menu2")); |
| 251 ASSERT_TRUE(bogey_listener.WaitUntilSatisfied()); | 249 ASSERT_TRUE(bogey_listener.WaitUntilSatisfied()); |
| 252 | 250 |
| 253 // There should only be one panel. | 251 // There should only be one panel. |
| 254 PanelManager* panel_manager = PanelManager::GetInstance(); | 252 PanelManager* panel_manager = PanelManager::GetInstance(); |
| 255 EXPECT_EQ(1, panel_manager->num_panels()); | 253 EXPECT_EQ(1, panel_manager->num_panels()); |
| 256 Panel* panel = panel_manager->panels().front(); | 254 Panel* panel = panel_manager->panels().front(); |
| 257 content::WebContents* web_contents = panel->GetWebContents(); | 255 content::WebContents* web_contents = panel->GetWebContents(); |
| 258 ASSERT_TRUE(web_contents); | 256 ASSERT_TRUE(web_contents); |
| 259 | 257 |
| 260 WebKit::WebContextMenuData data; | 258 content::ContextMenuParams params; |
| 261 content::ContextMenuParams params(data); | |
| 262 params.page_url = web_contents->GetURL(); | 259 params.page_url = web_contents->GetURL(); |
| 263 | 260 |
| 264 // Ensure context menu isn't swallowed by WebContentsDelegate (the panel). | 261 // Ensure context menu isn't swallowed by WebContentsDelegate (the panel). |
| 265 EXPECT_FALSE(web_contents->GetDelegate()->HandleContextMenu(params)); | 262 EXPECT_FALSE(web_contents->GetDelegate()->HandleContextMenu(params)); |
| 266 | 263 |
| 267 // Verify menu contents contains the custom item added by their own extension. | 264 // Verify menu contents contains the custom item added by their own extension. |
| 268 scoped_ptr<PanelContextMenu> menu; | 265 scoped_ptr<PanelContextMenu> menu; |
| 269 menu.reset(new PanelContextMenu(web_contents, params)); | 266 menu.reset(new PanelContextMenu(web_contents, params)); |
| 270 menu->Init(); | 267 menu->Init(); |
| 271 EXPECT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); | 268 EXPECT_TRUE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST)); |
| 272 EXPECT_FALSE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); | 269 EXPECT_FALSE(menu->HasCommandWithId(IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST + 1)); |
| 273 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 270 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| 274 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); | 271 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_UNDO)); |
| 275 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_PASTE)); | 272 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_PASTE)); |
| 276 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); | 273 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPY)); |
| 277 EXPECT_FALSE(menu->HasCommandWithId(IDC_BACK)); | 274 EXPECT_FALSE(menu->HasCommandWithId(IDC_BACK)); |
| 278 EXPECT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); | 275 EXPECT_FALSE(menu->HasCommandWithId(IDC_SAVE_PAGE)); |
| 279 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | 276 EXPECT_FALSE(menu->HasCommandWithId(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
| 280 | 277 |
| 281 // Execute the extension's custom menu item and wait for the extension's | 278 // Execute the extension's custom menu item and wait for the extension's |
| 282 // script to tell us its onclick fired. | 279 // script to tell us its onclick fired. |
| 283 ExtensionTestMessageListener onclick_listener("clicked", false); | 280 ExtensionTestMessageListener onclick_listener("clicked", false); |
| 284 int command_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; | 281 int command_id = IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; |
| 285 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id)); | 282 ASSERT_TRUE(menu->IsCommandIdEnabled(command_id)); |
| 286 menu->ExecuteCommand(command_id, 0); | 283 menu->ExecuteCommand(command_id, 0); |
| 287 EXPECT_TRUE(onclick_listener.WaitUntilSatisfied()); | 284 EXPECT_TRUE(onclick_listener.WaitUntilSatisfied()); |
| 288 } | 285 } |
| OLD | NEW |