OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/strings/utf_string_conversions.h" |
5 #include "chrome/browser/extensions/extension_install_prompt.h" | 6 #include "chrome/browser/extensions/extension_install_prompt.h" |
6 #include "chrome/browser/extensions/extension_service.h" | 7 #include "chrome/browser/extensions/extension_service.h" |
7 #include "chrome/browser/extensions/tab_helper.h" | 8 #include "chrome/browser/extensions/tab_helper.h" |
8 #include "chrome/browser/extensions/webstore_inline_installer.h" | 9 #include "chrome/browser/extensions/webstore_inline_installer.h" |
9 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" | 10 #include "chrome/browser/extensions/webstore_inline_installer_factory.h" |
10 #include "chrome/browser/extensions/webstore_installer_test.h" | 11 #include "chrome/browser/extensions/webstore_installer_test.h" |
11 #include "chrome/browser/extensions/webstore_standalone_installer.h" | 12 #include "chrome/browser/extensions/webstore_standalone_installer.h" |
12 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_finder.h" |
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
15 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 18 #include "components/content_settings/core/browser/host_content_settings_map.h" |
16 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
17 #include "extensions/browser/extension_registry.h" | 20 #include "extensions/browser/extension_registry.h" |
18 #include "extensions/browser/extension_system.h" | 21 #include "extensions/browser/extension_system.h" |
19 #include "url/gurl.h" | 22 #include "url/gurl.h" |
20 | 23 |
21 using content::WebContents; | 24 using content::WebContents; |
22 | 25 |
23 namespace extensions { | 26 namespace extensions { |
24 | 27 |
25 namespace { | 28 namespace { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 WebContents* contents, | 122 WebContents* contents, |
120 const std::string& webstore_item_id, | 123 const std::string& webstore_item_id, |
121 const GURL& requestor_url, | 124 const GURL& requestor_url, |
122 const WebstoreStandaloneInstaller::Callback& callback) override { | 125 const WebstoreStandaloneInstaller::Callback& callback) override { |
123 return new WebstoreInlineInstallerForTest( | 126 return new WebstoreInlineInstallerForTest( |
124 contents, webstore_item_id, requestor_url, callback); | 127 contents, webstore_item_id, requestor_url, callback); |
125 } | 128 } |
126 }; | 129 }; |
127 | 130 |
128 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, | 131 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, |
129 CloseTabBeforeInstallConfirmation) { | 132 CloseTabBeforeInstallConfirmation) { |
130 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html"); | 133 GURL install_url = GenerateTestServerUrl(kAppDomain, "install.html"); |
131 ui_test_utils::NavigateToURL(browser(), install_url); | 134 ui_test_utils::NavigateToURL(browser(), install_url); |
132 WebContents* web_contents = | 135 WebContents* web_contents = |
133 browser()->tab_strip_model()->GetActiveWebContents(); | 136 browser()->tab_strip_model()->GetActiveWebContents(); |
134 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); | 137 TabHelper* tab_helper = TabHelper::FromWebContents(web_contents); |
135 tab_helper->SetWebstoreInlineInstallerFactoryForTests( | 138 tab_helper->SetWebstoreInlineInstallerFactoryForTests( |
136 new WebstoreInlineInstallerForTestFactory()); | 139 new WebstoreInlineInstallerForTestFactory()); |
137 RunTestAsync("runTest"); | 140 RunTestAsync("runTest"); |
138 while (!ProgrammableInstallPrompt::Ready()) | 141 while (!ProgrammableInstallPrompt::Ready()) |
139 base::RunLoop().RunUntilIdle(); | 142 base::RunLoop().RunUntilIdle(); |
140 web_contents->Close(); | 143 web_contents->Close(); |
141 ProgrammableInstallPrompt::Accept(); | 144 ProgrammableInstallPrompt::Accept(); |
142 } | 145 } |
143 | 146 |
| 147 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, |
| 148 ShouldBlockInlineInstallFromPopupWindow) { |
| 149 GURL install_url = |
| 150 GenerateTestServerUrl(kAppDomain, "install_from_popup.html"); |
| 151 // Disable popup blocking for the test url. |
| 152 browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| 153 ContentSettingsPattern::FromURL(install_url), |
| 154 ContentSettingsPattern::Wildcard(), CONTENT_SETTINGS_TYPE_POPUPS, |
| 155 std::string(), CONTENT_SETTING_ALLOW); |
| 156 ui_test_utils::NavigateToURL(browser(), install_url); |
| 157 // The test page opens a popup which is a new |browser| window. |
| 158 Browser* popup_browser = chrome::FindLastActiveWithProfile( |
| 159 browser()->profile(), chrome::GetActiveDesktop()); |
| 160 WebContents* popup_contents = |
| 161 popup_browser->tab_strip_model()->GetActiveWebContents(); |
| 162 EXPECT_EQ(base::ASCIIToUTF16("POPUP"), popup_contents->GetTitle()); |
| 163 RunTest(popup_contents, "runTest"); |
| 164 } |
| 165 |
144 // Ensure that inline-installing a disabled extension simply re-enables it. | 166 // Ensure that inline-installing a disabled extension simply re-enables it. |
145 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, | 167 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerTest, |
146 ReinstallDisabledExtension) { | 168 ReinstallDisabledExtension) { |
147 // Install an extension via inline install, and confirm it is successful. | 169 // Install an extension via inline install, and confirm it is successful. |
148 ExtensionInstallPrompt::g_auto_confirm_for_tests = | 170 ExtensionInstallPrompt::g_auto_confirm_for_tests = |
149 ExtensionInstallPrompt::ACCEPT; | 171 ExtensionInstallPrompt::ACCEPT; |
150 ui_test_utils::NavigateToURL( | 172 ui_test_utils::NavigateToURL( |
151 browser(), GenerateTestServerUrl(kAppDomain, "install.html")); | 173 browser(), GenerateTestServerUrl(kAppDomain, "install.html")); |
152 RunTest("runTest"); | 174 RunTest("runTest"); |
153 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); | 175 ExtensionRegistry* registry = ExtensionRegistry::Get(profile()); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, | 240 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, |
219 DownloadProgressListenerTest) { | 241 DownloadProgressListenerTest) { |
220 RunTest("download_progress_listener.html"); | 242 RunTest("download_progress_listener.html"); |
221 } | 243 } |
222 | 244 |
223 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { | 245 IN_PROC_BROWSER_TEST_F(WebstoreInlineInstallerListenerTest, BothListenersTest) { |
224 RunTest("both_listeners.html"); | 246 RunTest("both_listeners.html"); |
225 } | 247 } |
226 | 248 |
227 } // namespace extensions | 249 } // namespace extensions |
OLD | NEW |