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/permission_bubble_manager.h" | |
24 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" | |
25 #include "chrome/browser/ui/website_settings/permission_bubble_view.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 |
56 class MockPermissionBubbleView : public PermissionBubbleView { | |
57 public: | |
58 MockPermissionBubbleView() {} | |
59 virtual ~MockPermissionBubbleView() {} | |
60 | |
61 virtual void SetDelegate(Delegate* delegate) override { | |
62 } | |
63 virtual void Show( | |
64 const std::vector<PermissionBubbleRequest*>& requests, | |
65 const std::vector<bool>& accept_state, | |
66 bool customization_mode) override { | |
67 } | |
68 | |
69 virtual bool CanAcceptRequestUpdate() override { | |
70 return true; | |
71 } | |
72 | |
73 virtual void Hide() override { | |
74 } | |
75 | |
76 virtual bool IsVisible() override { | |
77 return false; | |
78 } | |
79 }; | |
51 | 80 |
52 // ClosedInfoBarTracker ------------------------------------------------------- | 81 // ClosedInfoBarTracker ------------------------------------------------------- |
53 | 82 |
54 // We need to track which infobars were closed. | 83 // We need to track which infobars were closed. |
55 class ClosedInfoBarTracker : public content::NotificationObserver { | 84 class ClosedInfoBarTracker : public content::NotificationObserver { |
56 public: | 85 public: |
57 ClosedInfoBarTracker(); | 86 ClosedInfoBarTracker(); |
58 ~ClosedInfoBarTracker() override; | 87 ~ClosedInfoBarTracker() override; |
59 | 88 |
60 // content::NotificationObserver: | 89 // content::NotificationObserver: |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 PermissionRequestID RequestIDForTab(int tab, int bridge_id); | 141 PermissionRequestID RequestIDForTab(int tab, int bridge_id); |
113 InfoBarService* infobar_service() { | 142 InfoBarService* infobar_service() { |
114 return InfoBarService::FromWebContents(web_contents()); | 143 return InfoBarService::FromWebContents(web_contents()); |
115 } | 144 } |
116 InfoBarService* infobar_service_for_tab(int tab) { | 145 InfoBarService* infobar_service_for_tab(int tab) { |
117 return InfoBarService::FromWebContents(extra_tabs_[tab]); | 146 return InfoBarService::FromWebContents(extra_tabs_[tab]); |
118 } | 147 } |
119 | 148 |
120 void RequestGeolocationPermission(content::WebContents* web_contents, | 149 void RequestGeolocationPermission(content::WebContents* web_contents, |
121 const PermissionRequestID& id, | 150 const PermissionRequestID& id, |
122 const GURL& requesting_frame); | 151 const GURL& requesting_frame, |
123 | 152 bool user_gesture); |
124 void PermissionResponse(const PermissionRequestID& id, | 153 void PermissionResponse(const PermissionRequestID& id, |
125 bool allowed); | 154 bool allowed); |
126 void CheckPermissionMessageSent(int bridge_id, bool allowed); | 155 void CheckPermissionMessageSent(int bridge_id, bool allowed); |
127 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); | 156 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); |
128 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, | 157 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, |
129 int bridge_id, | 158 int bridge_id, |
130 bool allowed); | 159 bool allowed); |
131 void AddNewTab(const GURL& url); | 160 void AddNewTab(const GURL& url); |
132 void CheckTabContentsState(const GURL& requesting_frame, | 161 void CheckTabContentsState(const GURL& requesting_frame, |
133 ContentSetting expected_content_setting); | 162 ContentSetting expected_content_setting); |
163 base::string16 GetFirstRequestText(PermissionBubbleManager* mgr); | |
164 int GetBubblesQueueSize(PermissionBubbleManager* mgr); | |
165 void AcceptBubble(PermissionBubbleManager* mgr); | |
166 void DenyBubble(PermissionBubbleManager* mgr); | |
167 void CloseBubble(PermissionBubbleManager* mgr); | |
168 void BubbleManagerDocumentLoadCompleted(); | |
169 void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents); | |
134 | 170 |
135 // owned by the browser context | 171 // owned by the browser context |
136 GeolocationPermissionContext* geolocation_permission_context_; | 172 GeolocationPermissionContext* geolocation_permission_context_; |
137 ClosedInfoBarTracker closed_infobar_tracker_; | 173 ClosedInfoBarTracker closed_infobar_tracker_; |
174 MockPermissionBubbleView bubble_view_; | |
138 ScopedVector<content::WebContents> extra_tabs_; | 175 ScopedVector<content::WebContents> extra_tabs_; |
139 | 176 |
140 // A map between renderer child id and a pair represending the bridge id and | 177 // A map between renderer child id and a pair represending the bridge id and |
141 // whether the requested permission was allowed. | 178 // whether the requested permission was allowed. |
142 base::hash_map<int, std::pair<int, bool> > responses_; | 179 base::hash_map<int, std::pair<int, bool> > responses_; |
143 }; | 180 }; |
144 | 181 |
145 PermissionRequestID GeolocationPermissionContextTests::RequestID( | 182 PermissionRequestID GeolocationPermissionContextTests::RequestID( |
146 int bridge_id) { | 183 int bridge_id) { |
147 return PermissionRequestID( | 184 return PermissionRequestID( |
148 web_contents()->GetRenderProcessHost()->GetID(), | 185 web_contents()->GetRenderProcessHost()->GetID(), |
149 web_contents()->GetRenderViewHost()->GetRoutingID(), | 186 web_contents()->GetRenderViewHost()->GetRoutingID(), |
150 bridge_id, | 187 bridge_id, |
151 GURL()); | 188 GURL()); |
152 } | 189 } |
153 | 190 |
154 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( | 191 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( |
155 int tab, | 192 int tab, |
156 int bridge_id) { | 193 int bridge_id) { |
157 return PermissionRequestID( | 194 return PermissionRequestID( |
158 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), | 195 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), |
159 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), | 196 extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), |
160 bridge_id, | 197 bridge_id, |
161 GURL()); | 198 GURL()); |
162 } | 199 } |
163 | 200 |
164 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 201 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
165 content::WebContents* web_contents, | 202 content::WebContents* web_contents, |
166 const PermissionRequestID& id, | 203 const PermissionRequestID& id, |
167 const GURL& requesting_frame) { | 204 const GURL& requesting_frame, |
205 bool user_gesture) { | |
168 geolocation_permission_context_->RequestPermission( | 206 geolocation_permission_context_->RequestPermission( |
169 web_contents, id, requesting_frame, false, | 207 web_contents, id, requesting_frame, user_gesture, |
170 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, | 208 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, |
171 base::Unretained(this), id)); | 209 base::Unretained(this), id)); |
172 content::RunAllBlockingPoolTasksUntilIdle(); | 210 content::RunAllBlockingPoolTasksUntilIdle(); |
173 } | 211 } |
174 | 212 |
175 void GeolocationPermissionContextTests::PermissionResponse( | 213 void GeolocationPermissionContextTests::PermissionResponse( |
176 const PermissionRequestID& id, | 214 const PermissionRequestID& id, |
177 bool allowed) { | 215 bool allowed) { |
178 responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed); | 216 responses_[id.render_process_id()] = std::make_pair(id.bridge_id(), allowed); |
179 } | 217 } |
180 | 218 |
181 void GeolocationPermissionContextTests::CheckPermissionMessageSent( | 219 void GeolocationPermissionContextTests::CheckPermissionMessageSent( |
182 int bridge_id, | 220 int bridge_id, |
(...skipping 26 matching lines...) Expand all Loading... | |
209 new_tab->GetController().LoadURL( | 247 new_tab->GetController().LoadURL( |
210 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); | 248 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); |
211 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) | 249 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) |
212 ->SendNavigate(extra_tabs_.size() + 1, url); | 250 ->SendNavigate(extra_tabs_.size() + 1, url); |
213 | 251 |
214 // Set up required helpers, and make this be as "tabby" as the code requires. | 252 // Set up required helpers, and make this be as "tabby" as the code requires. |
215 #if defined(ENABLE_EXTENSIONS) | 253 #if defined(ENABLE_EXTENSIONS) |
216 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); | 254 extensions::SetViewType(new_tab, extensions::VIEW_TYPE_TAB_CONTENTS); |
217 #endif | 255 #endif |
218 InfoBarService::CreateForWebContents(new_tab); | 256 InfoBarService::CreateForWebContents(new_tab); |
257 PermissionBubbleManager::CreateForWebContents(new_tab); | |
258 PermissionBubbleManager::FromWebContents(new_tab)->SetView( | |
259 &bubble_view_); | |
219 | 260 |
220 extra_tabs_.push_back(new_tab); | 261 extra_tabs_.push_back(new_tab); |
221 } | 262 } |
222 | 263 |
223 void GeolocationPermissionContextTests::CheckTabContentsState( | 264 void GeolocationPermissionContextTests::CheckTabContentsState( |
224 const GURL& requesting_frame, | 265 const GURL& requesting_frame, |
225 ContentSetting expected_content_setting) { | 266 ContentSetting expected_content_setting) { |
226 TabSpecificContentSettings* content_settings = | 267 TabSpecificContentSettings* content_settings = |
227 TabSpecificContentSettings::FromWebContents(web_contents()); | 268 TabSpecificContentSettings::FromWebContents(web_contents()); |
228 const ContentSettingsUsagesState::StateMap& state_map = | 269 const ContentSettingsUsagesState::StateMap& state_map = |
(...skipping 14 matching lines...) Expand all Loading... | |
243 #if defined(ENABLE_EXTENSIONS) | 284 #if defined(ENABLE_EXTENSIONS) |
244 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); | 285 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); |
245 #endif | 286 #endif |
246 InfoBarService::CreateForWebContents(web_contents()); | 287 InfoBarService::CreateForWebContents(web_contents()); |
247 TabSpecificContentSettings::CreateForWebContents(web_contents()); | 288 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
248 #if defined(OS_ANDROID) | 289 #if defined(OS_ANDROID) |
249 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 290 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); |
250 #endif | 291 #endif |
251 geolocation_permission_context_ = | 292 geolocation_permission_context_ = |
252 GeolocationPermissionContextFactory::GetForProfile(profile()); | 293 GeolocationPermissionContextFactory::GetForProfile(profile()); |
294 PermissionBubbleManager::CreateForWebContents(web_contents()); | |
295 PermissionBubbleManager::FromWebContents(web_contents())->SetView( | |
296 &bubble_view_); | |
253 } | 297 } |
254 | 298 |
255 void GeolocationPermissionContextTests::TearDown() { | 299 void GeolocationPermissionContextTests::TearDown() { |
256 extra_tabs_.clear(); | 300 extra_tabs_.clear(); |
257 ChromeRenderViewHostTestHarness::TearDown(); | 301 ChromeRenderViewHostTestHarness::TearDown(); |
258 } | 302 } |
259 | 303 |
304 base::string16 GeolocationPermissionContextTests::GetFirstRequestText( | |
305 PermissionBubbleManager* mgr) { | |
Michael van Ouwerkerk
2014/12/17 17:20:19
s/mgr/manager/ - http://google-styleguide.googleco
felt
2014/12/18 22:09:10
Done.
| |
306 return mgr->requests_.front()->GetMessageText(); | |
307 } | |
308 | |
309 int GeolocationPermissionContextTests::GetBubblesQueueSize( | |
310 PermissionBubbleManager* mgr) { | |
311 return static_cast<int>(mgr->requests_.size()); | |
312 } | |
313 | |
314 void GeolocationPermissionContextTests::AcceptBubble( | |
315 PermissionBubbleManager* mgr) { | |
316 mgr->Accept(); | |
317 } | |
318 | |
319 void GeolocationPermissionContextTests::DenyBubble( | |
320 PermissionBubbleManager* mgr) { | |
321 mgr->Deny(); | |
322 } | |
323 | |
324 void GeolocationPermissionContextTests::CloseBubble( | |
325 PermissionBubbleManager* mgr) { | |
326 mgr->Closing(); | |
327 } | |
328 | |
329 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted() { | |
330 PermissionBubbleManager::FromWebContents(web_contents())-> | |
331 DocumentOnLoadCompletedInMainFrame(); | |
332 } | |
333 | |
334 void GeolocationPermissionContextTests::BubbleManagerDocumentLoadCompleted( | |
335 content::WebContents* web_contents) { | |
336 PermissionBubbleManager::FromWebContents(web_contents)-> | |
337 DocumentOnLoadCompletedInMainFrame(); | |
338 } | |
339 | |
340 // Needed to parameterize the tests for both infobars & permission bubbles. | |
341 class GeolocationPermissionContextParamTests : | |
342 public GeolocationPermissionContextTests, | |
343 public ::testing::WithParamInterface<bool> { | |
344 protected: | |
345 GeolocationPermissionContextParamTests() {} | |
346 ~GeolocationPermissionContextParamTests() override {} | |
347 | |
348 bool BubbleEnabled() { | |
349 return GetParam(); | |
350 } | |
351 | |
352 void SetUp() override { | |
353 GeolocationPermissionContextTests::SetUp(); | |
354 #if !defined(OS_ANDROID) | |
355 if (BubbleEnabled()) { | |
356 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
357 switches::kEnablePermissionsBubbles); | |
358 EXPECT_TRUE(PermissionBubbleManager::Enabled()); | |
359 } else { | |
360 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
361 switches::kDisablePermissionsBubbles); | |
362 EXPECT_FALSE(PermissionBubbleManager::Enabled()); | |
363 } | |
364 #endif | |
365 } | |
366 private: | |
367 DISALLOW_COPY_AND_ASSIGN(GeolocationPermissionContextParamTests); | |
368 }; | |
369 | |
260 // Tests ---------------------------------------------------------------------- | 370 // Tests ---------------------------------------------------------------------- |
261 | 371 |
262 TEST_F(GeolocationPermissionContextTests, SinglePermission) { | 372 TEST_P(GeolocationPermissionContextParamTests, SinglePermissionInfobar) { |
373 if (BubbleEnabled()) return; | |
374 | |
263 GURL requesting_frame("http://www.example.com/geolocation"); | 375 GURL requesting_frame("http://www.example.com/geolocation"); |
264 NavigateAndCommit(requesting_frame); | 376 NavigateAndCommit(requesting_frame); |
265 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 377 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
266 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 378 RequestGeolocationPermission( |
379 web_contents(), RequestID(0), requesting_frame, true); | |
267 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 380 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
268 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 381 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); |
269 ConfirmInfoBarDelegate* infobar_delegate = | 382 ConfirmInfoBarDelegate* infobar_delegate = |
270 infobar->delegate()->AsConfirmInfoBarDelegate(); | 383 infobar->delegate()->AsConfirmInfoBarDelegate(); |
271 ASSERT_TRUE(infobar_delegate); | 384 ASSERT_TRUE(infobar_delegate); |
272 infobar_delegate->Cancel(); | 385 infobar_delegate->Cancel(); |
273 infobar_service()->RemoveInfoBar(infobar); | 386 infobar_service()->RemoveInfoBar(infobar); |
274 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 387 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
275 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 388 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); |
276 } | 389 } |
277 | 390 |
278 #if defined(OS_ANDROID) | 391 TEST_P(GeolocationPermissionContextParamTests, SinglePermissionBubble) { |
279 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | 392 if (!BubbleEnabled()) return; |
393 | |
280 GURL requesting_frame("http://www.example.com/geolocation"); | 394 GURL requesting_frame("http://www.example.com/geolocation"); |
281 NavigateAndCommit(requesting_frame); | 395 NavigateAndCommit(requesting_frame); |
282 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | 396 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 | 397 |
292 Reload(); | 398 PermissionBubbleManager* mgr = |
293 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | 399 PermissionBubbleManager::FromWebContents(web_contents()); |
294 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 400 EXPECT_EQ(0, GetBubblesQueueSize(mgr)); |
295 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 401 RequestGeolocationPermission( |
296 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 402 web_contents(), RequestID(0), requesting_frame, true); |
403 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); | |
297 } | 404 } |
298 | 405 |
299 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { | 406 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"); | 407 GURL requesting_frame_0("http://www.example.com/geolocation"); |
326 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 408 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
327 EXPECT_EQ(CONTENT_SETTING_ASK, | 409 EXPECT_EQ(CONTENT_SETTING_ASK, |
328 profile()->GetHostContentSettingsMap()->GetContentSetting( | 410 profile()->GetHostContentSettingsMap()->GetContentSetting( |
329 requesting_frame_0, requesting_frame_0, | 411 requesting_frame_0, requesting_frame_0, |
330 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 412 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
331 EXPECT_EQ(CONTENT_SETTING_ASK, | 413 EXPECT_EQ(CONTENT_SETTING_ASK, |
332 profile()->GetHostContentSettingsMap()->GetContentSetting( | 414 profile()->GetHostContentSettingsMap()->GetContentSetting( |
333 requesting_frame_1, requesting_frame_0, | 415 requesting_frame_1, requesting_frame_0, |
334 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 416 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
335 | 417 |
418 PermissionBubbleManager* mgr = | |
419 PermissionBubbleManager::FromWebContents(web_contents()); | |
420 infobars::InfoBar* infobar_0; | |
421 infobars::InfoBar* infobar_1; | |
422 ConfirmInfoBarDelegate* infobar_delegate_0; | |
423 ConfirmInfoBarDelegate* infobar_delegate_1; | |
336 NavigateAndCommit(requesting_frame_0); | 424 NavigateAndCommit(requesting_frame_0); |
337 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 425 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
426 | |
427 // Check that no permission requests have happened yet. | |
428 if (BubbleEnabled()) | |
429 EXPECT_EQ(0, GetBubblesQueueSize(mgr)); | |
430 else | |
431 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
432 | |
338 // Request permission for two frames. | 433 // Request permission for two frames. |
339 RequestGeolocationPermission( | 434 RequestGeolocationPermission( |
340 web_contents(), RequestID(0), requesting_frame_0); | 435 web_contents(), RequestID(0), requesting_frame_0, BubbleEnabled()); |
341 RequestGeolocationPermission( | 436 RequestGeolocationPermission( |
342 web_contents(), RequestID(1), requesting_frame_1); | 437 web_contents(), RequestID(1), requesting_frame_1, BubbleEnabled()); |
438 | |
343 // Ensure only one infobar is created. | 439 // Ensure only one infobar is created. |
344 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 440 base::string16 text_0; |
345 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 441 if (BubbleEnabled()) { |
346 ConfirmInfoBarDelegate* infobar_delegate_0 = | 442 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
347 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 443 text_0 = GetFirstRequestText(mgr); |
348 ASSERT_TRUE(infobar_delegate_0); | 444 } else { |
349 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 445 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
446 infobar_0 = infobar_service()->infobar_at(0); | |
447 infobar_delegate_0 = infobar_0->delegate()->AsConfirmInfoBarDelegate(); | |
448 ASSERT_TRUE(infobar_delegate_0); | |
449 text_0 = infobar_delegate_0->GetMessageText(); | |
450 } | |
350 | 451 |
351 // Accept the first frame. | 452 // Accept the first frame. |
352 infobar_delegate_0->Accept(); | 453 if (BubbleEnabled()) |
454 AcceptBubble(mgr); | |
455 else | |
456 infobar_delegate_0->Accept(); | |
353 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 457 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
354 CheckPermissionMessageSent(0, true); | 458 CheckPermissionMessageSent(0, true); |
459 if (!BubbleEnabled()) { | |
460 infobar_service()->RemoveInfoBar(infobar_0); | |
461 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
462 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | |
463 closed_infobar_tracker_.Clear(); | |
464 } | |
355 | 465 |
356 infobar_service()->RemoveInfoBar(infobar_0); | 466 // Now we should have a new request for the second frame. |
357 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 467 base::string16 text_1; |
358 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 468 if (BubbleEnabled()) { |
359 closed_infobar_tracker_.Clear(); | 469 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
360 // Now we should have a new infobar for the second frame. | 470 text_1 = GetFirstRequestText(mgr); |
361 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 471 } else { |
472 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
473 infobar_1 = infobar_service()->infobar_at(0); | |
474 infobar_delegate_1 = infobar_1->delegate()->AsConfirmInfoBarDelegate(); | |
475 ASSERT_TRUE(infobar_delegate_1); | |
476 text_1 = infobar_delegate_1->GetMessageText(); | |
477 } | |
362 | 478 |
363 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 479 // 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); | 480 EXPECT_NE(text_0, text_1); |
369 | 481 |
370 // Cancel (block) this frame. | 482 // Cancel (block) this frame. |
371 infobar_delegate_1->Cancel(); | 483 if (BubbleEnabled()) |
484 DenyBubble(mgr); | |
485 else | |
486 infobar_delegate_1->Cancel(); | |
372 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); | 487 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
373 CheckPermissionMessageSent(1, false); | 488 CheckPermissionMessageSent(1, false); |
374 infobar_service()->RemoveInfoBar(infobar_1); | 489 if (!BubbleEnabled()) { |
375 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 490 infobar_service()->RemoveInfoBar(infobar_1); |
376 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 491 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
377 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 492 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); |
493 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
494 } | |
495 | |
378 // Ensure the persisted permissions are ok. | 496 // Ensure the persisted permissions are ok. |
379 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 497 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
380 profile()->GetHostContentSettingsMap()->GetContentSetting( | 498 profile()->GetHostContentSettingsMap()->GetContentSetting( |
381 requesting_frame_0, requesting_frame_0, | 499 requesting_frame_0, requesting_frame_0, |
382 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 500 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
383 | 501 |
384 EXPECT_EQ(CONTENT_SETTING_BLOCK, | 502 EXPECT_EQ(CONTENT_SETTING_BLOCK, |
385 profile()->GetHostContentSettingsMap()->GetContentSetting( | 503 profile()->GetHostContentSettingsMap()->GetContentSetting( |
386 requesting_frame_1, requesting_frame_0, | 504 requesting_frame_1, requesting_frame_0, |
387 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 505 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
388 } | 506 } |
389 | 507 |
390 TEST_F(GeolocationPermissionContextTests, HashIsIgnored) { | 508 TEST_P(GeolocationPermissionContextParamTests, HashIsIgnored) { |
509 PermissionBubbleManager* mgr = | |
510 PermissionBubbleManager::FromWebContents(web_contents()); | |
511 infobars::InfoBar* infobar; | |
512 ConfirmInfoBarDelegate* infobar_delegate; | |
513 | |
391 GURL url_a("http://www.example.com/geolocation#a"); | 514 GURL url_a("http://www.example.com/geolocation#a"); |
392 GURL url_b("http://www.example.com/geolocation#b"); | 515 GURL url_b("http://www.example.com/geolocation#b"); |
393 | 516 |
394 // Navigate to the first url and check permission is requested. | 517 // Navigate to the first url. |
395 NavigateAndCommit(url_a); | 518 NavigateAndCommit(url_a); |
396 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 519 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
397 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 520 |
398 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 521 // Check permission is requested. |
399 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 522 if (BubbleEnabled()) { |
Michael van Ouwerkerk
2014/12/17 17:20:19
These kinds of branches make the code harder to re
felt
2014/12/18 22:09:09
OK, I added a few helper methods. I think the code
| |
400 ConfirmInfoBarDelegate* infobar_delegate = | 523 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); |
401 infobar->delegate()->AsConfirmInfoBarDelegate(); | 524 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, true); |
402 ASSERT_TRUE(infobar_delegate); | 525 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
526 } else { | |
527 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
528 RequestGeolocationPermission(web_contents(), RequestID(0), url_a, false); | |
529 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
530 infobar = infobar_service()->infobar_at(0); | |
531 infobar_delegate = | |
532 infobar->delegate()->AsConfirmInfoBarDelegate(); | |
533 ASSERT_TRUE(infobar_delegate); | |
534 } | |
403 | 535 |
404 // Change the hash, we'll still be on the same page. | 536 // Change the hash, we'll still be on the same page. |
405 NavigateAndCommit(url_b); | 537 NavigateAndCommit(url_b); |
538 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); | |
406 | 539 |
407 // Accept. | 540 // Accept. |
408 infobar_delegate->Accept(); | 541 if (BubbleEnabled()) |
542 AcceptBubble(mgr); | |
543 else | |
544 infobar_delegate->Accept(); | |
409 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); | 545 CheckTabContentsState(url_a, CONTENT_SETTING_ALLOW); |
410 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); | 546 CheckTabContentsState(url_b, CONTENT_SETTING_ALLOW); |
411 CheckPermissionMessageSent(0, true); | 547 CheckPermissionMessageSent(0, true); |
412 | 548 |
413 // Cleanup. | 549 // Cleanup. |
414 infobar_service()->RemoveInfoBar(infobar); | 550 if (!BubbleEnabled()) { |
415 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 551 infobar_service()->RemoveInfoBar(infobar); |
416 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 552 EXPECT_EQ(1U, closed_infobar_tracker_.size()); |
553 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar)); | |
554 } | |
417 } | 555 } |
418 | 556 |
419 TEST_F(GeolocationPermissionContextTests, PermissionForFileScheme) { | 557 TEST_P(GeolocationPermissionContextParamTests, PermissionForFileScheme) { |
558 // TODO(felt): The bubble is rejecting file:// permission requests. | |
559 // Fix and enable this test. | |
560 if (BubbleEnabled()) return; | |
561 | |
562 PermissionBubbleManager* mgr = | |
563 PermissionBubbleManager::FromWebContents(web_contents()); | |
564 infobars::InfoBar* infobar; | |
565 ConfirmInfoBarDelegate* infobar_delegate; | |
566 | |
420 GURL requesting_frame("file://example/geolocation.html"); | 567 GURL requesting_frame("file://example/geolocation.html"); |
421 NavigateAndCommit(requesting_frame); | 568 NavigateAndCommit(requesting_frame); |
422 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 569 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
423 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 570 |
424 EXPECT_EQ(1U, infobar_service()->infobar_count()); | 571 // Check permission is requested. |
425 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 572 if (BubbleEnabled()) { |
426 ConfirmInfoBarDelegate* infobar_delegate = | 573 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); |
427 infobar->delegate()->AsConfirmInfoBarDelegate(); | 574 RequestGeolocationPermission( |
428 ASSERT_TRUE(infobar_delegate); | 575 web_contents(), RequestID(0), requesting_frame, true); |
576 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); | |
577 } else { | |
578 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
579 RequestGeolocationPermission( | |
580 web_contents(), RequestID(0), requesting_frame, false); | |
581 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
582 infobar = infobar_service()->infobar_at(0); | |
583 infobar_delegate = infobar->delegate()->AsConfirmInfoBarDelegate(); | |
584 ASSERT_TRUE(infobar_delegate); | |
585 } | |
586 | |
429 // Accept the frame. | 587 // Accept the frame. |
430 infobar_delegate->Accept(); | 588 if (BubbleEnabled()) |
589 AcceptBubble(mgr); | |
590 else | |
591 infobar_delegate->Accept(); | |
431 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 592 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
432 CheckPermissionMessageSent(0, true); | 593 CheckPermissionMessageSent(0, true); |
433 infobar_service()->RemoveInfoBar(infobar); | |
434 | 594 |
435 // Make sure the setting is not stored. | 595 // Make sure the setting is not stored. |
436 EXPECT_EQ(CONTENT_SETTING_ASK, | 596 EXPECT_EQ(CONTENT_SETTING_ASK, |
437 profile()->GetHostContentSettingsMap()->GetContentSetting( | 597 profile()->GetHostContentSettingsMap()->GetContentSetting( |
438 requesting_frame, | 598 requesting_frame, |
439 requesting_frame, | 599 requesting_frame, |
440 CONTENT_SETTINGS_TYPE_GEOLOCATION, | 600 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
441 std::string())); | 601 std::string())); |
442 } | 602 } |
443 | 603 |
444 TEST_F(GeolocationPermissionContextTests, CancelGeolocationPermissionRequest) { | 604 TEST_P(GeolocationPermissionContextParamTests, |
445 GURL requesting_frame_0("http://www.example.com/geolocation"); | 605 CancelGeolocationPermissionRequest) { |
446 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 606 GURL frame_0("http://www.example.com/geolocation"); |
447 EXPECT_EQ(CONTENT_SETTING_ASK, | 607 GURL frame_1("http://www.example-2.com/geolocation"); |
448 profile()->GetHostContentSettingsMap()->GetContentSetting( | 608 PermissionBubbleManager* mgr = |
449 requesting_frame_0, requesting_frame_0, | 609 PermissionBubbleManager::FromWebContents(web_contents()); |
450 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 610 EXPECT_EQ(CONTENT_SETTING_ASK, |
451 | 611 profile()->GetHostContentSettingsMap()->GetContentSetting( |
452 EXPECT_EQ(CONTENT_SETTING_ASK, | 612 frame_0, frame_0, |
453 profile()->GetHostContentSettingsMap()->GetContentSetting( | 613 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
454 requesting_frame_1, requesting_frame_0, | 614 |
455 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 615 EXPECT_EQ(CONTENT_SETTING_ASK, |
456 | 616 profile()->GetHostContentSettingsMap()->GetContentSetting( |
457 NavigateAndCommit(requesting_frame_0); | 617 frame_1, frame_0, |
458 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 618 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
619 | |
620 NavigateAndCommit(frame_0); | |
621 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); | |
622 | |
623 if (BubbleEnabled()) | |
624 EXPECT_EQ(0, GetBubblesQueueSize(mgr)); | |
625 else | |
626 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
459 | 627 |
460 // Request permission for two frames. | 628 // Request permission for two frames. |
461 RequestGeolocationPermission( | 629 RequestGeolocationPermission( |
462 web_contents(), RequestID(0), requesting_frame_0); | 630 web_contents(), RequestID(0), frame_0, BubbleEnabled()); |
463 RequestGeolocationPermission( | 631 RequestGeolocationPermission( |
464 web_contents(), RequestID(1), requesting_frame_1); | 632 web_contents(), RequestID(1), frame_1, BubbleEnabled()); |
465 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 633 if (BubbleEnabled()) |
466 | 634 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
467 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 635 else |
468 ConfirmInfoBarDelegate* infobar_delegate_0 = | 636 ASSERT_EQ(1U, infobar_service()->infobar_count()); |
469 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 637 |
470 ASSERT_TRUE(infobar_delegate_0); | 638 // Get the first permission request text. |
471 base::string16 text_0 = infobar_delegate_0->GetMessageText(); | 639 base::string16 text_0; |
472 | 640 infobars::InfoBar* infobar_0; |
473 // Simulate the frame going away, ensure the infobar for this frame | 641 if (BubbleEnabled()) { |
474 // is removed and the next pending infobar is created. | 642 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
475 geolocation_permission_context_->CancelPermissionRequest(web_contents(), | 643 text_0 = GetFirstRequestText(mgr); |
476 RequestID(0)); | 644 } else { |
477 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 645 infobar_0 = infobar_service()->infobar_at(0); |
478 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 646 ConfirmInfoBarDelegate* infobar_delegate_0 = |
479 closed_infobar_tracker_.Clear(); | 647 infobar_0->delegate()->AsConfirmInfoBarDelegate(); |
480 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 648 ASSERT_TRUE(infobar_delegate_0); |
481 | 649 text_0 = infobar_delegate_0->GetMessageText(); |
482 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 650 } |
483 ConfirmInfoBarDelegate* infobar_delegate_1 = | 651 ASSERT_NE(base::string16(), text_0); |
484 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 652 |
485 ASSERT_TRUE(infobar_delegate_1); | 653 // Simulate frame 0 going away; the request should be removed. |
486 base::string16 text_1 = infobar_delegate_1->GetMessageText(); | 654 if (BubbleEnabled()) { |
655 CloseBubble(mgr); | |
656 } else { | |
657 geolocation_permission_context_->CancelPermissionRequest(web_contents(), | |
658 RequestID(0)); | |
659 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
660 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | |
661 closed_infobar_tracker_.Clear(); | |
662 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
663 } | |
664 | |
665 // Check that the next pending request is created correctly. | |
666 base::string16 text_1; | |
667 infobars::InfoBar* infobar_1; | |
668 ConfirmInfoBarDelegate* infobar_delegate_1; | |
669 if (BubbleEnabled()) { | |
670 base::string16 text_1 = GetFirstRequestText(mgr); | |
671 } else { | |
672 infobar_1 = infobar_service()->infobar_at(0); | |
673 infobar_delegate_1 = infobar_1->delegate()->AsConfirmInfoBarDelegate(); | |
674 ASSERT_TRUE(infobar_delegate_1); | |
675 text_1 = infobar_delegate_1->GetMessageText(); | |
676 } | |
487 EXPECT_NE(text_0, text_1); | 677 EXPECT_NE(text_0, text_1); |
488 | 678 |
489 // Allow this frame. | 679 // Allow this frame and check that it worked. |
490 infobar_delegate_1->Accept(); | 680 if (BubbleEnabled()) { |
491 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 681 AcceptBubble(mgr); |
682 } else { | |
683 infobar_delegate_1->Accept(); | |
684 infobar_service()->RemoveInfoBar(infobar_1); | |
685 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
686 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | |
687 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
688 } | |
689 CheckTabContentsState(frame_1, CONTENT_SETTING_ALLOW); | |
492 CheckPermissionMessageSent(1, true); | 690 CheckPermissionMessageSent(1, true); |
493 infobar_service()->RemoveInfoBar(infobar_1); | 691 |
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. | 692 // Ensure the persisted permissions are ok. |
498 EXPECT_EQ(CONTENT_SETTING_ASK, | 693 EXPECT_EQ(CONTENT_SETTING_ASK, |
499 profile()->GetHostContentSettingsMap()->GetContentSetting( | 694 profile()->GetHostContentSettingsMap()->GetContentSetting( |
500 requesting_frame_0, requesting_frame_0, | 695 frame_0, frame_0, |
501 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 696 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
502 | 697 |
503 EXPECT_EQ(CONTENT_SETTING_ALLOW, | 698 EXPECT_EQ(CONTENT_SETTING_ALLOW, |
504 profile()->GetHostContentSettingsMap()->GetContentSetting( | 699 profile()->GetHostContentSettingsMap()->GetContentSetting( |
505 requesting_frame_1, requesting_frame_0, | 700 frame_1, frame_0, |
506 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 701 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
507 } | 702 } |
508 | 703 |
509 TEST_F(GeolocationPermissionContextTests, InvalidURL) { | 704 TEST_P(GeolocationPermissionContextParamTests, InvalidURL) { |
705 // Navigate to the first url. | |
510 GURL invalid_embedder("about:blank"); | 706 GURL invalid_embedder("about:blank"); |
511 GURL requesting_frame; | 707 GURL requesting_frame; |
512 NavigateAndCommit(invalid_embedder); | 708 NavigateAndCommit(invalid_embedder); |
513 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 709 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
514 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 710 |
515 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 711 // Nothing should be displayed. |
712 if (BubbleEnabled()) { | |
713 PermissionBubbleManager* mgr = | |
714 PermissionBubbleManager::FromWebContents(web_contents()); | |
715 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); | |
716 RequestGeolocationPermission( | |
717 web_contents(), RequestID(0), requesting_frame, true); | |
718 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); | |
719 } else { | |
720 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
721 RequestGeolocationPermission( | |
722 web_contents(), RequestID(0), requesting_frame, false); | |
723 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
724 } | |
516 CheckPermissionMessageSent(0, false); | 725 CheckPermissionMessageSent(0, false); |
517 } | 726 } |
518 | 727 |
519 TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { | 728 TEST_P(GeolocationPermissionContextParamTests, SameOriginMultipleTabs) { |
520 GURL url_a("http://www.example.com/geolocation"); | 729 GURL url_a("http://www.example.com/geolocation"); |
521 GURL url_b("http://www.example-2.com/geolocation"); | 730 GURL url_b("http://www.example-2.com/geolocation"); |
522 NavigateAndCommit(url_a); | 731 NavigateAndCommit(url_a); // Tab A0 |
523 AddNewTab(url_b); | 732 AddNewTab(url_b); // Tab B (extra_tabs_[0]) |
524 AddNewTab(url_a); | 733 AddNewTab(url_a); // Tab A1 (extra_tabs_[1]) |
525 | 734 if (BubbleEnabled()) { |
526 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 735 BubbleManagerDocumentLoadCompleted(); |
527 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 736 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]); |
528 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 737 BubbleManagerDocumentLoadCompleted(extra_tabs_[1]); |
529 | 738 } |
530 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_b); | 739 PermissionBubbleManager* mgr_a0 = |
531 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 740 PermissionBubbleManager::FromWebContents(web_contents()); |
532 | 741 PermissionBubbleManager* mgr_b = |
533 RequestGeolocationPermission(extra_tabs_[1], RequestIDForTab(1, 0), url_a); | 742 PermissionBubbleManager::FromWebContents(extra_tabs_[0]); |
534 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); | 743 PermissionBubbleManager* mgr_a1 = |
535 | 744 PermissionBubbleManager::FromWebContents(extra_tabs_[1]); |
536 infobars::InfoBar* removed_infobar = | 745 |
537 infobar_service_for_tab(1)->infobar_at(0); | 746 // Request permission in all three tabs. |
538 | 747 RequestGeolocationPermission( |
539 // Accept the first tab. | 748 web_contents(), RequestID(0), url_a, BubbleEnabled()); |
540 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 749 RequestGeolocationPermission( |
541 ConfirmInfoBarDelegate* infobar_delegate_0 = | 750 extra_tabs_[0], RequestIDForTab(0, 0), url_b, BubbleEnabled()); |
542 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 751 RequestGeolocationPermission( |
543 ASSERT_TRUE(infobar_delegate_0); | 752 extra_tabs_[1], RequestIDForTab(1, 0), url_a, BubbleEnabled()); |
544 infobar_delegate_0->Accept(); | 753 infobars::InfoBar* infobar_a1; |
754 if (BubbleEnabled()) { | |
755 ASSERT_EQ(1, GetBubblesQueueSize(mgr_a0)); | |
756 ASSERT_EQ(1, GetBubblesQueueSize(mgr_b)); | |
757 ASSERT_EQ(1, GetBubblesQueueSize(mgr_a1)); | |
758 } else { | |
759 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
760 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | |
761 ASSERT_EQ(1U, infobar_service_for_tab(1)->infobar_count()); | |
762 } | |
763 | |
764 // Accept the permission in tab A0. | |
765 if (BubbleEnabled()) { | |
766 AcceptBubble(mgr_a0); | |
767 } else { | |
768 infobars::InfoBar* infobar_a0 = infobar_service()->infobar_at(0); | |
769 infobar_a1 = infobar_service_for_tab(1)->infobar_at(0); // Save for later. | |
770 ConfirmInfoBarDelegate* infobar_delegate_a0 = | |
771 infobar_a0->delegate()->AsConfirmInfoBarDelegate(); | |
772 ASSERT_TRUE(infobar_delegate_a0); | |
773 infobar_delegate_a0->Accept(); | |
774 infobar_service()->RemoveInfoBar(infobar_a0); | |
775 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | |
776 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0)); | |
777 } | |
545 CheckPermissionMessageSent(0, true); | 778 CheckPermissionMessageSent(0, true); |
546 infobar_service()->RemoveInfoBar(infobar_0); | 779 |
547 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 780 // Because they're the same origin, this will cause tab A1's infobar to |
548 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 781 // 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. | 782 // TODO(felt): Update this test when the bubble's behavior is changed. |
550 EXPECT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); | 783 if (BubbleEnabled()) { |
551 CheckPermissionMessageSentForTab(1, 0, true); | 784 ASSERT_EQ(1, GetBubblesQueueSize(mgr_a1)); |
552 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 785 } else { |
553 closed_infobar_tracker_.Clear(); | 786 CheckPermissionMessageSentForTab(1, 0, true); |
554 | 787 ASSERT_EQ(0U, infobar_service_for_tab(1)->infobar_count()); |
555 // But the other tab should still have the info bar... | 788 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1)); |
556 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 789 closed_infobar_tracker_.Clear(); |
557 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 790 } |
558 ConfirmInfoBarDelegate* infobar_delegate_1 = | 791 |
559 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 792 // Either way, tab B should still have a pending permission request. |
560 ASSERT_TRUE(infobar_delegate_1); | 793 if (BubbleEnabled()) |
561 infobar_delegate_1->Cancel(); | 794 ASSERT_EQ(1, GetBubblesQueueSize(mgr_b)); |
562 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 795 else |
563 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 796 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
564 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 797 } |
565 } | 798 |
566 | 799 TEST_P(GeolocationPermissionContextParamTests, QueuedOriginMultipleTabs) { |
567 TEST_F(GeolocationPermissionContextTests, QueuedOriginMultipleTabs) { | |
568 GURL url_a("http://www.example.com/geolocation"); | 800 GURL url_a("http://www.example.com/geolocation"); |
569 GURL url_b("http://www.example-2.com/geolocation"); | 801 GURL url_b("http://www.example-2.com/geolocation"); |
570 NavigateAndCommit(url_a); | 802 NavigateAndCommit(url_a); // Tab A0. |
571 AddNewTab(url_a); | 803 AddNewTab(url_a); // Tab A1. |
572 | 804 if (BubbleEnabled()) { |
573 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 805 BubbleManagerDocumentLoadCompleted(); |
574 RequestGeolocationPermission(web_contents(), RequestID(0), url_a); | 806 BubbleManagerDocumentLoadCompleted(extra_tabs_[0]); |
575 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 807 } |
576 | 808 PermissionBubbleManager* mgr_a0 = |
577 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 0), url_a); | 809 PermissionBubbleManager::FromWebContents(web_contents()); |
578 EXPECT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 810 PermissionBubbleManager* mgr_a1 = |
579 | 811 PermissionBubbleManager::FromWebContents(extra_tabs_[0]); |
580 RequestGeolocationPermission(extra_tabs_[0], RequestIDForTab(0, 1), url_b); | 812 infobars::InfoBar* infobar_a0; |
581 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 813 |
582 | 814 // Request permission in both tabs; the extra tab will have two permission |
583 infobars::InfoBar* removed_infobar = infobar_service()->infobar_at(0); | 815 // requests from two origins. |
584 | 816 RequestGeolocationPermission( |
585 // Accept the second tab. | 817 web_contents(), RequestID(0), url_a, BubbleEnabled()); |
586 infobars::InfoBar* infobar_0 = infobar_service_for_tab(0)->infobar_at(0); | 818 RequestGeolocationPermission( |
587 ConfirmInfoBarDelegate* infobar_delegate_0 = | 819 extra_tabs_[0], RequestIDForTab(0, 0), url_a, BubbleEnabled()); |
588 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 820 RequestGeolocationPermission( |
589 ASSERT_TRUE(infobar_delegate_0); | 821 extra_tabs_[0], RequestIDForTab(0, 1), url_b, BubbleEnabled()); |
590 infobar_delegate_0->Accept(); | 822 if (BubbleEnabled()) { |
823 ASSERT_EQ(1, GetBubblesQueueSize(mgr_a0)); | |
824 ASSERT_EQ(1, GetBubblesQueueSize(mgr_a1)); | |
825 } else { | |
826 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
827 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | |
828 infobar_a0 = infobar_service()->infobar_at(0); // Save for later. | |
829 } | |
830 | |
831 // Accept the first request in tab A1. | |
832 if (BubbleEnabled()) { | |
833 AcceptBubble(mgr_a1); | |
834 } else { | |
835 infobars::InfoBar* infobar_a1 = infobar_service_for_tab(0)->infobar_at(0); | |
836 ConfirmInfoBarDelegate* infobar_delegate_a1 = | |
837 infobar_a1->delegate()->AsConfirmInfoBarDelegate(); | |
838 ASSERT_TRUE(infobar_delegate_a1); | |
839 infobar_delegate_a1->Accept(); | |
840 infobar_service_for_tab(0)->RemoveInfoBar(infobar_a1); | |
841 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | |
842 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a1)); | |
843 } | |
591 CheckPermissionMessageSentForTab(0, 0, true); | 844 CheckPermissionMessageSentForTab(0, 0, true); |
592 infobar_service_for_tab(0)->RemoveInfoBar(infobar_0); | 845 |
593 EXPECT_EQ(2U, closed_infobar_tracker_.size()); | 846 // Because they're the same origin, this will cause tab A0's infobar to |
594 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_0)); | 847 // 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. | 848 // TODO(felt): Update this test when the bubble's behavior is changed. |
596 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 849 if (BubbleEnabled()) { |
597 CheckPermissionMessageSent(0, true); | 850 EXPECT_EQ(1, GetBubblesQueueSize(mgr_a0)); |
598 EXPECT_TRUE(closed_infobar_tracker_.Contains(removed_infobar)); | 851 } else { |
599 closed_infobar_tracker_.Clear(); | 852 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
600 | 853 CheckPermissionMessageSent(0, true); |
601 // And we should have the queued infobar displayed now. | 854 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_a0)); |
602 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); | 855 closed_infobar_tracker_.Clear(); |
603 | 856 } |
604 // Accept the second infobar. | 857 |
605 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | 858 // The second request should now be visible in tab A1. |
606 ConfirmInfoBarDelegate* infobar_delegate_1 = | 859 if (BubbleEnabled()) |
607 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 860 ASSERT_EQ(1, GetBubblesQueueSize(mgr_a1)); |
608 ASSERT_TRUE(infobar_delegate_1); | 861 else |
609 infobar_delegate_1->Accept(); | 862 ASSERT_EQ(1U, infobar_service_for_tab(0)->infobar_count()); |
863 | |
864 // Accept the second request and check that it's gone. | |
865 if (BubbleEnabled()) { | |
866 AcceptBubble(mgr_a1); | |
867 EXPECT_EQ(0, GetBubblesQueueSize(mgr_a1)); | |
868 } else { | |
869 infobars::InfoBar* infobar_1 = infobar_service_for_tab(0)->infobar_at(0); | |
870 ConfirmInfoBarDelegate* infobar_delegate_1 = | |
871 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | |
872 ASSERT_TRUE(infobar_delegate_1); | |
873 infobar_delegate_1->Accept(); | |
874 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | |
875 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | |
876 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | |
877 } | |
610 CheckPermissionMessageSentForTab(0, 1, true); | 878 CheckPermissionMessageSentForTab(0, 1, true); |
611 infobar_service_for_tab(0)->RemoveInfoBar(infobar_1); | 879 } |
612 EXPECT_EQ(1U, closed_infobar_tracker_.size()); | 880 |
613 EXPECT_TRUE(closed_infobar_tracker_.Contains(infobar_1)); | 881 TEST_P(GeolocationPermissionContextParamTests, TabDestroyed) { |
614 } | 882 PermissionBubbleManager* mgr = |
615 | 883 PermissionBubbleManager::FromWebContents(web_contents()); |
616 TEST_F(GeolocationPermissionContextTests, TabDestroyed) { | |
617 GURL requesting_frame_0("http://www.example.com/geolocation"); | 884 GURL requesting_frame_0("http://www.example.com/geolocation"); |
618 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 885 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
619 EXPECT_EQ(CONTENT_SETTING_ASK, | 886 EXPECT_EQ(CONTENT_SETTING_ASK, |
620 profile()->GetHostContentSettingsMap()->GetContentSetting( | 887 profile()->GetHostContentSettingsMap()->GetContentSetting( |
621 requesting_frame_0, requesting_frame_0, | 888 requesting_frame_0, requesting_frame_0, |
622 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 889 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
623 | 890 |
624 EXPECT_EQ(CONTENT_SETTING_ASK, | 891 EXPECT_EQ(CONTENT_SETTING_ASK, |
625 profile()->GetHostContentSettingsMap()->GetContentSetting( | 892 profile()->GetHostContentSettingsMap()->GetContentSetting( |
626 requesting_frame_1, requesting_frame_0, | 893 requesting_frame_1, requesting_frame_0, |
627 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); | 894 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string())); |
628 | 895 |
629 NavigateAndCommit(requesting_frame_0); | 896 NavigateAndCommit(requesting_frame_0); |
630 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 897 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
898 | |
899 if (BubbleEnabled()) | |
900 EXPECT_EQ(0, GetBubblesQueueSize(mgr)); | |
901 else | |
902 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
903 | |
631 // Request permission for two frames. | 904 // Request permission for two frames. |
632 RequestGeolocationPermission( | 905 RequestGeolocationPermission( |
633 web_contents(), RequestID(0), requesting_frame_0); | 906 web_contents(), RequestID(0), requesting_frame_0, false); |
634 RequestGeolocationPermission( | 907 RequestGeolocationPermission( |
635 web_contents(), RequestID(1), requesting_frame_1); | 908 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 | 909 |
640 // Delete the tab contents. | 910 // Ensure only one infobar/bubble is created. |
641 DeleteContents(); | 911 if (BubbleEnabled()) |
912 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); | |
913 else | |
914 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
642 | 915 |
643 // During contents destruction, the infobar will have been closed, and the | 916 // Delete the tab contents and check that the infobar/bubble was removed. |
644 // pending request should have been cleared without an infobar being created. | 917 if (BubbleEnabled()) { |
645 ASSERT_EQ(1U, closed_infobar_tracker_.size()); | 918 DeleteContents(); |
646 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); | 919 ASSERT_EQ(0, GetBubblesQueueSize(mgr)); |
920 } else { | |
921 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | |
922 DeleteContents(); | |
923 ASSERT_EQ(1U, closed_infobar_tracker_.size()); | |
924 ASSERT_TRUE(closed_infobar_tracker_.Contains(infobar)); | |
925 } | |
647 } | 926 } |
648 | 927 |
649 TEST_F(GeolocationPermissionContextTests, LastUsageAudited) { | 928 TEST_P(GeolocationPermissionContextParamTests, LastUsageAudited) { |
929 PermissionBubbleManager* mgr = | |
930 PermissionBubbleManager::FromWebContents(web_contents()); | |
650 GURL requesting_frame("http://www.example.com/geolocation"); | 931 GURL requesting_frame("http://www.example.com/geolocation"); |
651 NavigateAndCommit(requesting_frame); | 932 NavigateAndCommit(requesting_frame); |
933 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); | |
652 | 934 |
653 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | 935 base::SimpleTestClock* test_clock = new base::SimpleTestClock; |
654 test_clock->SetNow(base::Time::UnixEpoch() + | 936 test_clock->SetNow(base::Time::UnixEpoch() + |
655 base::TimeDelta::FromSeconds(10)); | 937 base::TimeDelta::FromSeconds(10)); |
656 | 938 |
657 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | 939 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
658 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); | 940 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); |
659 | 941 |
660 // The permission shouldn't have been used yet. | 942 // The permission shouldn't have been used yet. |
661 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 943 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
662 requesting_frame.GetOrigin(), | 944 requesting_frame.GetOrigin(), |
663 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 945 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
664 0); | 946 0); |
665 | 947 |
666 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 948 if (BubbleEnabled()) |
667 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 949 EXPECT_EQ(0, GetBubblesQueueSize(mgr)); |
668 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 950 else |
669 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | 951 EXPECT_EQ(0U, infobar_service()->infobar_count()); |
670 ConfirmInfoBarDelegate* infobar_delegate = | 952 RequestGeolocationPermission( |
671 infobar->delegate()->AsConfirmInfoBarDelegate(); | 953 web_contents(), RequestID(0), requesting_frame, false); |
672 ASSERT_TRUE(infobar_delegate); | 954 if (BubbleEnabled()) { |
673 infobar_delegate->Accept(); | 955 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
956 AcceptBubble(mgr); | |
957 } else { | |
958 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
959 infobars::InfoBar* infobar = infobar_service()->infobar_at(0); | |
960 ConfirmInfoBarDelegate* infobar_delegate = | |
961 infobar->delegate()->AsConfirmInfoBarDelegate(); | |
962 ASSERT_TRUE(infobar_delegate); | |
963 infobar_delegate->Accept(); | |
964 } | |
674 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | 965 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); |
675 CheckPermissionMessageSent(0, true); | 966 CheckPermissionMessageSent(0, true); |
676 | 967 |
677 // Permission has been used at the starting time. | 968 // Permission has been used at the starting time. |
678 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 969 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
679 requesting_frame.GetOrigin(), | 970 requesting_frame.GetOrigin(), |
680 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 971 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
681 10); | 972 10); |
682 | 973 |
683 test_clock->Advance(base::TimeDelta::FromSeconds(3)); | 974 test_clock->Advance(base::TimeDelta::FromSeconds(3)); |
684 RequestGeolocationPermission(web_contents(), RequestID(0), requesting_frame); | 975 RequestGeolocationPermission( |
976 web_contents(), RequestID(0), requesting_frame, false); | |
685 | 977 |
686 // Permission has been used three seconds later. | 978 // Permission has been used three seconds later. |
687 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), | 979 EXPECT_EQ(map->GetLastUsage(requesting_frame.GetOrigin(), |
688 requesting_frame.GetOrigin(), | 980 requesting_frame.GetOrigin(), |
689 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 981 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
690 13); | 982 13); |
691 } | 983 } |
692 | 984 |
693 TEST_F(GeolocationPermissionContextTests, LastUsageAuditedMultipleFrames) { | 985 TEST_P(GeolocationPermissionContextParamTests, LastUsageAuditedMultipleFrames) { |
986 PermissionBubbleManager* mgr = | |
987 PermissionBubbleManager::FromWebContents(web_contents()); | |
694 base::SimpleTestClock* test_clock = new base::SimpleTestClock; | 988 base::SimpleTestClock* test_clock = new base::SimpleTestClock; |
695 test_clock->SetNow(base::Time::UnixEpoch() + | 989 test_clock->SetNow(base::Time::UnixEpoch() + |
696 base::TimeDelta::FromSeconds(10)); | 990 base::TimeDelta::FromSeconds(10)); |
697 | 991 |
698 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); | 992 HostContentSettingsMap* map = profile()->GetHostContentSettingsMap(); |
699 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); | 993 map->SetPrefClockForTesting(scoped_ptr<base::Clock>(test_clock)); |
700 | 994 |
701 GURL requesting_frame_0("http://www.example.com/geolocation"); | 995 GURL requesting_frame_0("http://www.example.com/geolocation"); |
702 GURL requesting_frame_1("http://www.example-2.com/geolocation"); | 996 GURL requesting_frame_1("http://www.example-2.com/geolocation"); |
703 | 997 |
704 // The permission shouldn't have been used yet. | 998 // The permission shouldn't have been used yet. |
705 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 999 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
706 requesting_frame_0.GetOrigin(), | 1000 requesting_frame_0.GetOrigin(), |
707 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1001 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
708 0); | 1002 0); |
709 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 1003 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
710 requesting_frame_0.GetOrigin(), | 1004 requesting_frame_0.GetOrigin(), |
711 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1005 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
712 0); | 1006 0); |
713 | 1007 |
714 NavigateAndCommit(requesting_frame_0); | 1008 NavigateAndCommit(requesting_frame_0); |
715 EXPECT_EQ(0U, infobar_service()->infobar_count()); | 1009 if (BubbleEnabled()) BubbleManagerDocumentLoadCompleted(); |
1010 | |
1011 if (BubbleEnabled()) | |
1012 EXPECT_EQ(0, GetBubblesQueueSize(mgr)); | |
1013 else | |
1014 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
716 | 1015 |
717 // Request permission for two frames. | 1016 // Request permission for two frames. |
718 RequestGeolocationPermission( | 1017 RequestGeolocationPermission( |
719 web_contents(), RequestID(0), requesting_frame_0); | 1018 web_contents(), RequestID(0), requesting_frame_0, false); |
720 RequestGeolocationPermission( | 1019 RequestGeolocationPermission( |
721 web_contents(), RequestID(1), requesting_frame_1); | 1020 web_contents(), RequestID(1), requesting_frame_1, false); |
722 | 1021 |
723 // Ensure only one infobar is created. | 1022 // Ensure only one request is created. |
724 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 1023 infobars::InfoBar* infobar_0; |
725 infobars::InfoBar* infobar_0 = infobar_service()->infobar_at(0); | 1024 ConfirmInfoBarDelegate* infobar_delegate_0; |
726 ConfirmInfoBarDelegate* infobar_delegate_0 = | 1025 if (BubbleEnabled()) { |
727 infobar_0->delegate()->AsConfirmInfoBarDelegate(); | 1026 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
1027 } else { | |
1028 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
1029 infobar_0 = infobar_service()->infobar_at(0); | |
1030 infobar_delegate_0 = infobar_0->delegate()->AsConfirmInfoBarDelegate(); | |
1031 } | |
728 | 1032 |
729 // Accept the first frame. | 1033 // Accept the first frame. |
730 infobar_delegate_0->Accept(); | 1034 if (BubbleEnabled()) { |
1035 AcceptBubble(mgr); | |
1036 } else { | |
1037 infobar_delegate_0->Accept(); | |
1038 infobar_service()->RemoveInfoBar(infobar_0); | |
1039 } | |
731 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); | 1040 CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
732 CheckPermissionMessageSent(0, true); | 1041 CheckPermissionMessageSent(0, true); |
733 infobar_service()->RemoveInfoBar(infobar_0); | |
734 | 1042 |
735 // Verify that accepting the first didn't accept because it's embedder | 1043 // Verify that accepting the first didn't accept because it's embedder |
736 // in the other. | 1044 // in the other. |
737 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 1045 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
738 requesting_frame_0.GetOrigin(), | 1046 requesting_frame_0.GetOrigin(), |
739 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1047 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
740 10); | 1048 10); |
741 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 1049 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
742 requesting_frame_0.GetOrigin(), | 1050 requesting_frame_0.GetOrigin(), |
743 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1051 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
744 0); | 1052 0); |
745 | 1053 |
746 ASSERT_EQ(1U, infobar_service()->infobar_count()); | 1054 infobars::InfoBar* infobar_1; |
747 infobars::InfoBar* infobar_1 = infobar_service()->infobar_at(0); | 1055 ConfirmInfoBarDelegate* infobar_delegate_1; |
748 ConfirmInfoBarDelegate* infobar_delegate_1 = | 1056 if (BubbleEnabled()) { |
749 infobar_1->delegate()->AsConfirmInfoBarDelegate(); | 1057 ASSERT_EQ(1, GetBubblesQueueSize(mgr)); |
1058 } else { | |
1059 ASSERT_EQ(1U, infobar_service()->infobar_count()); | |
1060 infobar_1 = infobar_service()->infobar_at(0); | |
1061 infobar_delegate_1 = infobar_1->delegate()->AsConfirmInfoBarDelegate(); | |
1062 } | |
750 | 1063 |
751 test_clock->Advance(base::TimeDelta::FromSeconds(1)); | 1064 test_clock->Advance(base::TimeDelta::FromSeconds(1)); |
752 | 1065 |
753 // Allow the second frame. | 1066 // Allow the second frame. |
754 infobar_delegate_1->Accept(); | 1067 if (BubbleEnabled()) { |
1068 AcceptBubble(mgr); | |
1069 } else { | |
1070 infobar_delegate_1->Accept(); | |
1071 infobar_service()->RemoveInfoBar(infobar_1); | |
1072 } | |
755 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); | 1073 CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
756 CheckPermissionMessageSent(1, true); | 1074 CheckPermissionMessageSent(1, true); |
757 infobar_service()->RemoveInfoBar(infobar_1); | |
758 | 1075 |
759 // Verify that the times are different. | 1076 // Verify that the times are different. |
760 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 1077 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
761 requesting_frame_0.GetOrigin(), | 1078 requesting_frame_0.GetOrigin(), |
762 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1079 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
763 10); | 1080 10); |
764 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 1081 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
765 requesting_frame_0.GetOrigin(), | 1082 requesting_frame_0.GetOrigin(), |
766 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1083 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
767 11); | 1084 11); |
768 | 1085 |
769 test_clock->Advance(base::TimeDelta::FromSeconds(2)); | 1086 test_clock->Advance(base::TimeDelta::FromSeconds(2)); |
770 RequestGeolocationPermission( | 1087 RequestGeolocationPermission( |
771 web_contents(), RequestID(0), requesting_frame_0); | 1088 web_contents(), RequestID(0), requesting_frame_0, false); |
772 | 1089 |
773 // Verify that requesting permission in one frame doesn't update other where | 1090 // Verify that requesting permission in one frame doesn't update other where |
774 // it is the embedder. | 1091 // it is the embedder. |
775 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), | 1092 EXPECT_EQ(map->GetLastUsage(requesting_frame_0.GetOrigin(), |
776 requesting_frame_0.GetOrigin(), | 1093 requesting_frame_0.GetOrigin(), |
777 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1094 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
778 13); | 1095 13); |
779 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), | 1096 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), |
780 requesting_frame_0.GetOrigin(), | 1097 requesting_frame_0.GetOrigin(), |
781 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), | 1098 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), |
782 11); | 1099 11); |
783 } | 1100 } |
1101 | |
1102 INSTANTIATE_TEST_CASE_P(GeolocationPermissionContextTestsWithAndWithoutBubbles, | |
1103 GeolocationPermissionContextParamTests, | |
1104 ::testing::Values(false, true)); | |
1105 | |
1106 // Infobar-only tests ---------------------------------------------------------- | |
1107 // Android doesn't support permission bubbles. | |
1108 | |
1109 #if defined(OS_ANDROID) | |
1110 TEST_F(GeolocationPermissionContextTests, GeolocationEnabledDisabled) { | |
1111 EXPECT_FALSE(PermissionBubbleManager::Enabled()); | |
1112 GURL requesting_frame("http://www.example.com/geolocation"); | |
1113 NavigateAndCommit(requesting_frame); | |
1114 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | |
1115 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
1116 RequestGeolocationPermission( | |
1117 web_contents(), RequestID(0), requesting_frame, true); | |
1118 EXPECT_EQ(1U, infobar_service()->infobar_count()); | |
1119 ConfirmInfoBarDelegate* infobar_delegate_0 = | |
1120 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | |
1121 ASSERT_TRUE(infobar_delegate_0); | |
1122 base::string16 text_0 = infobar_delegate_0->GetButtonLabel( | |
1123 ConfirmInfoBarDelegate::BUTTON_OK); | |
1124 | |
1125 Reload(); | |
1126 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | |
1127 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
1128 RequestGeolocationPermission( | |
1129 web_contents(), RequestID(0), requesting_frame, true); | |
1130 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
1131 } | |
1132 | |
1133 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsEnabled) { | |
1134 EXPECT_FALSE(PermissionBubbleManager::Enabled()); | |
1135 GURL requesting_frame("http://www.example.com/geolocation"); | |
1136 NavigateAndCommit(requesting_frame); | |
1137 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); | |
1138 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
1139 RequestGeolocationPermission( | |
1140 web_contents(), RequestID(0), requesting_frame, true); | |
1141 EXPECT_EQ(1U, infobar_service()->infobar_count()); | |
1142 ConfirmInfoBarDelegate* infobar_delegate = | |
1143 infobar_service()->infobar_at(0)->delegate()->AsConfirmInfoBarDelegate(); | |
1144 ASSERT_TRUE(infobar_delegate); | |
1145 infobar_delegate->Accept(); | |
1146 CheckTabContentsState(requesting_frame, CONTENT_SETTING_ALLOW); | |
1147 CheckPermissionMessageSent(0, true); | |
1148 } | |
1149 | |
1150 TEST_F(GeolocationPermissionContextTests, MasterEnabledGoogleAppsDisabled) { | |
1151 EXPECT_FALSE(PermissionBubbleManager::Enabled()); | |
1152 GURL requesting_frame("http://www.example.com/geolocation"); | |
1153 NavigateAndCommit(requesting_frame); | |
1154 MockGoogleLocationSettingsHelper::SetLocationStatus(true, false); | |
1155 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
1156 RequestGeolocationPermission( | |
1157 web_contents(), RequestID(0), requesting_frame, true); | |
1158 EXPECT_EQ(0U, infobar_service()->infobar_count()); | |
1159 } | |
1160 #endif | |
OLD | NEW |