Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(878)

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc

Issue 339153002: Use suggested filename for "Save Link As" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Modified test case Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 ContextMenuNotificationObserver menu_observer(IDC_CONTENT_CONTEXT_SAVELINKAS);
236
237 // Go to a page with a link having download attribute.
238 const std::string kSuggestedFilename("test_filename.png");
239 ui_test_utils::NavigateToURL(
240 browser(),
241 GURL("data:text/html,<a href='about:blank' download='" +
242 kSuggestedFilename + "'>link</a>"));
243
244 // Open a context menu.
245 blink::WebMouseEvent mouse_event;
246 mouse_event.type = blink::WebInputEvent::MouseDown;
247 mouse_event.button = blink::WebMouseEvent::ButtonRight;
248 mouse_event.x = 15;
249 mouse_event.y = 15;
250 content::WebContents* tab =
251 browser()->tab_strip_model()->GetActiveWebContents();
252 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
253 mouse_event.type = blink::WebInputEvent::MouseUp;
254 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
255
256 // Wait for context menu to be visible.
257 menu_observer.WaitForMenu();
258
259 // Compare filename.
260 base::string16 suggested_filename = menu_observer.GetSuggestedFilename();
261 ASSERT_EQ(kSuggestedFilename, base::UTF16ToUTF8(suggested_filename).c_str());
262 }
263
232 // Ensure that View Page Info won't crash if there is no visible entry. 264 // Ensure that View Page Info won't crash if there is no visible entry.
233 // See http://crbug.com/370863. 265 // See http://crbug.com/370863.
234 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ViewPageInfoWithNoEntry) { 266 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ViewPageInfoWithNoEntry) {
235 // Create a new tab with no committed entry. 267 // Create a new tab with no committed entry.
236 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( 268 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer(
237 content::NotificationService::AllSources()); 269 content::NotificationService::AllSources());
238 ASSERT_TRUE(content::ExecuteScript( 270 ASSERT_TRUE(content::ExecuteScript(
239 browser()->tab_strip_model()->GetActiveWebContents(), "window.open();")); 271 browser()->tab_strip_model()->GetActiveWebContents(), "window.open();"));
240 tab_observer.Wait(); 272 tab_observer.Wait();
241 content::WebContents* tab = tab_observer.GetTab(); 273 content::WebContents* tab = tab_observer.GetTab();
242 EXPECT_FALSE(tab->GetController().GetLastCommittedEntry()); 274 EXPECT_FALSE(tab->GetController().GetLastCommittedEntry());
243 EXPECT_FALSE(tab->GetController().GetVisibleEntry()); 275 EXPECT_FALSE(tab->GetController().GetVisibleEntry());
244 276
245 // Create a context menu. 277 // Create a context menu.
246 content::ContextMenuParams context_menu_params; 278 content::ContextMenuParams context_menu_params;
247 TestRenderViewContextMenu menu(tab->GetMainFrame(), context_menu_params); 279 TestRenderViewContextMenu menu(tab->GetMainFrame(), context_menu_params);
248 menu.Init(); 280 menu.Init();
249 281
250 // The item shouldn't be enabled in the menu. 282 // The item shouldn't be enabled in the menu.
251 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO)); 283 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO));
252 284
253 // Ensure that viewing page info doesn't crash even if you can get to it. 285 // Ensure that viewing page info doesn't crash even if you can get to it.
254 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0); 286 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0);
255 } 287 }
256 288
257 } // namespace 289 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698