| 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 "base/string_util.h" | 5 #include "base/string_util.h" |
| 6 #include "chrome/app/chrome_command_ids.h" |
| 6 #include "chrome/browser/extensions/extension_browsertest.h" | 7 #include "chrome/browser/extensions/extension_browsertest.h" |
| 7 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
| 8 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" | 9 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" |
| 9 #include "chrome/browser/infobars/infobar_tab_helper.h" | 10 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/themes/theme_service.h" |
| 11 #include "chrome/browser/themes/theme_service_factory.h" | 13 #include "chrome/browser/themes/theme_service_factory.h" |
| 12 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_commands.h" |
| 13 #include "chrome/browser/ui/browser_finder.h" | 16 #include "chrome/browser/ui/browser_finder.h" |
| 14 #include "chrome/browser/ui/browser_tabstrip.h" | 17 #include "chrome/browser/ui/browser_tabstrip.h" |
| 15 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 16 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" | 19 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" |
| 17 #include "chrome/test/base/ui_test_utils.h" | 20 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 19 | 22 |
| 20 using content::WebContents; | 23 using content::WebContents; |
| 21 using extensions::Extension; | 24 using extensions::Extension; |
| 22 | 25 |
| 23 class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { | 26 class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { |
| 24 public: | 27 public: |
| 25 // Checks that a theme info bar is currently visible and issues an undo to | 28 // Checks that a theme info bar is currently visible and issues an undo to |
| 26 // revert to the previous theme. | 29 // revert to the previous theme. |
| 27 void VerifyThemeInfoBarAndUndoInstall() { | 30 void VerifyThemeInfoBarAndUndoInstall() { |
| 28 TabContents* tab = chrome::GetActiveTabContents(browser()); | 31 TabContents* tab = chrome::GetActiveTabContents(browser()); |
| 29 ASSERT_TRUE(tab); | 32 ASSERT_TRUE(tab); |
| 30 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); | 33 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); |
| 31 ASSERT_EQ(1U, infobar_helper->GetInfoBarCount()); | 34 ASSERT_EQ(1U, infobar_helper->GetInfoBarCount()); |
| 32 ConfirmInfoBarDelegate* delegate = infobar_helper-> | 35 ConfirmInfoBarDelegate* delegate = infobar_helper-> |
| 33 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); | 36 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
| 34 ASSERT_TRUE(delegate); | 37 ASSERT_TRUE(delegate); |
| 35 delegate->Cancel(); | 38 delegate->Cancel(); |
| 36 ASSERT_EQ(0U, infobar_helper->GetInfoBarCount()); | 39 ASSERT_EQ(0U, infobar_helper->GetInfoBarCount()); |
| 37 } | 40 } |
| 38 | 41 |
| 42 // Install the given theme from the data dir and verify expected name. |
| 43 void InstallThemeAndVerify(const char* theme_name, |
| 44 const std::string& expected_name) { |
| 45 const FilePath theme_path = test_data_dir_.AppendASCII(theme_name); |
| 46 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path, 1, browser())); |
| 47 const Extension* theme = GetTheme(); |
| 48 ASSERT_TRUE(theme); |
| 49 ASSERT_EQ(theme->name(), expected_name); |
| 50 } |
| 51 |
| 39 const Extension* GetTheme() const { | 52 const Extension* GetTheme() const { |
| 40 return ThemeServiceFactory::GetThemeForProfile(browser()->profile()); | 53 return ThemeServiceFactory::GetThemeForProfile(browser()->profile()); |
| 41 } | 54 } |
| 42 }; | 55 }; |
| 43 | 56 |
| 44 #if defined(OS_LINUX) | 57 #if defined(OS_LINUX) |
| 45 // Fails consistently on bot chromium.chromiumos \ Linux. | 58 // Fails consistently on bot chromium.chromiumos \ Linux. |
| 46 // See: http://crbug.com/120647. | 59 // See: http://crbug.com/120647. |
| 47 #define MAYBE_TestThemeInstallUndoResetsToDefault DISABLED_TestThemeInstallUndoR
esetsToDefault | 60 #define MAYBE_TestThemeInstallUndoResetsToDefault DISABLED_TestThemeInstallUndoR
esetsToDefault |
| 48 #else | 61 #else |
| 49 #define MAYBE_TestThemeInstallUndoResetsToDefault TestThemeInstallUndoResetsToDe
fault | 62 #define MAYBE_TestThemeInstallUndoResetsToDefault TestThemeInstallUndoResetsToDe
fault |
| 50 #endif | 63 #endif |
| 51 | 64 |
| 52 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 65 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
| 53 MAYBE_TestThemeInstallUndoResetsToDefault) { | 66 MAYBE_TestThemeInstallUndoResetsToDefault) { |
| 54 ui_test_utils::CloseAllInfoBars(chrome::GetActiveTabContents(browser())); | |
| 55 | |
| 56 // Install theme once and undo to verify we go back to default theme. | 67 // Install theme once and undo to verify we go back to default theme. |
| 57 FilePath theme_crx = PackExtension(test_data_dir_.AppendASCII("theme")); | 68 FilePath theme_crx = PackExtension(test_data_dir_.AppendASCII("theme")); |
| 58 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 1, browser())); | 69 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 1, browser())); |
| 59 const Extension* theme = GetTheme(); | 70 const Extension* theme = GetTheme(); |
| 60 ASSERT_TRUE(theme); | 71 ASSERT_TRUE(theme); |
| 61 std::string theme_id = theme->id(); | 72 std::string theme_id = theme->id(); |
| 62 VerifyThemeInfoBarAndUndoInstall(); | 73 VerifyThemeInfoBarAndUndoInstall(); |
| 63 ASSERT_EQ(NULL, GetTheme()); | 74 ASSERT_EQ(NULL, GetTheme()); |
| 64 | 75 |
| 65 // Set the same theme twice and undo to verify we go back to default theme. | 76 // Set the same theme twice and undo to verify we go back to default theme. |
| 66 // We set the |expected_change| to zero in these 'InstallExtensionWithUI' | 77 // We set the |expected_change| to zero in these 'InstallExtensionWithUI' |
| 67 // calls since the theme has already been installed above and this is an | 78 // calls since the theme has already been installed above and this is an |
| 68 // overinstall to set the active theme. | 79 // overinstall to set the active theme. |
| 69 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); | 80 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); |
| 70 theme = GetTheme(); | 81 theme = GetTheme(); |
| 71 ASSERT_TRUE(theme); | 82 ASSERT_TRUE(theme); |
| 72 ASSERT_EQ(theme_id, theme->id()); | 83 ASSERT_EQ(theme_id, theme->id()); |
| 73 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); | 84 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); |
| 74 theme = GetTheme(); | 85 theme = GetTheme(); |
| 75 ASSERT_TRUE(theme); | 86 ASSERT_TRUE(theme); |
| 76 ASSERT_EQ(theme_id, theme->id()); | 87 ASSERT_EQ(theme_id, theme->id()); |
| 77 VerifyThemeInfoBarAndUndoInstall(); | 88 VerifyThemeInfoBarAndUndoInstall(); |
| 78 ASSERT_EQ(NULL, GetTheme()); | 89 ASSERT_EQ(NULL, GetTheme()); |
| 79 } | 90 } |
| 80 | 91 |
| 81 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 92 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
| 82 TestThemeInstallUndoResetsToPreviousTheme) { | 93 TestThemeInstallUndoResetsToPreviousTheme) { |
| 83 ui_test_utils::CloseAllInfoBars(chrome::GetActiveTabContents(browser())); | |
| 84 | |
| 85 // Install first theme. | 94 // Install first theme. |
| 86 FilePath theme_path = test_data_dir_.AppendASCII("theme"); | 95 InstallThemeAndVerify("theme", "camo theme"); |
| 87 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path, 1, browser())); | |
| 88 const Extension* theme = GetTheme(); | 96 const Extension* theme = GetTheme(); |
| 89 ASSERT_TRUE(theme); | |
| 90 std::string theme_id = theme->id(); | 97 std::string theme_id = theme->id(); |
| 91 | 98 |
| 92 // Then install second theme. | 99 // Then install second theme. |
| 93 FilePath theme_path2 = test_data_dir_.AppendASCII("theme2"); | 100 InstallThemeAndVerify("theme2", "snowflake theme"); |
| 94 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path2, 1, browser())); | |
| 95 const Extension* theme2 = GetTheme(); | 101 const Extension* theme2 = GetTheme(); |
| 96 ASSERT_TRUE(theme2); | |
| 97 EXPECT_FALSE(theme_id == theme2->id()); | 102 EXPECT_FALSE(theme_id == theme2->id()); |
| 98 | 103 |
| 99 // Undo second theme will revert to first theme. | 104 // Undo second theme will revert to first theme. |
| 100 VerifyThemeInfoBarAndUndoInstall(); | 105 VerifyThemeInfoBarAndUndoInstall(); |
| 101 EXPECT_EQ(theme, GetTheme()); | 106 EXPECT_EQ(theme, GetTheme()); |
| 102 } | 107 } |
| 103 | 108 |
| 109 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
| 110 TestThemeReset) { |
| 111 InstallThemeAndVerify("theme", "camo theme"); |
| 112 |
| 113 // Reset to default theme. |
| 114 ThemeServiceFactory::GetForProfile(browser()->profile())->UseDefaultTheme(); |
| 115 ASSERT_FALSE(GetTheme()); |
| 116 } |
| 117 |
| 118 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
| 119 TestInstallThemeInFullScreen) { |
| 120 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_FULLSCREEN)); |
| 121 InstallThemeAndVerify("theme", "camo theme"); |
| 122 } |
| 123 |
| 104 #if defined(OS_WIN) | 124 #if defined(OS_WIN) |
| 105 // http://crbug.com/141854 | 125 // http://crbug.com/141854 |
| 106 #define MAYBE_AppInstallConfirmation FLAKY_AppInstallConfirmation | 126 #define MAYBE_AppInstallConfirmation FLAKY_AppInstallConfirmation |
| 107 #else | 127 #else |
| 108 #define MAYBE_AppInstallConfirmation AppInstallConfirmation | 128 #define MAYBE_AppInstallConfirmation AppInstallConfirmation |
| 109 #endif | 129 #endif |
| 110 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 130 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
| 111 MAYBE_AppInstallConfirmation) { | 131 MAYBE_AppInstallConfirmation) { |
| 112 int num_tabs = browser()->tab_count(); | 132 int num_tabs = browser()->tab_count(); |
| 113 | 133 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 if (NewTabUI::ShouldShowApps()) { | 169 if (NewTabUI::ShouldShowApps()) { |
| 150 EXPECT_EQ(num_normal_tabs + 1, browser()->tab_count()); | 170 EXPECT_EQ(num_normal_tabs + 1, browser()->tab_count()); |
| 151 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 171 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 152 ASSERT_TRUE(web_contents); | 172 ASSERT_TRUE(web_contents); |
| 153 EXPECT_TRUE(StartsWithASCII(web_contents->GetURL().spec(), | 173 EXPECT_TRUE(StartsWithASCII(web_contents->GetURL().spec(), |
| 154 "chrome://newtab/", false)); | 174 "chrome://newtab/", false)); |
| 155 } else { | 175 } else { |
| 156 // TODO(xiyuan): Figure out how to test extension installed bubble? | 176 // TODO(xiyuan): Figure out how to test extension installed bubble? |
| 157 } | 177 } |
| 158 } | 178 } |
| OLD | NEW |