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

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

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT Created 7 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 | Annotate | Revision Log
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 <set> 5 #include <set>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/hash_tables.h" 10 #include "base/hash_tables.h"
11 #include "base/memory/scoped_vector.h" 11 #include "base/memory/scoped_vector.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "chrome/browser/content_settings/host_content_settings_map.h" 13 #include "chrome/browser/content_settings/host_content_settings_map.h"
14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
15 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" 15 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
16 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto ry.h" 16 #include "chrome/browser/geolocation/chrome_geolocation_permission_context_facto ry.h"
17 #include "chrome/browser/geolocation/geolocation_permission_request_id.h" 17 #include "chrome/browser/geolocation/geolocation_permission_request_id.h"
18 #include "chrome/browser/infobars/confirm_infobar_delegate.h" 18 #include "chrome/browser/infobars/confirm_infobar_delegate.h"
19 #include "chrome/browser/infobars/infobar.h" 19 #include "chrome/browser/infobars/infobar.h"
20 #include "chrome/browser/infobars/infobar_service.h" 20 #include "chrome/browser/infobars/infobar_service.h"
21 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 22 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
23 #include "chrome/test/base/testing_profile.h" 23 #include "chrome/test/base/testing_profile.h"
24 #include "content/public/browser/navigation_details.h" 24 #include "content/public/browser/navigation_details.h"
25 #include "content/public/browser/notification_registrar.h" 25 #include "content/public/browser/notification_registrar.h"
26 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
27 #include "content/public/browser/web_contents.h" 27 #include "content/public/browser/web_contents.h"
28 #include "content/public/test/mock_render_process_host.h" 28 #include "content/public/test/mock_render_process_host.h"
29 #include "content/public/test/test_browser_thread.h"
30 #include "content/public/test/test_renderer_host.h" 29 #include "content/public/test/test_renderer_host.h"
31 #include "content/public/test/web_contents_tester.h" 30 #include "content/public/test/web_contents_tester.h"
32 #include "extensions/browser/view_type_utils.h" 31 #include "extensions/browser/view_type_utils.h"
33 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
34 33
35 #if defined(OS_ANDROID) 34 #if defined(OS_ANDROID)
36 #include "base/prefs/pref_service.h" 35 #include "base/prefs/pref_service.h"
37 #include "chrome/browser/android/mock_google_location_settings_helper.h" 36 #include "chrome/browser/android/mock_google_location_settings_helper.h"
38 #include "chrome/common/pref_names.h" 37 #include "chrome/common/pref_names.h"
39 #endif 38 #endif
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 void ClosedDelegateTracker::Clear() { 90 void ClosedDelegateTracker::Clear() {
92 removed_infobar_delegates_.clear(); 91 removed_infobar_delegates_.clear();
93 } 92 }
94 93
95 94
96 // GeolocationPermissionContextTests ------------------------------------------ 95 // GeolocationPermissionContextTests ------------------------------------------
97 96
98 // This class sets up GeolocationArbitrator. 97 // This class sets up GeolocationArbitrator.
99 class GeolocationPermissionContextTests 98 class GeolocationPermissionContextTests
100 : public ChromeRenderViewHostTestHarness { 99 : public ChromeRenderViewHostTestHarness {
101 public:
102 GeolocationPermissionContextTests();
103
104 protected: 100 protected:
105 virtual ~GeolocationPermissionContextTests(); 101 // ChromeRenderViewHostTestHarness:
102 virtual void SetUp() OVERRIDE;
103 virtual void TearDown() OVERRIDE;
106 104
107 GeolocationPermissionRequestID RequestID(int bridge_id); 105 GeolocationPermissionRequestID RequestID(int bridge_id);
108 GeolocationPermissionRequestID RequestIDForTab(int tab, int bridge_id); 106 GeolocationPermissionRequestID RequestIDForTab(int tab, int bridge_id);
109 InfoBarService* infobar_service() { 107 InfoBarService* infobar_service() {
110 return InfoBarService::FromWebContents(web_contents()); 108 return InfoBarService::FromWebContents(web_contents());
111 } 109 }
112 InfoBarService* infobar_service_for_tab(int tab) { 110 InfoBarService* infobar_service_for_tab(int tab) {
113 return InfoBarService::FromWebContents(extra_tabs_[tab]); 111 return InfoBarService::FromWebContents(extra_tabs_[tab]);
114 } 112 }
115 113
(...skipping 11 matching lines...) Expand all
127 bool allowed); 125 bool allowed);
128 void AddNewTab(const GURL& url); 126 void AddNewTab(const GURL& url);
129 void CheckTabContentsState(const GURL& requesting_frame, 127 void CheckTabContentsState(const GURL& requesting_frame,
130 ContentSetting expected_content_setting); 128 ContentSetting expected_content_setting);
131 129
132 scoped_refptr<ChromeGeolocationPermissionContext> 130 scoped_refptr<ChromeGeolocationPermissionContext>
133 geolocation_permission_context_; 131 geolocation_permission_context_;
134 ClosedDelegateTracker closed_delegate_tracker_; 132 ClosedDelegateTracker closed_delegate_tracker_;
135 ScopedVector<content::WebContents> extra_tabs_; 133 ScopedVector<content::WebContents> extra_tabs_;
136 134
137 private:
138 // ChromeRenderViewHostTestHarness:
139 virtual void SetUp() OVERRIDE;
140 virtual void TearDown() OVERRIDE;
141
142 content::TestBrowserThread ui_thread_;
143 content::TestBrowserThread db_thread_;
144
145 // A map between renderer child id and a pair represending the bridge id and 135 // A map between renderer child id and a pair represending the bridge id and
146 // whether the requested permission was allowed. 136 // whether the requested permission was allowed.
147 base::hash_map<int, std::pair<int, bool> > responses_; 137 base::hash_map<int, std::pair<int, bool> > responses_;
148 }; 138 };
149 139
150 GeolocationPermissionContextTests::GeolocationPermissionContextTests()
151 : ChromeRenderViewHostTestHarness(),
152 ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()),
153 db_thread_(content::BrowserThread::DB) {
154 }
155
156 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() {
157 }
158
159 GeolocationPermissionRequestID GeolocationPermissionContextTests::RequestID( 140 GeolocationPermissionRequestID GeolocationPermissionContextTests::RequestID(
160 int bridge_id) { 141 int bridge_id) {
161 return GeolocationPermissionRequestID( 142 return GeolocationPermissionRequestID(
162 web_contents()->GetRenderProcessHost()->GetID(), 143 web_contents()->GetRenderProcessHost()->GetID(),
163 web_contents()->GetRenderViewHost()->GetRoutingID(), 144 web_contents()->GetRenderViewHost()->GetRoutingID(),
164 bridge_id); 145 bridge_id);
165 } 146 }
166 147
167 GeolocationPermissionRequestID 148 GeolocationPermissionRequestID
168 GeolocationPermissionContextTests::RequestIDForTab(int tab, int bridge_id) { 149 GeolocationPermissionContextTests::RequestIDForTab(int tab, int bridge_id) {
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); 227 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin()));
247 EXPECT_EQ(0U, state_map.count(requesting_frame)); 228 EXPECT_EQ(0U, state_map.count(requesting_frame));
248 GeolocationSettingsState::StateMap::const_iterator settings = 229 GeolocationSettingsState::StateMap::const_iterator settings =
249 state_map.find(requesting_frame.GetOrigin()); 230 state_map.find(requesting_frame.GetOrigin());
250 ASSERT_FALSE(settings == state_map.end()) 231 ASSERT_FALSE(settings == state_map.end())
251 << "geolocation state not found " << requesting_frame; 232 << "geolocation state not found " << requesting_frame;
252 EXPECT_EQ(expected_content_setting, settings->second); 233 EXPECT_EQ(expected_content_setting, settings->second);
253 } 234 }
254 235
255 void GeolocationPermissionContextTests::SetUp() { 236 void GeolocationPermissionContextTests::SetUp() {
256 db_thread_.Start();
257 ChromeRenderViewHostTestHarness::SetUp(); 237 ChromeRenderViewHostTestHarness::SetUp();
258 238
259 // Set up required helpers, and make this be as "tabby" as the code requires. 239 // Set up required helpers, and make this be as "tabby" as the code requires.
260 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS); 240 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_TAB_CONTENTS);
261 InfoBarService::CreateForWebContents(web_contents()); 241 InfoBarService::CreateForWebContents(web_contents());
262 TabSpecificContentSettings::CreateForWebContents(web_contents()); 242 TabSpecificContentSettings::CreateForWebContents(web_contents());
263 #if defined(OS_ANDROID) 243 #if defined(OS_ANDROID)
264 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true); 244 MockGoogleLocationSettingsHelper::SetLocationStatus(true, true);
265 #endif 245 #endif
266 geolocation_permission_context_ = 246 geolocation_permission_context_ =
267 ChromeGeolocationPermissionContextFactory::GetForProfile(profile()); 247 ChromeGeolocationPermissionContextFactory::GetForProfile(profile());
268 } 248 }
269 249
270 void GeolocationPermissionContextTests::TearDown() { 250 void GeolocationPermissionContextTests::TearDown() {
271 extra_tabs_.clear(); 251 extra_tabs_.clear();
272 ChromeRenderViewHostTestHarness::TearDown(); 252 ChromeRenderViewHostTestHarness::TearDown();
273 // Schedule another task on the DB thread to notify us that it's safe to
274 // carry on with the test.
275 base::WaitableEvent done(false, false);
276 content::BrowserThread::PostTask(
277 content::BrowserThread::DB, FROM_HERE,
278 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
279 done.Wait();
280 db_thread_.Stop();
281 } 253 }
282 254
283 // Tests ---------------------------------------------------------------------- 255 // Tests ----------------------------------------------------------------------
284 256
285 TEST_F(GeolocationPermissionContextTests, SinglePermission) { 257 TEST_F(GeolocationPermissionContextTests, SinglePermission) {
286 GURL requesting_frame("http://www.example.com/geolocation"); 258 GURL requesting_frame("http://www.example.com/geolocation");
287 NavigateAndCommit(requesting_frame); 259 NavigateAndCommit(requesting_frame);
288 EXPECT_EQ(0U, infobar_service()->infobar_count()); 260 EXPECT_EQ(0U, infobar_service()->infobar_count());
289 RequestGeolocationPermission(RequestID(0), requesting_frame); 261 RequestGeolocationPermission(RequestID(0), requesting_frame);
290 ASSERT_EQ(1U, infobar_service()->infobar_count()); 262 ASSERT_EQ(1U, infobar_service()->infobar_count());
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 details.entry = web_contents()->GetController().GetLastCommittedEntry(); 672 details.entry = web_contents()->GetController().GetLastCommittedEntry();
701 EXPECT_FALSE(infobar_0->ShouldExpire(details)); 673 EXPECT_FALSE(infobar_0->ShouldExpire(details));
702 // Ensure the infobar will expire when we commit the pending navigation. 674 // Ensure the infobar will expire when we commit the pending navigation.
703 details.entry = web_contents()->GetController().GetActiveEntry(); 675 details.entry = web_contents()->GetController().GetActiveEntry();
704 EXPECT_TRUE(infobar_0->ShouldExpire(details)); 676 EXPECT_TRUE(infobar_0->ShouldExpire(details));
705 677
706 // Delete the tab contents. 678 // Delete the tab contents.
707 DeleteContents(); 679 DeleteContents();
708 delete infobar_0; 680 delete infobar_0;
709 } 681 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698