background_mode_manager_unittest.cc revision dc0f95d653279beabeb9817299e2902918ba123e
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
3// found in the LICENSE file.
4
5#include "base/command_line.h"
6#include "base/scoped_ptr.h"
7#include "chrome/browser/background_mode_manager.h"
8#include "chrome/browser/browser_list.h"
9#include "chrome/common/chrome_switches.h"
10#include "chrome/test/testing_browser_process.h"
11#include "chrome/test/testing_browser_process_test.h"
12#include "chrome/test/testing_profile.h"
13#include "testing/gmock/include/gmock/gmock.h"
14#include "testing/gtest/include/gtest/gtest.h"
15
16using testing::InSequence;
17
18class BackgroundModeManagerTest : public TestingBrowserProcessTest {
19 public:
20  BackgroundModeManagerTest() {}
21  ~BackgroundModeManagerTest() {}
22  void SetUp() {
23    command_line_.reset(new CommandLine(CommandLine::NO_PROGRAM));
24  }
25  scoped_ptr<CommandLine> command_line_;
26};
27
28class TestBackgroundModeManager : public BackgroundModeManager {
29 public:
30  TestBackgroundModeManager(Profile* profile, CommandLine* cl)
31      : BackgroundModeManager(profile, cl) {
32  }
33  MOCK_METHOD1(EnableLaunchOnStartup, void(bool));
34  MOCK_METHOD0(CreateStatusTrayIcon, void());
35  MOCK_METHOD0(RemoveStatusTrayIcon, void());
36};
37
38TEST_F(BackgroundModeManagerTest, BackgroundAppLoadUnload) {
39  InSequence s;
40  TestingProfile profile;
41  TestBackgroundModeManager manager(&profile, command_line_.get());
42  EXPECT_CALL(manager, CreateStatusTrayIcon());
43  EXPECT_CALL(manager, RemoveStatusTrayIcon());
44  EXPECT_FALSE(BrowserList::WillKeepAlive());
45  // Call to AppLoaded() will cause the status tray to be created, then call to
46  // unloaded will result in call to remove the icon.
47  manager.OnBackgroundAppLoaded();
48  EXPECT_TRUE(BrowserList::WillKeepAlive());
49  manager.OnBackgroundAppUnloaded();
50  EXPECT_FALSE(BrowserList::WillKeepAlive());
51}
52
53TEST_F(BackgroundModeManagerTest, BackgroundAppInstallUninstall) {
54  InSequence s;
55  TestingProfile profile;
56  TestBackgroundModeManager manager(&profile, command_line_.get());
57  // Call to AppInstalled() will cause chrome to be set to launch on startup,
58  // and call to AppUninstalled() set chrome to not launch on startup.
59  EXPECT_CALL(manager, EnableLaunchOnStartup(true));
60  EXPECT_CALL(manager, CreateStatusTrayIcon());
61  EXPECT_CALL(manager, RemoveStatusTrayIcon());
62  EXPECT_CALL(manager, EnableLaunchOnStartup(false));
63  manager.OnBackgroundAppInstalled(NULL);
64  manager.OnBackgroundAppLoaded();
65  manager.OnBackgroundAppUnloaded();
66  manager.OnBackgroundAppUninstalled();
67}
68