summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/background_app_browsertest.cc
blob: 020953d3b25ae3599368c2bd60309d0f9d09199c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2013 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 "chrome/browser/background/background_mode_manager.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/profiles/profile_manager.h"

class TestBackgroundModeManager : public BackgroundModeManager {
 public:
  TestBackgroundModeManager(base::CommandLine* command_line,
                            ProfileInfoCache* profile_cache)
      : BackgroundModeManager(command_line, profile_cache),
        showed_background_app_installed_notification_for_test_(false) {}

  ~TestBackgroundModeManager() override {}

  void DisplayAppInstalledNotification(
      const extensions::Extension* extension) override {
    showed_background_app_installed_notification_for_test_ = true;
  }

  bool showed_background_app_installed_notification_for_test() {
    return showed_background_app_installed_notification_for_test_;
  }

  void set_showed_background_app_installed_notification_for_test(
      bool showed) {
    showed_background_app_installed_notification_for_test_ = showed;
  }

 private:
  // Tracks if we have shown a "Background App Installed" notification to the
  // user.  Used for unit tests only.
  bool showed_background_app_installed_notification_for_test_;

  FRIEND_TEST_ALL_PREFIXES(BackgroundAppBrowserTest,
                           ReloadBackgroundApp);

  DISALLOW_COPY_AND_ASSIGN(TestBackgroundModeManager);
};

class BackgroundAppBrowserTest: public ExtensionBrowserTest {};

// Tests that if we reload a background app, we don't get a popup bubble
// telling us that a new background app has been installed.
IN_PROC_BROWSER_TEST_F(BackgroundAppBrowserTest, ReloadBackgroundApp) {

  // Pass this in to the browser test.
  scoped_ptr<BackgroundModeManager> test_background_mode_manager(
      new TestBackgroundModeManager(
          base::CommandLine::ForCurrentProcess(),
          &(g_browser_process->profile_manager()->GetProfileInfoCache())));
  g_browser_process->set_background_mode_manager_for_test(
      test_background_mode_manager.Pass());
  TestBackgroundModeManager* manager =
      reinterpret_cast<TestBackgroundModeManager*>(
          g_browser_process->background_mode_manager());

  // Load our background extension
  ASSERT_FALSE(
      manager->showed_background_app_installed_notification_for_test());
  const extensions::Extension* extension = LoadExtension(
      test_data_dir_.AppendASCII("background_app"));
  ASSERT_FALSE(extension == NULL);

  // Set the test flag to not shown.
  manager->set_showed_background_app_installed_notification_for_test(false);

  // Reload our background extension
  ReloadExtension(extension->id());

  // Ensure that we did not see a "Background extension loaded" dialog.
  EXPECT_FALSE(
      manager->showed_background_app_installed_notification_for_test());
}