Bug 1262705 fix root path for microformats test class, r?mkaply
MozReview-Commit-ID: KvTsnmuHbx4
--- a/toolkit/components/microformats/test/interface-tests/index.html
+++ b/toolkit/components/microformats/test/interface-tests/index.html
@@ -1,14 +1,15 @@
<html><head><title>Mocha</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../static/css/mocha.css" />
<script src="../static/javascript/chai.js"></script>
<script src="../static/javascript/mocha.js"></script>
<link rel="stylesheet" href="../static/css/mocha-custom.css" />
+<link rel="icon" type="image/png" id="favicon" href="chrome://branding/content/icon32.png"/>
<script src="../static/javascript/DOMParser.js"></script>
<script data-cover src="../../microformat-shiv.js"></script>
<script>
var uncaughtError;
--- a/toolkit/components/microformats/test/marionette/microformats_tester.py
+++ b/toolkit/components/microformats/test/marionette/microformats_tester.py
@@ -2,50 +2,77 @@ from marionette import MarionetteTestCas
from marionette_driver.errors import NoSuchElementException
import threading
import SimpleHTTPServer
import SocketServer
import BaseHTTPServer
import urllib
import urlparse
import os
+import posixpath
DEBUG = True
# Example taken from mozilla-central/browser/components/loop/
# XXX Once we're on a branch with bug 993478 landed, we may want to get
# rid of this HTTP server and just use the built-in one from Marionette,
# since there will less code to maintain, and it will be faster. We'll
# need to consider whether this code wants to be shared with WebDriver tests
# for other browsers, though.
class ThreadingSimpleServer(SocketServer.ThreadingMixIn,
BaseHTTPServer.HTTPServer):
pass
-class QuietHttpRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
+class HttpRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler, object):
+ def __init__(self, *args):
+ # set root to toolkit/components/microformats/
+ self.root = os.path.dirname(os.path.dirname(os.path.dirname(os.path.normpath(__file__))))
+ super(HttpRequestHandler, self).__init__(*args)
+
def log_message(self, format, *args, **kwargs):
- pass
+ if DEBUG:
+ super(HttpRequestHandler, self).log_message(format, *args, **kwargs)
+
+ def translate_path(self, path):
+ """Translate a /-separated PATH to the local filename syntax.
+
+ Components that mean special things to the local file system
+ (e.g. drive or directory names) are ignored. (XXX They should
+ probably be diagnosed.)
+ """
+ # abandon query parameters
+ path = path.split('?',1)[0]
+ path = path.split('#',1)[0]
+ # Don't forget explicit trailing slash when normalizing. Issue17324
+ trailing_slash = path.rstrip().endswith('/')
+ path = posixpath.normpath(urllib.unquote(path))
+ words = path.split('/')
+ words = filter(None, words)
+ path = self.root
+ for word in words:
+ drive, word = os.path.splitdrive(word)
+ head, word = os.path.split(word)
+ if word in (os.curdir, os.pardir): continue
+ path = os.path.join(path, word)
+ if trailing_slash:
+ path += '/'
+ return path
class BaseTestFrontendUnits(MarionetteTestCase):
@classmethod
def setUpClass(cls):
super(BaseTestFrontendUnits, cls).setUpClass()
- if DEBUG:
- handler = SimpleHTTPServer.SimpleHTTPRequestHandler
- else:
- handler = QuietHttpRequestHandler
-
# Port 0 means to select an arbitrary unused port
- cls.server = ThreadingSimpleServer(('', 0), handler)
+ cls.server = ThreadingSimpleServer(('', 0), HttpRequestHandler)
cls.ip, cls.port = cls.server.server_address
cls.server_thread = threading.Thread(target=cls.server.serve_forever)
cls.server_thread.daemon = False
cls.server_thread.start()
@classmethod
def tearDownClass(cls):
@@ -74,32 +101,18 @@ class BaseTestFrontendUnits(MarionetteTe
# This extends the timeout for find_element. We need this as the tests
# take an amount of time to run after loading, which we have to wait for.
self.marionette.set_search_timeout(120000)
self.marionette.set_page_load_timeout(120000)
# srcdir_path should be the directory relative to this file.
def set_server_prefix(self, srcdir_path):
- # We may be run from a different path than topsrcdir, e.g. in the case
- # of packaged tests. If so, then we have to work out the right directory
- # for the local server.
-
- # First find the top of the working directory.
- commonPath = os.path.commonprefix([__file__, os.getcwd()])
-
- # Now get the relative path between the two
- self.relPath = os.path.relpath(os.path.dirname(__file__), commonPath)
-
- self.relPath = urllib.pathname2url(os.path.join(self.relPath, srcdir_path))
-
- print "http://localhost:" + str(self.port),self.relPath
- # Finally join the relative path with the given src path
self.server_prefix = urlparse.urljoin("http://localhost:" + str(self.port),
- self.relPath)
+ srcdir_path)
def check_page(self, page):
self.marionette.navigate(urlparse.urljoin(self.server_prefix, page))
try:
self.marionette.find_element("id", 'complete')
except NoSuchElementException:
fullPageUrl = urlparse.urljoin(self.relPath, page)
--- a/toolkit/components/microformats/test/marionette/test_interface.py
+++ b/toolkit/components/microformats/test/marionette/test_interface.py
@@ -6,12 +6,12 @@ sys.path.append(os.path.join(os.path.dir
from microformats_tester import BaseTestFrontendUnits
class TestInterfaceUnits(BaseTestFrontendUnits):
def setUp(self):
super(TestInterfaceUnits, self).setUp()
- self.set_server_prefix("../interface-tests/")
+ self.set_server_prefix("/test/interface-tests/")
def test_units(self):
self.check_page("index.html")
--- a/toolkit/components/microformats/test/marionette/test_modules.py
+++ b/toolkit/components/microformats/test/marionette/test_modules.py
@@ -6,12 +6,12 @@ sys.path.append(os.path.join(os.path.dir
from microformats_tester import BaseTestFrontendUnits
class TestModulesUnits(BaseTestFrontendUnits):
def setUp(self):
super(TestModulesUnits, self).setUp()
- self.set_server_prefix("../module-tests/")
+ self.set_server_prefix("/test/module-tests/")
def test_units(self):
self.check_page("index.html")
--- a/toolkit/components/microformats/test/marionette/test_standards.py
+++ b/toolkit/components/microformats/test/marionette/test_standards.py
@@ -1,17 +1,17 @@
# Code example copied from mozilla-central/browser/components/loop/
# need to get this dir in the path so that we make the import work
import os
import sys
-sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'marionette'))
+sys.path.append(os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'marionette')))
from microformats_tester import BaseTestFrontendUnits
class TestStandardsUnits(BaseTestFrontendUnits):
def setUp(self):
super(TestStandardsUnits, self).setUp()
- self.set_server_prefix("../standards-tests/")
+ self.set_server_prefix("/test/standards-tests/")
def test_units(self):
self.check_page("index.html")
--- a/toolkit/components/microformats/test/module-tests/index.html
+++ b/toolkit/components/microformats/test/module-tests/index.html
@@ -1,15 +1,15 @@
<html><head><title>Mocha</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../static/css/mocha.css" />
<script src="../static/javascript/chai.js"></script>
<script src="../static/javascript/mocha.js"></script>
<link rel="stylesheet" href="../static/css/mocha-custom.css" />
-
+<link rel="icon" type="image/png" id="favicon" href="chrome://branding/content/icon32.png"/>
<script src="../static/javascript/DOMParser.js"></script>
<script data-cover src="../lib/utilities.js"></script>
<script data-cover src="../lib/domutils.js"></script>
<script data-cover src="../lib/url.js"></script>
<script data-cover src="../lib/html.js"></script>
<script data-cover src="../lib/text.js"></script>
<script data-cover src="../lib/dates.js"></script>
--- a/toolkit/components/microformats/test/standards-tests/index.html
+++ b/toolkit/components/microformats/test/standards-tests/index.html
@@ -1,14 +1,15 @@
<html><head><title>Mocha</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../static/css/mocha.css" />
<script src="../static/javascript/chai.js"></script>
<script src="../static/javascript/mocha.js"></script>
<link rel="stylesheet" href="../static/css/mocha-custom.css" />
+<link rel="icon" type="image/png" id="favicon" href="chrome://branding/content/icon32.png"/>
<script src="../static/javascript/DOMParser.js"></script>
<script data-cover src="../../microformat-shiv.js"></script>
<script>
var uncaughtError;