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

Side by Side Diff: chrome/browser/background/background_mode_optimizer_unittest.cc

Issue 1931503002: Add BackgroundModeOptimizer that can restart the browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@PushKeepAlive
Patch Set: address comments. disable feature by default Created 4 years, 4 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 unified diff | Download patch
OLDNEW
(Empty)
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"
8 #include "chrome/browser/browser_shutdown.h"
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 }
OLDNEW
« no previous file with comments | « chrome/browser/background/background_mode_optimizer.cc ('k') | chrome/browser/browser_shutdown.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698