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

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

Issue 891213002: Add a test for the mouseleave event on window. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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/app/chrome_command_ids.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 NOTREACHED(); 43 NOTREACHED();
44 } 44 }
45 } 45 }
46 46
47 void ContextMenuNotificationObserver::ExecuteCommand( 47 void ContextMenuNotificationObserver::ExecuteCommand(
48 RenderViewContextMenu* context_menu) { 48 RenderViewContextMenu* context_menu) {
49 context_menu->ExecuteCommand(command_to_execute_, 0); 49 context_menu->ExecuteCommand(command_to_execute_, 0);
50 context_menu->Cancel(); 50 context_menu->Cancel();
51 } 51 }
52 52
53 SaveLinkAsContextMenuObserver::SaveLinkAsContextMenuObserver( 53 ContextMenuWaiter::ContextMenuWaiter(const content::NotificationSource& source)
54 const content::NotificationSource& source) 54 : menu_visible_(false) {
55 : ContextMenuNotificationObserver(IDC_CONTENT_CONTEXT_SAVELINKAS), 55 registrar_.Add(this, chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
56 menu_visible_(false) { 56 content::NotificationService::AllSources());
57 } 57 }
58 58
59 SaveLinkAsContextMenuObserver::~SaveLinkAsContextMenuObserver() { 59 ContextMenuWaiter::~ContextMenuWaiter() {
60 } 60 }
61 61
62 void SaveLinkAsContextMenuObserver::Observe( 62 void ContextMenuWaiter::Observe(int type,
63 int type, 63 const content::NotificationSource& source,
64 const content::NotificationSource& source, 64 const content::NotificationDetails& details) {
65 const content::NotificationDetails& details) {
66 switch (type) { 65 switch (type) {
67 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { 66 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: {
68 menu_visible_ = true; 67 menu_visible_ = true;
69 RenderViewContextMenu* context_menu = 68 RenderViewContextMenu* context_menu =
70 content::Source<RenderViewContextMenu>(source).ptr(); 69 content::Source<RenderViewContextMenu>(source).ptr();
71 base::MessageLoop::current()->PostTask( 70 base::MessageLoop::current()->PostTask(
72 FROM_HERE, 71 FROM_HERE, base::Bind(&ContextMenuWaiter::Cancel,
73 base::Bind(&SaveLinkAsContextMenuObserver::Cancel, 72 base::Unretained(this), context_menu));
74 base::Unretained(this),
75 context_menu));
76 break; 73 break;
77 } 74 }
78 75
79 default: 76 default:
80 NOTREACHED(); 77 NOTREACHED();
81 } 78 }
82 } 79 }
83 80
84 void SaveLinkAsContextMenuObserver::WaitForMenu() { 81 void ContextMenuWaiter::WaitForMenuOpenAndClose() {
85 content::WindowedNotificationObserver menu_observer( 82 content::WindowedNotificationObserver menu_observer(
86 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, 83 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
87 content::NotificationService::AllSources()); 84 content::NotificationService::AllSources());
88 if (!menu_visible_) 85 if (!menu_visible_)
89 menu_observer.Wait(); 86 menu_observer.Wait();
87
88 content::RunAllPendingInMessageLoop();
90 menu_visible_ = false; 89 menu_visible_ = false;
91 } 90 }
92 91
93 base::string16 SaveLinkAsContextMenuObserver::GetSuggestedFilename() { 92 content::ContextMenuParams& ContextMenuWaiter::params() {
94 return params_.suggested_filename; 93 return params_;
95 } 94 }
96 95
97 void SaveLinkAsContextMenuObserver::Cancel( 96 void ContextMenuWaiter::Cancel(RenderViewContextMenu* context_menu) {
98 RenderViewContextMenu* context_menu) {
99 params_ = context_menu->params(); 97 params_ = context_menu->params();
100 context_menu->Cancel(); 98 context_menu->Cancel();
101 } 99 }
OLDNEW
« no previous file with comments | « chrome/browser/renderer_context_menu/render_view_context_menu_browsertest_util.h ('k') | chrome/test/data/mouseleave.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698