OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/base_switches.h" | 5 #include "base/base_switches.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
8 #include "base/path_service.h" | 8 #include "base/path_service.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/permissions/permissions_browsertest.h" | 10 #include "chrome/browser/permissions/permissions_browsertest.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 // Assert that the popup's WebContents is now the active one. | 122 // Assert that the popup's WebContents is now the active one. |
123 ASSERT_NE(original_contents, GetWebContents()); | 123 ASSERT_NE(original_contents, GetWebContents()); |
124 | 124 |
125 PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( | 125 PermissionRequestManager* manager = PermissionRequestManager::FromWebContents( |
126 GetWebContents()); | 126 GetWebContents()); |
127 auto popup_prompt_factory = | 127 auto popup_prompt_factory = |
128 base::MakeUnique<MockPermissionPromptFactory>(manager); | 128 base::MakeUnique<MockPermissionPromptFactory>(manager); |
129 manager->DisplayPendingRequests(); | 129 manager->DisplayPendingRequests(); |
130 | 130 |
131 EXPECT_EQ(0, popup_prompt_factory->total_request_count()); | 131 EXPECT_EQ(0, popup_prompt_factory->TotalRequestCount()); |
132 popup_prompt_factory->set_response_type(PermissionRequestManager::ACCEPT_ALL); | 132 popup_prompt_factory->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
133 // FlashPermissionContext::UpdateTabContext will reload the page, we'll have | 133 // FlashPermissionContext::UpdateTabContext will reload the page, we'll have |
134 // to wait until it is ready. | 134 // to wait until it is ready. |
135 PageReloadWaiter reload_waiter(GetWebContents()); | 135 PageReloadWaiter reload_waiter(GetWebContents()); |
136 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); | 136 EXPECT_TRUE(RunScriptReturnBool("triggerPrompt();")); |
137 EXPECT_TRUE(reload_waiter.Wait()); | 137 EXPECT_TRUE(reload_waiter.Wait()); |
138 | 138 |
139 EXPECT_TRUE(FeatureUsageSucceeds()); | 139 EXPECT_TRUE(FeatureUsageSucceeds()); |
140 EXPECT_EQ(1, popup_prompt_factory->total_request_count()); | 140 EXPECT_EQ(1, popup_prompt_factory->TotalRequestCount()); |
141 | 141 |
142 // Shut down the popup window tab, as the normal test teardown assumes there | 142 // Shut down the popup window tab, as the normal test teardown assumes there |
143 // is only one test tab. | 143 // is only one test tab. |
144 popup_prompt_factory.reset(); | 144 popup_prompt_factory.reset(); |
145 GetWebContents()->Close(); | 145 GetWebContents()->Close(); |
146 } | 146 } |
147 | 147 |
148 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { | 148 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, TriggerPromptViaNewWindow) { |
149 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 149 EXPECT_EQ(0, prompt_factory()->TotalRequestCount()); |
150 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); | 150 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
151 // FlashPermissionContext::UpdateTabContext will reload the page, we'll have | 151 // FlashPermissionContext::UpdateTabContext will reload the page, we'll have |
152 // to wait until it is ready. | 152 // to wait until it is ready. |
153 PageReloadWaiter reload_waiter(GetWebContents()); | 153 PageReloadWaiter reload_waiter(GetWebContents()); |
154 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); | 154 EXPECT_TRUE(RunScriptReturnBool("triggerPromptViaNewWindow();")); |
155 EXPECT_TRUE(reload_waiter.Wait()); | 155 EXPECT_TRUE(reload_waiter.Wait()); |
156 | 156 |
157 EXPECT_TRUE(FeatureUsageSucceeds()); | 157 EXPECT_TRUE(FeatureUsageSucceeds()); |
158 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 158 EXPECT_EQ(1, prompt_factory()->TotalRequestCount()); |
159 } | 159 } |
160 | 160 |
161 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, | 161 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, |
162 TriggerPromptViaPluginPlaceholder) { | 162 TriggerPromptViaPluginPlaceholder) { |
163 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 163 EXPECT_EQ(0, prompt_factory()->TotalRequestCount()); |
164 EXPECT_FALSE(FeatureUsageSucceeds()); | 164 EXPECT_FALSE(FeatureUsageSucceeds()); |
165 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); | 165 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
166 // We need to simulate a mouse click to trigger the placeholder to prompt. | 166 // We need to simulate a mouse click to trigger the placeholder to prompt. |
167 // When the prompt is auto-accepted, the page will be reloaded. | 167 // When the prompt is auto-accepted, the page will be reloaded. |
168 PageReloadWaiter reload_waiter(GetWebContents()); | 168 PageReloadWaiter reload_waiter(GetWebContents()); |
169 content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */, | 169 content::SimulateMouseClickAt(GetWebContents(), 0 /* modifiers */, |
170 blink::WebMouseEvent::Button::kLeft, | 170 blink::WebMouseEvent::Button::kLeft, |
171 gfx::Point(50, 50)); | 171 gfx::Point(50, 50)); |
172 EXPECT_TRUE(reload_waiter.Wait()); | 172 EXPECT_TRUE(reload_waiter.Wait()); |
173 | 173 |
174 EXPECT_TRUE(FeatureUsageSucceeds()); | 174 EXPECT_TRUE(FeatureUsageSucceeds()); |
175 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 175 EXPECT_EQ(1, prompt_factory()->TotalRequestCount()); |
176 } | 176 } |
177 | 177 |
178 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, | 178 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, |
179 TriggerPromptViaMainFrameNavigationWithoutUserGesture) { | 179 TriggerPromptViaMainFrameNavigationWithoutUserGesture) { |
180 EXPECT_EQ(0, prompt_factory()->total_request_count()); | 180 EXPECT_EQ(0, prompt_factory()->TotalRequestCount()); |
181 EXPECT_FALSE(FeatureUsageSucceeds()); | 181 EXPECT_FALSE(FeatureUsageSucceeds()); |
182 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); | 182 prompt_factory()->set_response_type(PermissionRequestManager::ACCEPT_ALL); |
183 | 183 |
184 PageReloadWaiter reload_waiter(GetWebContents()); | 184 PageReloadWaiter reload_waiter(GetWebContents()); |
185 | 185 |
186 // Unlike the other tests, this JavaScript is called without a user gesture. | 186 // Unlike the other tests, this JavaScript is called without a user gesture. |
187 GetWebContents()->GetMainFrame()->ExecuteJavaScriptForTests( | 187 GetWebContents()->GetMainFrame()->ExecuteJavaScriptForTests( |
188 base::ASCIIToUTF16("triggerPromptWithMainFrameNavigation();")); | 188 base::ASCIIToUTF16("triggerPromptWithMainFrameNavigation();")); |
189 | 189 |
190 EXPECT_TRUE(reload_waiter.Wait()); | 190 EXPECT_TRUE(reload_waiter.Wait()); |
191 | 191 |
192 EXPECT_TRUE(FeatureUsageSucceeds()); | 192 EXPECT_TRUE(FeatureUsageSucceeds()); |
193 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 193 EXPECT_EQ(1, prompt_factory()->TotalRequestCount()); |
194 } | 194 } |
195 | 195 |
196 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, AllowFileURL) { | 196 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, AllowFileURL) { |
197 base::FilePath test_path; | 197 base::FilePath test_path; |
198 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | 198 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
199 ui_test_utils::NavigateToURL( | 199 ui_test_utils::NavigateToURL( |
200 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); | 200 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); |
201 CommonSucceedsIfAllowed(); | 201 CommonSucceedsIfAllowed(); |
202 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 202 EXPECT_EQ(1, prompt_factory()->TotalRequestCount()); |
203 | 203 |
204 // Navigate to a second URL to verify it's allowed on all file: URLs. | 204 // Navigate to a second URL to verify it's allowed on all file: URLs. |
205 ui_test_utils::NavigateToURL( | 205 ui_test_utils::NavigateToURL( |
206 browser(), | 206 browser(), |
207 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); | 207 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); |
208 EXPECT_TRUE(FeatureUsageSucceeds()); | 208 EXPECT_TRUE(FeatureUsageSucceeds()); |
209 } | 209 } |
210 | 210 |
211 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, BlockFileURL) { | 211 IN_PROC_BROWSER_TEST_F(FlashPermissionBrowserTest, BlockFileURL) { |
212 base::FilePath test_path; | 212 base::FilePath test_path; |
213 PathService::Get(chrome::DIR_TEST_DATA, &test_path); | 213 PathService::Get(chrome::DIR_TEST_DATA, &test_path); |
214 ui_test_utils::NavigateToURL( | 214 ui_test_utils::NavigateToURL( |
215 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); | 215 browser(), GURL("file://" + test_path.AsUTF8Unsafe() + test_url())); |
216 CommonFailsIfBlocked(); | 216 CommonFailsIfBlocked(); |
217 EXPECT_EQ(1, prompt_factory()->total_request_count()); | 217 EXPECT_EQ(1, prompt_factory()->TotalRequestCount()); |
218 | 218 |
219 // Navigate to a second URL to verify it's blocked on all file: URLs. | 219 // Navigate to a second URL to verify it's blocked on all file: URLs. |
220 ui_test_utils::NavigateToURL( | 220 ui_test_utils::NavigateToURL( |
221 browser(), | 221 browser(), |
222 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); | 222 GURL("file://" + test_path.AsUTF8Unsafe() + "/permissions/flash2.html")); |
223 EXPECT_FALSE(FeatureUsageSucceeds()); | 223 EXPECT_FALSE(FeatureUsageSucceeds()); |
224 } | 224 } |
OLD | NEW |