Skip to content

Commit

Permalink
merge excessive fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
sadym-chromium committed Jul 2, 2024
1 parent f7b9dd6 commit 5dbd158
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 32 deletions.
4 changes: 2 additions & 2 deletions tests/browsing_context/test_navigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ async def test_browsingContext_navigationStarted_sameDocumentNavigation(


@pytest.mark.asyncio
@pytest.mark.parametrize('capabilities', [{
@pytest.mark.parametrize('capabilities', [{}, {
'acceptInsecureCerts': True
}, {
'acceptInsecureCerts': False
Expand All @@ -533,7 +533,7 @@ async def navigate():
}
})

if capabilities['acceptInsecureCerts']:
if capabilities.get('acceptInsecureCerts'):
await navigate()
else:
with pytest.raises(Exception,
Expand Down
6 changes: 3 additions & 3 deletions tests/browsing_context/test_nested_browsing_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ async def test_nestedBrowsingContext_afterNavigation_getTreeWithNestedContexts_c

@pytest.mark.asyncio
async def test_browsingContext_addAndRemoveNestedContext_contextAddedAndRemoved(
websocket, context_id, url_cross_origin, html, iframe):
page_with_nested_iframe = html(iframe(url_cross_origin))
websocket, context_id, url_all_origins, html, iframe):
page_with_nested_iframe = html(iframe(url_all_origins))
await goto_url(websocket, context_id, page_with_nested_iframe, "complete")

result = await get_tree(websocket)
Expand All @@ -337,7 +337,7 @@ async def test_browsingContext_addAndRemoveNestedContext_contextAddedAndRemoved(
"context": context_id,
"children": [{
"context": ANY_STR,
"url": url_cross_origin,
"url": url_all_origins,
"children": [],
"userContext": "default",
"originalOpener": None
Expand Down
31 changes: 12 additions & 19 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,25 +214,18 @@ def url_same_origin():
return 'about:blank'


# TODO: make offline.
@pytest.fixture(params=[
'https://example.com/', # Another domain: Cross-origin
'data:text/html,<h2>child page</h2>', # Data URL: Cross-origin
])
def url_cross_origin(request):
"""Return a cross-origin URL."""
return request.param


# TODO: make offline.
@pytest.fixture(params=[
'about:blank', # Same-origin
'https://example.com/', # Another domain: Cross-origin
'data:text/html,<h2>child page</h2>', # Data URL: Cross-origin
])
def url_all_origins(request):
"""Return a URL exhaustively, including same-origin and cross-origin."""
return request.param
@pytest.fixture(
params=['url_example', 'url_another_example', 'html', 'about:blank'])
def url_all_origins(request, url_example, url_another_example, html):
if request.param == 'url_example':
return url_example
if request.param == 'url_another_example':
return url_another_example
if request.param == 'html':
return html('data:text/html,<h2>some page</h2>')
if request.param == 'about:blank':
return 'about:blank'
raise ValueError(f"Unknown parameter: {request.param}")


@pytest.fixture
Expand Down
6 changes: 3 additions & 3 deletions tests/script/test_add_preload_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,9 +667,9 @@ async def test_preloadScript_add_sandbox_existing_context(

@pytest.mark.asyncio
async def test_preloadScript_add_withUserGesture_blankTargetLink(
websocket, context_id, html, read_sorted_messages):
websocket, context_id, html, read_sorted_messages, url_example):
LINK_WITH_BLANK_TARGET = html(
'<a href="https://example.com" target="_blank">new tab</a>')
f'<a href="{url_example}" target="_blank">new tab</a>')

await execute_command(
websocket, {
Expand Down Expand Up @@ -714,7 +714,7 @@ async def test_preloadScript_add_withUserGesture_blankTargetLink(
"value": "my preload script"
}, {
'type': 'string',
'value': 'https://example.com/',
'value': url_example,
}]
}
})
Expand Down
6 changes: 3 additions & 3 deletions tests/tools/local_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class LocalHttpServer:

__protocol: Literal['http', 'https']

default_200_page_content: str = 'default 200 page'
content_200: str = 'default 200 page'

def clear(self):
self.__http_server.clear()
Expand Down Expand Up @@ -94,7 +94,7 @@ def html_doc(content):
self.__http_server \
.expect_request(self.__path_200) \
.respond_with_data(
html_doc(self.default_200_page_content),
html_doc(self.content_200),
headers={"Content-Type": "text/html"})

# Set up permanent redirect.
Expand Down Expand Up @@ -135,7 +135,7 @@ def hang_forever(_):
.respond_with_handler(hang_forever)

def cache(request: Request):
content = html_doc(self.default_200_page_content)
content = html_doc(self.content_200)
if_modified_since = request.headers.get("If-Modified-Since")

if if_modified_since is not None:
Expand Down
4 changes: 2 additions & 2 deletions tests/tools/test_local_http_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ async def get_content(websocket, context_id, url):
@pytest.mark.asyncio
async def test_local_server_200(websocket, context_id, local_server_http):
assert await get_content(websocket, context_id, local_server_http.url_200()) \
== local_server_http.default_200_page_content
== local_server_http.content_200


@pytest.mark.asyncio
async def test_local_server_redirect(websocket, context_id, local_server_http):
assert await get_content(websocket, context_id,
local_server_http.url_permanent_redirect()) \
== local_server_http.default_200_page_content
== local_server_http.content_200

0 comments on commit 5dbd158

Please sign in to comment.