1 // Copyright (c) 2012 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 "base/command_line.h"
6 #include "chrome/browser/chrome_notification_types.h"
7 #include "chrome/browser/extensions/crx_installer.h"
8 #include "chrome/browser/extensions/extension_install_prompt.h"
9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/themes/theme_service.h"
13 #include "chrome/browser/themes/theme_service_factory.h"
14 #include "chrome/browser/ui/browser.h"
15 #include "chrome/browser/ui/tabs/tab_strip_model.h"
16 #include "chrome/common/chrome_switches.h"
17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/test_switches.h"
19 #include "chrome/test/base/ui_test_utils.h"
20 #include "content/public/browser/notification_service.h"
21 #include "extensions/browser/extension_system.h"
22 #include "net/test/embedded_test_server/embedded_test_server.h"
24 class InfoBarsTest
: public InProcessBrowserTest
{
28 void InstallExtension(const char* filename
) {
29 base::FilePath path
= ui_test_utils::GetTestFilePath(
30 base::FilePath().AppendASCII("extensions"),
31 base::FilePath().AppendASCII(filename
));
32 ExtensionService
* service
= extensions::ExtensionSystem::Get(
33 browser()->profile())->extension_service();
35 content::WindowedNotificationObserver
observer(
36 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED
,
37 content::NotificationService::AllSources());
39 scoped_ptr
<ExtensionInstallPrompt
> client(new ExtensionInstallPrompt(
40 browser()->tab_strip_model()->GetActiveWebContents()));
41 scoped_refptr
<extensions::CrxInstaller
> installer(
42 extensions::CrxInstaller::Create(service
, client
.Pass()));
43 installer
->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION
);
44 installer
->InstallCrx(path
);
50 IN_PROC_BROWSER_TEST_F(InfoBarsTest
, TestInfoBarsCloseOnNewTheme
) {
51 ExtensionInstallPrompt::g_auto_confirm_for_tests
=
52 ExtensionInstallPrompt::ACCEPT
;
54 #if defined(OS_WIN) && defined(USE_ASH)
55 // Disable this test in Metro+Ash for now (http://crbug.com/262796).
56 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
57 switches::kAshBrowserTests
))
61 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
63 ui_test_utils::NavigateToURL(
64 browser(), embedded_test_server()->GetURL("/simple.html"));
66 content::WindowedNotificationObserver
infobar_added_1(
67 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED
,
68 content::NotificationService::AllSources());
69 InstallExtension("theme.crx");
70 infobar_added_1
.Wait();
72 ui_test_utils::NavigateToURLWithDisposition(
73 browser(), embedded_test_server()->GetURL("/simple.html"),
74 NEW_FOREGROUND_TAB
, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
75 content::WindowedNotificationObserver
infobar_added_2(
76 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED
,
77 content::NotificationService::AllSources());
78 content::WindowedNotificationObserver
infobar_removed_1(
79 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED
,
80 content::NotificationService::AllSources());
81 InstallExtension("theme2.crx");
82 infobar_added_2
.Wait();
83 infobar_removed_1
.Wait();
86 InfoBarService::FromWebContents(
87 browser()->tab_strip_model()->GetWebContentsAt(0))->infobar_count());
89 content::WindowedNotificationObserver
infobar_removed_2(
90 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED
,
91 content::NotificationService::AllSources());
92 ThemeServiceFactory::GetForProfile(browser()->profile())->UseDefaultTheme();
93 infobar_removed_2
.Wait();
95 InfoBarService::FromWebContents(
96 browser()->tab_strip_model()->GetActiveWebContents())->