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

Side by Side Diff: chrome/browser/geolocation/geolocation_permission_context_unittest.cc

Issue 1166603002: Move PermissionRequestID to chrome/browser/permissions/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@permission_rfh
Patch Set: fix build Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "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/command_line.h"
13 #include "base/containers/hash_tables.h" 13 #include "base/containers/hash_tables.h"
14 #include "base/id_map.h" 14 #include "base/id_map.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "base/synchronization/waitable_event.h" 16 #include "base/synchronization/waitable_event.h"
17 #include "base/test/simple_test_clock.h" 17 #include "base/test/simple_test_clock.h"
18 #include "base/time/clock.h" 18 #include "base/time/clock.h"
19 #include "chrome/browser/chrome_notification_types.h" 19 #include "chrome/browser/chrome_notification_types.h"
20 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 20 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
21 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h" 21 #include "chrome/browser/geolocation/geolocation_permission_context_factory.h"
22 #include "chrome/browser/infobars/infobar_service.h" 22 #include "chrome/browser/infobars/infobar_service.h"
23 #include "chrome/browser/permissions/permission_request_id.h"
23 #include "chrome/browser/ui/website_settings/mock_permission_bubble_view.h" 24 #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_manager.h"
25 #include "chrome/browser/ui/website_settings/permission_bubble_request.h" 26 #include "chrome/browser/ui/website_settings/permission_bubble_request.h"
26 #include "chrome/common/chrome_switches.h" 27 #include "chrome/common/chrome_switches.h"
27 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 28 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
28 #include "chrome/test/base/testing_profile.h" 29 #include "chrome/test/base/testing_profile.h"
29 #include "components/content_settings/core/browser/host_content_settings_map.h" 30 #include "components/content_settings/core/browser/host_content_settings_map.h"
30 #include "components/content_settings/core/common/permission_request_id.h"
31 #include "components/infobars/core/confirm_infobar_delegate.h" 31 #include "components/infobars/core/confirm_infobar_delegate.h"
32 #include "components/infobars/core/infobar.h" 32 #include "components/infobars/core/infobar.h"
33 #include "content/public/browser/browser_thread.h" 33 #include "content/public/browser/browser_thread.h"
34 #include "content/public/browser/navigation_details.h" 34 #include "content/public/browser/navigation_details.h"
35 #include "content/public/browser/navigation_entry.h" 35 #include "content/public/browser/navigation_entry.h"
36 #include "content/public/browser/notification_observer.h" 36 #include "content/public/browser/notification_observer.h"
37 #include "content/public/browser/notification_registrar.h" 37 #include "content/public/browser/notification_registrar.h"
38 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
39 #include "content/public/browser/render_frame_host.h" 39 #include "content/public/browser/render_frame_host.h"
40 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 109
110 // GeolocationPermissionContextTests ------------------------------------------ 110 // GeolocationPermissionContextTests ------------------------------------------
111 111
112 class GeolocationPermissionContextTests 112 class GeolocationPermissionContextTests
113 : public ChromeRenderViewHostTestHarness { 113 : public ChromeRenderViewHostTestHarness {
114 protected: 114 protected:
115 // ChromeRenderViewHostTestHarness: 115 // ChromeRenderViewHostTestHarness:
116 void SetUp() override; 116 void SetUp() override;
117 void TearDown() override; 117 void TearDown() override;
118 118
119 PermissionRequestID RequestID(int bridge_id); 119 PermissionRequestID RequestID(int request_id);
120 PermissionRequestID RequestIDForTab(int tab, int bridge_id); 120 PermissionRequestID RequestIDForTab(int tab, int request_id);
121 InfoBarService* infobar_service() { 121 InfoBarService* infobar_service() {
122 return InfoBarService::FromWebContents(web_contents()); 122 return InfoBarService::FromWebContents(web_contents());
123 } 123 }
124 InfoBarService* infobar_service_for_tab(int tab) { 124 InfoBarService* infobar_service_for_tab(int tab) {
125 return InfoBarService::FromWebContents(extra_tabs_[tab]); 125 return InfoBarService::FromWebContents(extra_tabs_[tab]);
126 } 126 }
127 127
128 void RequestGeolocationPermission(content::WebContents* web_contents, 128 void RequestGeolocationPermission(content::WebContents* web_contents,
129 const PermissionRequestID& id, 129 const PermissionRequestID& id,
130 const GURL& requesting_frame, 130 const GURL& requesting_frame,
131 bool user_gesture); 131 bool user_gesture);
132 132
133 void PermissionResponse(const PermissionRequestID& id, 133 void PermissionResponse(const PermissionRequestID& id,
134 ContentSetting content_setting); 134 ContentSetting content_setting);
135 void CheckPermissionMessageSent(int bridge_id, bool allowed); 135 void CheckPermissionMessageSent(int request_id, bool allowed);
136 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); 136 void CheckPermissionMessageSentForTab(int tab, int request_id, bool allowed);
137 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, 137 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
138 int bridge_id, 138 int request_id,
139 bool allowed); 139 bool allowed);
140 void AddNewTab(const GURL& url); 140 void AddNewTab(const GURL& url);
141 void CheckTabContentsState(const GURL& requesting_frame, 141 void CheckTabContentsState(const GURL& requesting_frame,
142 ContentSetting expected_content_setting); 142 ContentSetting expected_content_setting);
143 size_t GetBubblesQueueSize(PermissionBubbleManager* manager); 143 size_t GetBubblesQueueSize(PermissionBubbleManager* manager);
144 void AcceptBubble(PermissionBubbleManager* manager); 144 void AcceptBubble(PermissionBubbleManager* manager);
145 void DenyBubble(PermissionBubbleManager* manager); 145 void DenyBubble(PermissionBubbleManager* manager);
146 void CloseBubble(PermissionBubbleManager* manager); 146 void CloseBubble(PermissionBubbleManager* manager);
147 void BubbleManagerDocumentLoadCompleted(); 147 void BubbleManagerDocumentLoadCompleted();
148 void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents); 148 void BubbleManagerDocumentLoadCompleted(content::WebContents* web_contents);
149 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1); 149 ContentSetting GetGeolocationContentSetting(GURL frame_0, GURL frame_1);
150 150
151 // owned by the browser context 151 // owned by the browser context
152 GeolocationPermissionContext* geolocation_permission_context_; 152 GeolocationPermissionContext* geolocation_permission_context_;
153 ClosedInfoBarTracker closed_infobar_tracker_; 153 ClosedInfoBarTracker closed_infobar_tracker_;
154 MockPermissionBubbleView bubble_view_; 154 MockPermissionBubbleView bubble_view_;
155 ScopedVector<content::WebContents> extra_tabs_; 155 ScopedVector<content::WebContents> extra_tabs_;
156 156
157 // A map between renderer child id and a pair represending the bridge id and 157 // A map between renderer child id and a pair represending the bridge id and
158 // whether the requested permission was allowed. 158 // whether the requested permission was allowed.
159 base::hash_map<int, std::pair<int, bool> > responses_; 159 base::hash_map<int, std::pair<int, bool> > responses_;
160 }; 160 };
161 161
162 PermissionRequestID GeolocationPermissionContextTests::RequestID( 162 PermissionRequestID GeolocationPermissionContextTests::RequestID(
163 int bridge_id) { 163 int request_id) {
164 return PermissionRequestID( 164 return PermissionRequestID(
165 web_contents()->GetRenderProcessHost()->GetID(), 165 web_contents()->GetRenderProcessHost()->GetID(),
166 web_contents()->GetMainFrame()->GetRoutingID(), 166 web_contents()->GetMainFrame()->GetRoutingID(),
167 bridge_id, 167 request_id,
168 GURL()); 168 GURL());
169 } 169 }
170 170
171 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab( 171 PermissionRequestID GeolocationPermissionContextTests::RequestIDForTab(
172 int tab, 172 int tab,
173 int bridge_id) { 173 int request_id) {
174 return PermissionRequestID( 174 return PermissionRequestID(
175 extra_tabs_[tab]->GetRenderProcessHost()->GetID(), 175 extra_tabs_[tab]->GetRenderProcessHost()->GetID(),
176 extra_tabs_[tab]->GetMainFrame()->GetRoutingID(), 176 extra_tabs_[tab]->GetMainFrame()->GetRoutingID(),
177 bridge_id, 177 request_id,
178 GURL()); 178 GURL());
179 } 179 }
180 180
181 void GeolocationPermissionContextTests::RequestGeolocationPermission( 181 void GeolocationPermissionContextTests::RequestGeolocationPermission(
182 content::WebContents* web_contents, 182 content::WebContents* web_contents,
183 const PermissionRequestID& id, 183 const PermissionRequestID& id,
184 const GURL& requesting_frame, 184 const GURL& requesting_frame,
185 bool user_gesture) { 185 bool user_gesture) {
186 geolocation_permission_context_->RequestPermission( 186 geolocation_permission_context_->RequestPermission(
187 web_contents, id, requesting_frame, user_gesture, 187 web_contents, id, requesting_frame, user_gesture,
188 base::Bind(&GeolocationPermissionContextTests::PermissionResponse, 188 base::Bind(&GeolocationPermissionContextTests::PermissionResponse,
189 base::Unretained(this), id)); 189 base::Unretained(this), id));
190 content::RunAllBlockingPoolTasksUntilIdle(); 190 content::RunAllBlockingPoolTasksUntilIdle();
191 } 191 }
192 192
193 void GeolocationPermissionContextTests::PermissionResponse( 193 void GeolocationPermissionContextTests::PermissionResponse(
194 const PermissionRequestID& id, 194 const PermissionRequestID& id,
195 ContentSetting content_setting) { 195 ContentSetting content_setting) {
196 responses_[id.render_process_id()] = 196 responses_[id.render_process_id()] =
197 std::make_pair(id.bridge_id(), content_setting == CONTENT_SETTING_ALLOW); 197 std::make_pair(id.request_id(), content_setting == CONTENT_SETTING_ALLOW);
198 } 198 }
199 199
200 void GeolocationPermissionContextTests::CheckPermissionMessageSent( 200 void GeolocationPermissionContextTests::CheckPermissionMessageSent(
201 int bridge_id, 201 int request_id,
202 bool allowed) { 202 bool allowed) {
203 CheckPermissionMessageSentInternal(process(), bridge_id, allowed); 203 CheckPermissionMessageSentInternal(process(), request_id, allowed);
204 } 204 }
205 205
206 void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab( 206 void GeolocationPermissionContextTests::CheckPermissionMessageSentForTab(
207 int tab, 207 int tab,
208 int bridge_id, 208 int request_id,
209 bool allowed) { 209 bool allowed) {
210 CheckPermissionMessageSentInternal(static_cast<MockRenderProcessHost*>( 210 CheckPermissionMessageSentInternal(static_cast<MockRenderProcessHost*>(
211 extra_tabs_[tab]->GetRenderProcessHost()), 211 extra_tabs_[tab]->GetRenderProcessHost()),
212 bridge_id, allowed); 212 request_id, allowed);
213 } 213 }
214 214
215 void GeolocationPermissionContextTests::CheckPermissionMessageSentInternal( 215 void GeolocationPermissionContextTests::CheckPermissionMessageSentInternal(
216 MockRenderProcessHost* process, 216 MockRenderProcessHost* process,
217 int bridge_id, 217 int request_id,
218 bool allowed) { 218 bool allowed) {
219 ASSERT_EQ(responses_.count(process->GetID()), 1U); 219 ASSERT_EQ(responses_.count(process->GetID()), 1U);
220 EXPECT_EQ(bridge_id, responses_[process->GetID()].first); 220 EXPECT_EQ(request_id, responses_[process->GetID()].first);
221 EXPECT_EQ(allowed, responses_[process->GetID()].second); 221 EXPECT_EQ(allowed, responses_[process->GetID()].second);
222 responses_.erase(process->GetID()); 222 responses_.erase(process->GetID());
223 } 223 }
224 224
225 void GeolocationPermissionContextTests::AddNewTab(const GURL& url) { 225 void GeolocationPermissionContextTests::AddNewTab(const GURL& url) {
226 content::WebContents* new_tab = CreateTestWebContents(); 226 content::WebContents* new_tab = CreateTestWebContents();
227 new_tab->GetController().LoadURL( 227 new_tab->GetController().LoadURL(
228 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string()); 228 url, content::Referrer(), ui::PAGE_TRANSITION_TYPED, std::string());
229 content::NavigationEntry* entry = new_tab->GetController().GetPendingEntry(); 229 content::NavigationEntry* entry = new_tab->GetController().GetPendingEntry();
230 content::RenderFrameHostTester::For(new_tab->GetMainFrame()) 230 content::RenderFrameHostTester::For(new_tab->GetMainFrame())
(...skipping 741 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 13); 972 13);
973 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(), 973 EXPECT_EQ(map->GetLastUsage(requesting_frame_1.GetOrigin(),
974 requesting_frame_0.GetOrigin(), 974 requesting_frame_0.GetOrigin(),
975 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(), 975 CONTENT_SETTINGS_TYPE_GEOLOCATION).ToDoubleT(),
976 11); 976 11);
977 } 977 }
978 978
979 INSTANTIATE_TEST_CASE_P(GeolocationPermissionContextTestsWithAndWithoutBubbles, 979 INSTANTIATE_TEST_CASE_P(GeolocationPermissionContextTestsWithAndWithoutBubbles,
980 GeolocationPermissionContextParamTests, 980 GeolocationPermissionContextParamTests,
981 ::testing::Values(false, true)); 981 ::testing::Values(false, true));
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698