Index: chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc |
=================================================================== |
--- chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc (revision 163741) |
+++ chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc (working copy) |
@@ -42,6 +42,7 @@ |
using content::WebContents; |
using content::WebContentsTester; |
+ |
// ClosedDelegateTracker ------------------------------------------------------ |
// We need to track which infobars were closed. |
@@ -93,6 +94,7 @@ |
removed_infobar_delegates_.clear(); |
} |
+ |
// GeolocationPermissionContextTests ------------------------------------------ |
// This class sets up GeolocationArbitrator. |
@@ -104,19 +106,9 @@ |
protected: |
virtual ~GeolocationPermissionContextTests(); |
- int process_id() { |
- return web_contents()->GetRenderProcessHost()->GetID(); |
- } |
- int process_id_for_tab(int tab) { |
- return extra_tabs_[tab]->GetRenderProcessHost()->GetID(); |
- } |
- int render_id() { |
- return web_contents()->GetRenderViewHost()->GetRoutingID(); |
- } |
- int render_id_for_tab(int tab) { |
- return extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(); |
- } |
- int bridge_id() const { return 42; } // Not relevant at this level. |
+ content::GeolocationPermissionRequestID RequestID(int bridge_id); |
+ content::GeolocationPermissionRequestID RequestIDForTab(int tab, |
+ int bridge_id); |
InfoBarTabHelper* infobar_tab_helper() { |
return InfoBarTabHelper::FromWebContents(web_contents()); |
} |
@@ -124,13 +116,10 @@ |
return InfoBarTabHelper::FromWebContents(extra_tabs_[tab]); |
} |
- void RequestGeolocationPermission(int render_process_id, |
- int render_view_id, |
- int bridge_id, |
- const GURL& requesting_frame); |
- void PermissionResponse(int render_process_id, |
- int render_view_id, |
- int bridge_id, |
+ void RequestGeolocationPermission( |
+ const content::GeolocationPermissionRequestID& id, |
+ const GURL& requesting_frame); |
+ void PermissionResponse(const content::GeolocationPermissionRequestID& id, |
bool allowed); |
void CheckPermissionMessageSent(int bridge_id, bool allowed); |
void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed); |
@@ -168,26 +157,35 @@ |
GeolocationPermissionContextTests::~GeolocationPermissionContextTests() { |
} |
+content::GeolocationPermissionRequestID |
+ GeolocationPermissionContextTests::RequestID(int bridge_id) { |
+ return content::GeolocationPermissionRequestID( |
+ web_contents()->GetRenderProcessHost()->GetID(), |
+ web_contents()->GetRenderViewHost()->GetRoutingID(), |
+ bridge_id); |
+} |
+ |
+content::GeolocationPermissionRequestID |
+ GeolocationPermissionContextTests::RequestIDForTab(int tab, int bridge_id) { |
+ return content::GeolocationPermissionRequestID( |
+ extra_tabs_[tab]->GetRenderProcessHost()->GetID(), |
+ extra_tabs_[tab]->GetRenderViewHost()->GetRoutingID(), |
+ bridge_id); |
+} |
+ |
void GeolocationPermissionContextTests::RequestGeolocationPermission( |
- int render_process_id, |
- int render_view_id, |
- int bridge_id, |
+ const content::GeolocationPermissionRequestID& id, |
const GURL& requesting_frame) { |
geolocation_permission_context_->RequestGeolocationPermission( |
- render_process_id, render_view_id, bridge_id, requesting_frame, |
- base::Bind(&GeolocationPermissionContextTests::PermissionResponse, |
- base::Unretained(this), |
- render_process_id, |
- render_view_id, |
- bridge_id)); |
+ id, requesting_frame, base::Bind( |
+ &GeolocationPermissionContextTests::PermissionResponse, |
+ base::Unretained(this), id)); |
} |
void GeolocationPermissionContextTests::PermissionResponse( |
- int render_process_id, |
- int render_view_id, |
- int bridge_id, |
+ const content::GeolocationPermissionRequestID& id, |
bool allowed) { |
- responses_[render_process_id] = std::make_pair(bridge_id, allowed); |
+ responses_[id.render_process_id] = std::make_pair(id.bridge_id, allowed); |
} |
void GeolocationPermissionContextTests::CheckPermissionMessageSent( |
@@ -278,11 +276,10 @@ |
GURL requesting_frame("http://www.example.com/geolocation"); |
NavigateAndCommit(requesting_frame); |
EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id(), requesting_frame); |
+ RequestGeolocationPermission(RequestID(0), requesting_frame); |
ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
- ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> |
- GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
+ ConfirmInfoBarDelegate* infobar_0 = |
+ infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
infobar_0->Cancel(); |
infobar_tab_helper()->RemoveInfoBar(infobar_0); |
EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
@@ -302,17 +299,15 @@ |
NavigateAndCommit(requesting_frame); |
EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, false); |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id(), requesting_frame); |
+ RequestGeolocationPermission(RequestID(0), requesting_frame); |
ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
- CheckPermissionMessageSent(bridge_id(), false); |
+ CheckPermissionMessageSent(0, false); |
// Reenable the preference and check that the request now goes though. |
profile()->GetPrefs()->SetBoolean(prefs::kGeolocationEnabled, true); |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id() + 1, requesting_frame); |
+ RequestGeolocationPermission(RequestID(1), requesting_frame); |
ASSERT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
- CheckPermissionMessageSent(bridge_id() + 1, true); |
+ CheckPermissionMessageSent(1, true); |
} |
#endif |
@@ -336,21 +331,19 @@ |
NavigateAndCommit(requesting_frame_0); |
EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
// Request permission for two frames. |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id(), requesting_frame_0); |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id() + 1, requesting_frame_1); |
+ RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
+ RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
// Ensure only one infobar is created. |
ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
- ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> |
- GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
+ ConfirmInfoBarDelegate* infobar_0 = |
+ infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
ASSERT_TRUE(infobar_0); |
string16 text_0 = infobar_0->GetMessageText(); |
// Accept the first frame. |
infobar_0->Accept(); |
CheckTabContentsState(requesting_frame_0, CONTENT_SETTING_ALLOW); |
- CheckPermissionMessageSent(bridge_id(), true); |
+ CheckPermissionMessageSent(0, true); |
infobar_tab_helper()->RemoveInfoBar(infobar_0); |
EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
@@ -360,8 +353,8 @@ |
// Now we should have a new infobar for the second frame. |
ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
- ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> |
- GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
+ ConfirmInfoBarDelegate* infobar_1 = |
+ infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
ASSERT_TRUE(infobar_1); |
string16 text_1 = infobar_1->GetMessageText(); |
EXPECT_NE(text_0, text_1); |
@@ -369,7 +362,7 @@ |
// Cancel (block) this frame. |
infobar_1->Cancel(); |
CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_BLOCK); |
- CheckPermissionMessageSent(bridge_id() + 1, false); |
+ CheckPermissionMessageSent(1, false); |
infobar_tab_helper()->RemoveInfoBar(infobar_1); |
EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
@@ -412,29 +405,27 @@ |
NavigateAndCommit(requesting_frame_0); |
EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
// Request permission for two frames. |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id(), requesting_frame_0); |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id() + 1, requesting_frame_1); |
+ RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
+ RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
- ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> |
- GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
+ ConfirmInfoBarDelegate* infobar_0 = |
+ infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
ASSERT_TRUE(infobar_0); |
string16 text_0 = infobar_0->GetMessageText(); |
// Simulate the frame going away, ensure the infobar for this frame |
// is removed and the next pending infobar is created. |
geolocation_permission_context_->CancelGeolocationPermissionRequest( |
- process_id(), render_id(), bridge_id(), requesting_frame_0); |
+ RequestID(0), requesting_frame_0); |
EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
closed_delegate_tracker_.Clear(); |
infobar_0->InfoBarClosed(); |
ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
- ConfirmInfoBarDelegate* infobar_1 = infobar_tab_helper()-> |
- GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
+ ConfirmInfoBarDelegate* infobar_1 = |
+ infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
ASSERT_TRUE(infobar_1); |
string16 text_1 = infobar_1->GetMessageText(); |
EXPECT_NE(text_0, text_1); |
@@ -442,7 +433,7 @@ |
// Allow this frame. |
infobar_1->Accept(); |
CheckTabContentsState(requesting_frame_1, CONTENT_SETTING_ALLOW); |
- CheckPermissionMessageSent(bridge_id() + 1, true); |
+ CheckPermissionMessageSent(1, true); |
infobar_tab_helper()->RemoveInfoBar(infobar_1); |
EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
@@ -469,10 +460,9 @@ |
GURL requesting_frame; |
NavigateAndCommit(invalid_embedder); |
EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id(), requesting_frame); |
+ RequestGeolocationPermission(RequestID(0), requesting_frame); |
EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
- CheckPermissionMessageSent(bridge_id(), false); |
+ CheckPermissionMessageSent(0, false); |
} |
TEST_F(GeolocationPermissionContextTests, SameOriginMultipleTabs) { |
@@ -483,34 +473,31 @@ |
AddNewTab(url_a); |
EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id(), url_a); |
+ RequestGeolocationPermission(RequestID(0), url_a); |
ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
- RequestGeolocationPermission( |
- process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_b); |
+ RequestGeolocationPermission(RequestIDForTab(0, 0), url_b); |
EXPECT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
- RequestGeolocationPermission( |
- process_id_for_tab(1), render_id_for_tab(1), bridge_id(), url_a); |
+ RequestGeolocationPermission(RequestIDForTab(1, 0), url_a); |
ASSERT_EQ(1U, infobar_tab_helper_for_tab(1)->GetInfoBarCount()); |
ConfirmInfoBarDelegate* removed_infobar = infobar_tab_helper_for_tab(1)-> |
GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
// Accept the first tab. |
- ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> |
- GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
+ ConfirmInfoBarDelegate* infobar_0 = |
+ infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
ASSERT_TRUE(infobar_0); |
infobar_0->Accept(); |
- CheckPermissionMessageSent(bridge_id(), true); |
+ CheckPermissionMessageSent(0, true); |
infobar_tab_helper()->RemoveInfoBar(infobar_0); |
EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
infobar_0->InfoBarClosed(); |
// Now the infobar for the tab with the same origin should have gone. |
EXPECT_EQ(0U, infobar_tab_helper_for_tab(1)->GetInfoBarCount()); |
- CheckPermissionMessageSentForTab(1, bridge_id(), true); |
+ CheckPermissionMessageSentForTab(1, 0, true); |
EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
closed_delegate_tracker_.Clear(); |
// Destroy the infobar that has just been removed. |
@@ -534,16 +521,13 @@ |
AddNewTab(url_a); |
EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id(), url_a); |
+ RequestGeolocationPermission(RequestID(0), url_a); |
ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
- RequestGeolocationPermission( |
- process_id_for_tab(0), render_id_for_tab(0), bridge_id(), url_a); |
+ RequestGeolocationPermission(RequestIDForTab(0, 0), url_a); |
EXPECT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
- RequestGeolocationPermission( |
- process_id_for_tab(0), render_id_for_tab(0), bridge_id() + 1, url_b); |
+ RequestGeolocationPermission(RequestIDForTab(0, 1), url_b); |
ASSERT_EQ(1U, infobar_tab_helper_for_tab(0)->GetInfoBarCount()); |
ConfirmInfoBarDelegate* removed_infobar = |
@@ -554,14 +538,14 @@ |
GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
ASSERT_TRUE(infobar_0); |
infobar_0->Accept(); |
- CheckPermissionMessageSentForTab(0, bridge_id(), true); |
+ CheckPermissionMessageSentForTab(0, 0, true); |
infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_0); |
EXPECT_EQ(2U, closed_delegate_tracker_.size()); |
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_0)); |
infobar_0->InfoBarClosed(); |
// Now the infobar for the tab with the same origin should have gone. |
EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
- CheckPermissionMessageSent(bridge_id(), true); |
+ CheckPermissionMessageSent(0, true); |
EXPECT_TRUE(closed_delegate_tracker_.Contains(removed_infobar)); |
closed_delegate_tracker_.Clear(); |
// Destroy the infobar that has just been removed. |
@@ -575,7 +559,7 @@ |
GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
ASSERT_TRUE(infobar_1); |
infobar_1->Accept(); |
- CheckPermissionMessageSentForTab(0, bridge_id() + 1, true); |
+ CheckPermissionMessageSentForTab(0, 1, true); |
infobar_tab_helper_for_tab(0)->RemoveInfoBar(infobar_1); |
EXPECT_EQ(1U, closed_delegate_tracker_.size()); |
EXPECT_TRUE(closed_delegate_tracker_.Contains(infobar_1)); |
@@ -604,14 +588,12 @@ |
NavigateAndCommit(requesting_frame_0); |
EXPECT_EQ(0U, infobar_tab_helper()->GetInfoBarCount()); |
// Request permission for two frames. |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id(), requesting_frame_0); |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id() + 1, requesting_frame_1); |
+ RequestGeolocationPermission(RequestID(0), requesting_frame_0); |
+ RequestGeolocationPermission(RequestID(1), requesting_frame_1); |
// Ensure only one infobar is created. |
ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
- ConfirmInfoBarDelegate* infobar_0 = infobar_tab_helper()-> |
- GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
+ ConfirmInfoBarDelegate* infobar_0 = |
+ infobar_tab_helper()->GetInfoBarDelegateAt(0)->AsConfirmInfoBarDelegate(); |
ASSERT_TRUE(infobar_0); |
// Delete the tab contents. |
@@ -639,8 +621,7 @@ |
// permission. |
web_contents()->GetController().GoBack(); |
// Request permission for the committed frame (not the pending one). |
- RequestGeolocationPermission( |
- process_id(), render_id(), bridge_id(), requesting_frame_1); |
+ RequestGeolocationPermission(RequestID(0), requesting_frame_1); |
// Ensure the infobar is created. |
ASSERT_EQ(1U, infobar_tab_helper()->GetInfoBarCount()); |
InfoBarDelegate* infobar_0 = infobar_tab_helper()->GetInfoBarDelegateAt(0); |