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

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: phajdan feedback Created 8 years, 5 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)
15 int expected_notification) 15 : command_to_execute_(command_to_execute) {
16 : command_to_execute_(command_to_execute),
17 expected_notification_(expected_notification),
18 seen_expected_notification_(false) {
19 registrar_.Add(this, 16 registrar_.Add(this,
20 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN, 17 chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN,
21 content::NotificationService::AllSources()); 18 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 } 19 }
29 20
30 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() { 21 ContextMenuNotificationObserver::~ContextMenuNotificationObserver() {
31 } 22 }
32 23
33 void ContextMenuNotificationObserver::Observe( 24 void ContextMenuNotificationObserver::Observe(
34 int type, 25 int type,
35 const content::NotificationSource& source, 26 const content::NotificationSource& source,
36 const content::NotificationDetails& details) { 27 const content::NotificationDetails& details) {
37 if (type == expected_notification_) {
38 seen_expected_notification_ = true;
39 return;
40 }
41
42 switch (type) { 28 switch (type) {
43 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: { 29 case chrome::NOTIFICATION_RENDER_VIEW_CONTEXT_MENU_SHOWN: {
44 RenderViewContextMenu* context_menu = 30 RenderViewContextMenu* context_menu =
45 content::Source<RenderViewContextMenu>(source).ptr(); 31 content::Source<RenderViewContextMenu>(source).ptr();
46 MessageLoop::current()->PostTask( 32 MessageLoop::current()->PostTask(
47 FROM_HERE, 33 FROM_HERE,
48 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand, 34 base::Bind(&ContextMenuNotificationObserver::ExecuteCommand,
49 base::Unretained(this), context_menu)); 35 base::Unretained(this), context_menu));
50 break; 36 break;
51 } 37 }
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 38
64 default: 39 default:
65 NOTREACHED(); 40 NOTREACHED();
66 } 41 }
67 } 42 }
68 43
69 void ContextMenuNotificationObserver::ExecuteCommand( 44 void ContextMenuNotificationObserver::ExecuteCommand(
70 RenderViewContextMenu* context_menu) { 45 RenderViewContextMenu* context_menu) {
71 context_menu->ExecuteCommand(command_to_execute_); 46 context_menu->ExecuteCommand(command_to_execute_);
72 context_menu->Cancel(); 47 context_menu->Cancel();
73 } 48 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698