dgn | 3eaf67e | 2016-07-26 09:01:12 | [diff] [blame] | 1 | // 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 Drissman | d3092734 | 2018-05-22 15:04:27 | [diff] [blame] | 8 | #include "chrome/browser/lifetime/browser_shutdown.h" |
dgn | 3eaf67e | 2016-07-26 09:01:12 | [diff] [blame] | 9 | #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. |
| 14 | class DummyBackgroundModeOptimizer : public BackgroundModeOptimizer { |
| 15 | public: |
| 16 | DummyBackgroundModeOptimizer() {} |
| 17 | MOCK_METHOD0(DoRestart, void()); |
| 18 | }; |
| 19 | |
| 20 | TEST(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 | } |