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 "chrome/browser/extensions/crx_installer.h"
6 #include "chrome/browser/extensions/extension_install_prompt.h"
7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/infobars/infobar_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/themes/theme_service.h"
11 #include "chrome/browser/themes/theme_service_factory.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
14 #include "chrome/common/chrome_notification_types.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/ui_test_utils.h"
18 #include "chrome/test/ui/ui_test.h"
19 #include "content/public/browser/notification_service.h"
20 #include "net/test/test_server.h"
22 class InfoBarsTest
: public InProcessBrowserTest
{
26 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
27 command_line
->AppendSwitchASCII(
28 switches::kAppsGalleryInstallAutoConfirmForTests
, "accept");
31 void InstallExtension(const char* filename
) {
32 base::FilePath path
= ui_test_utils::GetTestFilePath(
33 base::FilePath().AppendASCII("extensions"),
34 base::FilePath().AppendASCII(filename
));
35 Profile
* profile
= browser()->profile();
36 ExtensionService
* service
= profile
->GetExtensionService();
38 content::WindowedNotificationObserver
observer(
39 chrome::NOTIFICATION_EXTENSION_LOADED
,
40 content::NotificationService::AllSources());
42 ExtensionInstallPrompt
* client
= new ExtensionInstallPrompt(
43 browser()->tab_strip_model()->GetActiveWebContents());
44 scoped_refptr
<extensions::CrxInstaller
> installer(
45 extensions::CrxInstaller::Create(service
, client
));
46 installer
->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION
);
47 installer
->InstallCrx(path
);
53 IN_PROC_BROWSER_TEST_F(InfoBarsTest
, TestInfoBarsCloseOnNewTheme
) {
54 ASSERT_TRUE(test_server()->Start());
56 ui_test_utils::NavigateToURL(
57 browser(), test_server()->GetURL("files/simple.html"));
59 content::WindowedNotificationObserver
infobar_added_1(
60 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED
,
61 content::NotificationService::AllSources());
62 InstallExtension("theme.crx");
63 infobar_added_1
.Wait();
65 ui_test_utils::NavigateToURLWithDisposition(
66 browser(), test_server()->GetURL("files/simple.html"),
67 NEW_FOREGROUND_TAB
, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION
);
68 content::WindowedNotificationObserver
infobar_added_2(
69 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED
,
70 content::NotificationService::AllSources());
71 content::WindowedNotificationObserver
infobar_removed_1(
72 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED
,
73 content::NotificationService::AllSources());
74 InstallExtension("theme2.crx");
75 infobar_added_2
.Wait();
76 infobar_removed_1
.Wait();
78 InfoBarService::FromWebContents(browser()->tab_strip_model()->
79 GetWebContentsAt(0))->GetInfoBarCount());
81 content::WindowedNotificationObserver
infobar_removed_2(
82 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED
,
83 content::NotificationService::AllSources());
84 ThemeServiceFactory::GetForProfile(browser()->profile())->UseDefaultTheme();
85 infobar_removed_2
.Wait();
87 InfoBarService::FromWebContents(browser()->tab_strip_model()->
88 GetActiveWebContents())->GetInfoBarCount());