Skip to content

Commit

Permalink
Allow popups, mouselock and https media-stream content by default.
Browse files Browse the repository at this point in the history
Add a simple HTTPS server for testing getUserMedia. Popups used to be allowed through
--disable-popup-blocking, but this has a bug where the resulting popup cannot be resized
smaller. Instead, allow popups by modifying the prefs.
BUG=chromedriver:118,chromedriver:126
TEST=none

Review URL: https://chromiumcodereview.appspot.com/10828135

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150214 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
kkania@chromium.org committed Aug 7, 2012
1 parent 43aeb0e commit 4d0a03e
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 49 deletions.
41 changes: 41 additions & 0 deletions chrome/test/webdriver/test/cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDQj2tPWPUgbuI4H3/3dnttqVbndwU33BdRCd67DFM44GRrsjDS
H4bY/EbFyX9D52d/iy6ZaAmDePcCz5k/fgP3DMujykYGqgNiV2ywxTlMj7NlN2C7
SRt68fQMZr5iI7rypdxuaZt9lSMD3ENBffYtuLTyZd9a3JPJe1TaIab5GwIDAQAB
AoGANHXu8z2YIzlhE+bwhGm8MGBpKL3qhRuKjeriqMA36tWezOw8lY4ymEAU+Ulv
BsCdaxqydQoTYou57m4TyUHEcxq9pq3H0zB0qL709DdHi/t4zbV9XIoAzC5v0/hG
9+Ca29TwC02FCw+qLkNrtwCpwOcQmc+bPxqvFu1iMiahURECQQD2I/Hi2413CMZz
TBjl8fMiVO9GhA2J0sc8Qi+YcgJakaLD9xcbaiLkTzPZDlA389C1b6Ia+poAr4YA
Ve0FFbxpAkEA2OobayyHE/QtPEqoy6NLR57jirmVBNmSWWd4lAyL5UIHIYVttJZg
8CLvbzaU/iDGwR+wKsM664rKPHEmtlyo4wJBAMeSqYO5ZOCJGu9NWjrHjM3fdAsG
8zs2zhiLya+fcU0iHIksBW5TBmt71Jw/wMc9R5J1K0kYvFml98653O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S+QDtifq1UgVfBbytvR2lFmnADOR55mo0gHQG3HHqq4g034LmoVXDHhUk8
Gb6aFiv4QubmVhLXcUelTRXwiNvGzkW7pC6Jrq105hdPjzXMKTcmiLaopm5Fqfc7
hj5Cn1Sjspc8pdeQjrbeMdvca7KlFrGP8YkwCU2xOOX9PiN9G0966BWfjnr/fZZp
+OQVuUFHdiAZwthEMuDpAAXHqYXIsermgdOpgJaA53cf8NqBV2QGhtFgtsJCRoiu
7DKqhyRWBGyz19VIH2b7y+6qvQVxuHk19kKRM0nftw/yNcJnm7gtttespMUPsOMa
a2SD1G0hm0TND6vxaBhgR3cVqpl/qIpAdFi00Tm7hTyYE7I43zPW03t+/DpCt3Um
EMRZsQ90co5q+bcx/vQ7YAtwUh30uMb0wpibeyCwDp8cqNmSiRkEuc/FjTYes5t8
5gR//WX1l0+qjrjusO9NmoLnq2Yk6UcioX+z+q6Z/dudGfqhLfeWD2Q0LWYA242C
d7km5Y3KAt1PJdVsof/aiVhVdddY/OIEKTRQhWEdDbosy2eh16BCKXT2FFvhNDg1
AYFvn6I8nj9IldMJiIc3DdhacEAEzRMeRgPdzAa1griKUGknxsyTyRii8ru0WS6w
DCNrlDOVXdzYGEZooBI76BDVY0W0akjV
-----END CERTIFICATE-----
67 changes: 63 additions & 4 deletions chrome/test/webdriver/test/chromedriver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,65 @@

"""Factory that creates ChromeDriver instances."""

import BaseHTTPServer
import os
import ssl
import threading
import unittest

from chromedriver_factory import ChromeDriverFactory
from chromedriver_launcher import ChromeDriverLauncher
import test_paths


class _FileRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
"""Sends back file resources relative to the server's |root_dir|."""

def do_GET(self):
if self.path.endswith('favicon.ico'):
self.send_error(404)
return
path = os.path.join(self.server.root_dir, *self.path.split('/'))
data = open(path, 'r').read()
self.send_response(200)
self.send_header('Content-Length', len(data))
self.end_headers()
self.wfile.write(data)


class _HttpsServer(object):
"""An HTTPS server that serves files on its own thread."""

