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

Unified Diff: chrome/browser/geolocation/chrome_geolocation_permission_context_unittest.cc

Issue 11269002: Introduce GeolocationPermissionRequestID, a wrapper struct to contain the (render process ID, rende… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 2 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 side-by-side diff with in-line comments
Download patch
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)
@@ -15,6 +15,7 @@
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/geolocation/chrome_geolocation_permission_context.h"
#include "chrome/browser/geolocation/chrome_geolocation_permission_context_factory.h"
+#include "chrome/browser/geolocation/geolocation_permission_request_id.h"
#include "chrome/browser/infobars/infobar.h"
#include "chrome/browser/infobars/infobar_tab_helper.h"
#include "chrome/browser/view_type_utils.h"
@@ -36,12 +37,9 @@
#include "chrome/common/pref_names.h"
#endif
-using content::BrowserThread;
using content::MockRenderProcessHost;
-using content::RenderViewHostTester;
-using content::WebContents;
-using content::WebContentsTester;
+
// ClosedDelegateTracker ------------------------------------------------------
// We need to track which infobars were closed.
@@ -93,6 +91,7 @@
removed_infobar_delegates_.clear();
}
+
// GeolocationPermissionContextTests ------------------------------------------
// This class sets up GeolocationArbitrator.
@@ -104,19 +103,8 @@
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.
+ GeolocationPermissionRequestID RequestID(int bridge_id);
+ GeolocationPermissionRequestID RequestIDForTab(int tab, int bridge_id);
InfoBarTabHelper* infobar_tab_helper() {
return InfoBarTabHelper::FromWebContents(web_contents());
}
@@ -124,13 +112,12 @@
return InfoBarTabHelper::FromWebContents(extra_tabs_[tab]);
}
- void RequestGeolocationPermission(int render_process_id,
- int render_view_id,
- int bridge_id,
+ void RequestGeolocationPermission(const GeolocationPermissionRequestID& id,
const GURL& requesting_frame);
- void PermissionResponse(int render_process_id,
- int render_view_id,
- int bridge_id,
+ void CancelGeolocationPermissionRequest(
+ const GeolocationPermissionRequestID& id,
+ const GURL& requesting_frame);
+ void PermissionResponse(const GeolocationPermissionRequestID& id,
bool allowed);
void CheckPermissionMessageSent(int bridge_id, bool allowed);
void CheckPermissionMessageSentForTab(int tab, int bridge_id, bool allowed);
@@ -144,7 +131,7 @@
scoped_refptr<ChromeGeolocationPermissionContext>
geolocation_permission_context_;
ClosedDelegateTracker closed_delegate_tracker_;
- ScopedVector<WebContents> extra_tabs_;
+ ScopedVector<content::WebContents> extra_tabs_;
private:
// ChromeRenderViewHostTestHarness:
@@ -161,33 +148,51 @@
GeolocationPermissionContextTests::GeolocationPermissionContextTests()
: ChromeRenderViewHostTestHarness(),
- ui_thread_(BrowserThread::UI, MessageLoop::current()),
- db_thread_(BrowserThread::DB) {
+ ui_thread_(content::BrowserThread::UI, MessageLoop::current()),
+ db_thread_(content::BrowserThread::DB) {
}
GeolocationPermissionContextTests::~GeolocationPermissionContextTests() {
}
+GeolocationPermissionRequestID GeolocationPermissionContextTests::RequestID(
+ int bridge_id) {
+ return GeolocationPermissionRequestID(
+ web_contents()->GetRenderProcessHost()->GetID(),
+ web_contents()->GetRenderViewHost()->GetRoutingID(),
+ bridge_id);
+}
+
+GeolocationPermissionRequestID
+ GeolocationPermissionContextTests::RequestIDForTab(int tab, int bridge_id) {
+ return 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 GeolocationPermissionRequestID& id,
const GURL& requesting_frame) {
geolocation_permission_context_->RequestGeolocationPermission(
- render_process_id, render_view_id, bridge_id, requesting_frame,
+ id.render_process_id(), id.render_view_id(), id.bridge_id(),
+ requesting_frame,
base::Bind(&GeolocationPermissionContextTests::PermissionResponse,
- base::Unretained(this),
- render_process_id,
- render_view_id,
- bridge_id));
+ base::Unretained(this), id));
}
+void GeolocationPermissionContextTests::CancelGeolocationPermissionRequest(
+ const GeolocationPermissionRequestID& id,
+ const GURL& requesting_frame) {
+ geolocation_permission_context_->CancelGeolocationPermissionRequest(
+ id.render_process_id(), id.render_view_id(), id.bridge_id(),
+ requesting_frame);
+}
+
void GeolocationPermissionContextTests::PermissionResponse(
- int render_process_id,
- int render_view_id,
- int bridge_id,
+ const 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(
@@ -216,11 +221,11 @@
}
void GeolocationPermissionContextTests::AddNewTab(const GURL& url) {
- WebContents* new_tab =
- WebContents::Create(profile(), NULL, MSG_ROUTING_NONE, NULL);
+ content::WebContents* new_tab =
+ content::WebContents::Create(profile(), NULL, MSG_ROUTING_NONE, NULL);
new_tab->GetController().LoadURL(
url, content::Referrer(), content::PAGE_TRANSITION_TYPED, std::string());
- RenderViewHostTester::For(new_tab->GetRenderViewHost())->
+ content::RenderViewHostTester::For(new_tab->GetRenderViewHost())->
SendNavigate(extra_tabs_.size() + 1, url);
// Set up required helpers, and make this be as "tabby" as the code requires.
@@ -265,7 +270,8 @@
// Schedule another task on the DB thread to notify us that it's safe to
// carry on with the test.
base::WaitableEvent done(false, false);
- BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
+ content::BrowserThread::PostTask(
+ content::BrowserThread::DB, FROM_HERE,
base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done)));
done.Wait();
db_thread_.Stop();
@@ -278,11 +284,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 +307,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 +339,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 +361,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 +370,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 +413,26 @@
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);
+ CancelGeolocationPermissionRequest(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 +440,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 +467,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 +480,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 +528,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 +545,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 +566,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,29 +595,22 @@
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.
DeleteContents();
infobar_0->InfoBarClosed();
- // During contents destruction, the infobar will have been closed, and a
- // second (with it's own new delegate) will have been created. In Chromium,
- // this would be properly deleted by the InfoBarContainer, but in this unit
- // test, the closest thing we have to that is the ClosedDelegateTracker.
- ASSERT_EQ(2U, closed_delegate_tracker_.size());
+ // During contents destruction, the infobar will have been closed, and the
+ // pending request should have been cleared without an infobar being created.
+ ASSERT_EQ(1U, closed_delegate_tracker_.size());
ASSERT_TRUE(closed_delegate_tracker_.Contains(infobar_0));
- closed_delegate_tracker_.removed_infobar_delegates_.erase(infobar_0);
- (*closed_delegate_tracker_.removed_infobar_delegates_.begin())->
- InfoBarClosed();
}
TEST_F(GeolocationPermissionContextTests, InfoBarUsesCommittedEntry) {
@@ -639,8 +623,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);
@@ -650,7 +633,7 @@
details.entry = web_contents()->GetController().GetLastCommittedEntry();
ASSERT_FALSE(infobar_0->ShouldExpire(details));
// Commit the "GoBack()" above, and ensure the infobar is now expired.
- WebContentsTester::For(web_contents())->CommitPendingNavigation();
+ content::WebContentsTester::For(web_contents())->CommitPendingNavigation();
details.entry = web_contents()->GetController().GetLastCommittedEntry();
ASSERT_TRUE(infobar_0->ShouldExpire(details));

Powered by Google App Engine
This is Rietveld 408576698