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

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.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 "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h" 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert est_util.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" 11 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
11 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
13 #include "content/public/test/test_utils.h"
12 14
13 ContextMenuNotificationObserver::ContextMenuNotificationObserver( 15 ContextMenuNotificationObserver::ContextMenuNotificationObserver(
14 int command_to_execute) 16 int command_to_execute)
15 : command_to_execute_(command_to_execute) { 17 : command_to_execute_(command_to_execute), menu_visible_(false) {
16 registrar_.Add(this, 18 registrar_.Add(this,
17 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, 19 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
18 content::NotificationService::AllSources()); 20 content::NotificationService::AllSources());
19 } 21 }
20 22
21 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() { 23 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() {
22 } 24 }
23 25
24 void ContextMenuNotificationObserver::Observe( 26 void ContextMenuNotificationObserver::Observe(
25 int type, 27 int type,
26 const content::NotificationSource& source, 28 const content::NotificationSource& source,
27 const content::NotificationDetails& details) { 29 const content::NotificationDetails& details) {
28 switch (type) { 30 switch (type) {
29 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { 31 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: {
30 RenderViewContextMenu* context_menu = 32 menu_visible_ = true;
31 content::Source<RenderViewContextMenu>(source).ptr(); 33 context_menu_ = content::Source<RenderViewContextMenu>(source).ptr();
lazyboy 2014/06/24 01:15:04 Instead of saving the raw pointer of RVContextMenu
Nikhil 2014/06/24 10:39:51 Done.
32 base::MessageLoop::current()->PostTask( 34 base::MessageLoop::current()->PostTask(
33 FROM_HERE, 35 FROM_HERE,
34 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand, 36 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand,
35 base::Unretained(this), context_menu)); 37 base::Unretained(this),
38 context_menu_));
36 break; 39 break;
37 } 40 }
38 41
39 default: 42 default:
40 NOTREACHED(); 43 NOTREACHED();
41 } 44 }
42 } 45 }
43 46
47 void ContextMenuNotificationObserver::WaitForMenu() {
48 content::WindowedNotificationObserver menu_observer(
49 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
50 content::NotificationService::AllSources());
51 if (!menu_visible_)
52 menu_observer.Wait();
53 menu_visible_ = false;
54 }
55
56 base::string16 ContextMenuNotificationObserver::GetSuggestedFilename() {
57 return context_menu_->params().suggested_filename;
58 }
59
44 void ContextMenuNotificationObserver::ExecuteCommand( 60 void ContextMenuNotificationObserver::ExecuteCommand(
45 RenderViewContextMenu* context_menu) { 61 RenderViewContextMenu* context_menu) {
46 context_menu->ExecuteCommand(command_to_execute_, 0); 62 switch (command_to_execute_) {
47 context_menu->Cancel(); 63 case IDC_CONTENT_CONTEXT_OPENLINKNEWTAB: {
lazyboy 2014/06/24 01:15:04 The class is named more generic as ContextMenUNoti
Nikhil 2014/06/24 10:39:51 Done.
64 context_menu->ExecuteCommand(command_to_execute_, 0);
65 context_menu->Cancel();
66 break;
67 }
68 case IDC_CONTENT_CONTEXT_SAVELINKAS: {
69 // Don't start download.
70 context_menu->Cancel();
71 break;
72 }
73
74 default:
75 NOTREACHED();
76 }
48 } 77 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h ('k') | content/common/frame_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698