示例#1
0
def test_timestamp(position, expected):
    if expected.geolocation.timestamp['value'] == 'REAL VALUE':
        if expected.geolocation.timestamp['accuracy'] == 'EXACTLY':
            # Values do not have to be strictly equal because executing command takes some time.
            # A deviation of less than 2 seconds is tolerated.
            assert abs(time() - int(position['timestamp'])/1000) < 2
        else:
            timestamp_accuracy = expected.geolocation.timestamp['accuracy']*1000
            # Should be rounded real value in accuracy.
            assert is_in_accuracy(position['timestamp'], timestamp_accuracy)
    else:
        # Should be spoofed value.
        assert position['timestamp'] == expected.geolocation.timestamp['value']
示例#2
0
def test_altitude(browser, position, expected):
    if expected.geolocation.altitude['value'] == 'REAL VALUE':
        if position['altitude'] == "null":
            # If current value is null, real value has to be null too.
            assert position['altitude'] == browser.real.geolocation.altitude
        else:
            if expected.geolocation.altitude['accuracy'] == 'EXACTLY':
                # Values do not have to be strictly equal.
                # A deviation of less than 10 meters is tolerated.
                assert abs(float(position['altitude']) - float(browser.real.geolocation.altitude)) < 10
            else:
                # Should be rounded real value in accuracy.
                assert is_in_accuracy(position['altitude'], expected.geolocation.altitude['accuracy'])
    else:
        # Should be spoofed value.
        assert position['altitude'] == expected.geolocation.altitude['value']
示例#3
0
def test_performance(browser, expected):
    is_performance_rounded = True
    # Make 3 measurement.
    for _ in range(3):
        # Wait a while to value of performance will be changed.
        time.sleep(random.randint(1, 3))
        performance = browser.driver.execute_script("return window.performance.now()")
        if expected.performance['accuracy'] == 'EXACTLY':
            if int(performance / 10) * 10 != performance:
                # Performance was not rounded. At least one of three measurement has to say value was not rounded.
                is_performance_rounded = False
        else:
            assert is_in_accuracy(performance, expected.performance['accuracy'])

    if expected.performance['accuracy'] == 'EXACTLY':
        # At least one of three measurement has to say value was not rounded.
        # is_performance_rounded should be false if EXACTLY value is required.
        assert not is_performance_rounded
示例#4
0
def test_milliseconds(browser, expected):
    is_millisecond_rounded = True
    # Make 3 measurement.
    for _ in range(3):
        # Wait a while to value of time will be changed.
        time.sleep(random.randint(1, 3))
        time_in_milliseconds = browser.driver.execute_script(
            "let d = new Date(); return d.getTime()")
        if expected.time['accuracy'] == 'EXACTLY':
            if int(time_in_milliseconds / 10) * 10 != time_in_milliseconds:
                # Time was not rounded. At least one of three measurement has to say value was not rounded.
                is_millisecond_rounded = False
        else:
            assert is_in_accuracy(time_in_milliseconds,
                                  int(expected.time['accuracy'] * 1000))

    if expected.time['accuracy'] == 'EXACTLY':
        # At least one of three measurement has to say value was not rounded.
        # is_millisecond_rounded should be false if EXACTLY value is required.
        assert not is_millisecond_rounded
示例#5
0
def test_longitude(browser, position, expected):
    if expected.geolocation.longitude['value'] == 'REAL VALUE':
        if position['longitude'] == "null":
            # If current value is null, real value has to be null too.
            assert position['longitude'] == browser.real.geolocation.longitude
        else:
            if expected.geolocation.longitude['accuracy'] == 'EXACTLY':
                # Values do not have to be strictly equal.
                # A deviation of less than 1 degrees is tolerated.
                assert abs(
                    float(position['longitude']) -
                    float(browser.real.geolocation.longitude)) < 1
            else:
                longitude = round(float(position['longitude']), 3) * 1000
                longitude_accuracy = expected.geolocation.longitude[
                    'accuracy'] * 1000
                # Should be rounded real value in accuracy.
                assert is_in_accuracy(longitude, longitude_accuracy)
    else:
        # Should be spoofed value.
        assert position['longitude'] == expected.geolocation.longitude['value']
示例#6
0
def test_accuracy(browser, position, expected):
    if expected.geolocation.accuracy['value'] == 'REAL VALUE':
        if position['accuracy'] == "null":
            # If current value is null, real value has to be null too.
            assert position['accuracy'] == browser.real.geolocation.accuracy
        else:
            if expected.geolocation.accuracy['accuracy'] == 'EXACTLY':                
                # x is real position (position returned without JShelter)
                # y should be real position too (position returned with JShelter level 0)
                #
                # It is clear that x and y will not be exact same values. This is due to the netural GPS inaccuracy.
				# A small difference is tolerated.
                # x.accuracy and y.accuracy will be probably different.
                # But distance between x and y should be less than (x.accuracy + y.accuracy).               
                assert calc_distance(float(browser.real.geolocation.latitude),
                                    float(browser.real.geolocation.longitude),
                                    float(position['latitude']),
                                    float(position['longitude'])) < (float(browser.real.geolocation.accuracy) + float(position['accuracy']))
            else:
                # Should be rounded real value in accuracy.
                assert is_in_accuracy(position['accuracy'], expected.geolocation.accuracy['accuracy'])
    else:
        # Should be spoofed value.
        assert position['accuracy'] == expected.geolocation.accuracy['value']