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 <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/api/infobars/confirm_infobar_delegate.h" | 13 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
14 #include "chrome/browser/content_settings/host_content_settings_map.h" | 14 #include "chrome/browser/content_settings/host_content_settings_map.h" |
15 #include "chrome/browser/content_settings/tab_specific_content_settings.h" | 15 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
16 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" | 16 #include "chrome/browser/geolocation/chrome_geolocation_permission_context.h" |
17 #include "chrome/browser/infobars/infobar.h" | 17 #include "chrome/browser/infobars/infobar.h" |
18 #include "chrome/browser/infobars/infobar_tab_helper.h" | 18 #include "chrome/browser/infobars/infobar_tab_helper.h" |
19 #include "chrome/browser/ui/tab_contents/tab_contents.h" | |
20 #include "chrome/browser/ui/tab_contents/test_tab_contents.h" | |
21 #include "chrome/browser/view_type_utils.h" | 19 #include "chrome/browser/view_type_utils.h" |
22 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
23 #include "chrome/test/base/testing_profile.h" | 22 #include "chrome/test/base/testing_profile.h" |
24 #include "content/public/browser/navigation_details.h" | 23 #include "content/public/browser/navigation_details.h" |
25 #include "content/public/browser/notification_registrar.h" | 24 #include "content/public/browser/notification_registrar.h" |
26 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
27 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
28 #include "content/public/test/mock_render_process_host.h" | 27 #include "content/public/test/mock_render_process_host.h" |
29 #include "content/public/test/test_browser_thread.h" | 28 #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 "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 return removed_infobar_delegates_.count(delegate) != 0; | 88 return removed_infobar_delegates_.count(delegate) != 0; |
90 } | 89 } |
91 | 90 |
92 void ClosedDelegateTracker::Clear() { | 91 void ClosedDelegateTracker::Clear() { |
93 removed_infobar_delegates_.clear(); | 92 removed_infobar_delegates_.clear(); |
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 : public TabContentsTestHarness { | 98 class GeolocationPermissionContextTests |
| 99 : public ChromeRenderViewHostTestHarness { |
100 public: | 100 public: |
101 GeolocationPermissionContextTests(); | 101 GeolocationPermissionContextTests(); |
102 | 102 |
103 protected: | 103 protected: |
104 virtual ~GeolocationPermissionContextTests(); | 104 virtual ~GeolocationPermissionContextTests(); |
105 | 105 |
106 int process_id() { | 106 int process_id() { |
107 return contents()->GetRenderProcessHost()->GetID(); | 107 return contents()->GetRenderProcessHost()->GetID(); |
108 } | 108 } |
109 int process_id_for_tab(int tab) { | 109 int process_id_for_tab(int tab) { |
(...skipping 27 matching lines...) Expand all Loading... |
137 void AddNewTab(const GURL& url); | 137 void AddNewTab(const GURL& url); |
138 void CheckTabContentsState(const GURL& requesting_frame, | 138 void CheckTabContentsState(const GURL& requesting_frame, |
139 ContentSetting expected_content_setting); | 139 ContentSetting expected_content_setting); |
140 | 140 |
141 scoped_refptr<ChromeGeolocationPermissionContext> | 141 scoped_refptr<ChromeGeolocationPermissionContext> |
142 geolocation_permission_context_; | 142 geolocation_permission_context_; |
143 ClosedDelegateTracker closed_delegate_tracker_; | 143 ClosedDelegateTracker closed_delegate_tracker_; |
144 ScopedVector<WebContents> extra_tabs_; | 144 ScopedVector<WebContents> extra_tabs_; |
145 | 145 |
146 private: | 146 private: |
147 // TabContentsTestHarness: | 147 // ChromeRenderViewHostTestHarness: |
148 virtual void SetUp() OVERRIDE; | 148 virtual void SetUp() OVERRIDE; |
149 virtual void TearDown() OVERRIDE; | 149 virtual void TearDown() OVERRIDE; |
150 | 150 |
151 content::TestBrowserThread ui_thread_; | 151 content::TestBrowserThread ui_thread_; |
152 content::TestBrowserThread db_thread_; | 152 content::TestBrowserThread db_thread_; |
153 | 153 |
154 // A map between renderer child id and a pair represending the bridge id and | 154 // A map between renderer child id and a pair represending the bridge id and |
155 // whether the requested permission was allowed. | 155 // whether the requested permission was allowed. |
156 base::hash_map<int, std::pair<int, bool> > responses_; | 156 base::hash_map<int, std::pair<int, bool> > responses_; |
157 }; | 157 }; |
158 | 158 |
159 GeolocationPermissionContextTests::GeolocationPermissionContextTests() | 159 GeolocationPermissionContextTests::GeolocationPermissionContextTests() |
160 : TabContentsTestHarness(), | 160 : ChromeRenderViewHostTestHarness(), |
161 ui_thread_(BrowserThread::UI, MessageLoop::current()), | 161 ui_thread_(BrowserThread::UI, MessageLoop::current()), |
162 db_thread_(BrowserThread::DB) { | 162 db_thread_(BrowserThread::DB) { |
163 } | 163 } |
164 | 164 |
165 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { | 165 GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { |
166 } | 166 } |
167 | 167 |
168 void GeolocationPermissionContextTests::RequestGeolocationPermission( | 168 void GeolocationPermissionContextTests::RequestGeolocationPermission( |
169 int render_process_id, | 169 int render_process_id, |
170 int render_view_id, | 170 int render_view_id, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 EXPECT_EQ(0U, state_map.count(requesting_frame)); | 238 EXPECT_EQ(0U, state_map.count(requesting_frame)); |
239 GeolocationSettingsState::StateMap::const_iterator settings = | 239 GeolocationSettingsState::StateMap::const_iterator settings = |
240 state_map.find(requesting_frame.GetOrigin()); | 240 state_map.find(requesting_frame.GetOrigin()); |
241 ASSERT_FALSE(settings == state_map.end()) | 241 ASSERT_FALSE(settings == state_map.end()) |
242 << "geolocation state not found " << requesting_frame; | 242 << "geolocation state not found " << requesting_frame; |
243 EXPECT_EQ(expected_content_setting, settings->second); | 243 EXPECT_EQ(expected_content_setting, settings->second); |
244 } | 244 } |
245 | 245 |
246 void GeolocationPermissionContextTests::SetUp() { | 246 void GeolocationPermissionContextTests::SetUp() { |
247 db_thread_.Start(); | 247 db_thread_.Start(); |
248 TabContentsTestHarness::SetUp(); | 248 ChromeRenderViewHostTestHarness::SetUp(); |
| 249 |
| 250 // Set up required helpers, and make this be as "tabby" as the code requires. |
| 251 chrome::SetViewType(web_contents(), chrome::VIEW_TYPE_TAB_CONTENTS); |
| 252 InfoBarTabHelper::CreateForWebContents(web_contents()); |
| 253 TabSpecificContentSettings::CreateForWebContents(web_contents()); |
| 254 |
249 geolocation_permission_context_ = | 255 geolocation_permission_context_ = |
250 new ChromeGeolocationPermissionContext(profile()); | 256 new ChromeGeolocationPermissionContext(profile()); |
251 } | 257 } |
252 | 258 |
253 void GeolocationPermissionContextTests::TearDown() { | 259 void GeolocationPermissionContextTests::TearDown() { |
254 extra_tabs_.clear(); | 260 extra_tabs_.clear(); |
255 TabContentsTestHarness::TearDown(); | 261 ChromeRenderViewHostTestHarness::TearDown(); |
256 // Schedule another task on the DB thread to notify us that it's safe to | 262 // Schedule another task on the DB thread to notify us that it's safe to |
257 // carry on with the test. | 263 // carry on with the test. |
258 base::WaitableEvent done(false, false); | 264 base::WaitableEvent done(false, false); |
259 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | 265 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, |
260 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | 266 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); |
261 done.Wait(); | 267 done.Wait(); |
262 db_thread_.Stop(); | 268 db_thread_.Stop(); |
263 } | 269 } |
264 | 270 |
265 | 271 |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
642 ASSERT_FALSE(infobar_0->ShouldExpire(details)); | 648 ASSERT_FALSE(infobar_0->ShouldExpire(details)); |
643 // Commit the "GoBack()" above, and ensure the infobar is now expired. | 649 // Commit the "GoBack()" above, and ensure the infobar is now expired. |
644 WebContentsTester::For(contents())->CommitPendingNavigation(); | 650 WebContentsTester::For(contents())->CommitPendingNavigation(); |
645 details.entry = contents()->GetController().GetLastCommittedEntry(); | 651 details.entry = contents()->GetController().GetLastCommittedEntry(); |
646 ASSERT_TRUE(infobar_0->ShouldExpire(details)); | 652 ASSERT_TRUE(infobar_0->ShouldExpire(details)); |
647 | 653 |
648 // Delete the tab contents. | 654 // Delete the tab contents. |
649 DeleteContents(); | 655 DeleteContents(); |
650 infobar_0->InfoBarClosed(); | 656 infobar_0->InfoBarClosed(); |
651 } | 657 } |
OLD | NEW |