summaryrefslogtreecommitdiffstats
path: root/chrome/browser/sessions/session_restore_test_helper.cc
blob: 016d7ae0d416db0141f9a4426c32eae26ef46d15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 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.

#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),
      weak_ptr_factory(this) {
  callback_subscription_ = SessionRestore::RegisterOnSessionRestoredCallback(
      base::Bind(&SessionRestoreTestHelper::OnSessionRestoreDone,
                 weak_ptr_factory.GetWeakPtr()));
}

SessionRestoreTestHelper::~SessionRestoreTestHelper() {
}

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(
    int /* num_tabs_restored */) {
  restore_notification_seen_ = true;
  if (!loop_is_running_)
    return;

  message_loop_runner_->Quit();
  loop_is_running_ = false;
}