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

Side by Side Diff: content/public/test/test_utils.h

Issue 24261010: Allow explicitly whitelisted apps/extensions in public sessions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: constness fix. Created 7 years, 2 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 #ifndef CONTENT_PUBLIC_TEST_TEST_UTILS_H_ 5 #ifndef CONTENT_PUBLIC_TEST_TEST_UTILS_H_
6 #define CONTENT_PUBLIC_TEST_TEST_UTILS_H_ 6 #define CONTENT_PUBLIC_TEST_TEST_UTILS_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 // A WindowedNotificationObserver allows code to wait until a condition is met. 94 // A WindowedNotificationObserver allows code to wait until a condition is met.
95 // Simple conditions are specified by providing a |notification_type| and a 95 // Simple conditions are specified by providing a |notification_type| and a
96 // |source|. When a notification of the expected type from the expected source 96 // |source|. When a notification of the expected type from the expected source
97 // is received, the condition is met. 97 // is received, the condition is met.
98 // More complex conditions can be specified by providing a |notification_type| 98 // More complex conditions can be specified by providing a |notification_type|
99 // and a |callback|. The callback is called whenever the notification is fired. 99 // and a |callback|. The callback is called whenever the notification is fired.
100 // If the callback returns |true|, the condition is met. Otherwise, the 100 // If the callback returns |true|, the condition is met. Otherwise, the
101 // condition is not yet met and the callback will be invoked again every time a 101 // condition is not yet met and the callback will be invoked again every time a
102 // notification of the expected type is received until the callback returns 102 // notification of the expected type is received until the callback returns
103 // |true|. 103 // |true|. For convenience, two callback types are defined, one that is provided
104 // with the notification source and details, and one that is not.
104 // 105 //
105 // This helper class exists to avoid the following common pattern in tests: 106 // This helper class exists to avoid the following common pattern in tests:
106 // PerformAction() 107 // PerformAction()
107 // WaitForCompletionNotification() 108 // WaitForCompletionNotification()
108 // The pattern leads to flakiness as there is a window between PerformAction 109 // The pattern leads to flakiness as there is a window between PerformAction
109 // returning and the observers getting registered, where a notification will be 110 // returning and the observers getting registered, where a notification will be
110 // missed. 111 // missed.
111 // 112 //
112 // Rather, one can do this: 113 // Rather, one can do this:
113 // WindowedNotificationObserver signal(...) 114 // WindowedNotificationObserver signal(...)
114 // PerformAction() 115 // PerformAction()
115 // signal.Wait() 116 // signal.Wait()
116 class WindowedNotificationObserver : public NotificationObserver { 117 class WindowedNotificationObserver : public NotificationObserver {
117 public: 118 public:
118 // Callback invoked on notifications. Should return |true| when the condition 119 // Callback invoked on notifications. Should return |true| when the condition
119 // being waited for is met. 120 // being waited for is met. For convenience, there is a choice between two
120 typedef base::Callback<bool(void)> ConditionTestCallback; 121 // callback types, one that is provided with the notification source and
122 // details, and one that is not.
123 typedef base::Callback<bool(const NotificationSource&,
124 const NotificationDetails&)>
125 ConditionTestCallback;
126 typedef base::Callback<bool(void)>
127 ConditionTestCallbackWithoutSourceAndDetails;
121 128
122 // Set up to wait for a simple condition. The condition is met when a 129 // Set up to wait for a simple condition. The condition is met when a
123 // notification of the given |notification_type| from the given |source| is 130 // notification of the given |notification_type| from the given |source| is
124 // received. To accept notifications from all sources, specify 131 // received. To accept notifications from all sources, specify
125 // NotificationService::AllSources() as |source|. 132 // NotificationService::AllSources() as |source|.
126 WindowedNotificationObserver(int notification_type, 133 WindowedNotificationObserver(int notification_type,
127 const NotificationSource& source); 134 const NotificationSource& source);
128 135
129 // Set up to wait for a complex condition. The condition is met when 136 // Set up to wait for a complex condition. The condition is met when
130 // |callback| returns |true|. The callback is invoked whenever a notification 137 // |callback| returns |true|. The callback is invoked whenever a notification
131 // of |notification_type| from any source is received. 138 // of |notification_type| from any source is received.
132 WindowedNotificationObserver(int notification_type, 139 WindowedNotificationObserver(int notification_type,
133 const ConditionTestCallback& callback); 140 const ConditionTestCallback& callback);
141 WindowedNotificationObserver(
142 int notification_type,
143 const ConditionTestCallbackWithoutSourceAndDetails& callback);
134 144
135 virtual ~WindowedNotificationObserver(); 145 virtual ~WindowedNotificationObserver();
136 146
137 // Wait until the specified condition is met. If the condition is already met 147 // Wait until the specified condition is met. If the condition is already met
138 // (that is, the expected notification has already been received or the 148 // (that is, the expected notification has already been received or the
139 // given callback returns |true| already), Wait() returns immediately. 149 // given callback returns |true| already), Wait() returns immediately.
140 void Wait(); 150 void Wait();
141 151
142 // Returns NotificationService::AllSources() if we haven't observed a 152 // Returns NotificationService::AllSources() if we haven't observed a
143 // notification yet. 153 // notification yet.
(...skipping 20 matching lines...) Expand all
164 NotificationSource source_; 174 NotificationSource source_;
165 NotificationDetails details_; 175 NotificationDetails details_;
166 scoped_refptr<MessageLoopRunner> message_loop_runner_; 176 scoped_refptr<MessageLoopRunner> message_loop_runner_;
167 177
168 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver); 178 DISALLOW_COPY_AND_ASSIGN(WindowedNotificationObserver);
169 }; 179 };
170 180
171 } // namespace content 181 } // namespace content
172 182
173 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_ 183 #endif // CONTENT_PUBLIC_TEST_TEST_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698