Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / background_app_browsertest.cc
blob373f5e3cb34b69791a0ef955560ef5c67e101e63
1 // Copyright 2013 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.
5 #include "chrome/browser/background/background_mode_manager.h"
6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/extensions/extension_browsertest.h"
8 #include "chrome/browser/profiles/profile_manager.h"
10 class TestBackgroundModeManager : public BackgroundModeManager {
11 public:
12 TestBackgroundModeManager(const base::CommandLine& command_line,
13 ProfileInfoCache* profile_cache)
14 : BackgroundModeManager(command_line, profile_cache),
15 showed_background_app_installed_notification_for_test_(false) {}
17 ~TestBackgroundModeManager() override {}
19 void DisplayClientInstalledNotification(const base::string16& name) override {
20 showed_background_app_installed_notification_for_test_ = true;
23 bool showed_background_app_installed_notification_for_test() {
24 return showed_background_app_installed_notification_for_test_;
27 void set_showed_background_app_installed_notification_for_test(
28 bool showed) {
29 showed_background_app_installed_notification_for_test_ = showed;
32 private:
33 // Tracks if we have shown a "Background App Installed" notification to the
34 // user. Used for unit tests only.
35 bool showed_background_app_installed_notification_for_test_;
37 FRIEND_TEST_ALL_PREFIXES(BackgroundAppBrowserTest,
38 ReloadBackgroundApp);
40 DISALLOW_COPY_AND_ASSIGN(TestBackgroundModeManager);
43 class BackgroundAppBrowserTest: public ExtensionBrowserTest {};
45 // Tests that if we reload a background app, we don't get a popup bubble
46 // telling us that a new background app has been installed.
47 IN_PROC_BROWSER_TEST_F(BackgroundAppBrowserTest, ReloadBackgroundApp) {
49 // Pass this in to the browser test.
50 scoped_ptr<BackgroundModeManager> test_background_mode_manager(
51 new TestBackgroundModeManager(
52 *base::CommandLine::ForCurrentProcess(),
53 &(g_browser_process->profile_manager()->GetProfileInfoCache())));
54 g_browser_process->set_background_mode_manager_for_test(
55 test_background_mode_manager.Pass());
56 TestBackgroundModeManager* manager =
57 reinterpret_cast<TestBackgroundModeManager*>(
58 g_browser_process->background_mode_manager());
60 // Load our background extension
61 ASSERT_FALSE(
62 manager->showed_background_app_installed_notification_for_test());
63 const extensions::Extension* extension = LoadExtension(
64 test_data_dir_.AppendASCII("background_app"));
65 ASSERT_FALSE(extension == NULL);
67 // Set the test flag to not shown.
68 manager->set_showed_background_app_installed_notification_for_test(false);
70 // Reload our background extension
71 ReloadExtension(extension->id());
73 // Ensure that we did not see a "Background extension loaded" dialog.
74 EXPECT_FALSE(
75 manager->showed_background_app_installed_notification_for_test());