Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / renderer_context_menu / render_view_context_menu_browsertest_util.cc
blob2f822262624025495b9eae10580395955148641d
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"
7 #include "base/bind.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) {
18 registrar_.Add(this,
19 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
20 content::NotificationService::AllSources());
23 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() {
26 void ContextMenuNotificationObserver::Observe(
27 int type,
28 const content::NotificationSource& source,
29 const content::NotificationDetails& details) {
30 switch (type) {
31 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: {
32 RenderViewContextMenu* context_menu =
33 content::Source<RenderViewContextMenu>(source).ptr();
34 base::MessageLoop::current()->PostTask(
35 FROM_HERE,
36 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand,
37 base::Unretained(this),
38 context_menu));
39 break;
42 default:
43 NOTREACHED();
47 void ContextMenuNotificationObserver::ExecuteCommand(
48 RenderViewContextMenu* context_menu) {
49 context_menu->ExecuteCommand(command_to_execute_, 0);
50 context_menu->Cancel();
53 ContextMenuWaiter::ContextMenuWaiter(const content::NotificationSource& source)
54 : menu_visible_(false) {
55 registrar_.Add(this, chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
56 content::NotificationService::AllSources());
59 ContextMenuWaiter::~ContextMenuWaiter() {
62 void ContextMenuWaiter::Observe(int type,
63 const content::NotificationSource& source,
64 const content::NotificationDetails& details) {
65 switch (type) {
66 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: {
67 menu_visible_ = true;
68 RenderViewContextMenu* context_menu =
69 content::Source<RenderViewContextMenu>(source).ptr();
70 base::MessageLoop::current()->PostTask(
71 FROM_HERE, base::Bind(&ContextMenuWaiter::Cancel,
72 base::Unretained(this), context_menu));
73 break;
76 default:
77 NOTREACHED();
81 void ContextMenuWaiter::WaitForMenuOpenAndClose() {
82 content::WindowedNotificationObserver menu_observer(
83 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
84 content::NotificationService::AllSources());
85 if (!menu_visible_)
86 menu_observer.Wait();
88 content::RunAllPendingInMessageLoop();
89 menu_visible_ = false;
92 content::ContextMenuParams& ContextMenuWaiter::params() {
93 return params_;
96 void ContextMenuWaiter::Cancel(RenderViewContextMenu* context_menu) {
97 params_ = context_menu->params();
98 context_menu->Cancel();