Chromium Code Reviews| Index: chrome/browser/geolocation/geolocation_browsertest.cc |
| diff --git a/chrome/browser/geolocation/geolocation_browsertest.cc b/chrome/browser/geolocation/geolocation_browsertest.cc |
| index 1b989fa1dfe1bcfac33f3720b6bbd6874f00866c..1de84e9414f26677c58f61650094c8e9c9166f6d 100644 |
| --- a/chrome/browser/geolocation/geolocation_browsertest.cc |
| +++ b/chrome/browser/geolocation/geolocation_browsertest.cc |
| @@ -4,6 +4,7 @@ |
| #include <string> |
| +#include "base/command_line.h" |
| #include "base/compiler_specific.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/stringprintf.h" |
| @@ -18,7 +19,9 @@ |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_commands.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/browser/ui/website_settings/permission_bubble_manager.h" |
| #include "chrome/common/chrome_paths.h" |
| +#include "chrome/common/chrome_switches.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "components/content_settings/core/browser/host_content_settings_map.h" |
| @@ -121,14 +124,76 @@ void IFrameLoader::Observe(int type, |
| base::MessageLoopForUI::current()->Quit(); |
| } |
| +// MockView ------------------------------------------------------------------- |
| + |
| +class MockView : public PermissionBubbleView { |
|
Michael van Ouwerkerk
2014/12/17 17:20:18
MockView seems quite a generic name, maybe MockBub
Michael van Ouwerkerk
2014/12/17 17:20:19
This looks like a completely generic class that co
felt
2014/12/18 22:09:09
Done.
felt
2014/12/18 22:09:09
Done.
|
| + public: |
| + MockView() : shown_(false), can_accept_updates_(true), delegate_(NULL) {} |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
We should use nullptr now. Here and below.
felt
2014/12/18 22:09:09
Done.
|
| + virtual ~MockView() {} |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
Overriding destructors use override now instead of
felt
2014/12/18 22:09:09
Done.
|
| + |
| + void Clear() { |
| + shown_ = false; |
| + can_accept_updates_ = true; |
| + delegate_ = NULL; |
| + permission_requests_.clear(); |
| + permission_states_.clear(); |
| + } |
| + |
| + // PermissionBubbleView: |
| + virtual void SetDelegate(Delegate* delegate) override { |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
Does this take ownership of the delegate? Maybe th
Michael van Ouwerkerk
2014/12/17 17:20:19
When using override, omit virtual. Here and below.
felt
2014/12/18 22:09:09
No, it doesn't take ownership.
felt
2014/12/18 22:09:09
Done.
|
| + delegate_ = delegate; |
| + } |
| + |
| + virtual void Show( |
| + const std::vector<PermissionBubbleRequest*>& requests, |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
From permission_bubble_view.h it seems this does n
felt
2014/12/18 22:09:09
Correct
|
| + const std::vector<bool>& accept_state, |
| + bool customization_state_) override { |
| + shown_ = true; |
| + permission_requests_ = requests; |
| + permission_states_ = accept_state; |
| + base::MessageLoopForUI::current()->Quit(); |
| + } |
| + |
| + virtual void Hide() override { |
| + shown_ = false; |
| + } |
| + |
| + virtual bool IsVisible() override { |
| + return shown_; |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
Maybe rename shown_ to visible_ for consistency?
felt
2014/12/18 22:09:09
Done.
|
| + } |
| + |
| + virtual bool CanAcceptRequestUpdate() override { |
| + return can_accept_updates_; |
| + } |
| + |
| + void Accept() { |
| + delegate_->Accept(); |
| + } |
| + |
| + void Deny() { |
| + delegate_->Deny(); |
| + } |
| + |
| + void Close() { |
| + delegate_->Closing(); |
| + } |
| + |
| + bool shown_; |
| + bool can_accept_updates_; |
| + Delegate* delegate_; |
| + std::vector<PermissionBubbleRequest*> permission_requests_; |
| + std::vector<bool> permission_states_; |
| +}; |
| + |
| // GeolocationNotificationObserver -------------------------------------------- |
| class GeolocationNotificationObserver : public content::NotificationObserver { |
| public: |
| - // If |wait_for_infobar| is true, AddWatchAndWaitForNotification will block |
| - // until the infobar has been displayed; otherwise it will block until the |
| + // If |wait_for_prompt| is true, AddWatchAndWaitForNotification will block |
| + // until the prompt has been displayed; otherwise it will block until the |
| // navigation is completed. |
| - explicit GeolocationNotificationObserver(bool wait_for_infobar); |
| + explicit GeolocationNotificationObserver( |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
No need for explicit anymore.
felt
2014/12/18 22:09:09
Done.
|
| + bool wait_for_prompt, MockView* view); |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
Does this take ownership of the view?
felt
2014/12/18 22:09:09
No, added note.
|
| ~GeolocationNotificationObserver() override; |
| // content::NotificationObserver: |
| @@ -136,6 +201,7 @@ class GeolocationNotificationObserver : public content::NotificationObserver { |
| const content::NotificationSource& source, |
| const content::NotificationDetails& details) override; |
| + // Note: also runs the 'geoStart' method in the test JS script. |
| void AddWatchAndWaitForNotification( |
| content::RenderFrameHost* render_frame_host); |
| @@ -144,27 +210,30 @@ class GeolocationNotificationObserver : public content::NotificationObserver { |
| private: |
| content::NotificationRegistrar registrar_; |
| - bool wait_for_infobar_; |
| + bool wait_for_prompt_; |
| infobars::InfoBar* infobar_; |
| bool navigation_started_; |
| bool navigation_completed_; |
| std::string javascript_response_; |
| + MockView* mock_view_; |
| DISALLOW_COPY_AND_ASSIGN(GeolocationNotificationObserver); |
| }; |
| GeolocationNotificationObserver::GeolocationNotificationObserver( |
| - bool wait_for_infobar) |
| - : wait_for_infobar_(wait_for_infobar), |
| + bool wait_for_prompt, |
| + MockView* view) |
| + : wait_for_prompt_(wait_for_prompt), |
| infobar_(NULL), |
| navigation_started_(false), |
| - navigation_completed_(false) { |
| + navigation_completed_(false), |
| + mock_view_(view) { |
| registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, |
| content::NotificationService::AllSources()); |
| - if (wait_for_infobar) { |
| + if (wait_for_prompt && !PermissionBubbleManager::Enabled()) { |
| registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED, |
| content::NotificationService::AllSources()); |
| - } else { |
| + } else if (!wait_for_prompt) { |
| registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| content::NotificationService::AllSources()); |
| registrar_.Add(this, content::NOTIFICATION_LOAD_START, |
| @@ -189,6 +258,8 @@ void GeolocationNotificationObserver::Observe( |
| content::Details<DomOperationNotificationDetails> dom_op_details(details); |
| javascript_response_ = dom_op_details->json; |
| LOG(WARNING) << "javascript_response " << javascript_response_; |
| + if (wait_for_prompt_ && PermissionBubbleManager::Enabled()) |
| + base::MessageLoopForUI::current()->Quit(); |
| } else if ((type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) || |
| (type == content::NOTIFICATION_LOAD_START)) { |
| navigation_started_ = true; |
| @@ -199,23 +270,35 @@ void GeolocationNotificationObserver::Observe( |
| // We're either waiting for just the infobar, or for both a javascript |
| // prompt and response. |
| - if ((wait_for_infobar_ && infobar_) || |
| + if ((wait_for_prompt_ && infobar_ && !PermissionBubbleManager::Enabled()) || |
| (navigation_completed_ && !javascript_response_.empty())) |
| base::MessageLoopForUI::current()->Quit(); |
| } |
| void GeolocationNotificationObserver::AddWatchAndWaitForNotification( |
| content::RenderFrameHost* render_frame_host) { |
| - LOG(WARNING) << "will add geolocation watch"; |
| - std::string script( |
| - "window.domAutomationController.setAutomationId(0);" |
| - "window.domAutomationController.send(geoStart());"); |
| - render_frame_host->ExecuteJavaScript(base::UTF8ToUTF16(script)); |
| - content::RunMessageLoop(); |
| - registrar_.RemoveAll(); |
| - LOG(WARNING) << "got geolocation watch" << javascript_response_; |
| - EXPECT_NE("\"0\"", javascript_response_); |
| - EXPECT_TRUE(wait_for_infobar_ ? (infobar_ != NULL) : navigation_completed_); |
| + if (!PermissionBubbleManager::Enabled()) { |
| + LOG(WARNING) << "will add geolocation watch"; |
| + std::string script( |
| + "window.domAutomationController.setAutomationId(0);" |
| + "window.domAutomationController.send(geoStart());"); |
| + render_frame_host->ExecuteJavaScript(base::UTF8ToUTF16(script)); |
| + content::RunMessageLoop(); |
| + registrar_.RemoveAll(); |
| + LOG(WARNING) << "got geolocation watch" << javascript_response_; |
| + EXPECT_NE("\"0\"", javascript_response_); |
| + EXPECT_TRUE(wait_for_prompt_ ? (infobar_ != NULL) : navigation_completed_); |
| + } else { |
| + LOG(WARNING) << "will add geolocation watch for bubble"; |
| + std::string script( |
| + "window.domAutomationController.setAutomationId(0);" |
| + "window.domAutomationController.send(geoStart());"); |
| + render_frame_host->ExecuteJavaScript(base::UTF8ToUTF16(script)); |
| + (new content::MessageLoopRunner())->Run(); |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
I think this runner is leaking, as no scoped_refpt
felt
2014/12/18 22:09:09
Done.
|
| + while (wait_for_prompt_ && !mock_view_->shown_) { |
| + (new content::MessageLoopRunner())->Run(); |
| + } |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
No need for curly braces for oneliners.
felt
2014/12/18 22:09:09
Done.
|
| + } |
| } |
| } // namespace |
| @@ -225,14 +308,15 @@ void GeolocationNotificationObserver::AddWatchAndWaitForNotification( |
| // This is a browser test for Geolocation. |
| // It exercises various integration points from javascript <-> browser: |
| -// 1. Infobar is displayed when a geolocation is requested from an unauthorized |
| -// origin. |
| -// 2. Denying the infobar triggers the correct error callback. |
| -// 3. Allowing the infobar does not trigger an error, and allow a geoposition to |
| -// be passed to javascript. |
| +// 1. Prompt is displayed when a geolocation is requested from an unauthorized |
| +// origin. |
| +// 2. Denying the request triggers the correct error callback. |
| +// 3. Allowing the request does not trigger an error, and allow a geoposition to |
| +// be passed to javascript. |
| // 4. Permissions persisted in disk are respected. |
| // 5. Incognito profiles don't use saved permissions. |
| -class GeolocationBrowserTest : public InProcessBrowserTest { |
| +class GeolocationBrowserTest : public InProcessBrowserTest, |
| + public testing::WithParamInterface<bool> { |
| public: |
| enum InitializationOptions { |
| INITIALIZATION_NONE, |
| @@ -267,19 +351,19 @@ class GeolocationBrowserTest : public InProcessBrowserTest { |
| // Specifies which frame is to be used for JavaScript calls. |
| void SetFrameHost(const std::string& frame_name); |
| - // Start watching for geolocation notifications. If |wait_for_infobar| is |
| - // true, wait for the infobar to be displayed. Otherwise wait for a javascript |
| - // response. |
| - void AddGeolocationWatch(bool wait_for_infobar); |
| + // Start watching for geolocation notifications. If |wait_for_prompt| is |
| + // true, wait for the prompt (infobar or bubble) to be displayed. Otherwise |
| + // wait for a javascript response. |
| + void AddGeolocationWatch(bool wait_for_prompt); |
| // Checks that no errors have been received in javascript, and checks that the |
| // position most recently received in javascript matches |latitude| and |
| // |longitude|. |
| void CheckGeoposition(double latitude, double longitude); |
| - // For |requesting_url| if |allowed| is true accept the infobar. Otherwise |
| + // For |requesting_url| if |allowed| is true accept the ptompt. Otherwise |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
prompt
felt
2014/12/18 22:09:09
Done.
|
| // cancel it. |
| - void SetInfoBarResponse(const GURL& requesting_url, bool allowed); |
| + void SetPromptResponse(const GURL& requesting_url, bool allowed); |
| // Executes |function| in |render_frame_host| and checks that the return value |
| // matches |expected|. |
| @@ -295,6 +379,9 @@ class GeolocationBrowserTest : public InProcessBrowserTest { |
| // Sets a new position and sends a notification with the new position. |
| void NotifyGeoposition(double latitude, double longitude); |
| + // Convenience method to look up the number of queued permission bubbles. |
| + int GetBubblesQueueSize(PermissionBubbleManager* mgr); |
| + |
| private: |
| infobars::InfoBar* infobar_; |
| Browser* current_browser_; |
| @@ -308,6 +395,7 @@ class GeolocationBrowserTest : public InProcessBrowserTest { |
| std::vector<GURL> iframe_urls_; |
| double fake_latitude_; |
| double fake_longitude_; |
| + MockView mock_bubble_view_; |
| DISALLOW_COPY_AND_ASSIGN(GeolocationBrowserTest); |
| }; |
| @@ -326,6 +414,17 @@ GeolocationBrowserTest::~GeolocationBrowserTest() { |
| void GeolocationBrowserTest::SetUpOnMainThread() { |
| ui_test_utils::OverrideGeolocation(fake_latitude_, fake_longitude_); |
| +#if !defined(OS_ANDROID) |
| + if (GetParam()) { |
| + base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| + switches::kEnablePermissionsBubbles); |
| + EXPECT_TRUE(PermissionBubbleManager::Enabled()); |
| + } else { |
| + base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| + switches::kDisablePermissionsBubbles); |
| + EXPECT_FALSE(PermissionBubbleManager::Enabled()); |
| + } |
| +#endif |
| } |
| void GeolocationBrowserTest::TearDownInProcessBrowserTestFixture() { |
| @@ -344,10 +443,18 @@ bool GeolocationBrowserTest::Initialize(InitializationOptions options) { |
| if (options == INITIALIZATION_OFFTHERECORD) { |
| current_browser_ = ui_test_utils::OpenURLOffTheRecord( |
| browser()->profile(), current_url_); |
| + WebContents* web_contents = |
| + current_browser_->tab_strip_model()->GetActiveWebContents(); |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
There's some pretty verbose duplication here. It w
felt
2014/12/18 22:09:09
Given that they're only used in this method for in
|
| + PermissionBubbleManager::FromWebContents(web_contents)->SetView( |
| + &mock_bubble_view_); |
| } else { |
| current_browser_ = browser(); |
| if (options == INITIALIZATION_NEWTAB) |
| chrome::NewTab(current_browser_); |
| + WebContents* web_contents = |
| + current_browser_->tab_strip_model()->GetActiveWebContents(); |
| + PermissionBubbleManager::FromWebContents(web_contents)->SetView( |
| + &mock_bubble_view_); |
| ui_test_utils::NavigateToURL(current_browser_, current_url_); |
| } |
| LOG(WARNING) << "after navigate"; |
| @@ -381,10 +488,11 @@ void GeolocationBrowserTest::SetFrameHost(const std::string& frame_name) { |
| DCHECK(render_frame_host_); |
| } |
| -void GeolocationBrowserTest::AddGeolocationWatch(bool wait_for_infobar) { |
| - GeolocationNotificationObserver notification_observer(wait_for_infobar); |
| +void GeolocationBrowserTest::AddGeolocationWatch(bool wait_for_prompt) { |
| + GeolocationNotificationObserver notification_observer( |
| + wait_for_prompt, &mock_bubble_view_); |
| notification_observer.AddWatchAndWaitForNotification(render_frame_host_); |
| - if (wait_for_infobar) { |
| + if (wait_for_prompt && !PermissionBubbleManager::Enabled()) { |
| EXPECT_TRUE(notification_observer.has_infobar()); |
| infobar_ = notification_observer.infobar(); |
| } |
| @@ -400,40 +508,63 @@ void GeolocationBrowserTest::CheckGeoposition(double latitude, |
| "geoGetLastPositionLongitude()"); |
| } |
| -void GeolocationBrowserTest::SetInfoBarResponse(const GURL& requesting_url, |
| +void GeolocationBrowserTest::SetPromptResponse(const GURL& requesting_url, |
| bool allowed) { |
| - WebContents* web_contents = |
| - current_browser_->tab_strip_model()->GetActiveWebContents(); |
| - TabSpecificContentSettings* content_settings = |
| - TabSpecificContentSettings::FromWebContents(web_contents); |
| - const ContentSettingsUsagesState& usages_state = |
| - content_settings->geolocation_usages_state(); |
| - size_t state_map_size = usages_state.state_map().size(); |
| - ASSERT_TRUE(infobar_); |
| - LOG(WARNING) << "will set infobar response"; |
| - { |
| - content::WindowedNotificationObserver observer( |
| - content::NOTIFICATION_LOAD_STOP, |
| - content::Source<NavigationController>(&web_contents->GetController())); |
| + if (PermissionBubbleManager::Enabled()) { |
| + WebContents* web_contents = |
| + current_browser_->tab_strip_model()->GetActiveWebContents(); |
| + TabSpecificContentSettings* content_settings = |
| + TabSpecificContentSettings::FromWebContents(web_contents); |
| + const ContentSettingsUsagesState& usages_state = |
| + content_settings->geolocation_usages_state(); |
| + size_t state_map_size = usages_state.state_map().size(); |
| if (allowed) |
| - infobar_->delegate()->AsConfirmInfoBarDelegate()->Accept(); |
| + mock_bubble_view_.Accept(); |
| else |
| - infobar_->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
| - observer.Wait(); |
| + mock_bubble_view_.Deny(); |
| + |
| + EXPECT_GT(usages_state.state_map().size(), state_map_size); |
| + GURL requesting_origin(requesting_url.GetOrigin()); |
| + EXPECT_EQ(1U, usages_state.state_map().count(requesting_origin)); |
| + ContentSetting expected_setting = |
| + allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| + EXPECT_EQ(expected_setting, |
| + usages_state.state_map().find(requesting_origin)->second); |
| + } else { |
| + WebContents* web_contents = |
| + current_browser_->tab_strip_model()->GetActiveWebContents(); |
| + TabSpecificContentSettings* content_settings = |
| + TabSpecificContentSettings::FromWebContents(web_contents); |
| + const ContentSettingsUsagesState& usages_state = |
| + content_settings->geolocation_usages_state(); |
| + size_t state_map_size = usages_state.state_map().size(); |
| + ASSERT_TRUE(infobar_); |
| + LOG(WARNING) << "will set infobar response"; |
| + { |
| + content::WindowedNotificationObserver observer( |
| + content::NOTIFICATION_LOAD_STOP, |
| + content::Source<NavigationController>( |
| + &web_contents->GetController())); |
| + if (allowed) |
| + infobar_->delegate()->AsConfirmInfoBarDelegate()->Accept(); |
| + else |
| + infobar_->delegate()->AsConfirmInfoBarDelegate()->Cancel(); |
| + observer.Wait(); |
| + } |
| + |
| + InfoBarService* infobar_service = |
| + InfoBarService::FromWebContents(web_contents); |
| + infobar_service->RemoveInfoBar(infobar_); |
| + LOG(WARNING) << "infobar response set"; |
| + infobar_ = NULL; |
| + EXPECT_GT(usages_state.state_map().size(), state_map_size); |
| + GURL requesting_origin(requesting_url.GetOrigin()); |
| + EXPECT_EQ(1U, usages_state.state_map().count(requesting_origin)); |
| + ContentSetting expected_setting = |
| + allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| + EXPECT_EQ(expected_setting, |
| + usages_state.state_map().find(requesting_origin)->second); |
| } |
| - |
| - InfoBarService* infobar_service = |
| - InfoBarService::FromWebContents(web_contents); |
| - infobar_service->RemoveInfoBar(infobar_); |
| - LOG(WARNING) << "infobar response set"; |
| - infobar_ = NULL; |
| - EXPECT_GT(usages_state.state_map().size(), state_map_size); |
| - GURL requesting_origin(requesting_url.GetOrigin()); |
| - EXPECT_EQ(1U, usages_state.state_map().count(requesting_origin)); |
| - ContentSetting expected_setting = |
| - allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK; |
| - EXPECT_EQ(expected_setting, |
| - usages_state.state_map().find(requesting_origin)->second); |
| } |
| void GeolocationBrowserTest::CheckStringValueFromJavascriptForFrame( |
| @@ -463,50 +594,55 @@ void GeolocationBrowserTest::NotifyGeoposition(double latitude, |
| LOG(WARNING) << "MockLocationProvider listeners updated"; |
| } |
| +int GeolocationBrowserTest::GetBubblesQueueSize(PermissionBubbleManager* mgr) { |
| + return static_cast<int>(mgr->requests_.size()); |
| +} |
| // Tests ---------------------------------------------------------------------- |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DisplaysPermissionBar) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, DisplaysPrompt) { |
| ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| SetFrameHost(""); |
| AddGeolocationWatch(true); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, Geoposition) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, Geoposition) { |
| ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| SetFrameHost(""); |
| AddGeolocationWatch(true); |
| - SetInfoBarResponse(current_url(), true); |
| + SetPromptResponse(current_url(), true); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, |
| ErrorOnPermissionDenied) { |
| ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| SetFrameHost(""); |
| AddGeolocationWatch(true); |
| - // Infobar was displayed, deny access and check for error code. |
| - SetInfoBarResponse(current_url(), false); |
| + // Prompt was displayed, deny access and check for error code. |
| + SetPromptResponse(current_url(), false); |
| + if (PermissionBubbleManager::Enabled()) |
| + content::RunAllPendingInMessageLoop(); |
|
Michael van Ouwerkerk
2014/12/17 17:20:19
Could this be part of SetPromptResponse?
felt
2014/12/18 22:09:09
Done.
|
| CheckStringValueFromJavascript("1", "geoGetLastError()"); |
| } |
| // See http://crbug.com/308358 |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_NoInfobarForSecondTab) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, DISABLED_NoPromptForSecondTab) { |
| ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| SetFrameHost(""); |
| AddGeolocationWatch(true); |
| - SetInfoBarResponse(current_url(), true); |
| + SetPromptResponse(current_url(), true); |
| // Disables further prompts from this tab. |
| CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| - // Checks infobar will not be created in a second tab. |
| + // Checks prompt will not be created in a second tab. |
| ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); |
| SetFrameHost(""); |
| AddGeolocationWatch(false); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForDeniedOrigin) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoPromptForDeniedOrigin) { |
| ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| @@ -516,61 +652,63 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForDeniedOrigin) { |
| AddGeolocationWatch(false); |
| // Checks we have an error for this denied origin. |
| CheckStringValueFromJavascript("1", "geoGetLastError()"); |
| - // Checks infobar will not be created a second tab. |
| + // Checks prompt will not be created a second tab. |
| ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB)); |
| SetFrameHost(""); |
| AddGeolocationWatch(false); |
| CheckStringValueFromJavascript("1", "geoGetLastError()"); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForAllowedOrigin) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoPromptForAllowedOrigin) { |
| ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| current_browser()->profile()->GetHostContentSettingsMap()->SetContentSetting( |
| ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| ContentSettingsPattern::FromURLNoWildcard(current_url()), |
| CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), CONTENT_SETTING_ALLOW); |
| - // Checks no infobar will be created and there's no error callback. |
| + // Checks no prompt will be created and there's no error callback. |
| SetFrameHost(""); |
| AddGeolocationWatch(false); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForOffTheRecord) { |
| - // First, check infobar will be created for regular profile |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoPromptForOffTheRecord) { |
| + // First, check prompt will be created for regular profile |
| ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| SetFrameHost(""); |
| AddGeolocationWatch(true); |
| // Response will be persisted. |
| - SetInfoBarResponse(current_url(), true); |
| + SetPromptResponse(current_url(), true); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| // Disables further prompts from this tab. |
| CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| - // Go incognito, and checks no infobar will be created. |
| + // Go incognito, and checks no prompt will be created. |
| ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD)); |
| SetFrameHost(""); |
| AddGeolocationWatch(false); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoLeakFromOffTheRecord) { |
| - // First, check infobar will be created for incognito profile. |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoLeakFromOffTheRecord) { |
| + // First, check prompt will be created for incognito profile. |
| ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD)); |
| SetFrameHost(""); |
| AddGeolocationWatch(true); |
| // Response won't be persisted. |
| - SetInfoBarResponse(current_url(), true); |
| + SetPromptResponse(current_url(), true); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| // Disables further prompts from this tab. |
| CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| - // Go to the regular profile, infobar will be created. |
| + // Go to the regular profile, prompt will be created. |
| ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| SetFrameHost(""); |
| AddGeolocationWatch(true); |
| - SetInfoBarResponse(current_url(), false); |
| + SetPromptResponse(current_url(), false); |
| + if (PermissionBubbleManager::Enabled()) |
| + content::RunAllPendingInMessageLoop(); |
| CheckStringValueFromJavascript("1", "geoGetLastError()"); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, IFramesWithFreshPosition) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, IFramesWithFreshPosition) { |
| set_html_for_tests("/geolocation/iframes_different_origin.html"); |
| ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| LoadIFrames(2); |
| @@ -578,13 +716,13 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, IFramesWithFreshPosition) { |
| SetFrameHost("iframe_0"); |
| AddGeolocationWatch(true); |
| - SetInfoBarResponse(iframe_url(0), true); |
| + SetPromptResponse(iframe_url(0), true); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| // Disables further prompts from this iframe. |
| CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| // Test second iframe from a different origin with a cached geoposition will |
| - // create the infobar. |
| + // create the prompt. |
| SetFrameHost("iframe_1"); |
| AddGeolocationWatch(true); |
| @@ -608,13 +746,13 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, IFramesWithFreshPosition) { |
| // Now go ahead an authorize the second frame. |
| SetFrameHost("iframe_1"); |
| // Infobar was displayed, allow access and check there's no error code. |
| - SetInfoBarResponse(iframe_url(1), true); |
| + SetPromptResponse(iframe_url(1), true); |
| LOG(WARNING) << "Checking position..."; |
| CheckGeoposition(fresh_position_latitude, fresh_position_longitude); |
| LOG(WARNING) << "...done."; |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, |
| IFramesWithCachedPosition) { |
| set_html_for_tests("/geolocation/iframes_different_origin.html"); |
| ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| @@ -622,7 +760,7 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
| SetFrameHost("iframe_0"); |
| AddGeolocationWatch(true); |
| - SetInfoBarResponse(iframe_url(0), true); |
| + SetPromptResponse(iframe_url(0), true); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| // Refresh geoposition, but let's not yet create the watch on the second frame |
| @@ -648,11 +786,11 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, |
| // afterwards. We're only interested in the first navigation for the success |
| // callback from the cached position. |
| CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)"); |
| - SetInfoBarResponse(iframe_url(1), true); |
| + SetPromptResponse(iframe_url(1), true); |
| CheckGeoposition(cached_position_latitude, cached_position_lognitude); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, CancelPermissionForFrame) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, CancelPermissionForFrame) { |
| set_html_for_tests("/geolocation/iframes_different_origin.html"); |
| ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| LoadIFrames(2); |
| @@ -660,26 +798,37 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, CancelPermissionForFrame) { |
| SetFrameHost("iframe_0"); |
| AddGeolocationWatch(true); |
| - SetInfoBarResponse(iframe_url(0), true); |
| + SetPromptResponse(iframe_url(0), true); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| // Disables further prompts from this iframe. |
| CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| // Test second iframe from a different origin with a cached geoposition will |
| - // create the infobar. |
| + // create the prompt. |
| SetFrameHost("iframe_1"); |
| AddGeolocationWatch(true); |
| - InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| - current_browser()->tab_strip_model()->GetActiveWebContents()); |
| - size_t num_infobars_before_cancel = infobar_service->infobar_count(); |
| - // Change the iframe, and ensure the infobar is gone. |
| - IFrameLoader change_iframe_1(current_browser(), 1, current_url()); |
| - size_t num_infobars_after_cancel = infobar_service->infobar_count(); |
| - EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); |
| + // Change the iframe, and ensure the prompt is gone. |
| + if (PermissionBubbleManager::Enabled()) { |
| + WebContents* web_contents = |
| + current_browser()->tab_strip_model()->GetActiveWebContents(); |
| + int num_bubbles_before_cancel = GetBubblesQueueSize( |
| + PermissionBubbleManager::FromWebContents(web_contents)); |
| + IFrameLoader change_iframe_1(current_browser(), 1, current_url()); |
| + int num_bubbles_after_cancel = GetBubblesQueueSize( |
| + PermissionBubbleManager::FromWebContents(web_contents)); |
| + EXPECT_EQ(num_bubbles_before_cancel, num_bubbles_after_cancel + 1); |
| + } else { |
| + InfoBarService* infobar_service = InfoBarService::FromWebContents( |
| + current_browser()->tab_strip_model()->GetActiveWebContents()); |
| + size_t num_infobars_before_cancel = infobar_service->infobar_count(); |
| + IFrameLoader change_iframe_1(current_browser(), 1, current_url()); |
| + size_t num_infobars_after_cancel = infobar_service->infobar_count(); |
| + EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1); |
| + } |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, InvalidUrlRequest) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, InvalidUrlRequest) { |
| // Tests that an invalid URL (e.g. from a popup window) is rejected |
| // correctly. Also acts as a regression test for http://crbug.com/40478 |
| set_html_for_tests("/geolocation/invalid_request_url.html"); |
| @@ -693,7 +842,7 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, InvalidUrlRequest) { |
| original_tab->GetMainFrame()); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfoBarBeforeStart) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, NoInfoBarBeforeStart) { |
| // See http://crbug.com/42789 |
| set_html_for_tests("/geolocation/iframes_different_origin.html"); |
| ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| @@ -706,18 +855,18 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfoBarBeforeStart) { |
| SetFrameHost("iframe_0"); |
| AddGeolocationWatch(true); |
| - SetInfoBarResponse(iframe_url(0), true); |
| + SetPromptResponse(iframe_url(0), true); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)"); |
| // Permission should be requested after adding a watch. |
| SetFrameHost("iframe_1"); |
| AddGeolocationWatch(true); |
| - SetInfoBarResponse(iframe_url(1), true); |
| + SetPromptResponse(iframe_url(1), true); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, TwoWatchesInOneFrame) { |
| set_html_for_tests("/geolocation/two_watches.html"); |
| ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| @@ -736,7 +885,7 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { |
| // Send a position which both geolocation watches will receive. |
| SetFrameHost(""); |
| AddGeolocationWatch(true); |
| - SetInfoBarResponse(current_url(), true); |
| + SetPromptResponse(current_url(), true); |
| CheckGeoposition(fake_latitude(), fake_longitude()); |
| // The second watch will now have cancelled. Ensure an update still makes |
| @@ -751,7 +900,11 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) { |
| CheckGeoposition(final_position_latitude, final_position_longitude); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TabDestroyed) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, TabDestroyed) { |
| + // This test triggers crbug.com/433877. |
| + // TODO(felt): Reenable this test for permission bubbles once that's fixed. |
| + if (PermissionBubbleManager::Enabled()) return; |
| + |
| set_html_for_tests("/geolocation/tab_destroyed.html"); |
| ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES)); |
| LoadIFrames(3); |
| @@ -772,7 +925,7 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TabDestroyed) { |
| EXPECT_EQ(result, true); |
| } |
| -IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, LastUsageUpdated) { |
| +IN_PROC_BROWSER_TEST_P(GeolocationBrowserTest, LastUsageUpdated) { |
| ASSERT_TRUE(Initialize(INITIALIZATION_NONE)); |
| base::SimpleTestClock* clock_ = new base::SimpleTestClock(); |
| current_browser() |
| @@ -816,3 +969,7 @@ IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, LastUsageUpdated) { |
| .ToDoubleT(), |
| 13); |
| } |
| + |
| +INSTANTIATE_TEST_CASE_P(GeolocationBrowserTestWithParams, |
| + GeolocationBrowserTest, |
| + testing::Values(false, true)); |