Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "chrome/browser/lifetime/keep_alive_registry.h" | |
| 6 | |
| 7 #include "base/memory/scoped_ptr.h" | |
| 8 #include "chrome/browser/lifetime/application_lifetime.h" | |
| 9 #include "chrome/browser/lifetime/keep_alive_types.h" | |
| 10 #include "chrome/browser/lifetime/scoped_keep_alive.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 class KeepAliveRegistryTest : public testing::Test { | |
|
sky
2016/02/25 18:43:50
nit: remove this and instead using the TEST() macr
dgn
2016/02/26 11:51:59
Done.
| |
| 14 public: | |
| 15 KeepAliveRegistryTest() {} | |
| 16 ~KeepAliveRegistryTest() override {} | |
| 17 }; | |
| 18 | |
| 19 // Test the WillKeepAlive state and when we interact with the browser with | |
| 20 // a KeepAlive registered. | |
| 21 TEST_F(KeepAliveRegistryTest, BasicKeepAliveTest) { | |
| 22 const int base_keep_alive_count = chrome::GetKeepAliveCountForTesting(); | |
| 23 KeepAliveRegistry* registry = KeepAliveRegistry::GetInstance(); | |
| 24 | |
| 25 EXPECT_FALSE(registry->WillKeepAlive()); | |
| 26 | |
| 27 { | |
| 28 ScopedKeepAlive test_keep_alive(KeepAliveOrigin::TEST); | |
| 29 | |
| 30 // We should require the browser to stay alive | |
| 31 EXPECT_EQ(base_keep_alive_count + 1, chrome::GetKeepAliveCountForTesting()); | |
| 32 EXPECT_TRUE(registry->WillKeepAlive()); | |
| 33 } | |
| 34 | |
| 35 // We should be back to normal now. | |
| 36 EXPECT_EQ(base_keep_alive_count, chrome::GetKeepAliveCountForTesting()); | |
| 37 EXPECT_FALSE(registry->WillKeepAlive()); | |
| 38 } | |
| 39 | |
| 40 // Test the WillKeepAlive state and when we interact with the browser with | |
| 41 // more than one KeepAlive registered. | |
| 42 TEST_F(KeepAliveRegistryTest, DoubleKeepAliveTest) { | |
| 43 const int base_keep_alive_count = chrome::GetKeepAliveCountForTesting(); | |
| 44 KeepAliveRegistry* registry = KeepAliveRegistry::GetInstance(); | |
| 45 scoped_ptr<ScopedKeepAlive> keep_alive_1, keep_alive_2; | |
| 46 | |
| 47 keep_alive_1.reset(new ScopedKeepAlive(KeepAliveOrigin::TEST)); | |
| 48 EXPECT_EQ(base_keep_alive_count + 1, chrome::GetKeepAliveCountForTesting()); | |
| 49 EXPECT_TRUE(registry->WillKeepAlive()); | |
| 50 | |
| 51 keep_alive_2.reset(new ScopedKeepAlive(KeepAliveOrigin::TEST)); | |
| 52 // We should not increment the count twice | |
| 53 EXPECT_EQ(base_keep_alive_count + 1, chrome::GetKeepAliveCountForTesting()); | |
| 54 EXPECT_TRUE(registry->WillKeepAlive()); | |
| 55 | |
| 56 keep_alive_1.reset(); | |
| 57 // We should not decrement the count before the last keep alive is released. | |
| 58 EXPECT_EQ(base_keep_alive_count + 1, chrome::GetKeepAliveCountForTesting()); | |
| 59 EXPECT_TRUE(registry->WillKeepAlive()); | |
| 60 | |
| 61 keep_alive_2.reset(); | |
| 62 EXPECT_EQ(base_keep_alive_count, chrome::GetKeepAliveCountForTesting()); | |
| 63 EXPECT_FALSE(registry->WillKeepAlive()); | |
| 64 } | |
| OLD | NEW |