9
9
from tbselenium .utils import SECURITY_HIGH , SECURITY_MEDIUM , SECURITY_LOW
10
10
11
11
12
+ GET_WEBGL_ORG_URL = "https://get.webgl.org/"
13
+
14
+
12
15
class SecurityLevelTest (unittest .TestCase ):
13
16
17
+ def get_webgl_test_page_status_text (self , driver ):
18
+ status = driver .find_element_by (
19
+ "h1.good" , find_by = By .CSS_SELECTOR , timeout = 5 )
20
+ return status .text
21
+
22
+ def get_webgl_test_page_webgl_container_inner_html (self , driver ):
23
+ webgl_container = driver .find_element_by (
24
+ "logo-container" , find_by = By .ID , timeout = 5 )
25
+ return webgl_container .get_attribute ('innerHTML' ).strip ()
26
+
14
27
def test_set_security_low (self ):
15
28
with TBDriverFixture (TBB_PATH ) as driver :
16
29
set_security_level (driver , SECURITY_LOW )
@@ -22,18 +35,57 @@ def test_set_security_low(self):
22
35
except (NoSuchElementException , TimeoutException ):
23
36
pass
24
37
25
- # TODO: find a better way to test for this
38
+ def test_set_security_low_webgl (self ):
39
+ with TBDriverFixture (TBB_PATH ) as driver :
40
+ set_security_level (driver , SECURITY_LOW )
41
+ driver .load_url_ensure (GET_WEBGL_ORG_URL )
42
+ try :
43
+ # test the status text
44
+ status_text = self .get_webgl_test_page_status_text (driver )
45
+ assert status_text == "Your browser supports WebGL"
46
+
47
+ # make sure WebGL is enabled
48
+ webgl_container_inner_html = \
49
+ self .get_webgl_test_page_webgl_container_inner_html (driver )
50
+ assert webgl_container_inner_html .startswith (
51
+ '<canvas id="webgl-logo"' )
52
+
53
+ except (NoSuchElementException , TimeoutException ) as exc :
54
+ self .fail (
55
+ "Security level does not seem to be set to Standard: %s"
56
+ % exc )
57
+
26
58
def test_set_security_medium (self ):
27
59
with TBDriverFixture (TBB_PATH ) as driver :
28
60
set_security_level (driver , SECURITY_MEDIUM )
29
61
driver .load_url_ensure (CHECK_TPO_URL )
30
62
try :
31
63
driver .find_element_by ("JavaScript is disabled." ,
32
64
find_by = By .LINK_TEXT , timeout = 5 )
33
- self .fail ("Security level does not seem to be set to Safer " )
65
+ self .fail ("Security level does not seem to be set to Standard " )
34
66
except (NoSuchElementException , TimeoutException ):
35
67
pass
36
68
69
+ def test_set_security_medium_webgl (self ):
70
+ with TBDriverFixture (TBB_PATH ) as driver :
71
+ set_security_level (driver , SECURITY_MEDIUM )
72
+ driver .load_url_ensure (GET_WEBGL_ORG_URL )
73
+ try :
74
+ # test the status text
75
+ status_text = self .get_webgl_test_page_status_text (driver )
76
+ assert status_text == "Your browser supports WebGL"
77
+
78
+ # make sure WebGL is click-to-play (NoScript)
79
+ webgl_container_inner_html = \
80
+ self .get_webgl_test_page_webgl_container_inner_html (driver )
81
+ assert webgl_container_inner_html .startswith (
82
+ '<a class="__NoScript_PlaceHolder__' )
83
+
84
+ except (NoSuchElementException , TimeoutException ) as exc :
85
+ self .fail (
86
+ "Security level does not seem to be set to Medium: %s"
87
+ % exc )
88
+
37
89
@pytest .mark .skipif (
38
90
CI_ALPHA_TEST ,
39
91
reason = "Not compatible with the current alpha (10.5a1)" )
@@ -48,6 +100,20 @@ def test_set_security_high(self):
48
100
except (NoSuchElementException , TimeoutException ):
49
101
pass
50
102
103
+ @pytest .mark .skipif (
104
+ CI_ALPHA_TEST ,
105
+ reason = "Not compatible with the current alpha (10.5a1)" )
106
+ def test_set_security_high_webgl (self ):
107
+ with TBDriverFixture (TBB_PATH ) as driver :
108
+ set_security_level (driver , SECURITY_HIGH )
109
+ driver .load_url_ensure (GET_WEBGL_ORG_URL )
110
+
111
+ try :
112
+ status_text = self .get_webgl_test_page_status_text (driver )
113
+ assert status_text == ""
114
+ except (NoSuchElementException , TimeoutException ):
115
+ self .fail ("Security level does not seem to be set to Safest" )
116
+
51
117
52
118
if __name__ == "__main__" :
53
119
unittest .main ()
0 commit comments