o
    i                     @   s8   d Z ddlmZ ddlmZ dd Zdd Zd	d
 ZdS )z}Test display isolation.

An object whose metadata contains an "isolated" tag must be isolated
from the rest of the document.
    )By   )wait_for_tagc                 C   sP   d}| j d|d | | j zt|  t|  W | jj  d S | jj  w )Nz@from IPython.core.display import HTML, SVG, display, display_svgr   )indexcontent)	edit_cellexecute_cellcurrent_cellisolated_htmlisolated_svgbrowser	switch_todefault_content)notebook	import_ln r   i/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/notebook/tests/selenium/test_display_isolation.pytest_display_isolation   s   
r   c                 C   s  d}d}d}| j d|dd d| d}d|d	}| j |d d| d
}d|d}| j |d t| jddd}| jtjd}	|	d|ksMJ | jtjd}
|
d|ks^J | jj	| | jtjd}|d|ksvJ | jj
  tdt| jD ]}| d qdS )zTest HTML display isolation.

    HTML styling rendered without isolation will affect the whole
    document, whereas styling applied with isolation will affect only
    the local display object.
    zrgb(255, 0, 0)zrgb(0, 0, 255)z7<div id='test'>Should turn red from non-isolation</div>zdisplay(HTML(z))r   z<style>div{color:z4;}</style><div id='non-isolated'>Should be red</div>z), metadata={'isolated':False})z1;}</style><div id='isolated'>Should be blue</div>z), metadata={'isolated':True})iframeT)singleznon-isolatedcolortestisolatedr   N)add_and_execute_cellr   r   bodyfind_elementr   IDvalue_of_css_propertyr   framer   rangelencellsdelete_cell)r   redbluetest_strnon_isolated
display_nir   	display_ir   non_isolated_divtest_divisolated_divir   r   r   r
      s0   

r
   c           	      C   s   d}d}d| d}d}| j |d | j |d | j dd | j dd t| jd	d
d}| jj|d  | jtjd}|d|ksFJ | jj	  | jj|d  | jtjd}|d|ksfJ t
dt| jD ]}| d qndS )z|Test that multiple isolated SVGs have different scopes.

    Asserts that there no CSS leaks between two isolated SVGs.
    zrgb(255, 255, 0)zrgb(0, 0, 0)zUs1 = '''<svg width="1cm" height="1cm" viewBox="0 0 1000 500"><defs><style>rect {fill:zU;}; </style></defs><rect id="r1" x="200" y="100" width="600" height="300" /></svg>'''zs2 = '''<svg width="1cm" height="1cm" viewBox="0 0 1000 500"><rect id="r2" x="200" y="100" width="600" height="300" /></svg>'''r   z2display_svg(SVG(s1), metadata=dict(isolated=True))z2display_svg(SVG(s2), metadata=dict(isolated=True))r      )
wait_for_nr   r1fillr   r2N)r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   )	r   yellowblack	svg_1_str	svg_2_striframesisolated_svg_1isolated_svg_2r-   r   r   r   r   B   s.   r   N)__doc__selenium.webdriver.common.byr   utilsr   r   r
   r   r   r   r   r   <module>   s    *