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

Unified Diff: chrome/browser/sessions/session_restore_test_helper.h

Issue 871013006: Use callbacks in SessionRestore unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add destructor Created 5 years, 11 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: chrome/browser/sessions/session_restore_test_helper.h
diff --git a/chrome/browser/sessions/session_restore_test_helper.h b/chrome/browser/sessions/session_restore_test_helper.h
new file mode 100644
index 0000000000000000000000000000000000000000..1e44d401d349ba89e61a7e48aed20c083ecce2cd
--- /dev/null
+++ b/chrome/browser/sessions/session_restore_test_helper.h
@@ -0,0 +1,50 @@
+// Copyright 2015 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.
+
+#ifndef CHROME_BROWSER_SESSIONS_SESSION_RESTORE_TEST_HELPER_H_
+#define CHROME_BROWSER_SESSIONS_SESSION_RESTORE_TEST_HELPER_H_
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "chrome/browser/sessions/session_restore.h"
+
+namespace content {
+class MessageLoopRunner;
+}
+
+// This class waits on the SessionRestore notification. It is a replacement for
+// content::WindowedNotificationObserver, which uses notification service. This
+// class uses the callback-based notification instead.
+class SessionRestoreTestHelper {
+ public:
+ SessionRestoreTestHelper();
+ ~SessionRestoreTestHelper();
+
+ // Blocks until OnSessionRestore() is called.
+ void Wait();
+
+ private:
+ // Callback for session restore notifications.
+ void OnSessionRestoreDone();
+
+ // Indicates whether a session restore notification has been received.
+ bool restore_notification_seen_;
+
+ // Indicates whether |message_loop_runner_| is running.
+ bool loop_is_running_;
+
+ // Loop that runs while waiting for notification callback.
+ scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
+
+ // For automatically unsubscribing from callback-based notifications.
+ SessionRestore::CallbackSubscription callback_subscription_;
+
+ // For safely binding pointers to callbacks.
+ base::WeakPtrFactory<SessionRestoreTestHelper> weak_ptr_factory;
+
+ DISALLOW_COPY_AND_ASSIGN(SessionRestoreTestHelper);
+};
+
+#endif // CHROME_BROWSER_SESSIONS_SESSION_RESTORE_TEST_HELPER_H_
« no previous file with comments | « chrome/browser/sessions/session_restore_browsertest.cc ('k') | chrome/browser/sessions/session_restore_test_helper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698