OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/string16.h" | 8 #include "base/strings/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 | 222 |
223 // Verify that the referrer on the page matches |kEmptyReferrer|. | 223 // Verify that the referrer on the page matches |kEmptyReferrer|. |
224 std::string page_referrer; | 224 std::string page_referrer; |
225 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 225 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
226 tab, | 226 tab, |
227 "window.domAutomationController.send(window.document.referrer);", | 227 "window.domAutomationController.send(window.document.referrer);", |
228 &page_referrer)); | 228 &page_referrer)); |
229 ASSERT_EQ(kEmptyReferrer, page_referrer); | 229 ASSERT_EQ(kEmptyReferrer, page_referrer); |
230 } | 230 } |
231 | 231 |
| 232 // Check filename on clicking "Save Link As" via a "real" context menu. |
| 233 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, SuggestedFileName) { |
| 234 // Register observer. |
| 235 SaveLinkAsContextMenuObserver menu_observer( |
| 236 content::NotificationService::AllSources()); |
| 237 |
| 238 // Go to a page with a link having download attribute. |
| 239 const std::string kSuggestedFilename("test_filename.png"); |
| 240 ui_test_utils::NavigateToURL( |
| 241 browser(), |
| 242 GURL("data:text/html,<a href='about:blank' download='" + |
| 243 kSuggestedFilename + "'>link</a>")); |
| 244 |
| 245 // Open a context menu. |
| 246 blink::WebMouseEvent mouse_event; |
| 247 mouse_event.type = blink::WebInputEvent::MouseDown; |
| 248 mouse_event.button = blink::WebMouseEvent::ButtonRight; |
| 249 mouse_event.x = 15; |
| 250 mouse_event.y = 15; |
| 251 content::WebContents* tab = |
| 252 browser()->tab_strip_model()->GetActiveWebContents(); |
| 253 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 254 mouse_event.type = blink::WebInputEvent::MouseUp; |
| 255 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event); |
| 256 |
| 257 // Wait for context menu to be visible. |
| 258 menu_observer.WaitForMenu(); |
| 259 |
| 260 // Compare filename. |
| 261 base::string16 suggested_filename = menu_observer.GetSuggestedFilename(); |
| 262 ASSERT_EQ(kSuggestedFilename, base::UTF16ToUTF8(suggested_filename).c_str()); |
| 263 } |
| 264 |
232 // Ensure that View Page Info won't crash if there is no visible entry. | 265 // Ensure that View Page Info won't crash if there is no visible entry. |
233 // See http://crbug.com/370863. | 266 // See http://crbug.com/370863. |
234 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ViewPageInfoWithNoEntry) { | 267 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ViewPageInfoWithNoEntry) { |
235 // Create a new tab with no committed entry. | 268 // Create a new tab with no committed entry. |
236 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( | 269 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( |
237 content::NotificationService::AllSources()); | 270 content::NotificationService::AllSources()); |
238 ASSERT_TRUE(content::ExecuteScript( | 271 ASSERT_TRUE(content::ExecuteScript( |
239 browser()->tab_strip_model()->GetActiveWebContents(), "window.open();")); | 272 browser()->tab_strip_model()->GetActiveWebContents(), "window.open();")); |
240 tab_observer.Wait(); | 273 tab_observer.Wait(); |
241 content::WebContents* tab = tab_observer.GetTab(); | 274 content::WebContents* tab = tab_observer.GetTab(); |
242 EXPECT_FALSE(tab->GetController().GetLastCommittedEntry()); | 275 EXPECT_FALSE(tab->GetController().GetLastCommittedEntry()); |
243 EXPECT_FALSE(tab->GetController().GetVisibleEntry()); | 276 EXPECT_FALSE(tab->GetController().GetVisibleEntry()); |
244 | 277 |
245 // Create a context menu. | 278 // Create a context menu. |
246 content::ContextMenuParams context_menu_params; | 279 content::ContextMenuParams context_menu_params; |
247 TestRenderViewContextMenu menu(tab->GetMainFrame(), context_menu_params); | 280 TestRenderViewContextMenu menu(tab->GetMainFrame(), context_menu_params); |
248 menu.Init(); | 281 menu.Init(); |
249 | 282 |
250 // The item shouldn't be enabled in the menu. | 283 // The item shouldn't be enabled in the menu. |
251 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO)); | 284 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO)); |
252 | 285 |
253 // Ensure that viewing page info doesn't crash even if you can get to it. | 286 // Ensure that viewing page info doesn't crash even if you can get to it. |
254 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0); | 287 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0); |
255 } | 288 } |
256 | 289 |
257 } // namespace | 290 } // namespace |
OLD | NEW |