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

Unified 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, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/background/background_mode_optimizer.cc ('k') | chrome/browser/browser_shutdown.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
+}
« 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