99from tbselenium .utils import SECURITY_HIGH , SECURITY_MEDIUM , SECURITY_LOW
1010
1111
12+ GET_WEBGL_ORG_URL = "https://get.webgl.org/"
13+
14+
1215class SecurityLevelTest (unittest .TestCase ):
1316
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+
1427 def test_set_security_low (self ):
1528 with TBDriverFixture (TBB_PATH ) as driver :
1629 set_security_level (driver , SECURITY_LOW )
@@ -22,18 +35,57 @@ def test_set_security_low(self):
2235 except (NoSuchElementException , TimeoutException ):
2336 pass
2437
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+
2658 def test_set_security_medium (self ):
2759 with TBDriverFixture (TBB_PATH ) as driver :
2860 set_security_level (driver , SECURITY_MEDIUM )
2961 driver .load_url_ensure (CHECK_TPO_URL )
3062 try :
3163 driver .find_element_by ("JavaScript is disabled." ,
3264 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 " )
3466 except (NoSuchElementException , TimeoutException ):
3567 pass
3668
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+
3789 @pytest .mark .skipif (
3890 CI_ALPHA_TEST ,
3991 reason = "Not compatible with the current alpha (10.5a1)" )
@@ -48,6 +100,20 @@ def test_set_security_high(self):
48100 except (NoSuchElementException , TimeoutException ):
49101 pass
50102
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+
51117
52118if __name__ == "__main__" :
53119 unittest .main ()
0 commit comments