This source file includes following definitions.
- iframe_url
- javascript_completed_
- Observe
- has_infobar
- infobar
- navigation_completed_
- AddWatchAndWaitForNotification
- current_browser
- set_html_for_tests
- frame_host
- current_url
- iframe_url
- fake_latitude
- fake_longitude
- fake_longitude_
- SetUpOnMainThread
- TearDownInProcessBrowserTestFixture
- Initialize
- LoadIFrames
- SetFrameHost
- AddGeolocationWatch
- CheckGeoposition
- SetInfoBarResponse
- CheckStringValueFromJavascriptForFrame
- CheckStringValueFromJavascript
- NotifyGeoposition
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include <string>
#include "base/compiler_specific.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/content_settings/content_settings_usages_state.h"
#include "chrome/browser/content_settings/host_content_settings_map.h"
#include "chrome/browser/content_settings/tab_specific_content_settings.h"
#include "chrome/browser/infobars/confirm_infobar_delegate.h"
#include "chrome/browser/infobars/infobar.h"
#include "chrome/browser/infobars/infobar_manager.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/content_settings_pattern.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/dom_operation_notification_details.h"
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/notification_details.h"
#include "content/public/browser/notification_service.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "net/base/net_util.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
using content::DomOperationNotificationDetails;
using content::NavigationController;
using content::WebContents;
namespace {
class IFrameLoader : public content::NotificationObserver {
public:
IFrameLoader(Browser* browser, int iframe_id, const GURL& url);
virtual ~IFrameLoader();
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
const GURL& iframe_url() const { return iframe_url_; }
private:
content::NotificationRegistrar registrar_;
bool navigation_completed_;
bool javascript_completed_;
std::string javascript_response_;
GURL iframe_url_;
DISALLOW_COPY_AND_ASSIGN(IFrameLoader);
};
IFrameLoader::IFrameLoader(Browser* browser, int iframe_id, const GURL& url)
: navigation_completed_(false),
javascript_completed_(false) {
WebContents* web_contents =
browser->tab_strip_model()->GetActiveWebContents();
NavigationController* controller = &web_contents->GetController();
registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(controller));
registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE,
content::NotificationService::AllSources());
std::string script(base::StringPrintf(
"window.domAutomationController.setAutomationId(0);"
"window.domAutomationController.send(addIFrame(%d, \"%s\"));",
iframe_id, url.spec().c_str()));
web_contents->GetMainFrame()->ExecuteJavaScript(base::UTF8ToUTF16(script));
content::RunMessageLoop();
EXPECT_EQ(base::StringPrintf("\"%d\"", iframe_id), javascript_response_);
registrar_.RemoveAll();
script = base::StringPrintf(
"window.domAutomationController.send(getIFrameSrc(%d))", iframe_id);
std::string iframe_src;
EXPECT_TRUE(content::ExecuteScriptAndExtractString(web_contents, script,
&iframe_src));
iframe_url_ = GURL(iframe_src);
}
IFrameLoader::~IFrameLoader() {
}
void IFrameLoader::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == content::NOTIFICATION_LOAD_STOP) {
navigation_completed_ = true;
} else if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) {
content::Details<DomOperationNotificationDetails> dom_op_details(details);
javascript_response_ = dom_op_details->json;
javascript_completed_ = true;
}
if (javascript_completed_ && navigation_completed_)
base::MessageLoopForUI::current()->Quit();
}
class GeolocationNotificationObserver : public content::NotificationObserver {
public:
explicit GeolocationNotificationObserver(bool wait_for_infobar);
virtual ~GeolocationNotificationObserver();
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void AddWatchAndWaitForNotification(
content::RenderFrameHost* render_frame_host);
bool has_infobar() const { return !!infobar_; }
InfoBar* infobar() { return infobar_; }
private:
content::NotificationRegistrar registrar_;
bool wait_for_infobar_;
InfoBar* infobar_;
bool navigation_started_;
bool navigation_completed_;
std::string javascript_response_;
DISALLOW_COPY_AND_ASSIGN(GeolocationNotificationObserver);
};
GeolocationNotificationObserver::GeolocationNotificationObserver(
bool wait_for_infobar)
: wait_for_infobar_(wait_for_infobar),
infobar_(NULL),
navigation_started_(false),
navigation_completed_(false) {
registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE,
content::NotificationService::AllSources());
if (wait_for_infobar) {
registrar_.Add(this, chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED,
content::NotificationService::AllSources());
} else {
registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
content::NotificationService::AllSources());
registrar_.Add(this, content::NOTIFICATION_LOAD_START,
content::NotificationService::AllSources());
registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
content::NotificationService::AllSources());
}
}
GeolocationNotificationObserver::~GeolocationNotificationObserver() {
}
void GeolocationNotificationObserver::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
if (type == chrome::NOTIFICATION_TAB_CONTENTS_INFOBAR_ADDED) {
infobar_ = content::Details<InfoBar::AddedDetails>(details).ptr();
ASSERT_FALSE(infobar_->delegate()->GetIcon().IsEmpty());
ASSERT_TRUE(infobar_->delegate()->AsConfirmInfoBarDelegate());
} else if (type == content::NOTIFICATION_DOM_OPERATION_RESPONSE) {
content::Details<DomOperationNotificationDetails> dom_op_details(details);
javascript_response_ = dom_op_details->json;
LOG(WARNING) << "javascript_response " << javascript_response_;
} else if ((type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) ||
(type == content::NOTIFICATION_LOAD_START)) {
navigation_started_ = true;
} else if ((type == content::NOTIFICATION_LOAD_STOP) && navigation_started_) {
navigation_started_ = false;
navigation_completed_ = true;
}
if ((wait_for_infobar_ && infobar_) ||
(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_);
}
}
class GeolocationBrowserTest : public InProcessBrowserTest {
public:
enum InitializationOptions {
INITIALIZATION_NONE,
INITIALIZATION_OFFTHERECORD,
INITIALIZATION_NEWTAB,
INITIALIZATION_IFRAMES,
};
GeolocationBrowserTest();
virtual ~GeolocationBrowserTest();
virtual void SetUpOnMainThread() OVERRIDE;
virtual void TearDownInProcessBrowserTestFixture() OVERRIDE;
Browser* current_browser() { return current_browser_; }
void set_html_for_tests(const std::string& html_for_tests) {
html_for_tests_ = html_for_tests;
}
content::RenderFrameHost* frame_host() const { return render_frame_host_; }
const GURL& current_url() const { return current_url_; }
const GURL& iframe_url(size_t i) const { return iframe_urls_[i]; }
double fake_latitude() const { return fake_latitude_; }
double fake_longitude() const { return fake_longitude_; }
bool Initialize(InitializationOptions options) WARN_UNUSED_RESULT;
void LoadIFrames(int number_iframes);
void SetFrameHost(const std::string& frame_name);
void AddGeolocationWatch(bool wait_for_infobar);
void CheckGeoposition(double latitude, double longitude);
void SetInfoBarResponse(const GURL& requesting_url, bool allowed);
void CheckStringValueFromJavascriptForFrame(
const std::string& expected,
const std::string& function,
content::RenderFrameHost* render_frame_host);
void CheckStringValueFromJavascript(const std::string& expected,
const std::string& function);
void NotifyGeoposition(double latitude, double longitude);
private:
InfoBar* infobar_;
Browser* current_browser_;
std::string html_for_tests_;
content::RenderFrameHost* render_frame_host_;
GURL current_url_;
std::vector<GURL> iframe_urls_;
double fake_latitude_;
double fake_longitude_;
DISALLOW_COPY_AND_ASSIGN(GeolocationBrowserTest);
};
GeolocationBrowserTest::GeolocationBrowserTest()
: infobar_(NULL),
current_browser_(NULL),
html_for_tests_("/geolocation/simple.html"),
render_frame_host_(NULL),
fake_latitude_(1.23),
fake_longitude_(4.56) {
}
GeolocationBrowserTest::~GeolocationBrowserTest() {
}
void GeolocationBrowserTest::SetUpOnMainThread() {
ui_test_utils::OverrideGeolocation(fake_latitude_, fake_longitude_);
}
void GeolocationBrowserTest::TearDownInProcessBrowserTestFixture() {
LOG(WARNING) << "TearDownInProcessBrowserTestFixture. Test Finished.";
}
bool GeolocationBrowserTest::Initialize(InitializationOptions options) {
if (!embedded_test_server()->Started() &&
!embedded_test_server()->InitializeAndWaitUntilReady()) {
ADD_FAILURE() << "Test server failed to start.";
return false;
}
current_url_ = embedded_test_server()->GetURL(html_for_tests_);
LOG(WARNING) << "before navigate";
if (options == INITIALIZATION_OFFTHERECORD) {
current_browser_ = ui_test_utils::OpenURLOffTheRecord(
browser()->profile(), current_url_);
} else {
current_browser_ = browser();
if (options == INITIALIZATION_NEWTAB)
chrome::NewTab(current_browser_);
ui_test_utils::NavigateToURL(current_browser_, current_url_);
}
LOG(WARNING) << "after navigate";
EXPECT_TRUE(current_browser_);
return !!current_browser_;
}
void GeolocationBrowserTest::LoadIFrames(int number_iframes) {
DCHECK_LT(0, number_iframes);
DCHECK_LE(number_iframes, 3);
iframe_urls_.resize(number_iframes);
for (int i = 0; i < number_iframes; ++i) {
IFrameLoader loader(current_browser_, i, GURL());
iframe_urls_[i] = loader.iframe_url();
}
}
void GeolocationBrowserTest::SetFrameHost(const std::string& frame_name) {
WebContents* web_contents =
current_browser_->tab_strip_model()->GetActiveWebContents();
render_frame_host_ = NULL;
if (frame_name.empty()) {
render_frame_host_ = web_contents->GetMainFrame();
} else {
render_frame_host_ = content::FrameMatchingPredicate(
web_contents, base::Bind(&content::FrameMatchesName, frame_name));
}
DCHECK(render_frame_host_);
}
void GeolocationBrowserTest::AddGeolocationWatch(bool wait_for_infobar) {
GeolocationNotificationObserver notification_observer(wait_for_infobar);
notification_observer.AddWatchAndWaitForNotification(render_frame_host_);
if (wait_for_infobar) {
EXPECT_TRUE(notification_observer.has_infobar());
infobar_ = notification_observer.infobar();
}
}
void GeolocationBrowserTest::CheckGeoposition(double latitude,
double longitude) {
CheckStringValueFromJavascript("0", "geoGetLastError()");
CheckStringValueFromJavascript(base::DoubleToString(latitude),
"geoGetLastPositionLatitude()");
CheckStringValueFromJavascript(base::DoubleToString(longitude),
"geoGetLastPositionLongitude()");
}
void GeolocationBrowserTest::SetInfoBarResponse(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 (allowed)
infobar_->delegate()->AsConfirmInfoBarDelegate()->Accept();
else
infobar_->delegate()->AsConfirmInfoBarDelegate()->Cancel();
observer.Wait();
}
InfoBarManager* infobar_manager =
InfoBarService::FromWebContents(web_contents)->infobar_manager();
infobar_manager->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(
const std::string& expected,
const std::string& function,
content::RenderFrameHost* render_frame_host) {
std::string script(base::StringPrintf(
"window.domAutomationController.send(%s)", function.c_str()));
std::string result;
ASSERT_TRUE(content::ExecuteScriptAndExtractString(
render_frame_host, script, &result));
EXPECT_EQ(expected, result);
}
void GeolocationBrowserTest::CheckStringValueFromJavascript(
const std::string& expected,
const std::string& function) {
CheckStringValueFromJavascriptForFrame(
expected, function, render_frame_host_);
}
void GeolocationBrowserTest::NotifyGeoposition(double latitude,
double longitude) {
fake_latitude_ = latitude;
fake_longitude_ = longitude;
ui_test_utils::OverrideGeolocation(latitude, longitude);
LOG(WARNING) << "MockLocationProvider listeners updated";
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DisplaysPermissionBar) {
ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
SetFrameHost("");
AddGeolocationWatch(true);
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, Geoposition) {
ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
SetFrameHost("");
AddGeolocationWatch(true);
SetInfoBarResponse(current_url(), true);
CheckGeoposition(fake_latitude(), fake_longitude());
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest,
ErrorOnPermissionDenied) {
ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
SetFrameHost("");
AddGeolocationWatch(true);
SetInfoBarResponse(current_url(), false);
CheckStringValueFromJavascript("1", "geoGetLastError()");
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, DISABLED_NoInfobarForSecondTab) {
ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
SetFrameHost("");
AddGeolocationWatch(true);
SetInfoBarResponse(current_url(), true);
CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB));
SetFrameHost("");
AddGeolocationWatch(false);
CheckGeoposition(fake_latitude(), fake_longitude());
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForDeniedOrigin) {
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_BLOCK);
SetFrameHost("");
AddGeolocationWatch(false);
CheckStringValueFromJavascript("1", "geoGetLastError()");
ASSERT_TRUE(Initialize(INITIALIZATION_NEWTAB));
SetFrameHost("");
AddGeolocationWatch(false);
CheckStringValueFromJavascript("1", "geoGetLastError()");
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForAllowedOrigin) {
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);
SetFrameHost("");
AddGeolocationWatch(false);
CheckGeoposition(fake_latitude(), fake_longitude());
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfobarForOffTheRecord) {
ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
SetFrameHost("");
AddGeolocationWatch(true);
SetInfoBarResponse(current_url(), true);
CheckGeoposition(fake_latitude(), fake_longitude());
CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD));
SetFrameHost("");
AddGeolocationWatch(false);
CheckGeoposition(fake_latitude(), fake_longitude());
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoLeakFromOffTheRecord) {
ASSERT_TRUE(Initialize(INITIALIZATION_OFFTHERECORD));
SetFrameHost("");
AddGeolocationWatch(true);
SetInfoBarResponse(current_url(), true);
CheckGeoposition(fake_latitude(), fake_longitude());
CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
SetFrameHost("");
AddGeolocationWatch(true);
SetInfoBarResponse(current_url(), false);
CheckStringValueFromJavascript("1", "geoGetLastError()");
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, IFramesWithFreshPosition) {
set_html_for_tests("/geolocation/iframes_different_origin.html");
ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES));
LoadIFrames(2);
LOG(WARNING) << "frames loaded";
SetFrameHost("iframe_0");
AddGeolocationWatch(true);
SetInfoBarResponse(iframe_url(0), true);
CheckGeoposition(fake_latitude(), fake_longitude());
CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
SetFrameHost("iframe_1");
AddGeolocationWatch(true);
SetFrameHost("iframe_0");
CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)");
double fresh_position_latitude = 3.17;
double fresh_position_longitude = 4.23;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(
¤t_browser()->tab_strip_model()->GetActiveWebContents()->
GetController()));
NotifyGeoposition(fresh_position_latitude, fresh_position_longitude);
observer.Wait();
CheckGeoposition(fresh_position_latitude, fresh_position_longitude);
CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
SetFrameHost("iframe_1");
SetInfoBarResponse(iframe_url(1), true);
LOG(WARNING) << "Checking position...";
CheckGeoposition(fresh_position_latitude, fresh_position_longitude);
LOG(WARNING) << "...done.";
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest,
IFramesWithCachedPosition) {
set_html_for_tests("/geolocation/iframes_different_origin.html");
ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES));
LoadIFrames(2);
SetFrameHost("iframe_0");
AddGeolocationWatch(true);
SetInfoBarResponse(iframe_url(0), true);
CheckGeoposition(fake_latitude(), fake_longitude());
double cached_position_latitude = 5.67;
double cached_position_lognitude = 8.09;
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(
¤t_browser()->tab_strip_model()->GetActiveWebContents()->
GetController()));
NotifyGeoposition(cached_position_latitude, cached_position_lognitude);
observer.Wait();
CheckGeoposition(cached_position_latitude, cached_position_lognitude);
CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
SetFrameHost("iframe_1");
AddGeolocationWatch(true);
CheckStringValueFromJavascript("1", "geoSetMaxNavigateCount(1)");
SetInfoBarResponse(iframe_url(1), true);
CheckGeoposition(cached_position_latitude, cached_position_lognitude);
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, CancelPermissionForFrame) {
set_html_for_tests("/geolocation/iframes_different_origin.html");
ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES));
LoadIFrames(2);
LOG(WARNING) << "frames loaded";
SetFrameHost("iframe_0");
AddGeolocationWatch(true);
SetInfoBarResponse(iframe_url(0), true);
CheckGeoposition(fake_latitude(), fake_longitude());
CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
SetFrameHost("iframe_1");
AddGeolocationWatch(true);
InfoBarService* infobar_service = InfoBarService::FromWebContents(
current_browser()->tab_strip_model()->GetActiveWebContents());
InfoBarManager* infobar_manager = infobar_service->infobar_manager();
size_t num_infobars_before_cancel = infobar_manager->infobar_count();
IFrameLoader change_iframe_1(current_browser(), 1, current_url());
size_t num_infobars_after_cancel = infobar_manager->infobar_count();
EXPECT_EQ(num_infobars_before_cancel, num_infobars_after_cancel + 1);
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, InvalidUrlRequest) {
set_html_for_tests("/geolocation/invalid_request_url.html");
ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
SetFrameHost("");
WebContents* original_tab =
current_browser()->tab_strip_model()->GetActiveWebContents();
CheckStringValueFromJavascript("1", "requestGeolocationFromInvalidUrl()");
CheckStringValueFromJavascriptForFrame("1", "isAlive()",
original_tab->GetMainFrame());
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, NoInfoBarBeforeStart) {
set_html_for_tests("/geolocation/iframes_different_origin.html");
ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES));
LoadIFrames(2);
LOG(WARNING) << "frames loaded";
SetFrameHost("iframe_1");
CheckStringValueFromJavascript("object", "geoAccessNavigatorGeolocation()");
SetFrameHost("iframe_0");
AddGeolocationWatch(true);
SetInfoBarResponse(iframe_url(0), true);
CheckGeoposition(fake_latitude(), fake_longitude());
CheckStringValueFromJavascript("0", "geoSetMaxNavigateCount(0)");
SetFrameHost("iframe_1");
AddGeolocationWatch(true);
SetInfoBarResponse(iframe_url(1), true);
CheckGeoposition(fake_latitude(), fake_longitude());
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TwoWatchesInOneFrame) {
set_html_for_tests("/geolocation/two_watches.html");
ASSERT_TRUE(Initialize(INITIALIZATION_NONE));
double final_position_latitude = 3.17;
double final_position_longitude = 4.23;
std::string script = base::StringPrintf(
"window.domAutomationController.send(geoSetFinalPosition(%f, %f))",
final_position_latitude, final_position_longitude);
std::string js_result;
EXPECT_TRUE(content::ExecuteScriptAndExtractString(
current_browser()->tab_strip_model()->GetActiveWebContents(), script,
&js_result));
EXPECT_EQ(js_result, "ok");
SetFrameHost("");
AddGeolocationWatch(true);
SetInfoBarResponse(current_url(), true);
CheckGeoposition(fake_latitude(), fake_longitude());
content::WindowedNotificationObserver observer(
content::NOTIFICATION_LOAD_STOP,
content::Source<NavigationController>(
¤t_browser()->tab_strip_model()->GetActiveWebContents()->
GetController()));
NotifyGeoposition(final_position_latitude, final_position_longitude);
observer.Wait();
CheckGeoposition(final_position_latitude, final_position_longitude);
}
IN_PROC_BROWSER_TEST_F(GeolocationBrowserTest, TabDestroyed) {
set_html_for_tests("/geolocation/tab_destroyed.html");
ASSERT_TRUE(Initialize(INITIALIZATION_IFRAMES));
LoadIFrames(3);
SetFrameHost("iframe_0");
AddGeolocationWatch(true);
SetFrameHost("iframe_1");
AddGeolocationWatch(false);
SetFrameHost("iframe_2");
AddGeolocationWatch(false);
std::string script =
"window.domAutomationController.send(window.close());";
bool result = content::ExecuteScript(
current_browser()->tab_strip_model()->GetActiveWebContents(), script);
EXPECT_EQ(result, true);
}