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

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: Added 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 observers
235 ContextMenuNotificationObserver menu_observer(IDC_CONTENT_CONTEXT_SAVELINKAS);
lazyboy 2014/06/20 17:23:31 Using ContextMenuNotificationObserver would result
Nikhil 2014/06/20 19:37:51 I tried similar approach earlier by modifying exis
lazyboy 2014/06/20 19:50:56 The notification observer in that class should acc
Nikhil 2014/06/23 08:02:35 Modified existing ContextMenuNotificationObserver
236 content::WindowedNotificationObserver download_observer(
237 chrome::NOTIFICATION_DOWNLOAD_INITIATED,
238 content::NotificationService::AllSources());
239
240 // Go to a page with a link having download attribute
241 const std::string kSuggestedFilename("test_filename.png");
242 ui_test_utils::NavigateToURL(
243 browser(),
244 GURL("data:text/html,<a href='about:blank' download='" +
245 kSuggestedFilename + "'>link</a>"));
246
247 // Open a context menu.
248 blink::WebMouseEvent mouse_event;
249 mouse_event.type = blink::WebInputEvent::MouseDown;
250 mouse_event.button = blink::WebMouseEvent::ButtonRight;
251 mouse_event.x = 15;
252 mouse_event.y = 15;
253 content::WebContents* tab =
254 browser()->tab_strip_model()->GetActiveWebContents();
255 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
256 mouse_event.type = blink::WebInputEvent::MouseUp;
257 tab->GetRenderViewHost()->ForwardMouseEvent(mouse_event);
258
259 // Wait for context menu to get created and download to initiate
260 download_observer.Wait();
261
262 base::string16 suggested_filename = menu_observer.GetSuggestedFilename();
263 ASSERT_EQ(kSuggestedFilename, base::UTF16ToUTF8(suggested_filename).c_str());
264 }
265
232 // Ensure that View Page Info won't crash if there is no visible entry. 266 // Ensure that View Page Info won't crash if there is no visible entry.
233 // See http://crbug.com/370863. 267 // See http://crbug.com/370863.
234 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ViewPageInfoWithNoEntry) { 268 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, ViewPageInfoWithNoEntry) {
235 // Create a new tab with no committed entry. 269 // Create a new tab with no committed entry.
236 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer( 270 ui_test_utils::WindowedTabAddedNotificationObserver tab_observer(
237 content::NotificationService::AllSources()); 271 content::NotificationService::AllSources());
238 ASSERT_TRUE(content::ExecuteScript( 272 ASSERT_TRUE(content::ExecuteScript(
239 browser()->tab_strip_model()->GetActiveWebContents(), "window.open();")); 273 browser()->tab_strip_model()->GetActiveWebContents(), "window.open();"));
240 tab_observer.Wait(); 274 tab_observer.Wait();
241 content::WebContents* tab = tab_observer.GetTab(); 275 content::WebContents* tab = tab_observer.GetTab();
242 EXPECT_FALSE(tab->GetController().GetLastCommittedEntry()); 276 EXPECT_FALSE(tab->GetController().GetLastCommittedEntry());
243 EXPECT_FALSE(tab->GetController().GetVisibleEntry()); 277 EXPECT_FALSE(tab->GetController().GetVisibleEntry());
244 278
245 // Create a context menu. 279 // Create a context menu.
246 content::ContextMenuParams context_menu_params; 280 content::ContextMenuParams context_menu_params;
247 TestRenderViewContextMenu menu(tab->GetMainFrame(), context_menu_params); 281 TestRenderViewContextMenu menu(tab->GetMainFrame(), context_menu_params);
248 menu.Init(); 282 menu.Init();
249 283
250 // The item shouldn't be enabled in the menu. 284 // The item shouldn't be enabled in the menu.
251 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO)); 285 EXPECT_FALSE(menu.IsCommandIdEnabled(IDC_CONTENT_CONTEXT_VIEWPAGEINFO));
252 286
253 // Ensure that viewing page info doesn't crash even if you can get to it. 287 // Ensure that viewing page info doesn't crash even if you can get to it.
254 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0); 288 menu.ExecuteCommand(IDC_CONTENT_CONTEXT_VIEWPAGEINFO, 0);
255 } 289 }
256 290
257 } // namespace 291 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698