def __init__(self, server_cert_and_key_path, root_dir):
"""Starts the HTTPS server on its own thread on an ephemeral port.
After this function returns, it is safe to assume the server is ready
to receive requests.
Args:
server_cert_and_key_path: path to a PEM file containing the cert and key.
root_dir: root path to serve files from.
"""
self._server = BaseHTTPServer.HTTPServer(
('127.0.0.1', 0), _FileRequestHandler)
self._server.root_dir = root_dir
self._server.socket = ssl.wrap_socket(
self._server.socket, certfile=server_cert_and_key_path,
server_side=True)

self._thread = threading.Thread(target=self._server.serve_forever)
self._thread.start()

def GetUrl(self):
"""Returns the base URL of the server."""
return 'https://127.0.0.1:%s' % self._server.server_port

def Shutdown(self):
"""Shuts down the server synchronously."""
self._server.shutdown()
self._thread.join()


class ChromeDriverTest(unittest.TestCase):
"""Fixture for tests that need to instantiate ChromeDriver(s)."""

Expand All @@ -27,18 +78,26 @@ def GlobalSetUp(other_driver=None, other_chrome=None):
ChromeDriverTest._driver_path = driver_path
ChromeDriverTest._chrome_path = chrome_path
ChromeDriverTest._server = ChromeDriverLauncher(driver_path).Launch()
ChromeDriverTest._webserver = ChromeDriverLauncher(
ChromeDriverTest._http_server = ChromeDriverLauncher(
driver_path, test_paths.TEST_DATA_PATH).Launch()
ChromeDriverTest._https_server = _HttpsServer(
test_paths.PEM_CERT_AND_KEY, test_paths.TEST_DATA_PATH)

@staticmethod
def GlobalTearDown():
ChromeDriverTest._server.Kill()
ChromeDriverTest._webserver.Kill()
ChromeDriverTest._http_server.Kill()
ChromeDriverTest._https_server.Shutdown()

@staticmethod
def GetTestDataUrl():
"""Returns the base url for serving files from the ChromeDriver test dir."""
return ChromeDriverTest._webserver.GetUrl()
"""Returns the base http url for serving files from the test dir."""
return ChromeDriverTest._http_server.GetUrl()

@staticmethod
def GetHttpsTestDataUrl():
"""Returns the base https url for serving files from the test dir."""
return ChromeDriverTest._https_server.GetUrl()

@staticmethod
def GetDriverPath():
Expand Down
61 changes: 48 additions & 13 deletions chrome/test/webdriver/test/chromedriver_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,28 +288,19 @@ def testInstallExtensions(self):
self.assertTrue('ExtTest2' in extension_names)
driver.quit()

def testUseWebsiteTestingDefaults(self):
"""Test that chromedriver initializes options for website testing."""
driver = self.GetNewDriver()
driver.get(self.GetTestDataUrl() + '/content_setting_test.html')
driver.set_script_timeout(10)
# Will timeout if infobar appears.
driver.execute_async_script('waitForGeo(arguments[0])')

def testPrefs(self):
"""Test that chromedriver can set user preferences."""
driver = self.GetNewDriver({
'chrome.noWebsiteTestingDefaults': True,
'chrome.prefs': {
'profile.default_content_settings': {
'geolocation': 1
'popups': 1
},
}
})
driver.get(self.GetTestDataUrl() + '/content_setting_test.html')
driver.set_script_timeout(10)
# Will timeout if infobar appears.
driver.execute_async_script('waitForGeo(arguments[0])')
driver.get(self.GetTestDataUrl() + '/empty.html')
driver.execute_script('window.open("about:blank")')
self.assertEquals(2, len(driver.window_handles))


class DetachProcessTest(ChromeDriverTest):
Expand Down Expand Up @@ -1147,6 +1138,7 @@ def is_page_action_visible(driver):
ext.click_page_action()
self._testExtensionView(driver, ext.get_popup_handle(), ext)


class BadJSTest(ChromeDriverTest):
"""Tests that ensure sites with hacky JS don't break ChromeDriver."""

Expand All @@ -1155,3 +1147,46 @@ def testFindElementDoesNotUseNativeFuncs(self):
driver.get(self.GetTestDataUrl() + '/bad_native_funcs.html')
# This will throw an exception if any native funcs are used.
driver.find_element_by_tag_name('body').find_elements_by_tag_name('div')


class ContentSettingsTest(ChromeDriverTest):
"""Tests that various types of content are allowed by default."""

def testPopups(self):
driver = self.GetNewDriver()
driver.get(self.GetTestDataUrl() + '/empty.html')
driver.execute_script('window.open("about:blank")')
self.assertEquals(2, len(driver.window_handles))

def testPopupsCanBeResized(self):
"""Regression test for chromedriver issue 126."""
driver = self.GetNewDriver()
driver.get(self.GetTestDataUrl() + '/empty.html')
driver.execute_script(
'window.open("empty.html", "popup", "width=500,height=500")')
driver.switch_to_window(driver.window_handles[1])
size = driver.get_window_size()
bigger_size = dict(map(lambda x: (x, size[x] + 100), size))
smaller_size = dict(map(lambda x: (x, size[x] - 100), size))
driver.set_window_size(bigger_size['width'], bigger_size['height'])
self.assertEquals(bigger_size, driver.get_window_size())
driver.set_window_size(smaller_size['width'], smaller_size['height'])
self.assertEquals(smaller_size, driver.get_window_size())

def testGeolocation(self):
driver = self.GetNewDriver()
driver.get(self.GetTestDataUrl() + '/empty.html')
driver.set_script_timeout(10)
# Will timeout if infobar appears.
driver.execute_async_script(
'navigator.geolocation.getCurrentPosition(arguments[0], arguments[0]);')

def testMediaStream(self):
driver = self.GetNewDriver()
# Allowing camera/mic access by default only works for https sites.
driver.get(self.GetHttpsTestDataUrl() + '/empty.html')
driver.set_script_timeout(10)
# Will timeout if infobar appears.
driver.execute_async_script(
'navigator.webkitGetUserMedia({audio:true, video:true},' +
' arguments[0], arguments[0]);')
21 changes: 0 additions & 21 deletions chrome/test/webdriver/test/content_setting_test.html

This file was deleted.

2 changes: 2 additions & 0 deletions chrome/test/webdriver/test/empty.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<html>
</html>
5 changes: 3 additions & 2 deletions chrome/test/webdriver/test/test_paths.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

Expand Down Expand Up @@ -26,8 +26,9 @@ def _SetupPaths():
global SRC_PATH
SRC_PATH = J(start_dir, os.pardir, os.pardir, os.pardir, os.pardir)

global TEST_DATA_PATH
global TEST_DATA_PATH, PEM_CERT_AND_KEY
TEST_DATA_PATH = start_dir
PEM_CERT_AND_KEY = J(start_dir, 'cert.pem')

global CHROME_TEST_DATA_PATH
CHROME_TEST_DATA_PATH = J(SRC_PATH, 'chrome', 'test', 'data')
Expand Down
5 changes: 1 addition & 4 deletions chrome/test/webdriver/webdriver_automation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ namespace webdriver {
Automation::BrowserOptions::BrowserOptions()
: command(CommandLine::NO_PROGRAM),
detach_process(false),
ignore_certificate_errors(false),
disable_popup_blocking(false) {}
ignore_certificate_errors(false) {}

Automation::BrowserOptions::~BrowserOptions() {}

Expand Down Expand Up @@ -367,8 +366,6 @@ void Automation::Init(
command.AppendSwitch(switches::kAutomationReinitializeOnChannelError);
if (options.ignore_certificate_errors)
command.AppendSwitch(switches::kIgnoreCertificateErrors);
if (options.disable_popup_blocking)
command.AppendSwitch(switches::kDisablePopupBlocking);
if (options.user_data_dir.empty())
command.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL);

Expand Down
3 changes: 0 additions & 3 deletions chrome/test/webdriver/webdriver_automation.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ class Automation {

// True if the browser should ignore certificate related errors.
bool ignore_certificate_errors;

// True if the browser should disable popup blocking.
bool disable_popup_blocking;
};

explicit Automation(const Logger& logger);
Expand Down
20 changes: 18 additions & 2 deletions chrome/test/webdriver/webdriver_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ Error* Session::Init(const DictionaryValue* capabilities_dict) {
browser_options.user_data_dir = capabilities_.profile;
if (!capabilities_.no_website_testing_defaults) {
browser_options.ignore_certificate_errors = true;
browser_options.disable_popup_blocking = true;
}
RunSessionTask(base::Bind(
&Session::InitOnSessionThread,
Expand Down Expand Up @@ -1900,11 +1899,28 @@ Error* Session::InitForWebsiteTesting() {
if (error)
return error;

// Allow certain content by default.
// Allow content by default.
// Media-stream cannot be enabled by default; we must specify
// particular host patterns and devices.
DictionaryValue* devices = new DictionaryValue();
devices->SetString("audio", "Default");
devices->SetString("video", "Default");
DictionaryValue* content_settings = new DictionaryValue();
content_settings->Set("media-stream", devices);
DictionaryValue* pattern_pairs = new DictionaryValue();
pattern_pairs->Set("https://*,*", content_settings);
error = SetPreference(
"profile.content_settings.pattern_pairs",
true /* is_user_pref */,
pattern_pairs);
if (error)
return error;
const int kAllowContent = 1;
DictionaryValue* default_content_settings = new DictionaryValue();
default_content_settings->SetInteger("geolocation", kAllowContent);
default_content_settings->SetInteger("mouselock", kAllowContent);
default_content_settings->SetInteger("notifications", kAllowContent);
default_content_settings->SetInteger("popups", kAllowContent);
return SetPreference(
"profile.default_content_settings",
true /* is_user_pref */,
Expand Down

0 comments on commit 4d0a03e

Please sign in to comment.