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

Unified Diff: content/public/test/repeated_notification_observer.cc

Issue 2798143004: Fix for URL opening code (Closed)
Patch Set: Added new files for added tests. Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/public/test/repeated_notification_observer.cc
diff --git a/content/public/test/repeated_notification_observer.cc b/content/public/test/repeated_notification_observer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f9e6a99904806bb90d4b3fea9efdf9c5e6eb1361
--- /dev/null
+++ b/content/public/test/repeated_notification_observer.cc
@@ -0,0 +1,38 @@
+// Copyright (c) 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/public/test/repeated_notification_observer.h"
+
+#include "base/macros.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/notification_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+RepeatedNotificationObserver::RepeatedNotificationObserver(int type, int count)
+ : num_outstanding_(count), running_(false) {
+ registrar_.Add(this, type, NotificationService::AllSources());
+}
+
+void RepeatedNotificationObserver::Observe(int type,
+ const NotificationSource& source,
+ const NotificationDetails& details) {
+ ASSERT_GT(num_outstanding_, 0);
+ if (!--num_outstanding_ && running_) {
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ run_loop_.QuitClosure());
+ }
+}
+
+void RepeatedNotificationObserver::Wait() {
+ if (num_outstanding_ <= 0)
+ return;
+
+ running_ = true;
+ run_loop_.Run();
+ running_ = false;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698