Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(272)

Side by Side Diff: chrome/browser/extensions/extension_install_ui_browsertest.cc

Issue 10702029: Move tab functions off Browser into browser_tabstrip and browser_tabrestore. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/browser/extensions/extension_browsertest.h" 6 #include "chrome/browser/extensions/extension_browsertest.h"
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h" 8 #include "chrome/browser/extensions/theme_installed_infobar_delegate.h"
9 #include "chrome/browser/infobars/infobar_tab_helper.h" 9 #include "chrome/browser/infobars/infobar_tab_helper.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/ui/browser.h" 11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h" 12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_tabstrip.h"
13 #include "chrome/browser/ui/tab_contents/tab_contents.h" 14 #include "chrome/browser/ui/tab_contents/tab_contents.h"
14 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h" 15 #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
15 #include "chrome/browser/themes/theme_service_factory.h" 16 #include "chrome/browser/themes/theme_service_factory.h"
16 #include "chrome/test/base/ui_test_utils.h" 17 #include "chrome/test/base/ui_test_utils.h"
17 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
18 19
19 using content::WebContents; 20 using content::WebContents;
20 using extensions::Extension; 21 using extensions::Extension;
21 22
22 class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest { 23 class ExtensionInstallUIBrowserTest : public ExtensionBrowserTest {
23 public: 24 public:
24 // Checks that a theme info bar is currently visible and issues an undo to 25 // Checks that a theme info bar is currently visible and issues an undo to
25 // revert to the previous theme. 26 // revert to the previous theme.
26 void VerifyThemeInfoBarAndUndoInstall() { 27 void VerifyThemeInfoBarAndUndoInstall() {
27 TabContents* tab = browser()->GetActiveTabContents(); 28 TabContents* tab = chrome::GetActiveTabContents(browser());
28 ASSERT_TRUE(tab); 29 ASSERT_TRUE(tab);
29 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper(); 30 InfoBarTabHelper* infobar_helper = tab->infobar_tab_helper();
30 ASSERT_EQ(1U, infobar_helper->infobar_count()); 31 ASSERT_EQ(1U, infobar_helper->infobar_count());
31 ConfirmInfoBarDelegate* delegate = infobar_helper-> 32 ConfirmInfoBarDelegate* delegate = infobar_helper->
32 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); 33 GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate();
33 ASSERT_TRUE(delegate); 34 ASSERT_TRUE(delegate);
34 delegate->Cancel(); 35 delegate->Cancel();
35 ASSERT_EQ(0U, infobar_helper->infobar_count()); 36 ASSERT_EQ(0U, infobar_helper->infobar_count());
36 } 37 }
37 38
38 const Extension* GetTheme() const { 39 const Extension* GetTheme() const {
39 return ThemeServiceFactory::GetThemeForProfile(browser()->profile()); 40 return ThemeServiceFactory::GetThemeForProfile(browser()->profile());
40 } 41 }
41 }; 42 };
42 43
43 #if defined(OS_LINUX) 44 #if defined(OS_LINUX)
44 // Fails consistently on bot chromium.chromiumos \ Linux. 45 // Fails consistently on bot chromium.chromiumos \ Linux.
45 // See: http://crbug.com/120647. 46 // See: http://crbug.com/120647.
46 #define MAYBE_TestThemeInstallUndoResetsToDefault DISABLED_TestThemeInstallUndoR esetsToDefault 47 #define MAYBE_TestThemeInstallUndoResetsToDefault DISABLED_TestThemeInstallUndoR esetsToDefault
47 #else 48 #else
48 #define MAYBE_TestThemeInstallUndoResetsToDefault TestThemeInstallUndoResetsToDe fault 49 #define MAYBE_TestThemeInstallUndoResetsToDefault TestThemeInstallUndoResetsToDe fault
49 #endif 50 #endif
50 51
51 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, 52 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest,
52 MAYBE_TestThemeInstallUndoResetsToDefault) { 53 MAYBE_TestThemeInstallUndoResetsToDefault) {
53 ui_test_utils::CloseAllInfoBars(browser()->GetActiveTabContents()); 54 ui_test_utils::CloseAllInfoBars(chrome::GetActiveTabContents(browser()));
54 55
55 // Install theme once and undo to verify we go back to default theme. 56 // Install theme once and undo to verify we go back to default theme.
56 FilePath theme_crx = PackExtension(test_data_dir_.AppendASCII("theme")); 57 FilePath theme_crx = PackExtension(test_data_dir_.AppendASCII("theme"));
57 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 1, browser())); 58 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 1, browser()));
58 const Extension* theme = GetTheme(); 59 const Extension* theme = GetTheme();
59 ASSERT_TRUE(theme); 60 ASSERT_TRUE(theme);
60 std::string theme_id = theme->id(); 61 std::string theme_id = theme->id();
61 VerifyThemeInfoBarAndUndoInstall(); 62 VerifyThemeInfoBarAndUndoInstall();
62 ASSERT_EQ(NULL, GetTheme()); 63 ASSERT_EQ(NULL, GetTheme());
63 64
64 // Set the same theme twice and undo to verify we go back to default theme. 65 // Set the same theme twice and undo to verify we go back to default theme.
65 // We set the |expected_change| to zero in these 'InstallExtensionWithUI' 66 // We set the |expected_change| to zero in these 'InstallExtensionWithUI'
66 // calls since the theme has already been installed above and this is an 67 // calls since the theme has already been installed above and this is an
67 // overinstall to set the active theme. 68 // overinstall to set the active theme.
68 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); 69 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser()));
69 theme = GetTheme(); 70 theme = GetTheme();
70 ASSERT_TRUE(theme); 71 ASSERT_TRUE(theme);
71 ASSERT_EQ(theme_id, theme->id()); 72 ASSERT_EQ(theme_id, theme->id());
72 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser())); 73 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_crx, 0, browser()));
73 theme = GetTheme(); 74 theme = GetTheme();
74 ASSERT_TRUE(theme); 75 ASSERT_TRUE(theme);
75 ASSERT_EQ(theme_id, theme->id()); 76 ASSERT_EQ(theme_id, theme->id());
76 VerifyThemeInfoBarAndUndoInstall(); 77 VerifyThemeInfoBarAndUndoInstall();
77 ASSERT_EQ(NULL, GetTheme()); 78 ASSERT_EQ(NULL, GetTheme());
78 } 79 }
79 80
80 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, 81 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest,
81 TestThemeInstallUndoResetsToPreviousTheme) { 82 TestThemeInstallUndoResetsToPreviousTheme) {
82 ui_test_utils::CloseAllInfoBars(browser()->GetActiveTabContents()); 83 ui_test_utils::CloseAllInfoBars(chrome::GetActiveTabContents(browser()));
83 84
84 // Install first theme. 85 // Install first theme.
85 FilePath theme_path = test_data_dir_.AppendASCII("theme"); 86 FilePath theme_path = test_data_dir_.AppendASCII("theme");
86 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path, 1, browser())); 87 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path, 1, browser()));
87 const Extension* theme = GetTheme(); 88 const Extension* theme = GetTheme();
88 ASSERT_TRUE(theme); 89 ASSERT_TRUE(theme);
89 std::string theme_id = theme->id(); 90 std::string theme_id = theme->id();
90 91
91 // Then install second theme. 92 // Then install second theme.
92 FilePath theme_path2 = test_data_dir_.AppendASCII("theme2"); 93 FilePath theme_path2 = test_data_dir_.AppendASCII("theme2");
93 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path2, 1, browser())); 94 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(theme_path2, 1, browser()));
94 const Extension* theme2 = GetTheme(); 95 const Extension* theme2 = GetTheme();
95 ASSERT_TRUE(theme2); 96 ASSERT_TRUE(theme2);
96 EXPECT_FALSE(theme_id == theme2->id()); 97 EXPECT_FALSE(theme_id == theme2->id());
97 98
98 // Undo second theme will revert to first theme. 99 // Undo second theme will revert to first theme.
99 VerifyThemeInfoBarAndUndoInstall(); 100 VerifyThemeInfoBarAndUndoInstall();
100 EXPECT_EQ(theme, GetTheme()); 101 EXPECT_EQ(theme, GetTheme());
101 } 102 }
102 103
103 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, 104 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest,
104 AppInstallConfirmation) { 105 AppInstallConfirmation) {
105 int num_tabs = browser()->tab_count(); 106 int num_tabs = browser()->tab_count();
106 107
107 FilePath app_dir = test_data_dir_.AppendASCII("app"); 108 FilePath app_dir = test_data_dir_.AppendASCII("app");
108 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(app_dir, 1, browser())); 109 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(app_dir, 1, browser()));
109 110
110 if (NewTabUI::ShouldShowApps()) { 111 if (NewTabUI::ShouldShowApps()) {
111 EXPECT_EQ(num_tabs + 1, browser()->tab_count()); 112 EXPECT_EQ(num_tabs + 1, browser()->tab_count());
112 WebContents* web_contents = browser()->GetActiveWebContents(); 113 WebContents* web_contents = chrome::GetActiveWebContents(browser());
113 ASSERT_TRUE(web_contents); 114 ASSERT_TRUE(web_contents);
114 EXPECT_TRUE(StartsWithASCII(web_contents->GetURL().spec(), 115 EXPECT_TRUE(StartsWithASCII(web_contents->GetURL().spec(),
115 "chrome://newtab/", false)); 116 "chrome://newtab/", false));
116 } else { 117 } else {
117 // TODO(xiyuan): Figure out how to test extension installed bubble? 118 // TODO(xiyuan): Figure out how to test extension installed bubble?
118 } 119 }
119 } 120 }
120 121
121 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest, 122 IN_PROC_BROWSER_TEST_F(ExtensionInstallUIBrowserTest,
122 AppInstallConfirmation_Incognito) { 123 AppInstallConfirmation_Incognito) {
123 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile(); 124 Profile* incognito_profile = browser()->profile()->GetOffTheRecordProfile();
124 Browser* incognito_browser = browser::FindOrCreateTabbedBrowser( 125 Browser* incognito_browser = browser::FindOrCreateTabbedBrowser(
125 incognito_profile); 126 incognito_profile);
126 127
127 int num_incognito_tabs = incognito_browser->tab_count(); 128 int num_incognito_tabs = incognito_browser->tab_count();
128 int num_normal_tabs = browser()->tab_count(); 129 int num_normal_tabs = browser()->tab_count();
129 130
130 FilePath app_dir = test_data_dir_.AppendASCII("app"); 131 FilePath app_dir = test_data_dir_.AppendASCII("app");
131 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(app_dir, 1, 132 ASSERT_TRUE(InstallExtensionWithUIAutoConfirm(app_dir, 1,
132 incognito_browser)); 133 incognito_browser));
133 134
134 EXPECT_EQ(num_incognito_tabs, incognito_browser->tab_count()); 135 EXPECT_EQ(num_incognito_tabs, incognito_browser->tab_count());
135 if (NewTabUI::ShouldShowApps()) { 136 if (NewTabUI::ShouldShowApps()) {
136 EXPECT_EQ(num_normal_tabs + 1, browser()->tab_count()); 137 EXPECT_EQ(num_normal_tabs + 1, browser()->tab_count());
137 WebContents* web_contents = browser()->GetActiveWebContents(); 138 WebContents* web_contents = chrome::GetActiveWebContents(browser());
138 ASSERT_TRUE(web_contents); 139 ASSERT_TRUE(web_contents);
139 EXPECT_TRUE(StartsWithASCII(web_contents->GetURL().spec(), 140 EXPECT_TRUE(StartsWithASCII(web_contents->GetURL().spec(),
140 "chrome://newtab/", false)); 141 "chrome://newtab/", false));
141 } else { 142 } else {
142 // TODO(xiyuan): Figure out how to test extension installed bubble? 143 // TODO(xiyuan): Figure out how to test extension installed bubble?
143 } 144 }
144 } 145 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_incognito_apitest.cc ('k') | chrome/browser/extensions/extension_install_ui_default.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698