| Index: chrome/browser/background/background_mode_optimizer_unittest.cc
|
| diff --git a/chrome/browser/background/background_mode_optimizer_unittest.cc b/chrome/browser/background/background_mode_optimizer_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..e4b1f30ddb85cfa92f5ecc9789c1c6c4f4d0f1e7
|
| --- /dev/null
|
| +++ b/chrome/browser/background/background_mode_optimizer_unittest.cc
|
| @@ -0,0 +1,41 @@
|
| +// Copyright 2016 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 <memory>
|
| +
|
| +#include "chrome/browser/background/background_mode_optimizer.h"
|
| +#include "chrome/browser/browser_shutdown.h"
|
| +#include "testing/gmock/include/gmock/gmock.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +// Dummy optimizer that skips doing the restart.
|
| +// friend with BackgroundModeOptimizer, can't be in the anonymous namespace.
|
| +class DummyBackgroundModeOptimizer : public BackgroundModeOptimizer {
|
| + public:
|
| + DummyBackgroundModeOptimizer() {}
|
| + MOCK_METHOD0(DoRestart, void());
|
| +};
|
| +
|
| +TEST(BackgroundModeOptimizerTest, Foo) {
|
| + // Strict mock, will fail the test if a non expected call is made.
|
| + testing::StrictMock<DummyBackgroundModeOptimizer> optimizer;
|
| +
|
| + // No restart until we have at least one browser that got opened
|
| + optimizer.OnKeepAliveRestartStateChanged(true);
|
| +
|
| + optimizer.OnBrowserAdded(nullptr);
|
| + EXPECT_CALL(optimizer, DoRestart()).RetiresOnSaturation();
|
| + optimizer.OnKeepAliveRestartStateChanged(true);
|
| +
|
| + // Restart should not be called when we are trying to quit
|
| + browser_shutdown::SetTryingToQuit(true);
|
| + optimizer.OnKeepAliveRestartStateChanged(true);
|
| +
|
| + // Restart should check that restart changed to be allowed.
|
| + browser_shutdown::SetTryingToQuit(false);
|
| + optimizer.OnKeepAliveRestartStateChanged(false);
|
| +
|
| + EXPECT_CALL(optimizer, DoRestart()).RetiresOnSaturation();
|
| + optimizer.OnKeepAliveRestartStateChanged(true);
|
| +}
|
|
|