Fix - Preview media slider repeatedly shows "Error Occurred" dialogue box

bzr-revno: 2493
This commit is contained in:
Philip Ridout 2015-02-01 15:04:37 +00:00 committed by Tim Bentley
commit b40f931618
3 changed files with 48 additions and 26 deletions

View File

@ -22,11 +22,11 @@
"""
The :mod:`~openlp.core.ui.media.webkit` module contains our WebKit video player
"""
from PyQt4 import QtGui
from PyQt4 import QtGui, QtWebKit
import logging
from openlp.core.common import Settings, is_macosx
from openlp.core.common import Settings
from openlp.core.lib import translate
from openlp.core.ui.media import MediaState
from openlp.core.ui.media.mediaplayer import MediaPlayer
@ -222,13 +222,15 @@ class WebkitPlayer(MediaPlayer):
def check_available(self):
"""
Check the availability of the media player
Check the availability of the media player.
:return: boolean. True if available
"""
# At the moment we don't have support for webkitplayer on Mac OS X
if is_macosx():
return False
else:
return True
web = QtWebKit.QWebPage()
# This script should return '[object HTMLVideoElement]' if the html5 video is available in webkit. Otherwise it
# should return '[object HTMLUnknownElement]'
return web.mainFrame().evaluateJavaScript(
"Object.prototype.toString.call(document.createElement('video'));") == '[object HTMLVideoElement]'
def load(self, display):
"""

View File

@ -23,7 +23,7 @@
Package to test the openlp.core.ui.media.webkitplayer package.
"""
from unittest import TestCase
from tests.functional import patch
from tests.functional import MagicMock, patch
from openlp.core.ui.media.webkitplayer import WebkitPlayer
@ -33,32 +33,36 @@ class TestWebkitPlayer(TestCase):
Test the functions in the :mod:`webkitplayer` module.
"""
def check_available_mac_test(self):
def check_available_video_disabled_test(self):
"""
Simple test of webkitplayer availability on Mac OS X
Test of webkit video unavailability
"""
# GIVEN: A WebkitPlayer and a mocked is_macosx
with patch('openlp.core.ui.media.webkitplayer.is_macosx') as mocked_is_macosx:
mocked_is_macosx.return_value = True
# GIVEN: A WebkitPlayer instance and a mocked QWebPage
mocked_qwebpage = MagicMock()
mocked_qwebpage.mainFrame().evaluateJavaScript.return_value = '[object HTMLUnknownElement]'
with patch('openlp.core.ui.media.webkitplayer.QtWebKit.QWebPage', **{'return_value': mocked_qwebpage}):
webkit_player = WebkitPlayer(None)
# WHEN: An checking if the player is available
available = webkit_player.check_available()
# THEN: The player should not be available on Mac OS X
self.assertEqual(False, available, 'The WebkitPlayer should not be available on Mac OS X.')
# THEN: The player should not be available when '[object HTMLUnknownElement]' is returned
self.assertEqual(False, available,
'The WebkitPlayer should not be available when video feature detection fails')
def check_available_non_mac_test(self):
def check_available_video_enabled_test(self):
"""
Simple test of webkitplayer availability when not on Mac OS X
Test of webkit video availability
"""
# GIVEN: A WebkitPlayer and a mocked is_macosx
with patch('openlp.core.ui.media.webkitplayer.is_macosx') as mocked_is_macosx:
mocked_is_macosx.return_value = False
# GIVEN: A WebkitPlayer instance and a mocked QWebPage
mocked_qwebpage = MagicMock()
mocked_qwebpage.mainFrame().evaluateJavaScript.return_value = '[object HTMLVideoElement]'
with patch('openlp.core.ui.media.webkitplayer.QtWebKit.QWebPage', **{'return_value': mocked_qwebpage}):
webkit_player = WebkitPlayer(None)
# WHEN: An checking if the player is available
available = webkit_player.check_available()
# THEN: The player should be available when not on Mac OS X
self.assertEqual(True, available, 'The WebkitPlayer should be available when not on Mac OS X.')
# THEN: The player should be available when '[object HTMLVideoElement]' is returned
self.assertEqual(True, available,
'The WebkitPlayer should be available when video feature detection passes')

View File

@ -24,6 +24,7 @@ Package to test the openlp.core.__init__ package.
"""
from optparse import Values
import os
import sys
from unittest import TestCase
from unittest.mock import MagicMock, patch
@ -118,12 +119,27 @@ class TestInit(TestCase, TestMixin):
"""
Test that parse_options parses short options correctly
"""
# GIVEN: A list of vaild short options
# GIVEN: A list of valid short options
options = ['-e', '-l', 'debug', '-pd', '-s', 'style', 'extra', 'qt', 'args']
# WHEN: Calling parse_options
resluts = parse_options(options)
results = parse_options(options)
# THEN: A tuple should be returned with the parsed options and left over args
self.assertEqual(resluts, (Values({'no_error_form': True, 'dev_version': True, 'portable': True,
self.assertEqual(results, (Values({'no_error_form': True, 'dev_version': True, 'portable': True,
'style': 'style', 'loglevel': 'debug'}), ['extra', 'qt', 'args']))
def parse_options_valid_argv_short_options_test(self):
"""
Test that parse_options parses valid short options correctly when passed through sys.argv
"""
# GIVEN: A list of valid options
options = ['openlp.py', '-e', '-l', 'debug', '-pd', '-s', 'style', 'extra', 'qt', 'args']
# WHEN: Passing in the options through sys.argv and calling parse_args with None
with patch.object(sys, 'argv', options):
results = parse_options(None)
# THEN: parse_args should return a tuple of valid options and of left over options that OpenLP does not use
self.assertEqual(results, (Values({'no_error_form': True, 'dev_version': True, 'portable': True,
'style': 'style', 'loglevel': 'debug'}), ['extra', 'qt', 'args']))