|
| 1 | +/* |
| 2 | + * Copyright (c) Microsoft Corporation. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.microsoft.playwright; |
| 18 | + |
| 19 | +import org.junit.jupiter.api.Test; |
| 20 | + |
| 21 | +import java.io.OutputStreamWriter; |
| 22 | + |
| 23 | +import static com.microsoft.playwright.BrowserContext.EventType.PAGE; |
| 24 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 25 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 26 | + |
| 27 | +public class TestBrowserContextBasic extends TestBase { |
| 28 | + @Test |
| 29 | + void shouldNotReportFramelessPagesOnError() { |
| 30 | + BrowserContext context = browser.newContext(); |
| 31 | + Page page = context.newPage(); |
| 32 | + server.setRoute("/empty.html", exchange -> { |
| 33 | + exchange.sendResponseHeaders(200, 0); |
| 34 | + try (OutputStreamWriter writer = new OutputStreamWriter(exchange.getResponseBody())) { |
| 35 | + writer.write("<a href='" + server.EMPTY_PAGE + "' target='_blank'>Click me</a>"); |
| 36 | + } |
| 37 | + }); |
| 38 | + Page[] popup = {null}; |
| 39 | + context.addListener(PAGE, event -> popup[0] = (Page) event.data()); |
| 40 | + page.navigate(server.EMPTY_PAGE); |
| 41 | + page.click("'Click me'"); |
| 42 | + context.close(); |
| 43 | + if (popup[0] != null) { |
| 44 | + // This races on Firefox :/ |
| 45 | + assertTrue(popup[0].isClosed()); |
| 46 | + assertNotNull(popup[0].mainFrame()); |
| 47 | + } |
| 48 | + } |
| 49 | +} |
0 commit comments