blob: 570cb576398114db39b1b4ef6521d78d6fae28c7 [file] [log] [blame]
dgn3eaf67e2016-07-26 09:01:121// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <memory>
6
7#include "chrome/browser/background/background_mode_optimizer.h"
Avi Drissmand30927342018-05-22 15:04:278#include "chrome/browser/lifetime/browser_shutdown.h"
dgn3eaf67e2016-07-26 09:01:129#include "testing/gmock/include/gmock/gmock.h"
10#include "testing/gtest/include/gtest/gtest.h"
11
12// Dummy optimizer that skips doing the restart.
13// friend with BackgroundModeOptimizer, can't be in the anonymous namespace.
14class DummyBackgroundModeOptimizer : public BackgroundModeOptimizer {
15 public:
16 DummyBackgroundModeOptimizer() {}
17 MOCK_METHOD0(DoRestart, void());
18};
19
20TEST(BackgroundModeOptimizerTest, Foo) {
21 // Strict mock, will fail the test if a non expected call is made.
22 testing::StrictMock<DummyBackgroundModeOptimizer> optimizer;
23
24 // No restart until we have at least one browser that got opened
25 optimizer.OnKeepAliveRestartStateChanged(true);
26
27 optimizer.OnBrowserAdded(nullptr);
28 EXPECT_CALL(optimizer, DoRestart()).RetiresOnSaturation();
29 optimizer.OnKeepAliveRestartStateChanged(true);
30
31 // Restart should not be called when we are trying to quit
32 browser_shutdown::SetTryingToQuit(true);
33 optimizer.OnKeepAliveRestartStateChanged(true);
34
35 // Restart should check that restart changed to be allowed.
36 browser_shutdown::SetTryingToQuit(false);
37 optimizer.OnKeepAliveRestartStateChanged(false);
38
39 EXPECT_CALL(optimizer, DoRestart()).RetiresOnSaturation();
40 optimizer.OnKeepAliveRestartStateChanged(true);
41}