OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/test/automation/automation_proxy.h" | 5 #include "chrome/browser/extensions/crx_installer.h" |
6 #include "chrome/test/automation/browser_proxy.h" | 6 #include "chrome/browser/extensions/extension_install_ui.h" |
7 #include "chrome/test/automation/extension_proxy.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
8 #include "chrome/test/automation/tab_proxy.h" | 8 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 9 #include "chrome/browser/themes/theme_service.h" |
| 10 #include "chrome/browser/themes/theme_service_factory.h" |
| 11 #include "chrome/browser/ui/browser.h" |
| 12 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 13 #include "chrome/common/chrome_notification_types.h" |
| 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "content/public/browser/notification_service.h" |
| 16 #include "chrome/test/base/in_process_browser_test.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" |
9 #include "chrome/test/ui/ui_test.h" | 18 #include "chrome/test/ui/ui_test.h" |
10 #include "net/test/test_server.h" | 19 #include "net/test/test_server.h" |
11 | 20 |
12 class InfoBarsUITest : public UITest { | 21 class InfoBarsTest : public InProcessBrowserTest { |
13 public: | 22 public: |
14 InfoBarsUITest() { | 23 InfoBarsTest() {} |
15 show_window_ = true; | 24 |
| 25 void InstallExtension(const char* filename) { |
| 26 FilePath path = ui_test_utils::GetTestFilePath( |
| 27 FilePath().AppendASCII("extensions"), FilePath().AppendASCII(filename)); |
| 28 Profile* profile = browser()->profile(); |
| 29 ExtensionService* service = profile->GetExtensionService(); |
| 30 |
| 31 ui_test_utils::WindowedNotificationObserver observer( |
| 32 chrome::NOTIFICATION_EXTENSION_LOADED, |
| 33 content::NotificationService::AllSources()); |
| 34 |
| 35 ExtensionInstallUI* client = new ExtensionInstallUI(profile); |
| 36 scoped_refptr<CrxInstaller> installer( |
| 37 CrxInstaller::Create(service, client)); |
| 38 installer->set_install_cause(extension_misc::INSTALL_CAUSE_AUTOMATION); |
| 39 installer->InstallCrx(path); |
| 40 |
| 41 observer.Wait(); |
16 } | 42 } |
17 }; | 43 }; |
18 | 44 |
19 TEST_F(InfoBarsUITest, TestInfoBarsCloseOnNewTheme) { | 45 IN_PROC_BROWSER_TEST_F(InfoBarsTest, TestInfoBarsCloseOnNewTheme) { |
20 net::TestServer test_server(net::TestServer::TYPE_HTTP, | 46 ASSERT_TRUE(test_server()->Start()); |
21 net::TestServer::kLocalhost, | |
22 FilePath(FILE_PATH_LITERAL("chrome/test/data"))); | |
23 ASSERT_TRUE(test_server.Start()); | |
24 | 47 |
25 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 48 ui_test_utils::NavigateToURL( |
26 ASSERT_TRUE(browser.get()); | 49 browser(), test_server()->GetURL("files/simple.html")); |
27 | 50 |
28 scoped_refptr<TabProxy> tab_1(browser->GetActiveTab()); | 51 ui_test_utils::WindowedNotificationObserver infobar_added_1( |
29 ASSERT_TRUE(tab_1.get()); | 52 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
30 EXPECT_TRUE(tab_1->NavigateToURL( | 53 content::NotificationService::AllSources()); |
31 test_server.GetURL("files/simple.html"))); | 54 InstallExtension("theme.crx"); |
32 scoped_refptr<ExtensionProxy> theme = automation()->InstallExtension( | 55 infobar_added_1.Wait(); |
33 test_data_directory_.AppendASCII("extensions").AppendASCII("theme.crx"), | |
34 true); | |
35 ASSERT_TRUE(theme != NULL); | |
36 EXPECT_TRUE(tab_1->WaitForInfoBarCount(1)); | |
37 | 56 |
38 EXPECT_TRUE(browser->AppendTab( | 57 ui_test_utils::NavigateToURLWithDisposition( |
39 test_server.GetURL("files/simple.html"))); | 58 browser(), test_server()->GetURL("files/simple.html"), |
40 WaitUntilTabCount(2); | 59 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
41 scoped_refptr<TabProxy> tab_2(browser->GetActiveTab()); | 60 ui_test_utils::WindowedNotificationObserver infobar_added_2( |
42 ASSERT_TRUE(tab_2.get()); | 61 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
43 theme = automation()->InstallExtension( | 62 content::NotificationService::AllSources()); |
44 test_data_directory_.AppendASCII("extensions").AppendASCII("theme2.crx"), | 63 ui_test_utils::WindowedNotificationObserver infobar_removed_1( |
45 true); | 64 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
46 ASSERT_TRUE(theme != NULL); | 65 content::NotificationService::AllSources()); |
47 EXPECT_TRUE(tab_2->WaitForInfoBarCount(1)); | 66 InstallExtension("theme2.crx"); |
48 EXPECT_TRUE(tab_1->WaitForInfoBarCount(0)); | 67 infobar_added_2.Wait(); |
| 68 infobar_removed_1.Wait(); |
| 69 EXPECT_EQ(0u, |
| 70 browser()->GetTabContentsWrapperAt(0)->infobar_tab_helper()-> |
| 71 infobar_count()); |
49 | 72 |
50 EXPECT_TRUE(automation()->ResetToDefaultTheme()); | 73 ui_test_utils::WindowedNotificationObserver infobar_removed_2( |
51 EXPECT_TRUE(tab_2->WaitForInfoBarCount(0)); | 74 chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_REMOVED, |
| 75 content::NotificationService::AllSources()); |
| 76 ThemeServiceFactory::GetForProfile(browser()->profile())->UseDefaultTheme(); |
| 77 infobar_removed_2.Wait(); |
| 78 EXPECT_EQ(0u, |
| 79 browser()->GetSelectedTabContentsWrapper()->infobar_tab_helper()-> |
| 80 infobar_count()); |
52 } | 81 } |
OLD | NEW |