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

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

Issue 10479018: Add base::RunLoop and update ui_test_utils to use it to reduce flakiness (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: darin feedback Created 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/tab_contents/render_view_context_menu_browsertest_util. h" 5 #include "chrome/browser/tab_contents/render_view_context_menu_browsertest_util. h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "chrome/browser/tab_contents/render_view_context_menu.h" 9 #include "chrome/browser/tab_contents/render_view_context_menu.h"
10 #include "chrome/common/chrome_notification_types.h" 10 #include "chrome/common/chrome_notification_types.h"
11 #include "content/public/browser/notification_service.h" 11 #include "content/public/browser/notification_service.h"
12 12
13 ContextMenuNotificationObserver::ContextMenuNotificationObserver( 13 ContextMenuNotificationObserver::ContextMenuNotificationObserver(
14 int command_to_execute, 14 int command_to_execute) : command_to_execute_(command_to_execute) {
jar (doing other things) 2012/06/23 02:43:19 nit: When we can't fit it all on one line... init
jbates 2012/06/25 20:04:57 Done.
15 int expected_notification)
16 : command_to_execute_(command_to_execute),
17 expected_notification_(expected_notification),
18 seen_expected_notification_(false) {
19 registrar_.Add(this, 15 registrar_.Add(this,
20 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, 16 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
21 content::NotificationService::AllSources()); 17 content::NotificationService::AllSources());
22 registrar_.Add(this,
23 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_CLOSED,
24 content::NotificationService::AllSources());
25 registrar_.Add(this,
26 expected_notification_,
27 content::NotificationService::AllSources());
28 } 18 }
29 19
30 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() { 20 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() {
31 } 21 }
32 22
33 void ContextMenuNotificationObserver::Observe( 23 void ContextMenuNotificationObserver::Observe(
34 int type, 24 int type,
35 const content::NotificationSource& source, 25 const content::NotificationSource& source,
36 const content::NotificationDetails& details) { 26 const content::NotificationDetails& details) {
37 if (type == expected_notification_) {
38 seen_expected_notification_ = true;
39 return;
40 }
41
42 switch (type) { 27 switch (type) {
43 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { 28 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: {
44 RenderViewContextMenu* context_menu = 29 RenderViewContextMenu* context_menu =
45 content::Source<RenderViewContextMenu>(source).ptr(); 30 content::Source<RenderViewContextMenu>(source).ptr();
46 MessageLoop::current()->PostTask( 31 MessageLoop::current()->PostTask(
47 FROM_HERE, 32 FROM_HERE,
48 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand, 33 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand,
49 base::Unretained(this), context_menu)); 34 base::Unretained(this), context_menu));
50 break; 35 break;
51 } 36 }
52 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_CLOSED: {
53 // Aura is running a nested message loop for menus. That means that
54 // whatever the test running us is waiting for (e.g. a new tab to be
55 // added) happened while the menu message loop was running, so the
56 // message loop run by this test never quits.
57 if (seen_expected_notification_ &&
58 MessageLoop::current()->is_running()) {
59 MessageLoop::current()->QuitNow();
60 }
61 break;
62 }
63 37
64 default: 38 default:
65 NOTREACHED(); 39 NOTREACHED();
66 } 40 }
67 } 41 }
68 42
69 void ContextMenuNotificationObserver::ExecuteCommand( 43 void ContextMenuNotificationObserver::ExecuteCommand(
70 RenderViewContextMenu* context_menu) { 44 RenderViewContextMenu* context_menu) {
71 context_menu->ExecuteCommand(command_to_execute_); 45 context_menu->ExecuteCommand(command_to_execute_);
72 context_menu->Cancel(); 46 context_menu->Cancel();
73 } 47 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698