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 "chrome/browser/geolocation/geolocation_permission_context.h" | 5 #include "chrome/browser/geolocation/geolocation_permission_context.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | |
12 #include "base/containers/hash_tables.h" | 13 #include "base/containers/hash_tables.h" |
13 #include "base/id_map.h" | 14 #include "base/id_map.h" |
14 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
15 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
16 #include "base/test/simple_test_clock.h" | 17 #include "base/test/simple_test_clock.h" |
17 #include "base/time/clock.h" | 18 #include "base/time/clock.h" |
18 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
19 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 20 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
20 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" | 21 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" |
21 #include "chrome/browser/infobars/infobar_service.h" | 22 #include "chrome/browser/infobars/infobar_service.h" |
23 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h" | |
24 #include "chrome/browser/ui/website_settings/permission_bubble_manager.h" | |
25 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | |
26 #include "chrome/common/chrome_switches.h" | |
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
23 #include "chrome/test/base/testing_profile.h" | 28 #include "chrome/test/base/testing_profile.h" |
24 #include "components/content_settings/core/browser/host_content_settings_map.h" | 29 #include "components/content_settings/core/browser/host_content_settings_map.h" |
25 #include "components/content_settings/core/common/permission_request_id.h" | 30 #include "components/content_settings/core/common/permission_request_id.h" |
26 #include "components/infobars/core/confirm_infobar_delegate.h" | 31 #include "components/infobars/core/confirm_infobar_delegate.h" |
27 #include "components/infobars/core/infobar.h" | 32 #include "components/infobars/core/infobar.h" |
28 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
29 #include "content/public/browser/navigation_details.h" | 34 #include "content/public/browser/navigation_details.h" |
30 #include "content/public/browser/notification_observer.h" | 35 #include "content/public/browser/notification_observer.h" |
31 #include "content/public/browser/notification_registrar.h" | 36 #include "content/public/browser/notification_registrar.h" |
32 #include "content/public/browser/notification_service.h" | 37 #include "content/public/browser/notification_service.h" |
33 #include "content/public/browser/web_contents.h" | 38 #include "content/public/browser/web_contents.h" |
34 #include "content/public/test/mock_render_process_host.h" | 39 #include "content/public/test/mock_render_process_host.h" |
35 #include "content/public/test/test_renderer_host.h" | 40 #include "content/public/test/test_renderer_host.h" |
36 #include "content/public/test/test_utils.h" | 41 #include "content/public/test/test_utils.h" |
37 #include "content/public/test/web_contents_tester.h" | 42 #include "content/public/test/web_contents_tester.h" |
38 #include "testing/gtest/include/gtest/gtest.h" | 43 #include "testing/gtest/include/gtest/gtest.h" |
39 | 44 |
40 #if defined(OS_ANDROID) | 45 #if defined(OS_ANDROID) |
41 #include "base/prefs/pref_service.h" | 46 #include "base/prefs/pref_service.h" |
42 #include "chrome/browser/android/mock_google_location_settings_helper.h" | 47 #include "chrome/browser/android/mock_google_location_settings_helper.h" |
43 #endif | 48 #endif |
44 | 49 |
45 #if defined(ENABLE_EXTENSIONS) | 50 #if defined(ENABLE_EXTENSIONS) |
46 #include "extensions/browser/view_type_utils.h" | 51 #include "extensions/browser/view_type_utils.h" |
47 #endif | 52 #endif |
48 | 53 |
49 using content::MockRenderProcessHost; | 54 using content::MockRenderProcessHost; |
50 | 55 |
51 | |
52 // ClosedInfoBarTracker ------------------------------------------------------- | 56 // ClosedInfoBarTracker ------------------------------------------------------- |
53 | 57 |
54 // We need to track which infobars were closed. | 58 // We need to track which infobars were closed. |
55 class ClosedInfoBarTracker : public content::NotificationObserver { | 59 class ClosedInfoBarTracker : public content::NotificationObserver { |
56 public: | 60 public: |
57 ClosedInfoBarTracker(); | 61 ClosedInfoBarTracker(); |
58 ~ClosedInfoBarTracker() override; | 62 ~ClosedInfoBarTracker() override; |
59 | 63 |
60 // content::NotificationObserver: | 64 // content::NotificationObserver: |
61 void Observe(int type, | 65 void Observe(int type, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 PermissionRequestID RequestIDForTab(int tab, int bridge_id); | 116 PermissionRequestID RequestIDForTab(int tab, int bridge_id); |
113 InfoBarService* infobar_service() { | 117 InfoBarService* infobar_service() { |
114 return InfoBarService::FromWebContents(web_contents()); | 118 return InfoBarService::FromWebContents(web_contents()); |
115 } | 119 } |
116 InfoBarService* infobar_service_for_tab(int tab) { | 120 InfoBarService* infobar_service_for_tab(int tab) { |
117 return InfoBarService::FromWebContents(extra_tabs_[tab]); | 121 return InfoBarService::FromWebContents(extra_tabs_[tab]); |
118 } | 122 } |
119 | 123 |
120 void RequestGeolocationPermission(content::WebContents* web_contents, | 124 void RequestGeolocationPermission(content::WebContents* web_contents, |
121 const PermissionRequestID& id, | 125 const PermissionRequestID& id, |
122 const GURL& requesting_frame); | 126 const GURL& requesting_frame, |
123 | 127 bool user_gesture); |
124 void PermissionResponse(const PermissionRequestID& id, | 128 void PermissionResponse(const PermissionRequestID& id, |
125 bool allowed); | 129 bool allowed); |
126 void CheckPermissionMessageSent(int bridge_id, bool allowed); | 130 void CheckPermissionMessageSent(int bridge_id, bool allowed); |
127 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); | 131 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); |
128 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, | 132 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, |
129 int bridge_id, | 133 int bridge_id, |
130 bool allowed); | 134 bool allowed); |
131 void AddNewTab(const GURL& url); | 135 void AddNewTab(const GURL& url); |
132 void CheckTabContentsState(const GURL& requesting_frame, | 136 void CheckTabContentsState(const GURL& requesting_frame, |
133 ContentSetting expected_content_setting); | 137 ContentSetting expected_content_setting); |
138 base::string16 GetFirstRequestText(PermissionBubbleManager* manager); | |
139 int GetBubblesQueueSize(PermissionBubbleManager* manager); | |
140 void AcceptBubble(PermissionBubbleManager* manager); | |
141 void DenyBubble(PermissionBubbleManager* manager); | |
142 void CloseBubble(PermissionBubbleManager* manager); | |
143 void BubbleManagerDocumentLoadCompleted(); | |
144 void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents); | |
134 | 145 |
135 // owned by the browser context | 146 // owned by the browser context |
136 GeolocationPermissionContext* geolocation_permission_context_; | 147 GeolocationPermissionContext* geolocation_permission_context_; |
137 ClosedInfoBarTracker closed_infobar_tracker_; | 148 ClosedInfoBarTracker closed_infobar_tracker_; |
149 MockPermissionBubbleView bubble_view_; | |
138 ScopedVector<content::WebContents> extra_tabs_; | 150 ScopedVector<content::WebContents> extra_tabs_; |
139 | 151 |
140 // A map between renderer child id and a pair represending the bridge id and | 152 // A map between renderer child id and a pair represending the bridge id and |
141 // whether the requested permission was allowed. | 153 // whether the requested permission was allowed. |
142 base::hash_map<int, std::pair<int, bool> > responses_; | 154 base::hash_map<int, std::pair<int, bool> > responses_; |
143 }; | 155 }; |
144 | 156 |
145 PermissionRequestID GeolocationPermissionContextTests::RequestID( | 157 PermissionRequestID GeolocationPermissionContextTests::RequestID( |
146 int bridge_id) { | 158 int bridge_id) { |
147 return PermissionRequestID( | 159 return PermissionRequestID( |
148 web_contents()->GetRenderProcessHost()->GetID(), | 160 web_contents()->GetRenderProcessHost()->GetID(), |
149 web_contents()->GetRenderViewHost()->GetRoutingID(), | 161 web_contents()->GetRenderViewHost()->GetRoutingID(), |
150 bridge_id, | 162 bridge_id, |
151 GURL()); | 163 GURL()); |
152 } | 164 } |
153 | 165 |
154 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( | 166 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( |
155 int tab, | 167 int tab, |
156 int bridge_id) { | 168 int bridge_id) { |
157 return PermissionRequestID( | 169 return PermissionRequestID( |
158 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), | 170 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), |
159 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), | 171 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), |
160 bridge_id, | 172 bridge_id, |
161 GURL()); | 173 GURL()); |
162 } | 174 } |
163 | 175 |
164 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 176 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
165 content::WebContents* web_contents, | 177 content::WebContents* web_contents, |
166 const PermissionRequestID& id, | 178 const PermissionRequestID& id, |
167 const GURL& requesting_frame) { | 179 const GURL& requesting_frame, |
180 bool user_gesture) { | |
168 geolocation_permission_context_->RequestPermission( | 181 geolocation_permission_context_->RequestPermission( |
169 web_contents, id, requesting_frame, false, | 182 web_contents, id, requesting_frame, user_gesture, |
170 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, | 183 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, |
171 base::Unretained(this), id)); | 184 base::Unretained(this), id)); |
172 content::RunAllBlockingPoolTasksUntilIdle(); | 185 content::RunAllBlockingPoolTasksUntilIdle(); |
173 } | 186 } |
174 | 187 |
175 void GeolocationPermissionContextTests::PermissionResponse( | 188 void GeolocationPermissionContextTests::PermissionResponse( |
176 const PermissionRequestID& id, | 189 const PermissionRequestID& id, |
177 bool allowed) { | 190 bool allowed) { |
178 responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed); | 191 responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed); |
179 } | 192 } |
180 | 193 |
181 void GeolocationPermissionContextTests::CheckPermissionMessageSent( | 194 void GeolocationPermissionContextTests::CheckPermissionMessageSent( |
182 int bridge_id, | 195 int bridge_id, |
(...skipping 26 matching lines...) Expand all Loading... | |
209 new_tab->GetController().LoadURL( | 222 new_tab->GetController().LoadURL( |
210 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 223 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
211 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) | 224 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) |
212 ->SendNavigate(extra_tabs_.size() + 1, url); | 225 ->SendNavigate(extra_tabs_.size() + 1, url); |
213 | 226 |
214 // Set up required helpers, and make this be as "tabby" as the code requires. | 227 // Set up required helpers, and make this be as "tabby" as the code requires. |
215 #if defined(ENABLE_EXTENSIONS) | 228 #if defined(ENABLE_EXTENSIONS) |
216 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); | 229 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); |
217 #endif | 230 #endif |
218 InfoBarService::CreateForWebContents(new_tab); | 231 InfoBarService::CreateForWebContents(new_tab); |
232 PermissionBubbleManager::CreateForWebContents(new_tab); | |
233 PermissionBubbleManager::FromWebContents(new_tab)->SetView( | |
234 &bubble_view_); | |
219 | 235 |
220 extra_tabs_.push_back(new_tab); | 236 extra_tabs_.push_back(new_tab); |
221 } | 237 } |
222 | 238 |
223 void GeolocationPermissionContextTests::CheckTabContentsState( | 239 void GeolocationPermissionContextTests::CheckTabContentsState( |
224 const GURL& requesting_frame, | 240 const GURL& requesting_frame, |
225 ContentSetting expected_content_setting) { | 241 ContentSetting expected_content_setting) { |
226 TabSpecificContentSettings* content_settings = | 242 TabSpecificContentSettings* content_settings = |
227 TabSpecificContentSettings::FromWebContents(web_contents()); | 243 TabSpecificContentSettings::FromWebContents(web_contents()); |
228 const ContentSettingsUsagesState::StateMap& state_map = | 244 const ContentSettingsUsagesState::StateMap& state_map = |
(...skipping 14 matching lines...) Expand all Loading... | |
243 #if defined(ENABLE_EXTENSIONS) | 259 #if defined(ENABLE_EXTENSIONS) |
244 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); | 260 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); |
245 #endif | 261 #endif |
246 InfoBarService::CreateForWebContents(web_contents()); | 262 InfoBarService::CreateForWebContents(web_contents()); |
247 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 263 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
248 #if defined(OS_ANDROID) | 264 #if defined(OS_ANDROID) |
249 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 265 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
250 #endif | 266 #endif |
251 geolocation_permission_context_ = | 267 geolocation_permission_context_ = |
252 GeolocationPermissionContextFactory::GetForProfile(profile()); | 268 GeolocationPermissionContextFactory::GetForProfile(profile()); |
269 PermissionBubbleManager::CreateForWebContents(web_contents()); | |
270 PermissionBubbleManager::FromWebContents(web_contents())->SetView( | |
271 &bubble_view_); | |
253 } | 272 } |
254 | 273 |
255 void GeolocationPermissionContextTests::TearDown() { | 274 void GeolocationPermissionContextTests::TearDown() { |
256 extra_tabs_.clear(); | 275 extra_tabs_.clear(); |
257 ChromeRenderViewHostTestHarness::TearDown(); | 276 ChromeRenderViewHostTestHarness::TearDown(); |
258 } | 277 } |
259 | 278 |
279 base::string16 GeolocationPermissionContextTests::GetFirstRequestText( | |
280 PermissionBubbleManager* manager) { | |
281 return manager->requests_.front()->GetMessageText(); | |
282 } | |
283 | |
284 int GeolocationPermissionContextTests::GetBubblesQueueSize( | |
timvolodine
2014/12/19 16:02:20
nit: no need for cast? you could just return a siz
felt
2014/12/19 16:46:31
Done.
| |
285 PermissionBubbleManager* manager) { | |
286 return static_cast<int>(manager->requests_.size()); | |
287 } | |
288 | |
289 void GeolocationPermissionContextTests::AcceptBubble( | |
timvolodine
2014/12/19 16:02:21
why are those methods needed: AcceptBubble, DenyBu
felt
2014/12/19 16:46:30
The methods ->Accept and ->Deny are private; I hav
| |
290 PermissionBubbleManager* manager) { | |
291 manager->Accept(); | |
292 } | |
293 | |
294 void GeolocationPermissionContextTests::DenyBubble( | |
295 PermissionBubbleManager* manager) { | |
296 manager->Deny(); | |
297 } | |
298 | |
299 void GeolocationPermissionContextTests::CloseBubble( | |
300 PermissionBubbleManager* manager) { | |
301 manager->Closing(); | |
302 } | |
303 | |
304 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted() { | |
305 PermissionBubbleManager::FromWebContents(web_contents())-> | |
timvolodine
2014/12/19 16:02:21
nit: BubbleManagerDocumentLoadCompleted(web_conten
felt
2014/12/19 16:46:31
Done.
| |
306 DocumentOnLoadCompletedInMainFrame(); | |
307 } | |
308 | |
309 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted( | |
310 content::WebContents* web_contents) { | |
311 PermissionBubbleManager::FromWebContents(web_contents)-> | |
312 DocumentOnLoadCompletedInMainFrame(); | |
313 } | |
314 | |
315 // Needed to parameterize the tests for both infobars & permission bubbles. | |
316 class GeolocationPermissionContextParamTests : | |
317 public GeolocationPermissionContextTests, | |
318 public ::testing::WithParamInterface<bool> { | |
319 protected: | |
320 GeolocationPermissionContextParamTests() {} | |
321 ~GeolocationPermissionContextParamTests() override {} | |
322 | |
323 bool BubbleEnabled() { | |
timvolodine
2014/12/19 16:02:21
nit: .. const
felt
2014/12/19 16:46:31
Done.
| |
324 return GetParam(); | |
325 } | |
326 | |
327 void SetUp() override { | |
328 GeolocationPermissionContextTests::SetUp(); | |
329 #if !defined(OS_ANDROID) | |
330 if (BubbleEnabled()) { | |
331 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
332 switches::kEnablePermissionsBubbles); | |
333 EXPECT_TRUE(PermissionBubbleManager::Enabled()); | |
334 } else { | |
335 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
336 switches::kDisablePermissionsBubbles); | |
337 EXPECT_FALSE(PermissionBubbleManager::Enabled()); | |
338 } | |
339 #endif | |
340 } | |
341 | |
342 size_t GetNumberOfPrompts() { | |
343 if (BubbleEnabled()) { | |
344 PermissionBubbleManager* manager = | |
345 PermissionBubbleManager::FromWebContents(web_contents()); | |
346 return static_cast<size_t>(GetBubblesQueueSize(manager)); | |
347 } else { | |
348 return infobar_service()->infobar_count(); | |
349 } | |
350 } | |
351 | |
352 void AcceptPrompt() { | |
353 if (BubbleEnabled()) { | |
354 PermissionBubbleManager* manager = | |
355 PermissionBubbleManager::FromWebContents(web_contents()); | |
356 AcceptBubble(manager); | |
357 } else { | |
358 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | |
359 ConfirmInfoBarDelegate* infobar_delegate = | |
360 infobar->delegate()->AsConfirmInfoBarDelegate(); | |
361 infobar_delegate->Accept(); | |
362 } | |
363 } | |
364 | |
365 base::string16 GetPromptText() { | |
366 if (BubbleEnabled()) { | |
367 PermissionBubbleManager* manager = | |
368 PermissionBubbleManager::FromWebContents(web_contents()); | |
369 return GetFirstRequestText(manager); | |
370 } | |
371 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | |
372 ConfirmInfoBarDelegate* infobar_delegate = | |
373 infobar->delegate()->AsConfirmInfoBarDelegate(); | |
374 return infobar_delegate->GetMessageText(); | |
375 } | |
376 private: | |
377 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextParamTests); | |
378 }; | |
379 | |
260 // Tests ---------------------------------------------------------------------- | 380 // Tests ---------------------------------------------------------------------- |
timvolodine
2014/12/19 16:02:21
do we have/want a test for bubbles when user_gestu
felt
2014/12/19 16:46:31
that's a good question, I will check, but it belon
timvolodine
2014/12/19 19:47:03
it's up to you where to put it, but I think this f
felt
2015/01/30 00:59:20
I added a test to PermissionBubbleManagerTest in a
| |
261 | 381 |
262 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 382 TEST_P(GeolocationPermissionContextParamTests, SinglePermissionInfobar) { |
383 if (BubbleEnabled()) return; | |
384 | |
263 GURL requesting_frame("http://www.example.com/geolocation"); | 385 GURL requesting_frame("http://www.example.com/geolocation"); |
264 NavigateAndCommit(requesting_frame); | 386 NavigateAndCommit(requesting_frame); |
265 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 387 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
266 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 388 RequestGeolocationPermission( |
389 web_contents(), RequestID(0), requesting_frame, true); | |
267 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 390 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
268 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 391 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
269 ConfirmInfoBarDelegate* infobar_delegate = | 392 ConfirmInfoBarDelegate* infobar_delegate = |
270 infobar->delegate()->AsConfirmInfoBarDelegate(); | 393 infobar->delegate()->AsConfirmInfoBarDelegate(); |
271 ASSERT_TRUE(infobar_delegate); | 394 ASSERT_TRUE(infobar_delegate); |
272 infobar_delegate->Cancel(); | 395 infobar_delegate->Cancel(); |
273 infobar_service()->RemoveInfoBar(infobar); | 396 infobar_service()->RemoveInfoBar(infobar); |
274 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 397 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
275 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 398 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
276 } | 399 } |
277 | 400 |
278 #if defined(OS_ANDROID) | 401 TEST_P(GeolocationPermissionContextParamTests, SinglePermissionBubble) { |
279 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | 402 if (!BubbleEnabled()) return; |
403 | |
280 GURL requesting_frame("http://www.example.com/geolocation"); | 404 GURL requesting_frame("http://www.example.com/geolocation"); |
281 NavigateAndCommit(requesting_frame); | 405 NavigateAndCommit(requesting_frame); |
282 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 406 BubbleManagerDocumentLoadCompleted(); |
283 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
284 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | |
285 EXPECT_EQ(1U, infobar_service()->infobar_count()); | |
286 ConfirmInfoBarDelegate* infobar_delegate_0 = | |
287 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | |
288 ASSERT_TRUE(infobar_delegate_0); | |
289 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( | |
290 ConfirmInfoBarDelegate::BUTTON_OK); | |
291 | 407 |
292 Reload(); | 408 EXPECT_EQ(0U, GetNumberOfPrompts()); |
293 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 409 RequestGeolocationPermission( |
294 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 410 web_contents(), RequestID(0), requesting_frame, true); |
295 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 411 ASSERT_EQ(1U, GetNumberOfPrompts()); |
296 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
297 } | 412 } |
298 | 413 |
299 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { | 414 TEST_P(GeolocationPermissionContextParamTests, QueuedPermission) { |
300 GURL requesting_frame("http://www.example.com/geolocation"); | |
301 NavigateAndCommit(requesting_frame); | |
302 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | |
303 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
304 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | |
305 EXPECT_EQ(1U, infobar_service()->infobar_count()); | |
306 ConfirmInfoBarDelegate* infobar_delegate = | |
307 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | |
308 ASSERT_TRUE(infobar_delegate); | |
309 infobar_delegate->Accept(); | |
310 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | |
311 CheckPermissionMessageSent(0, true); | |
312 } | |
313 | |
314 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { | |
315 GURL requesting_frame("http://www.example.com/geolocation"); | |
316 NavigateAndCommit(requesting_frame); | |
317 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | |
318 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
319 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | |
320 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
321 } | |
322 #endif | |
323 | |
324 TEST_F(GeolocationPermissionContextTests, QueuedPermission) { | |
325 GURL requesting_frame_0("http://www.example.com/geolocation"); | 415 GURL requesting_frame_0("http://www.example.com/geolocation"); |
326 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 416 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
327 EXPECT_EQ(CONTENT_SETTING_ASK, | 417 EXPECT_EQ(CONTENT_SETTING_ASK, |
328 profile()->GetHostContentSettingsMap()->GetContentSetting( | 418 profile()->GetHostContentSettingsMap()->GetContentSetting( |
329 requesting_frame_0, requesting_frame_0, | 419 requesting_frame_0, requesting_frame_0, |
330 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 420 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
331 EXPECT_EQ(CONTENT_SETTING_ASK, | 421 EXPECT_EQ(CONTENT_SETTING_ASK, |
332 profile()->GetHostContentSettingsMap()->GetContentSetting( | 422 profile()->GetHostContentSettingsMap()->GetContentSetting( |
333 requesting_frame_1, requesting_frame_0, | 423 requesting_frame_1, requesting_frame_0, |
334 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 424 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
335 | 425 |
336 NavigateAndCommit(requesting_frame_0); | 426 NavigateAndCommit(requesting_frame_0); |
337 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 427 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
428 | |
429 // Check that no permission requests have happened yet. | |
430 EXPECT_EQ(0U, GetNumberOfPrompts()); | |
431 | |
338 // Request permission for two frames. | 432 // Request permission for two frames. |
339 RequestGeolocationPermission( | 433 RequestGeolocationPermission( |
340 web_contents(), RequestID(0), requesting_frame_0); | 434 web_contents(), RequestID(0), requesting_frame_0, BubbleEnabled()); |
timvolodine
2014/12/19 16:02:21
you are using BubbleEnabled() to pass user_gesture
felt
2014/12/19 16:46:31
I'm forcing the user gesture to be true for the bu
timvolodine
2014/12/19 19:47:03
I see, in this case could you make it explicitly "
felt
2015/01/30 00:59:20
Done.
| |
341 RequestGeolocationPermission( | 435 RequestGeolocationPermission( |
342 web_contents(), RequestID(1), requesting_frame_1); | 436 web_contents(), RequestID(1), requesting_frame_1, BubbleEnabled()); |
437 | |
343 // Ensure only one infobar is created. | 438 // Ensure only one infobar is created. |
344 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 439 ASSERT_EQ(1U, GetNumberOfPrompts()); |
345 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 440 base::string16 text_0 = GetPromptText(); |
346 ConfirmInfoBarDelegate* infobar_delegate_0 = | |
347 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | |
348 ASSERT_TRUE(infobar_delegate_0); | |
349 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | |
350 | 441 |
351 // Accept the first frame. | 442 // Accept the first frame. |
352 infobar_delegate_0->Accept(); | 443 AcceptPrompt(); |
353 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 444 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
354 CheckPermissionMessageSent(0, true); | 445 CheckPermissionMessageSent(0, true); |
446 if (!BubbleEnabled()) { | |
447 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | |
448 infobar_service()->RemoveInfoBar(infobar_0); | |
449 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
450 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | |
451 closed_infobar_tracker_.Clear(); | |
452 } | |
355 | 453 |
356 infobar_service()->RemoveInfoBar(infobar_0); | 454 // Now we should have a new request for the second frame. |
357 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 455 ASSERT_EQ(1U, GetNumberOfPrompts()); |
358 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 456 base::string16 text_1 = GetPromptText(); |
359 closed_infobar_tracker_.Clear(); | |
360 // Now we should have a new infobar for the second frame. | |
361 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
362 | 457 |
363 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 458 // Check that the messages differ. |
364 ConfirmInfoBarDelegate* infobar_delegate_1 = | |
365 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | |
366 ASSERT_TRUE(infobar_delegate_1); | |
367 base::string16 text_1 = infobar_delegate_1->GetMessageText(); | |
368 EXPECT_NE(text_0, text_1); | 459 EXPECT_NE(text_0, text_1); |
369 | 460 |
370 // Cancel (block) this frame. | 461 // Cancel (block) this frame. |
371 infobar_delegate_1->Cancel(); | 462 if (BubbleEnabled()) { |
463 PermissionBubbleManager* manager = | |
464 PermissionBubbleManager::FromWebContents(web_contents()); | |
465 DenyBubble(manager); | |
466 } else { | |
467 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); | |
468 infobar_1->delegate()->AsConfirmInfoBarDelegate()->Cancel(); | |
469 } | |
372 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 470 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
373 CheckPermissionMessageSent(1, false); | 471 CheckPermissionMessageSent(1, false); |
374 infobar_service()->RemoveInfoBar(infobar_1); | 472 |
375 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
376 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | |
377 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
378 // Ensure the persisted permissions are ok. | 473 // Ensure the persisted permissions are ok. |
379 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 474 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
380 profile()->GetHostContentSettingsMap()->GetContentSetting( | 475 profile()->GetHostContentSettingsMap()->GetContentSetting( |
381 requesting_frame_0, requesting_frame_0, | 476 requesting_frame_0, requesting_frame_0, |
382 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 477 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
383 | 478 |
384 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 479 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
385 profile()->GetHostContentSettingsMap()->GetContentSetting( | 480 profile()->GetHostContentSettingsMap()->GetContentSetting( |
386 requesting_frame_1, requesting_frame_0, | 481 requesting_frame_1, requesting_frame_0, |
387 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 482 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
388 } | 483 } |
389 | 484 |
390 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { | 485 TEST_P(GeolocationPermissionContextParamTests, HashIsIgnored) { |
391 GURL url_a("http://www.example.com/geolocation#a"); | 486 GURL url_a("http://www.example.com/geolocation#a"); |
392 GURL url_b("http://www.example.com/geolocation#b"); | 487 GURL url_b("http://www.example.com/geolocation#b"); |
393 | 488 |
394 // Navigate to the first url and check permission is requested. | 489 // Navigate to the first url. |
395 NavigateAndCommit(url_a); | 490 NavigateAndCommit(url_a); |
396 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 491 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
397 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 492 |
398 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 493 // Check permission is requested. |
399 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 494 ASSERT_EQ(0U, GetNumberOfPrompts()); |
400 ConfirmInfoBarDelegate* infobar_delegate = | 495 RequestGeolocationPermission( |
401 infobar->delegate()->AsConfirmInfoBarDelegate(); | 496 web_contents(), RequestID(0), url_a, BubbleEnabled()); |
402 ASSERT_TRUE(infobar_delegate); | 497 ASSERT_EQ(1U, GetNumberOfPrompts()); |
403 | 498 |
404 // Change the hash, we'll still be on the same page. | 499 // Change the hash, we'll still be on the same page. |
405 NavigateAndCommit(url_b); | 500 NavigateAndCommit(url_b); |
501 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); | |
406 | 502 |
407 // Accept. | 503 // Accept. |
408 infobar_delegate->Accept(); | 504 AcceptPrompt(); |
409 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); | 505 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
410 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); | 506 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
411 CheckPermissionMessageSent(0, true); | 507 CheckPermissionMessageSent(0, true); |
412 | 508 |
413 // Cleanup. | 509 // Cleanup. |
414 infobar_service()->RemoveInfoBar(infobar); | 510 if (!BubbleEnabled()) { |
415 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 511 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
416 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 512 infobar_service()->RemoveInfoBar(infobar); |
513 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
514 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | |
515 } | |
417 } | 516 } |
418 | 517 |
419 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { | 518 TEST_P(GeolocationPermissionContextParamTests, PermissionForFileScheme) { |
519 // TODO(felt): The bubble is rejecting file:// permission requests. | |
timvolodine
2014/12/19 16:02:20
is there a crbug for this?
felt
2014/12/19 16:46:30
crbug.com/444047. added to comment.
| |
520 // Fix and enable this test. | |
521 if (BubbleEnabled()) return; | |
522 | |
420 GURL requesting_frame("file://example/geolocation.html"); | 523 GURL requesting_frame("file://example/geolocation.html"); |
421 NavigateAndCommit(requesting_frame); | 524 NavigateAndCommit(requesting_frame); |
422 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 525 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
423 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 526 |
424 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 527 // Check permission is requested. |
425 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 528 ASSERT_EQ(0U, GetNumberOfPrompts()); |
426 ConfirmInfoBarDelegate* infobar_delegate = | 529 RequestGeolocationPermission( |
427 infobar->delegate()->AsConfirmInfoBarDelegate(); | 530 web_contents(), RequestID(0), requesting_frame, BubbleEnabled()); |
428 ASSERT_TRUE(infobar_delegate); | 531 ASSERT_EQ(1U, GetNumberOfPrompts()); |
532 | |
429 // Accept the frame. | 533 // Accept the frame. |
430 infobar_delegate->Accept(); | 534 AcceptPrompt(); |
431 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 535 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
432 CheckPermissionMessageSent(0, true); | 536 CheckPermissionMessageSent(0, true); |
433 infobar_service()->RemoveInfoBar(infobar); | |
434 | 537 |
435 // Make sure the setting is not stored. | 538 // Make sure the setting is not stored. |
436 EXPECT_EQ(CONTENT_SETTING_ASK, | 539 EXPECT_EQ(CONTENT_SETTING_ASK, |
437 profile()->GetHostContentSettingsMap()->GetContentSetting( | 540 profile()->GetHostContentSettingsMap()->GetContentSetting( |
438 requesting_frame, | 541 requesting_frame, |
439 requesting_frame, | 542 requesting_frame, |
440 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 543 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
441 std::string())); | 544 std::string())); |
442 } | 545 } |
443 | 546 |
444 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { | 547 TEST_P(GeolocationPermissionContextParamTests, |
445 GURL requesting_frame_0("http://www.example.com/geolocation"); | 548 CancelGeolocationPermissionRequest) { |
446 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 549 GURL frame_0("http://www.example.com/geolocation"); |
447 EXPECT_EQ(CONTENT_SETTING_ASK, | 550 GURL frame_1("http://www.example-2.com/geolocation"); |
448 profile()->GetHostContentSettingsMap()->GetContentSetting( | 551 EXPECT_EQ(CONTENT_SETTING_ASK, |
449 requesting_frame_0, requesting_frame_0, | 552 profile()->GetHostContentSettingsMap()->GetContentSetting( |
450 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 553 frame_0, frame_0, |
451 | 554 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
452 EXPECT_EQ(CONTENT_SETTING_ASK, | 555 |
453 profile()->GetHostContentSettingsMap()->GetContentSetting( | 556 EXPECT_EQ(CONTENT_SETTING_ASK, |
454 requesting_frame_1, requesting_frame_0, | 557 profile()->GetHostContentSettingsMap()->GetContentSetting( |
455 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 558 frame_1, frame_0, |
456 | 559 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
457 NavigateAndCommit(requesting_frame_0); | 560 |
458 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 561 NavigateAndCommit(frame_0); |
562 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); | |
563 | |
564 ASSERT_EQ(0U, GetNumberOfPrompts()); | |
459 | 565 |
460 // Request permission for two frames. | 566 // Request permission for two frames. |
461 RequestGeolocationPermission( | 567 RequestGeolocationPermission( |
462 web_contents(), RequestID(0), requesting_frame_0); | 568 web_contents(), RequestID(0), frame_0, BubbleEnabled()); |
463 RequestGeolocationPermission( | 569 RequestGeolocationPermission( |
464 web_contents(), RequestID(1), requesting_frame_1); | 570 web_contents(), RequestID(1), frame_1, BubbleEnabled()); |
465 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 571 ASSERT_EQ(1U, GetNumberOfPrompts()); |
466 | 572 |
467 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 573 // Get the first permission request text. |
468 ConfirmInfoBarDelegate* infobar_delegate_0 = | 574 ASSERT_EQ(1U, GetNumberOfPrompts()); |
469 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 575 base::string16 text_0 = GetPromptText(); |
470 ASSERT_TRUE(infobar_delegate_0); | 576 ASSERT_NE(base::string16(), text_0); |
timvolodine
2014/12/19 16:02:20
ASSERT_FALSE(text_0.empty()) ?
felt
2014/12/19 16:46:30
Done.
felt
2014/12/19 16:46:31
Done.
| |
471 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 577 |
472 | 578 // Simulate frame 0 going away; the request should be removed. |
473 // Simulate the frame going away, ensure the infobar for this frame | 579 if (BubbleEnabled()) { |
474 // is removed and the next pending infobar is created. | 580 PermissionBubbleManager* manager = |
475 geolocation_permission_context_->CancelPermissionRequest(web_contents(), | 581 PermissionBubbleManager::FromWebContents(web_contents()); |
476 RequestID(0)); | 582 CloseBubble(manager); |
477 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 583 } else { |
478 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 584 geolocation_permission_context_->CancelPermissionRequest(web_contents(), |
479 closed_infobar_tracker_.Clear(); | 585 RequestID(0)); |
480 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 586 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
481 | 587 } |
482 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 588 |
483 ConfirmInfoBarDelegate* infobar_delegate_1 = | 589 // Check that the next pending request is created correctly. |
484 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 590 base::string16 text_1 = GetPromptText();; |
485 ASSERT_TRUE(infobar_delegate_1); | |
486 base::string16 text_1 = infobar_delegate_1->GetMessageText(); | |
487 EXPECT_NE(text_0, text_1); | 591 EXPECT_NE(text_0, text_1); |
488 | 592 |
489 // Allow this frame. | 593 // Allow this frame and check that it worked. |
490 infobar_delegate_1->Accept(); | 594 AcceptPrompt(); |
491 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 595 CheckTabContentsState(frame_1, CONTENT_SETTING_ALLOW); |
492 CheckPermissionMessageSent(1, true); | 596 CheckPermissionMessageSent(1, true); |
493 infobar_service()->RemoveInfoBar(infobar_1); | 597 |
494 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
495 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | |
496 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
497 // Ensure the persisted permissions are ok. | 598 // Ensure the persisted permissions are ok. |
498 EXPECT_EQ(CONTENT_SETTING_ASK, | 599 EXPECT_EQ(CONTENT_SETTING_ASK, |
499 profile()->GetHostContentSettingsMap()->GetContentSetting( | 600 profile()->GetHostContentSettingsMap()->GetContentSetting( |
500 requesting_frame_0, requesting_frame_0, | 601 frame_0, frame_0, |
501 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 602 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
502 | 603 |
503 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 604 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
504 profile()->GetHostContentSettingsMap()->GetContentSetting( | 605 profile()->GetHostContentSettingsMap()->GetContentSetting( |
505 requesting_frame_1, requesting_frame_0, | 606 frame_1, frame_0, |
506 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 607 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
507 } | 608 } |
508 | 609 |
509 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 610 TEST_P(GeolocationPermissionContextParamTests, InvalidURL) { |
611 // Navigate to the first url. | |
510 GURL invalid_embedder("about:blank"); | 612 GURL invalid_embedder("about:blank"); |
511 GURL requesting_frame; | 613 GURL requesting_frame; |
512 NavigateAndCommit(invalid_embedder); | 614 NavigateAndCommit(invalid_embedder); |
513 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 615 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
514 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 616 |
515 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 617 // Nothing should be displayed. |
618 EXPECT_EQ(0U, GetNumberOfPrompts()); | |
619 RequestGeolocationPermission( | |
620 web_contents(), RequestID(0), requesting_frame, BubbleEnabled()); | |
621 EXPECT_EQ(0U, GetNumberOfPrompts()); | |
516 CheckPermissionMessageSent(0, false); | 622 CheckPermissionMessageSent(0, false); |
517 } | 623 } |
518 | 624 |
519 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 625 TEST_P(GeolocationPermissionContextParamTests, SameOriginMultipleTabs) { |
520 GURL url_a("http://www.example.com/geolocation"); | 626 GURL url_a("http://www.example.com/geolocation"); |
521 GURL url_b("http://www.example-2.com/geolocation"); | 627 GURL url_b("http://www.example-2.com/geolocation"); |
522 NavigateAndCommit(url_a); | 628 NavigateAndCommit(url_a); // Tab A0 |
523 AddNewTab(url_b); | 629 AddNewTab(url_b); // Tab B (extra_tabs_[0]) |
524 AddNewTab(url_a); | 630 AddNewTab(url_a); // Tab A1 (extra_tabs_[1]) |
525 | 631 if (BubbleEnabled()) { |
526 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 632 BubbleManagerDocumentLoadCompleted(); |
527 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 633 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]); |
528 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 634 BubbleManagerDocumentLoadCompleted(extra_tabs_[1]); |
529 | 635 } |
530 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_b); | 636 PermissionBubbleManager* manager_a0 = |
531 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 637 PermissionBubbleManager::FromWebContents(web_contents()); |
532 | 638 PermissionBubbleManager* manager_b = |
533 RequestGeolocationPermission(extra_tabs_[1], RequestIDForTab(1, 0), url_a); | 639 PermissionBubbleManager::FromWebContents(extra_tabs_[0]); |
534 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); | 640 PermissionBubbleManager* manager_a1 = |
535 | 641 PermissionBubbleManager::FromWebContents(extra_tabs_[1]); |
536 infobars::InfoBar* removed_infobar = | 642 |
537 infobar_service_for_tab(1)->infobar_at(0); | 643 // Request permission in all three tabs. |
538 | 644 RequestGeolocationPermission( |
539 // Accept the first tab. | 645 web_contents(), RequestID(0), url_a, BubbleEnabled()); |
540 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 646 RequestGeolocationPermission( |
541 ConfirmInfoBarDelegate* infobar_delegate_0 = | 647 extra_tabs_[0], RequestIDForTab(0, 0), url_b, BubbleEnabled()); |
542 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 648 RequestGeolocationPermission( |
543 ASSERT_TRUE(infobar_delegate_0); | 649 extra_tabs_[1], RequestIDForTab(1, 0), url_a, BubbleEnabled()); |
544 infobar_delegate_0->Accept(); | 650 ASSERT_EQ(1U, GetNumberOfPrompts()); // For A0. |
651 if (BubbleEnabled()) { | |
652 ASSERT_EQ(1, GetBubblesQueueSize(manager_b)); | |
653 ASSERT_EQ(1, GetBubblesQueueSize(manager_a1)); | |
654 } else { | |
655 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | |
656 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); | |
657 } | |
658 | |
659 // Accept the permission in tab A0. | |
660 if (BubbleEnabled()) { | |
661 AcceptBubble(manager_a0); | |
662 } else { | |
663 infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0); | |
664 ConfirmInfoBarDelegate* infobar_delegate_a0 = | |
665 infobar_a0->delegate()->AsConfirmInfoBarDelegate(); | |
666 ASSERT_TRUE(infobar_delegate_a0); | |
667 infobar_delegate_a0->Accept(); | |
668 infobar_service()->RemoveInfoBar(infobar_a0); | |
669 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | |
670 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0)); | |
671 } | |
545 CheckPermissionMessageSent(0, true); | 672 CheckPermissionMessageSent(0, true); |
546 infobar_service()->RemoveInfoBar(infobar_0); | 673 |
547 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 674 // Because they're the same origin, this will cause tab A1's infobar to |
548 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 675 // disappear. It does not cause the bubble to disappear: crbug.com/443013. |
549 // Now the infobar for the tab with the same origin should have gone. | 676 // TODO(felt): Update this test when the bubble's behavior is changed. |
550 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); | 677 if (BubbleEnabled()) |
551 CheckPermissionMessageSentForTab(1, 0, true); | 678 ASSERT_EQ(1, GetBubblesQueueSize(manager_a1)); |
552 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 679 else |
553 closed_infobar_tracker_.Clear(); | 680 CheckPermissionMessageSentForTab(1, 0, true); |
554 | 681 |
555 // But the other tab should still have the info bar... | 682 // Either way, tab B should still have a pending permission request. |
556 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 683 if (BubbleEnabled()) |
557 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 684 ASSERT_EQ(1, GetBubblesQueueSize(manager_b)); |
558 ConfirmInfoBarDelegate* infobar_delegate_1 = | 685 else |
559 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 686 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
560 ASSERT_TRUE(infobar_delegate_1); | 687 } |
561 infobar_delegate_1->Cancel(); | 688 |
562 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 689 TEST_P(GeolocationPermissionContextParamTests, QueuedOriginMultipleTabs) { |
563 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
564 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | |
565 } | |
566 | |
567 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | |
568 GURL url_a("http://www.example.com/geolocation"); | 690 GURL url_a("http://www.example.com/geolocation"); |
569 GURL url_b("http://www.example-2.com/geolocation"); | 691 GURL url_b("http://www.example-2.com/geolocation"); |
570 NavigateAndCommit(url_a); | 692 NavigateAndCommit(url_a); // Tab A0. |
571 AddNewTab(url_a); | 693 AddNewTab(url_a); // Tab A1. |
572 | 694 if (BubbleEnabled()) { |
573 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 695 BubbleManagerDocumentLoadCompleted(); |
574 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 696 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]); |
575 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 697 } |
576 | 698 PermissionBubbleManager* manager_a0 = |
577 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_a); | 699 PermissionBubbleManager::FromWebContents(web_contents()); |
578 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 700 PermissionBubbleManager* manager_a1 = |
579 | 701 PermissionBubbleManager::FromWebContents(extra_tabs_[0]); |
580 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 1), url_b); | 702 infobars::InfoBar* infobar_a0; |
581 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 703 |
582 | 704 // Request permission in both tabs; the extra tab will have two permission |
583 infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0); | 705 // requests from two origins. |
584 | 706 RequestGeolocationPermission( |
585 // Accept the second tab. | 707 web_contents(), RequestID(0), url_a, BubbleEnabled()); |
586 infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); | 708 RequestGeolocationPermission( |
587 ConfirmInfoBarDelegate* infobar_delegate_0 = | 709 extra_tabs_[0], RequestIDForTab(0, 0), url_a, BubbleEnabled()); |
588 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 710 RequestGeolocationPermission( |
589 ASSERT_TRUE(infobar_delegate_0); | 711 extra_tabs_[0], RequestIDForTab(0, 1), url_b, BubbleEnabled()); |
590 infobar_delegate_0->Accept(); | 712 if (BubbleEnabled()) { |
713 ASSERT_EQ(1, GetBubblesQueueSize(manager_a0)); | |
714 ASSERT_EQ(1, GetBubblesQueueSize(manager_a1)); | |
715 } else { | |
716 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
717 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | |
718 infobar_a0 = infobar_service()->infobar_at(0); // Save for later. | |
719 } | |
720 | |
721 // Accept the first request in tab A1. | |
722 if (BubbleEnabled()) { | |
723 AcceptBubble(manager_a1); | |
724 } else { | |
725 infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0); | |
726 ConfirmInfoBarDelegate* infobar_delegate_a1 = | |
727 infobar_a1->delegate()->AsConfirmInfoBarDelegate(); | |
728 ASSERT_TRUE(infobar_delegate_a1); | |
729 infobar_delegate_a1->Accept(); | |
730 infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1); | |
731 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | |
732 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1)); | |
733 } | |
591 CheckPermissionMessageSentForTab(0, 0, true); | 734 CheckPermissionMessageSentForTab(0, 0, true); |
592 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); | 735 |
593 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 736 // Because they're the same origin, this will cause tab A0's infobar to |
594 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 737 // disappear. It does not cause the bubble to disappear: crbug.com/443013. |
595 // Now the infobar for the tab with the same origin should have gone. | 738 // TODO(felt): Update this test when the bubble's behavior is changed. |
596 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 739 if (BubbleEnabled()) { |
597 CheckPermissionMessageSent(0, true); | 740 EXPECT_EQ(1, GetBubblesQueueSize(manager_a0)); |
598 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 741 } else { |
599 closed_infobar_tracker_.Clear(); | 742 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
600 | 743 CheckPermissionMessageSent(0, true); |
601 // And we should have the queued infobar displayed now. | 744 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0)); |
602 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 745 closed_infobar_tracker_.Clear(); |
603 | 746 } |
604 // Accept the second infobar. | 747 |
605 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 748 // The second request should now be visible in tab A1. |
606 ConfirmInfoBarDelegate* infobar_delegate_1 = | 749 if (BubbleEnabled()) |
607 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 750 ASSERT_EQ(1, GetBubblesQueueSize(manager_a1)); |
608 ASSERT_TRUE(infobar_delegate_1); | 751 else |
609 infobar_delegate_1->Accept(); | 752 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
753 | |
754 // Accept the second request and check that it's gone. | |
755 if (BubbleEnabled()) { | |
756 AcceptBubble(manager_a1); | |
757 EXPECT_EQ(0, GetBubblesQueueSize(manager_a1)); | |
758 } else { | |
759 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | |
760 ConfirmInfoBarDelegate* infobar_delegate_1 = | |
761 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | |
762 ASSERT_TRUE(infobar_delegate_1); | |
763 infobar_delegate_1->Accept(); | |
764 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | |
765 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
766 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | |
767 } | |
610 CheckPermissionMessageSentForTab(0, 1, true); | 768 CheckPermissionMessageSentForTab(0, 1, true); |
611 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 769 } |
612 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 770 |
613 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 771 TEST_P(GeolocationPermissionContextParamTests, TabDestroyed) { |
614 } | |
615 | |
616 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | |
617 GURL requesting_frame_0("http://www.example.com/geolocation"); | 772 GURL requesting_frame_0("http://www.example.com/geolocation"); |
618 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 773 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
619 EXPECT_EQ(CONTENT_SETTING_ASK, | 774 EXPECT_EQ(CONTENT_SETTING_ASK, |
620 profile()->GetHostContentSettingsMap()->GetContentSetting( | 775 profile()->GetHostContentSettingsMap()->GetContentSetting( |
621 requesting_frame_0, requesting_frame_0, | 776 requesting_frame_0, requesting_frame_0, |
622 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 777 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
623 | 778 |
624 EXPECT_EQ(CONTENT_SETTING_ASK, | 779 EXPECT_EQ(CONTENT_SETTING_ASK, |
625 profile()->GetHostContentSettingsMap()->GetContentSetting( | 780 profile()->GetHostContentSettingsMap()->GetContentSetting( |
626 requesting_frame_1, requesting_frame_0, | 781 requesting_frame_1, requesting_frame_0, |
627 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 782 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
628 | 783 |
629 NavigateAndCommit(requesting_frame_0); | 784 NavigateAndCommit(requesting_frame_0); |
630 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 785 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
786 | |
787 ASSERT_EQ(0U, GetNumberOfPrompts()); | |
788 | |
631 // Request permission for two frames. | 789 // Request permission for two frames. |
632 RequestGeolocationPermission( | 790 RequestGeolocationPermission( |
633 web_contents(), RequestID(0), requesting_frame_0); | 791 web_contents(), RequestID(0), requesting_frame_0, false); |
634 RequestGeolocationPermission( | 792 RequestGeolocationPermission( |
635 web_contents(), RequestID(1), requesting_frame_1); | 793 web_contents(), RequestID(1), requesting_frame_1, false); |
636 // Ensure only one infobar is created. | |
637 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
638 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | |
639 | 794 |
640 // Delete the tab contents. | 795 // Ensure only one infobar/bubble is created. |
641 DeleteContents(); | 796 ASSERT_EQ(1U, GetNumberOfPrompts()); |
642 | 797 |
643 // During contents destruction, the infobar will have been closed, and the | 798 // Delete the tab contents and check that the infobar was removed. |
644 // pending request should have been cleared without an infobar being created. | 799 if (!BubbleEnabled()) { |
645 ASSERT_EQ(1U, closed_infobar_tracker_.size()); | 800 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
646 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 801 DeleteContents(); |
802 ASSERT_EQ(1U, closed_infobar_tracker_.size()); | |
803 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); | |
804 } | |
805 | |
806 // The content settings should not have changed. | |
807 EXPECT_EQ(CONTENT_SETTING_ASK, | |
808 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
timvolodine
2014/12/19 16:02:20
nit: I guess you could extract this into a helper
felt
2014/12/19 16:46:31
Done.
| |
809 requesting_frame_0, requesting_frame_0, | |
810 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | |
811 | |
812 EXPECT_EQ(CONTENT_SETTING_ASK, | |
813 profile()->GetHostContentSettingsMap()->GetContentSetting( | |
814 requesting_frame_1, requesting_frame_0, | |
815 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | |
647 } | 816 } |
648 | 817 |
649 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) { | 818 TEST_P(GeolocationPermissionContextParamTests, LastUsageAudited) { |
650 GURL requesting_frame("http://www.example.com/geolocation"); | 819 GURL requesting_frame("http://www.example.com/geolocation"); |
651 NavigateAndCommit(requesting_frame); | 820 NavigateAndCommit(requesting_frame); |
821 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); | |
652 | 822 |
653 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | 823 base::SimpleTestClock* test_clock = new base::SimpleTestClock; |
654 test_clock->SetNow(base::Time::UnixEpoch() + | 824 test_clock->SetNow(base::Time::UnixEpoch() + |
655 base::TimeDelta::FromSeconds(10)); | 825 base::TimeDelta::FromSeconds(10)); |
656 | 826 |
657 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | 827 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
658 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); | 828 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); |
659 | 829 |
660 // The permission shouldn't have been used yet. | 830 // The permission shouldn't have been used yet. |
661 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 831 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
662 requesting_frame.GetOrigin(), | 832 requesting_frame.GetOrigin(), |
663 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 833 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
664 0); | 834 0); |
665 | 835 ASSERT_EQ(0U, GetNumberOfPrompts()); |
666 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 836 RequestGeolocationPermission( |
667 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 837 web_contents(), RequestID(0), requesting_frame, false); |
668 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 838 ASSERT_EQ(1U, GetNumberOfPrompts()); |
669 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 839 AcceptPrompt(); |
670 ConfirmInfoBarDelegate* infobar_delegate = | |
671 infobar->delegate()->AsConfirmInfoBarDelegate(); | |
672 ASSERT_TRUE(infobar_delegate); | |
673 infobar_delegate->Accept(); | |
674 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 840 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
675 CheckPermissionMessageSent(0, true); | 841 CheckPermissionMessageSent(0, true); |
676 | 842 |
677 // Permission has been used at the starting time. | 843 // Permission has been used at the starting time. |
678 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 844 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
679 requesting_frame.GetOrigin(), | 845 requesting_frame.GetOrigin(), |
680 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 846 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
681 10); | 847 10); |
682 | 848 |
683 test_clock->Advance(base::TimeDelta::FromSeconds(3)); | 849 test_clock->Advance(base::TimeDelta::FromSeconds(3)); |
684 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 850 RequestGeolocationPermission( |
851 web_contents(), RequestID(0), requesting_frame, false); | |
685 | 852 |
686 // Permission has been used three seconds later. | 853 // Permission has been used three seconds later. |
687 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 854 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
688 requesting_frame.GetOrigin(), | 855 requesting_frame.GetOrigin(), |
689 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 856 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
690 13); | 857 13); |
691 } | 858 } |
692 | 859 |
693 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) { | 860 TEST_P(GeolocationPermissionContextParamTests, LastUsageAuditedMultipleFrames) { |
694 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | 861 base::SimpleTestClock* test_clock = new base::SimpleTestClock; |
695 test_clock->SetNow(base::Time::UnixEpoch() + | 862 test_clock->SetNow(base::Time::UnixEpoch() + |
696 base::TimeDelta::FromSeconds(10)); | 863 base::TimeDelta::FromSeconds(10)); |
697 | 864 |
698 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | 865 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
699 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); | 866 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); |
700 | 867 |
701 GURL requesting_frame_0("http://www.example.com/geolocation"); | 868 GURL requesting_frame_0("http://www.example.com/geolocation"); |
702 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 869 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
703 | 870 |
704 // The permission shouldn't have been used yet. | 871 // The permission shouldn't have been used yet. |
705 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 872 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
706 requesting_frame_0.GetOrigin(), | 873 requesting_frame_0.GetOrigin(), |
707 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 874 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
708 0); | 875 0); |
709 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 876 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
710 requesting_frame_0.GetOrigin(), | 877 requesting_frame_0.GetOrigin(), |
711 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 878 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
712 0); | 879 0); |
713 | 880 |
714 NavigateAndCommit(requesting_frame_0); | 881 NavigateAndCommit(requesting_frame_0); |
715 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 882 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
883 | |
884 EXPECT_EQ(0U, GetNumberOfPrompts()); | |
716 | 885 |
717 // Request permission for two frames. | 886 // Request permission for two frames. |
718 RequestGeolocationPermission( | 887 RequestGeolocationPermission( |
719 web_contents(), RequestID(0), requesting_frame_0); | 888 web_contents(), RequestID(0), requesting_frame_0, false); |
720 RequestGeolocationPermission( | 889 RequestGeolocationPermission( |
721 web_contents(), RequestID(1), requesting_frame_1); | 890 web_contents(), RequestID(1), requesting_frame_1, false); |
722 | 891 |
723 // Ensure only one infobar is created. | 892 // Ensure only one request is created. |
724 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 893 ASSERT_EQ(1U, GetNumberOfPrompts()); |
725 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | |
726 ConfirmInfoBarDelegate* infobar_delegate_0 = | |
727 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | |
728 | 894 |
729 // Accept the first frame. | 895 // Accept the first frame. |
730 infobar_delegate_0->Accept(); | 896 AcceptPrompt(); |
897 if (!BubbleEnabled()) | |
898 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); | |
731 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 899 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
732 CheckPermissionMessageSent(0, true); | 900 CheckPermissionMessageSent(0, true); |
733 infobar_service()->RemoveInfoBar(infobar_0); | |
734 | 901 |
735 // Verify that accepting the first didn't accept because it's embedder | 902 // Verify that accepting the first didn't accept because it's embedded |
736 // in the other. | 903 // in the other. |
737 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 904 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
738 requesting_frame_0.GetOrigin(), | 905 requesting_frame_0.GetOrigin(), |
739 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 906 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
740 10); | 907 10); |
741 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 908 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
742 requesting_frame_0.GetOrigin(), | 909 requesting_frame_0.GetOrigin(), |
743 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 910 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
744 0); | 911 0); |
745 | 912 |
746 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 913 ASSERT_EQ(1U, GetNumberOfPrompts()); |
747 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); | |
748 ConfirmInfoBarDelegate* infobar_delegate_1 = | |
749 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | |
750 | 914 |
751 test_clock->Advance(base::TimeDelta::FromSeconds(1)); | 915 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
752 | 916 |
753 // Allow the second frame. | 917 // Allow the second frame. |
754 infobar_delegate_1->Accept(); | 918 AcceptPrompt(); |
755 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 919 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
756 CheckPermissionMessageSent(1, true); | 920 CheckPermissionMessageSent(1, true); |
757 infobar_service()->RemoveInfoBar(infobar_1); | 921 if (!BubbleEnabled()) |
922 infobar_service()->RemoveInfoBar(infobar_service()->infobar_at(0)); | |
758 | 923 |
759 // Verify that the times are different. | 924 // Verify that the times are different. |
760 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 925 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
761 requesting_frame_0.GetOrigin(), | 926 requesting_frame_0.GetOrigin(), |
762 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 927 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
763 10); | 928 10); |
764 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 929 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
765 requesting_frame_0.GetOrigin(), | 930 requesting_frame_0.GetOrigin(), |
766 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 931 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
767 11); | 932 11); |
768 | 933 |
769 test_clock->Advance(base::TimeDelta::FromSeconds(2)); | 934 test_clock->Advance(base::TimeDelta::FromSeconds(2)); |
770 RequestGeolocationPermission( | 935 RequestGeolocationPermission( |
771 web_contents(), RequestID(0), requesting_frame_0); | 936 web_contents(), RequestID(0), requesting_frame_0, false); |
772 | 937 |
773 // Verify that requesting permission in one frame doesn't update other where | 938 // Verify that requesting permission in one frame doesn't update other where |
774 // it is the embedder. | 939 // it is the embedder. |
775 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 940 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
776 requesting_frame_0.GetOrigin(), | 941 requesting_frame_0.GetOrigin(), |
777 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 942 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
778 13); | 943 13); |
779 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 944 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
780 requesting_frame_0.GetOrigin(), | 945 requesting_frame_0.GetOrigin(), |
781 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 946 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
782 11); | 947 11); |
783 } | 948 } |
949 | |
950 INSTANTIATE_TEST_CASE_P(GeolocationPermissionContextTestsWithAndWithoutBubbles, | |
951 GeolocationPermissionContextParamTests, | |
952 ::testing::Values(false, true)); | |
953 | |
954 // Infobar-only tests ---------------------------------------------------------- | |
955 // Android doesn't support permission bubbles. | |
956 | |
957 #if defined(OS_ANDROID) | |
timvolodine
2014/12/19 16:02:21
why is this android-only? we support infobars on o
felt
2014/12/19 16:46:30
I don't know. It was already if-def'ed, I just mov
timvolodine
2014/12/19 19:47:03
fair enough ;)
| |
958 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | |
959 EXPECT_FALSE(PermissionBubbleManager::Enabled()); | |
960 GURL requesting_frame("http://www.example.com/geolocation"); | |
961 NavigateAndCommit(requesting_frame); | |
962 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | |
963 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
964 RequestGeolocationPermission( | |
965 web_contents(), RequestID(0), requesting_frame, true); | |
966 EXPECT_EQ(1U, infobar_service()->infobar_count()); | |
967 ConfirmInfoBarDelegate* infobar_delegate_0 = | |
968 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | |
969 ASSERT_TRUE(infobar_delegate_0); | |
970 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( | |
971 ConfirmInfoBarDelegate::BUTTON_OK); | |
972 | |
973 Reload(); | |
974 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | |
975 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
976 RequestGeolocationPermission( | |
977 web_contents(), RequestID(0), requesting_frame, true); | |
978 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
979 } | |
980 | |
981 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { | |
982 EXPECT_FALSE(PermissionBubbleManager::Enabled()); | |
983 GURL requesting_frame("http://www.example.com/geolocation"); | |
984 NavigateAndCommit(requesting_frame); | |
985 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | |
986 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
987 RequestGeolocationPermission( | |
988 web_contents(), RequestID(0), requesting_frame, true); | |
989 EXPECT_EQ(1U, infobar_service()->infobar_count()); | |
990 ConfirmInfoBarDelegate* infobar_delegate = | |
991 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | |
992 ASSERT_TRUE(infobar_delegate); | |
993 infobar_delegate->Accept(); | |
994 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | |
995 CheckPermissionMessageSent(0, true); | |
996 } | |
997 | |
998 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { | |
999 EXPECT_FALSE(PermissionBubbleManager::Enabled()); | |
1000 GURL requesting_frame("http://www.example.com/geolocation"); | |
1001 NavigateAndCommit(requesting_frame); | |
1002 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | |
1003 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
1004 RequestGeolocationPermission( | |
1005 web_contents(), RequestID(0), requesting_frame, true); | |
1006 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
1007 } | |
1008 #endif | |
OLD | NEW |