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
3 // found in the LICENSE file.
5 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h"
8 #include "base/message_loop/message_loop.h"
9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/chrome_notification_types.h"
11 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h"
12 #include "content/public/browser/notification_service.h"
13 #include "content/public/test/test_utils.h"
15 ContextMenuNotificationObserver::ContextMenuNotificationObserver(
16 int command_to_execute
)
17 : command_to_execute_(command_to_execute
) {
19 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN
,
20 content::NotificationService::AllSources());
23 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() {
26 void ContextMenuNotificationObserver::Observe(
28 const content::NotificationSource
& source
,
29 const content::NotificationDetails
& details
) {
31 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN
: {
32 RenderViewContextMenu
* context_menu
=
33 content::Source
<RenderViewContextMenu
>(source
).ptr();
34 base::MessageLoop::current()->PostTask(
36 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand
,
37 base::Unretained(this),
47 void ContextMenuNotificationObserver::ExecuteCommand(
48 RenderViewContextMenu
* context_menu
) {
49 context_menu
->ExecuteCommand(command_to_execute_
, 0);
50 context_menu
->Cancel();
53 SaveLinkAsContextMenuObserver::SaveLinkAsContextMenuObserver(
54 const content::NotificationSource
& source
)
55 : ContextMenuNotificationObserver(IDC_CONTENT_CONTEXT_SAVELINKAS
),
56 menu_visible_(false) {
59 SaveLinkAsContextMenuObserver::~SaveLinkAsContextMenuObserver() {
62 void SaveLinkAsContextMenuObserver::Observe(
64 const content::NotificationSource
& source
,
65 const content::NotificationDetails
& details
) {
67 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN
: {
69 RenderViewContextMenu
* context_menu
=
70 content::Source
<RenderViewContextMenu
>(source
).ptr();
71 base::MessageLoop::current()->PostTask(
73 base::Bind(&SaveLinkAsContextMenuObserver::Cancel
,
74 base::Unretained(this),
84 void SaveLinkAsContextMenuObserver::WaitForMenu() {
85 content::WindowedNotificationObserver
menu_observer(
86 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN
,
87 content::NotificationService::AllSources());
90 menu_visible_
= false;
93 base::string16
SaveLinkAsContextMenuObserver::GetSuggestedFilename() {
94 return params_
.suggested_filename
;
97 void SaveLinkAsContextMenuObserver::Cancel(
98 RenderViewContextMenu
* context_menu
) {
99 params_
= context_menu
->params();
100 context_menu
->Cancel();