#!/usr/bin/env python

import math
import os
import unittest

import selenium_test
from selenium_test import FirefoxTest, ChromeTest, ThresholdException


setUpModule = selenium_test.setUpModule
tearDownModule = selenium_test.tearDownModule


class glLinesSpeedBase(object):

    testCase = ('glLinesSpeed',)
    testRevision = 1

    def loadPage(self):
        self.resizeWindow(640, 480)
        self.loadURL('glLinesSpeed/index.html')
        self.wait()

    def testGlLinesSpeed(self):
        self.loadPage()

        testName = 'drawGlLinesSpeed'
        self.loadTimeTest(testName)
        self.framerateTest(testName)

    def loadTimeTest(self, testName, revision=None):
        # Threshold is in milliseconds.  We need the value to be less than the
        # threshold.
        el = self.getElement('#loadResults')
        value = float(el.get_attribute('results'))
        threshold = float(os.environ.get('LOAD_SPEED_THRESHOLD', '1000'))
        print 'Average load time %1.0f ms (must be less than %1.0f ms)' % (
            value, threshold)
        if value > threshold or math.isnan(value):
            raise ThresholdException({'value': value, 'threshold': threshold})

    def framerateTest(self, testName, revision=None):
        # Threshold is in frames-per-second.  We need the value to be greater
        # than the threshold.
        el = self.getElement('#framerateResults')
        value = float(el.get_attribute('results'))  # in milliseconds
        threshold = float(os.environ.get('FRAMERATE_THRESHOLD', '10'))
        print 'Average framerate %4.2f fps (must be at least %4.2f fps)' % (
            value, threshold)
        if value < threshold or math.isnan(value):
            raise ThresholdException({'value': value, 'threshold': threshold})


class FirefoxOSM(glLinesSpeedBase, FirefoxTest):
    testCase = glLinesSpeedBase.testCase + ('firefox',)


class ChromeOSM(glLinesSpeedBase, ChromeTest):
    testCase = glLinesSpeedBase.testCase + ('chrome',)


if __name__ == '__main__':
    unittest.main()

@@ -1139,34 +1139,29 @@
 ception(
-%7B'
 value
-': 
+=
 value, 
-'
 threshol
@@ -1153,35 +1153,33 @@
 value, threshold
-': 
+=
 threshold%7D)%0A%0A   
@@ -1171,17 +1171,16 @@
 hreshold
-%7D
 )%0A%0A    d
@@ -1726,26 +1726,21 @@
 ion(
-%7B'
 value
-': 
+=
 value, 
-'
 thre
@@ -1748,11 +1748,9 @@
 hold
-': 
+=
 thre
@@ -1758,9 +1758,8 @@
 hold
-%7D
 )%0A%0A%0A

Fix threshold exception call