MCPcopy
hub / github.com/plotly/dash / test_rdif001_sandbox_allow_scripts

Function test_rdif001_sandbox_allow_scripts

tests/integration/renderer/test_iframe.py:7–65  ·  view source on GitHub ↗
(dash_duo)

Source from the content-addressed store, hash-verified

5
6
7def test_rdif001_sandbox_allow_scripts(dash_duo):
8 app = Dash(__name__)
9
10 N_OUTPUTS = 50
11
12 app.layout = html.Div(
13 [html.Button("click me", id="btn")]
14 + [html.Div(id="output-{}".format(i)) for i in range(N_OUTPUTS)]
15 )
16
17 @app.callback(
18 [Output("output-{}".format(i), "children") for i in range(N_OUTPUTS)],
19 [Input("btn", "n_clicks")],
20 )
21 def update_output(n_clicks):
22 if n_clicks is None:
23 raise PreventUpdate
24
25 return ["{}={}".format(i, i + n_clicks) for i in range(N_OUTPUTS)]
26
27 @app.server.route("/iframe-wrapper")
28 def iframe_wrapper():
29 iframe_html = """
30 <!DOCTYPE html>
31 <html>
32 <iframe src="/" sandbox="allow-scripts" style="width:100%;height:100vh;border:none;">
33 </iframe>
34 </html>
35 """
36 response = make_response(iframe_html)
37 response.headers["Content-Type"] = "text/html"
38 return response
39
40 @app.server.after_request
41 def apply_cors(response):
42 response.headers["Access-Control-Allow-Origin"] = "*"
43 response.headers[
44 "Access-Control-Allow-Headers"
45 ] = "Origin, X-Requested-With, Content-Type, Accept, Authorization"
46 return response
47
48 dash_duo.start_server(app)
49
50 dash_duo.find_element("#btn").click()
51 dash_duo.wait_for_element("#output-0").text == "0=1"
52
53 assert dash_duo.get_logs() == []
54
55 # Navigate to the iframe wrapper served from the same origin
56 dash_duo.driver.get(dash_duo.server_url + "/iframe-wrapper")
57
58 dash_duo.driver.switch_to.frame(0)
59
60 assert dash_duo.get_logs() == []
61
62 dash_duo.find_element("#btn").click()
63 dash_duo.wait_for_text_to_equal("#output-0", "0=1")
64

Callers

nothing calls this directly

Calls 9

DashClass · 0.90
find_elementMethod · 0.80
wait_for_elementMethod · 0.80
get_logsMethod · 0.80
formatMethod · 0.45
start_serverMethod · 0.45
clickMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…