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

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

Issue 10542010: TabContentsWrapper -> TabContents, part 2. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase, rename Created 8 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/infobars/infobar.h" 16 #include "chrome/browser/infobars/infobar.h"
17 #include "chrome/browser/infobars/infobar_tab_helper.h" 17 #include "chrome/browser/infobars/infobar_tab_helper.h"
18 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 18 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
20 #include "chrome/browser/ui/tab_contents/test_tab_contents_wrapper.h" 20 #include "chrome/browser/ui/tab_contents/test_tab_contents.h"
21 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/test/base/testing_profile.h" 22 #include "chrome/test/base/testing_profile.h"
23 #include "content/public/browser/navigation_details.h" 23 #include "content/public/browser/navigation_details.h"
24 #include "content/public/browser/notification_registrar.h" 24 #include "content/public/browser/notification_registrar.h"
25 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
27 #include "content/public/test/mock_render_process_host.h" 27 #include "content/public/test/mock_render_process_host.h"
28 #include "content/public/test/test_browser_thread.h" 28 #include "content/public/test/test_browser_thread.h"
29 #include "content/public/test/test_renderer_host.h" 29 #include "content/public/test/test_renderer_host.h"
30 #include "content/public/test/web_contents_tester.h" 30 #include "content/public/test/web_contents_tester.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 return removed_infobar_delegates_.count(delegate) != 0; 83 return removed_infobar_delegates_.count(delegate) != 0;
84 } 84 }
85 85
86 void ClosedDelegateTracker::Clear() { 86 void ClosedDelegateTracker::Clear() {
87 removed_infobar_delegates_.clear(); 87 removed_infobar_delegates_.clear();
88 } 88 }
89 89
90 // GeolocationPermissionContextTests ------------------------------------------ 90 // GeolocationPermissionContextTests ------------------------------------------
91 91
92 // This class sets up GeolocationArbitrator. 92 // This class sets up GeolocationArbitrator.
93 class GeolocationPermissionContextTests : public TabContentsWrapperTestHarness { 93 class GeolocationPermissionContextTests : public TabContentsTestHarness {
94 public: 94 public:
95 GeolocationPermissionContextTests(); 95 GeolocationPermissionContextTests();
96 96
97 protected: 97 protected:
98 virtual ~GeolocationPermissionContextTests(); 98 virtual ~GeolocationPermissionContextTests();
99 99
100 int process_id() { 100 int process_id() {
101 return contents()->GetRenderProcessHost()->GetID(); 101 return contents()->GetRenderProcessHost()->GetID();
102 } 102 }
103 int process_id_for_tab(int tab) { 103 int process_id_for_tab(int tab) {
104 return extra_tabs_[tab]->web_contents()->GetRenderProcessHost()->GetID(); 104 return extra_tabs_[tab]->web_contents()->GetRenderProcessHost()->GetID();
105 } 105 }
106 int render_id() { return contents()->GetRenderViewHost()->GetRoutingID(); } 106 int render_id() { return contents()->GetRenderViewHost()->GetRoutingID(); }
107 int render_id_for_tab(int tab) { 107 int render_id_for_tab(int tab) {
108 return extra_tabs_[tab]->web_contents()-> 108 return extra_tabs_[tab]->web_contents()->
109 GetRenderViewHost()->GetRoutingID(); 109 GetRenderViewHost()->GetRoutingID();
110 } 110 }
111 int bridge_id() const { return 42; } // Not relevant at this level. 111 int bridge_id() const { return 42; } // Not relevant at this level.
112 InfoBarTabHelper* infobar_tab_helper() { 112 InfoBarTabHelper* infobar_tab_helper() {
113 return contents_wrapper()->infobar_tab_helper(); 113 return tab_contents()->infobar_tab_helper();
114 } 114 }
115 115
116 void RequestGeolocationPermission(int render_process_id, 116 void RequestGeolocationPermission(int render_process_id,
117 int render_view_id, 117 int render_view_id,
118 int bridge_id, 118 int bridge_id,
119 const GURL& requesting_frame); 119 const GURL& requesting_frame);
120 void PermissionResponse(int render_process_id, 120 void PermissionResponse(int render_process_id,
121 int render_view_id, 121 int render_view_id,
122 int bridge_id, 122 int bridge_id,
123 bool allowed); 123 bool allowed);
124 void CheckPermissionMessageSent(int bridge_id, bool allowed); 124 void CheckPermissionMessageSent(int bridge_id, bool allowed);
125 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); 125 void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed);
126 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process, 126 void CheckPermissionMessageSentInternal(MockRenderProcessHost* process,
127 int bridge_id, 127 int bridge_id,
128 bool allowed); 128 bool allowed);
129 void AddNewTab(const GURL& url); 129 void AddNewTab(const GURL& url);
130 void CheckTabContentsState(const GURL& requesting_frame, 130 void CheckTabContentsState(const GURL& requesting_frame,
131 ContentSetting expected_content_setting); 131 ContentSetting expected_content_setting);
132 132
133 scoped_refptr<ChromeGeolocationPermissionContext> 133 scoped_refptr<ChromeGeolocationPermissionContext>
134 geolocation_permission_context_; 134 geolocation_permission_context_;
135 ClosedDelegateTracker closed_delegate_tracker_; 135 ClosedDelegateTracker closed_delegate_tracker_;
136 ScopedVector<TabContentsWrapper> extra_tabs_; 136 ScopedVector<TabContentsWrapper> extra_tabs_;
137 137
138 private: 138 private:
139 // TabContentsWrapperTestHarness: 139 // TabContentsTestHarness:
140 virtual void SetUp() OVERRIDE; 140 virtual void SetUp() OVERRIDE;
141 virtual void TearDown() OVERRIDE; 141 virtual void TearDown() OVERRIDE;
142 142
143 content::TestBrowserThread ui_thread_; 143 content::TestBrowserThread ui_thread_;
144 content::TestBrowserThread db_thread_; 144 content::TestBrowserThread db_thread_;
145 145
146 // A map between renderer child id and a pair represending the bridge id and 146 // A map between renderer child id and a pair represending the bridge id and
147 // whether the requested permission was allowed. 147 // whether the requested permission was allowed.
148 base::hash_map<int, std::pair<int, bool> > responses_; 148 base::hash_map<int, std::pair<int, bool> > responses_;
149 }; 149 };
150 150
151 GeolocationPermissionContextTests::GeolocationPermissionContextTests() 151 GeolocationPermissionContextTests::GeolocationPermissionContextTests()
152 : TabContentsWrapperTestHarness(), 152 : TabContentsTestHarness(),
153 ui_thread_(BrowserThread::UI, MessageLoop::current()), 153 ui_thread_(BrowserThread::UI, MessageLoop::current()),
154 db_thread_(BrowserThread::DB) { 154 db_thread_(BrowserThread::DB) {
155 } 155 }
156 156
157 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { 157 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() {
158 } 158 }
159 159
160 void GeolocationPermissionContextTests::RequestGeolocationPermission( 160 void GeolocationPermissionContextTests::RequestGeolocationPermission(
161 int render_process_id, 161 int render_process_id,
162 int render_view_id, 162 int render_view_id,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string()); 211 url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
212 RenderViewHostTester::For(new_tab->GetRenderViewHost())-> 212 RenderViewHostTester::For(new_tab->GetRenderViewHost())->
213 SendNavigate(extra_tabs_.size() + 1, url); 213 SendNavigate(extra_tabs_.size() + 1, url);
214 extra_tabs_.push_back(new TabContentsWrapper(new_tab)); 214 extra_tabs_.push_back(new TabContentsWrapper(new_tab));
215 } 215 }
216 216
217 void GeolocationPermissionContextTests::CheckTabContentsState( 217 void GeolocationPermissionContextTests::CheckTabContentsState(
218 const GURL& requesting_frame, 218 const GURL& requesting_frame,
219 ContentSetting expected_content_setting) { 219 ContentSetting expected_content_setting) {
220 TabSpecificContentSettings* content_settings = 220 TabSpecificContentSettings* content_settings =
221 contents_wrapper()->content_settings(); 221 tab_contents()->content_settings();
222 const GeolocationSettingsState::StateMap& state_map = 222 const GeolocationSettingsState::StateMap& state_map =
223 content_settings->geolocation_settings_state().state_map(); 223 content_settings->geolocation_settings_state().state_map();
224 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin())); 224 EXPECT_EQ(1U, state_map.count(requesting_frame.GetOrigin()));
225 EXPECT_EQ(0U, state_map.count(requesting_frame)); 225 EXPECT_EQ(0U, state_map.count(requesting_frame));
226 GeolocationSettingsState::StateMap::const_iterator settings = 226 GeolocationSettingsState::StateMap::const_iterator settings =
227 state_map.find(requesting_frame.GetOrigin()); 227 state_map.find(requesting_frame.GetOrigin());
228 ASSERT_FALSE(settings == state_map.end()) 228 ASSERT_FALSE(settings == state_map.end())
229 << "geolocation state not found " << requesting_frame; 229 << "geolocation state not found " << requesting_frame;
230 EXPECT_EQ(expected_content_setting, settings->second); 230 EXPECT_EQ(expected_content_setting, settings->second);
231 } 231 }
232 232
233 void GeolocationPermissionContextTests::SetUp() { 233 void GeolocationPermissionContextTests::SetUp() {
234 db_thread_.Start(); 234 db_thread_.Start();
235 TabContentsWrapperTestHarness::SetUp(); 235 TabContentsTestHarness::SetUp();
236 geolocation_permission_context_ = 236 geolocation_permission_context_ =
237 new ChromeGeolocationPermissionContext(profile()); 237 new ChromeGeolocationPermissionContext(profile());
238 } 238 }
239 239
240 void GeolocationPermissionContextTests::TearDown() { 240 void GeolocationPermissionContextTests::TearDown() {
241 extra_tabs_.reset(); 241 extra_tabs_.reset();
242 TabContentsWrapperTestHarness::TearDown(); 242 TabContentsTestHarness::TearDown();
243 // Schedule another task on the DB thread to notify us that it's safe to 243 // Schedule another task on the DB thread to notify us that it's safe to
244 // carry on with the test. 244 // carry on with the test.
245 base::WaitableEvent done(false, false); 245 base::WaitableEvent done(false, false);
246 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 246 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
247 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); 247 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
248 done.Wait(); 248 done.Wait();
249 db_thread_.Stop(); 249 db_thread_.Stop();
250 } 250 }
251 251
252 252
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 ASSERT_FALSE(infobar_0->ShouldExpire(details)); 603 ASSERT_FALSE(infobar_0->ShouldExpire(details));
604 // Commit the "GoBack()" above, and ensure the infobar is now expired. 604 // Commit the "GoBack()" above, and ensure the infobar is now expired.
605 WebContentsTester::For(contents())->CommitPendingNavigation(); 605 WebContentsTester::For(contents())->CommitPendingNavigation();
606 details.entry = contents()->GetController().GetLastCommittedEntry(); 606 details.entry = contents()->GetController().GetLastCommittedEntry();
607 ASSERT_TRUE(infobar_0->ShouldExpire(details)); 607 ASSERT_TRUE(infobar_0->ShouldExpire(details));
608 608
609 // Delete the tab contents. 609 // Delete the tab contents.
610 DeleteContents(); 610 DeleteContents();
611 infobar_0->InfoBarClosed(); 611 infobar_0->InfoBarClosed();
612 } 612 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698