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. 4 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" 9 #include "chrome/test/base/ui_test_utils.h" 10 11 class TestBackgroundModeManager : public BackgroundModeManager { 12 public: TestBackgroundModeManager(CommandLine * command_line,ProfileInfoCache * profile_cache)13 TestBackgroundModeManager(CommandLine* command_line, 14 ProfileInfoCache* profile_cache) 15 : BackgroundModeManager(command_line, profile_cache), 16 showed_background_app_installed_notification_for_test_(false) {} 17 ~TestBackgroundModeManager()18 virtual ~TestBackgroundModeManager() {} 19 DisplayAppInstalledNotification(const extensions::Extension * extension)20 virtual void DisplayAppInstalledNotification( 21 const extensions::Extension* extension) OVERRIDE { 22 showed_background_app_installed_notification_for_test_ = true; 23 } 24 showed_background_app_installed_notification_for_test()25 bool showed_background_app_installed_notification_for_test() { 26 return showed_background_app_installed_notification_for_test_; 27 } 28 set_showed_background_app_installed_notification_for_test(bool showed)29 void set_showed_background_app_installed_notification_for_test( 30 bool showed) { 31 showed_background_app_installed_notification_for_test_ = showed; 32 } 33 34 private: 35 // Tracks if we have shown a "Background App Installed" notification to the 36 // user. Used for unit tests only. 37 bool showed_background_app_installed_notification_for_test_; 38 39 FRIEND_TEST_ALL_PREFIXES(BackgroundAppBrowserTest, 40 ReloadBackgroundApp); 41 42 DISALLOW_COPY_AND_ASSIGN(TestBackgroundModeManager); 43 }; 44 45 class BackgroundAppBrowserTest: public ExtensionBrowserTest {}; 46 47 // Tests that if we reload a background app, we don't get a popup bubble 48 // telling us that a new background app has been installed. IN_PROC_BROWSER_TEST_F(BackgroundAppBrowserTest,ReloadBackgroundApp)49IN_PROC_BROWSER_TEST_F(BackgroundAppBrowserTest, ReloadBackgroundApp) { 50 51 // Pass this in to the browser test. 52 scoped_ptr<BackgroundModeManager> test_background_mode_manager( 53 new TestBackgroundModeManager( 54 CommandLine::ForCurrentProcess(), 55 &(g_browser_process->profile_manager()->GetProfileInfoCache()))); 56 g_browser_process->set_background_mode_manager_for_test( 57 test_background_mode_manager.Pass()); 58 TestBackgroundModeManager* manager = 59 reinterpret_cast<TestBackgroundModeManager*>( 60 g_browser_process->background_mode_manager()); 61 62 // Load our background extension 63 ASSERT_FALSE( 64 manager->showed_background_app_installed_notification_for_test()); 65 const extensions::Extension* extension = LoadExtension( 66 test_data_dir_.AppendASCII("background_app")); 67 ASSERT_FALSE(extension == NULL); 68 69 // Set the test flag to not shown. 70 manager->set_showed_background_app_installed_notification_for_test(false); 71 72 // Reload our background extension 73 ReloadExtension(extension->id()); 74 75 // Ensure that we did not see a "Background extension loaded" dialog. 76 EXPECT_FALSE( 77 manager->showed_background_app_installed_notification_for_test()); 78 } 79