OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/background/background_mode_manager.h" | 8 #include "chrome/browser/background/background_mode_manager.h" |
9 #include "chrome/browser/browser_shutdown.h" | |
10 #include "chrome/browser/lifetime/application_lifetime.h" | 9 #include "chrome/browser/lifetime/application_lifetime.h" |
11 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
12 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/test/base/testing_browser_process.h" | 12 #include "chrome/test/base/testing_browser_process.h" |
14 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
15 #include "chrome/test/base/testing_profile_manager.h" | 14 #include "chrome/test/base/testing_profile_manager.h" |
16 #include "content/public/test/test_browser_thread_bundle.h" | |
17 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
19 #include "ui/gfx/image/image_unittest_util.h" | 17 #include "ui/gfx/image/image_unittest_util.h" |
20 #include "ui/message_center/message_center.h" | |
21 | 18 |
22 class BackgroundModeManagerTest : public testing::Test { | 19 class BackgroundModeManagerTest : public testing::Test { |
23 protected: | 20 public: |
24 BackgroundModeManagerTest() | 21 BackgroundModeManagerTest() |
25 : profile_manager_(TestingBrowserProcess::GetGlobal()) { | 22 : profile_manager_(TestingBrowserProcess::GetGlobal()) {} |
| 23 virtual ~BackgroundModeManagerTest() {} |
| 24 virtual void SetUp() { |
26 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); | 25 command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM)); |
27 CHECK(profile_manager_.SetUp()); | 26 ASSERT_TRUE(profile_manager_.SetUp()); |
28 #if defined(OS_CHROMEOS) | |
29 // Because of the http://crbug.com/119175 workaround in the test | |
30 // constructor, browser shutdown needs to be reset otherwise | |
31 // subsequent test will fail. | |
32 browser_shutdown::SetTryingToQuit(false); | |
33 #endif // defined(OS_CHROMEOS) | |
34 } | 27 } |
35 | |
36 static void SetUpTestCase() { | |
37 message_center::MessageCenter::Initialize(); | |
38 #if defined(OS_CHROMEOS) | |
39 // Needed to handle http://crbug.com/119175. | |
40 CommandLine::ForCurrentProcess()->AppendSwitch( | |
41 switches::kDisableZeroBrowsersOpenForTests); | |
42 #endif // defined(OS_CHROMEOS) | |
43 } | |
44 static void TearDownTestCase() { | |
45 message_center::MessageCenter::Shutdown(); | |
46 } | |
47 | |
48 scoped_ptr<CommandLine> command_line_; | 28 scoped_ptr<CommandLine> command_line_; |
49 content::TestBrowserThreadBundle thread_bundle_; | |
50 TestingProfileManager profile_manager_; | 29 TestingProfileManager profile_manager_; |
51 }; | 30 }; |
52 | 31 |
53 class TestBackgroundModeManager : public BackgroundModeManager { | 32 class TestBackgroundModeManager : public BackgroundModeManager { |
54 public: | 33 public: |
55 TestBackgroundModeManager( | 34 TestBackgroundModeManager( |
56 CommandLine* command_line, ProfileInfoCache* cache, bool enabled) | 35 CommandLine* command_line, ProfileInfoCache* cache, bool enabled) |
57 : BackgroundModeManager(command_line, cache), | 36 : BackgroundModeManager(command_line, cache), |
58 enabled_(enabled), | 37 enabled_(enabled), |
59 app_count_(0), | 38 app_count_(0), |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 303 |
325 TEST_F(BackgroundModeManagerTest, | 304 TEST_F(BackgroundModeManagerTest, |
326 BackgroundModeDisabledPreventsKeepAliveOnStartup) { | 305 BackgroundModeDisabledPreventsKeepAliveOnStartup) { |
327 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); | 306 TestingProfile* profile1 = profile_manager_.CreateTestingProfile("p1"); |
328 command_line_->AppendSwitch(switches::kKeepAliveForTest); | 307 command_line_->AppendSwitch(switches::kKeepAliveForTest); |
329 TestBackgroundModeManager manager( | 308 TestBackgroundModeManager manager( |
330 command_line_.get(), profile_manager_.profile_info_cache(), false); | 309 command_line_.get(), profile_manager_.profile_info_cache(), false); |
331 manager.RegisterProfile(profile1); | 310 manager.RegisterProfile(profile1); |
332 EXPECT_FALSE(manager.ShouldBeInBackgroundMode()); | 311 EXPECT_FALSE(manager.ShouldBeInBackgroundMode()); |
333 } | 312 } |
OLD | NEW |