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