Chromium Code Reviews| 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 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 76 ASSERT_EQ(theme_id, theme->id()); | 89 ASSERT_EQ(theme_id, theme->id()); |
| 77 VerifyThemeInfoBarAndUndoInstall(); | 90 VerifyThemeInfoBarAndUndoInstall(); |
| 78 ASSERT_EQ(NULL, GetTheme()); | 91 ASSERT_EQ(NULL, GetTheme()); |
| 79 } | 92 } |
| 80 | 93 |
| 81 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 94 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
| 82 TestThemeInstallUndoResetsToPreviousTheme) { | 95 TestThemeInstallUndoResetsToPreviousTheme) { |
| 83 ui_test_utils::CloseAllInfoBars(chrome::GetActiveTabContents(browser())); | 96 ui_test_utils::CloseAllInfoBars(chrome::GetActiveTabContents(browser())); |
| 84 | 97 |
| 85 // Install first theme. | 98 // Install first theme. |
| 86 FilePath theme_path = test_data_dir_.AppendASCII("theme"); | 99 InstallThemeAndVerify("theme", "camo theme"); |
| 87 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path, 1, browser())); | |
| 88 const Extension* theme = GetTheme(); | 100 const Extension* theme = GetTheme(); |
| 89 ASSERT_TRUE(theme); | |
| 90 std::string theme_id = theme->id(); | 101 std::string theme_id = theme->id(); |
| 91 | 102 |
| 92 // Then install second theme. | 103 // Then install second theme. |
| 93 FilePath theme_path2 = test_data_dir_.AppendASCII("theme2"); | 104 InstallThemeAndVerify("theme2", "snowflake theme"); |
| 94 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path2, 1, browser())); | |
| 95 const Extension* theme2 = GetTheme(); | 105 const Extension* theme2 = GetTheme(); |
| 96 ASSERT_TRUE(theme2); | |
| 97 EXPECT_FALSE(theme_id == theme2->id()); | 106 EXPECT_FALSE(theme_id == theme2->id()); |
| 98 | 107 |
| 99 // Undo second theme will revert to first theme. | 108 // Undo second theme will revert to first theme. |
| 100 VerifyThemeInfoBarAndUndoInstall(); | 109 VerifyThemeInfoBarAndUndoInstall(); |
| 101 EXPECT_EQ(theme, GetTheme()); | 110 EXPECT_EQ(theme, GetTheme()); |
| 102 } | 111 } |
| 103 | 112 |
| 113 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | |
| 114 TestThemeReset) { | |
| 115 ui_test_utils::CloseAllInfoBars(chrome::GetActiveTabContents(browser())); | |
|
jam
2012/09/18 15:41:17
just noticed this. this shouldn't be necessary sin
Nirnimesh
2012/09/18 18:09:14
This was already there in other tests in this file
jam
2012/09/18 18:19:46
ah, those are unnecessary too. can you take them a
Nirnimesh
2012/09/18 18:34:08
Removed all.
| |
| 116 | |
| 117 InstallThemeAndVerify("theme", "camo theme"); | |
| 118 | |
| 119 // Reset to default theme. | |
| 120 ThemeServiceFactory::GetForProfile(browser()->profile())->UseDefaultTheme(); | |
| 121 ASSERT_FALSE(GetTheme()); | |
| 122 } | |
| 123 | |
| 124 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | |
| 125 TestInstallThemeInFullScreen) { | |
| 126 EXPECT_TRUE(chrome::ExecuteCommand(browser(), IDC_FULLSCREEN)); | |
| 127 InstallThemeAndVerify("theme", "camo theme"); | |
| 128 } | |
| 129 | |
| 104 #if defined(OS_WIN) | 130 #if defined(OS_WIN) |
| 105 // http://crbug.com/141854 | 131 // http://crbug.com/141854 |
| 106 #define MAYBE_AppInstallConfirmation FLAKY_AppInstallConfirmation | 132 #define MAYBE_AppInstallConfirmation FLAKY_AppInstallConfirmation |
| 107 #else | 133 #else |
| 108 #define MAYBE_AppInstallConfirmation AppInstallConfirmation | 134 #define MAYBE_AppInstallConfirmation AppInstallConfirmation |
| 109 #endif | 135 #endif |
| 110 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, | 136 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, |
| 111 MAYBE_AppInstallConfirmation) { | 137 MAYBE_AppInstallConfirmation) { |
| 112 int num_tabs = browser()->tab_count(); | 138 int num_tabs = browser()->tab_count(); |
| 113 | 139 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 if (NewTabUI::ShouldShowApps()) { | 175 if (NewTabUI::ShouldShowApps()) { |
| 150 EXPECT_EQ(num_normal_tabs + 1, browser()->tab_count()); | 176 EXPECT_EQ(num_normal_tabs + 1, browser()->tab_count()); |
| 151 WebContents* web_contents = chrome::GetActiveWebContents(browser()); | 177 WebContents* web_contents = chrome::GetActiveWebContents(browser()); |
| 152 ASSERT_TRUE(web_contents); | 178 ASSERT_TRUE(web_contents); |
| 153 EXPECT_TRUE(StartsWithASCII(web_contents->GetURL().spec(), | 179 EXPECT_TRUE(StartsWithASCII(web_contents->GetURL().spec(), |
| 154 "chrome://newtab/", false)); | 180 "chrome://newtab/", false)); |
| 155 } else { | 181 } else { |
| 156 // TODO(xiyuan): Figure out how to test extension installed bubble? | 182 // TODO(xiyuan): Figure out how to test extension installed bubble? |
| 157 } | 183 } |
| 158 } | 184 } |
| OLD | NEW |