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

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

Issue 871013006: Use callbacks in SessionRestore unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased 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.cc
diff --git a/chrome/browser/sessions/session_restore_test_helper.cc b/chrome/browser/sessions/session_restore_test_helper.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c64395a790e2ec76c9de156c30e6dabb5cffff9e
--- /dev/null
+++ b/chrome/browser/sessions/session_restore_test_helper.cc
@@ -0,0 +1,35 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
sky 2015/01/26 16:50:01 2015 and no copyright.
Simon Que 2015/01/26 18:40:49 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sessions/session_restore_test_helper.h"
+
+#include "content/public/test/test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+SessionRestoreTestHelper::SessionRestoreTestHelper()
+ : restore_notification_seen_(false),
+ loop_is_running_(false) {
+ callback_subscription_ = SessionRestore::RegisterOnSessionRestoredCallback(
+ base::Bind(&SessionRestoreTestHelper::OnSessionRestoreDone,
+ base::Unretained(this)));
sky 2015/01/26 16:50:01 As it's entirely possible for this to be destroyed
Simon Que 2015/01/26 18:40:49 Done.
+}
+
+void SessionRestoreTestHelper::Wait() {
+ if (restore_notification_seen_)
+ return;
+
+ loop_is_running_ = true;
+ message_loop_runner_ = new content::MessageLoopRunner;
+ message_loop_runner_->Run();
+ EXPECT_TRUE(restore_notification_seen_);
+}
+
+void SessionRestoreTestHelper::OnSessionRestoreDone() {
+ restore_notification_seen_ = true;
+ if (!loop_is_running_)
+ return;
+
+ message_loop_runner_->Quit();
+ loop_is_running_ = false;
+}

Powered by Google App Engine
This is Rietveld 408576698