commit 838c00e3f9b562ccd3b4b5809b6fb4fe34b3814d Author: Alex Catarineu acat@torproject.org Date: Mon May 18 11:42:53 2020 +0200
Fix svg tests --- TBBTestSuite/TestSuite/BrowserBundleTests.pm | 10 +---- marionette/tor_browser_tests/test_svg.py | 67 +++++++++++++--------------- test-data/svg/object_data_url.html | 2 +- 3 files changed, 33 insertions(+), 46 deletions(-)
diff --git a/TBBTestSuite/TestSuite/BrowserBundleTests.pm b/TBBTestSuite/TestSuite/BrowserBundleTests.pm index 365b7bc..90d445c 100644 --- a/TBBTestSuite/TestSuite/BrowserBundleTests.pm +++ b/TBBTestSuite/TestSuite/BrowserBundleTests.pm @@ -439,11 +439,8 @@ our @tests = ( use_net => 1, prefs => { 'extensions.torbutton.security_custom' => 'true', - 'svg.in-content.enabled' => 'false', + 'svg.disabled' => 'true', }, - # Bug 28798: temporarily disable test - enable => sub { undef }, - #enable => sub { $OSNAME eq 'linux' }, }, { name => 'svg-enable', @@ -453,11 +450,8 @@ our @tests = ( use_net => 1, prefs => { 'extensions.torbutton.security_custom' => 'true', - 'svg.in-content.enabled' => 'true', + 'svg.disabled' => 'false', }, - # Bug 28798: temporarily disable test - enable => sub { undef }, - #enable => sub { $OSNAME eq 'linux' }, }, { name => 'download_pdf', diff --git a/marionette/tor_browser_tests/test_svg.py b/marionette/tor_browser_tests/test_svg.py index e420d60..af55b1b 100644 --- a/marionette/tor_browser_tests/test_svg.py +++ b/marionette/tor_browser_tests/test_svg.py @@ -1,11 +1,9 @@ -from marionette_driver import By from marionette_driver.errors import MarionetteException, JavascriptException, NoSuchElementException
from marionette_harness import MarionetteTestCase
import testsuite
- class Test(MarionetteTestCase):
def setUp(self): @@ -14,62 +12,58 @@ class Test(MarionetteTestCase): ts = testsuite.TestSuite() self.ts = ts
- self.svg_dir = "file://%s/svg/" % ts.t['options']['test_data_dir'] + self.marionette.set_pref("network.proxy.allow_hijacking_localhost", False)
def test_svg(self): m = self.marionette svg_enabled = self.ts.t['test']['name'] == 'svg-enable' - self.assertEqual(self.marionette.get_pref('svg.in-content.enabled'), - svg_enabled, - msg="svg.in-content.enabled is not set correctly") + self.assertEqual(self.marionette.get_pref('svg.disabled'), + not svg_enabled, + msg="svg.disabled is not set correctly")
- m.set_search_timeout(1000) + self.marionette.timeout.implicit = 1
with m.using_context('content'):
# img src url - m.navigate("%s/img_src_url.html" % self.svg_dir) + m.navigate(self.marionette.absolute_url("svg/img_src_url.html")) svg_elt = m.find_element('id', 'svgImgElem') self.assertEqual(svg_elt.get_property('width'), 450 if svg_enabled else 24, msg="img src url")
# img data url - m.navigate("%s/img_data_url.html" % self.svg_dir) + m.navigate(self.marionette.absolute_url("svg/img_data_url.html")) svg_elt = m.find_element('id', 'svgImgElem') self.assertEqual(svg_elt.get_property('width'), 300 if svg_enabled else 24, msg="img data url")
# object data url - m.navigate("%s/object_data_url.html" % self.svg_dir) - try: - visibility = m.execute_script(''' + m.navigate(self.marionette.absolute_url("svg/object_data_url.html")) + width = m.execute_script(''' var elt = document.getElementById("svgObjectElem"); - return elt.contentDocument.visibilityState; + return elt.getBoundingClientRect().width; ''') - except JavascriptException: - visibility = 'invisible' - self.assertEqual(visibility, - 'visible' if svg_enabled else 'invisible', - msg='object data url') + self.assertEqual(width, + 450 if svg_enabled else 300, + msg="object data url")
# object remote url - m.navigate("%s/object_remote_url.html" % self.svg_dir) - try: - visibility = m.execute_script(''' + m.navigate(self.marionette.absolute_url("svg/object_remote_url.html")) + svg_elt = m.find_element('id', 'svgObjectElem') + + width = m.execute_script(''' var elt = document.getElementById("svgObjectElem"); - return elt.contentDocument.visibilityState; + return elt.getBoundingClientRect().width; ''') - except JavascriptException: - visibility = 'invisible' - self.assertEqual(visibility, - 'visible' if svg_enabled else 'invisible', - msg='object remote url') + self.assertEqual(width, + 450 if svg_enabled else 300, + msg="object remote url")
# inline svg - m.navigate('%s/inline_svg.html' % self.svg_dir) + m.navigate(self.marionette.absolute_url("svg/inline_svg.html")) try: elt_width = m.execute_script(''' var elt = document.getElementById("inlineSVG"); @@ -77,19 +71,18 @@ class Test(MarionetteTestCase): ''') except JavascriptException: elt_width = None - print "width: %s" % elt_width self.assertEqual(elt_width, 300 if svg_enabled else None, msg='inline svg')
# iframe remote url - m.navigate('%s/iframe_remote_url.html' % self.svg_dir) + m.navigate(self.marionette.absolute_url("svg/iframe_remote_url.html")) m.switch_to_frame(m.find_element('id', 'svgIframeElem')) - found_elt = True - try: - svg_elt = m.find_element('tag name', 'svg') - except NoSuchElementException: - found_elt = False - self.assertEqual(found_elt, True if svg_enabled else False, + svg_elt = m.find_element('tag name', 'svg') + width = m.execute_script(''' + var elt = document.getElementsByTagName("svg")[0]; + return elt.getBoundingClientRect().width; + ''') + self.assertEqual(width, + 450 if svg_enabled else 500, msg="iframe remote url prompt") - diff --git a/test-data/svg/object_data_url.html b/test-data/svg/object_data_url.html index 6d2a8b4..9e3344d 100644 --- a/test-data/svg/object_data_url.html +++ b/test-data/svg/object_data_url.html @@ -5,7 +5,7 @@ <title>SVG Test</title> <body> <div>object with data URL:<br> - <object id="svgObjectElem" type="image/svg+xml" data="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'><linearGradient id='g' x2='0' y2='100%'><stop stop-color='%23faf'/><stop offset='100%' stop-color='white'/></linearGradient><rect fill='url(%23g)' width='100%' height='100%'/></svg>"> + <object id="svgObjectElem" type="image/svg+xml" data="data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='450'><linearGradient id='g' x2='0' y2='100%'><stop stop-color='%23faf'/><stop offset='100%' stop-color='white'/></linearGradient><rect fill='url(%23g)' width='100%' height='100%'/></svg>"> this text appears when SVG is disabled </object> </div>