|
| 1 | +// Licensed to the Software Freedom Conservancy (SFC) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The SFC licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +package org.openqa.selenium.bidi.network; |
| 19 | + |
| 20 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
| 21 | +import static org.openqa.selenium.testing.Safely.safelyCall; |
| 22 | +import static org.openqa.selenium.testing.drivers.Browser.EDGE; |
| 23 | +import static org.openqa.selenium.testing.drivers.Browser.FIREFOX; |
| 24 | +import static org.openqa.selenium.testing.drivers.Browser.IE; |
| 25 | +import static org.openqa.selenium.testing.drivers.Browser.SAFARI; |
| 26 | + |
| 27 | +import java.util.List; |
| 28 | +import org.junit.jupiter.api.AfterEach; |
| 29 | +import org.junit.jupiter.api.BeforeEach; |
| 30 | +import org.junit.jupiter.api.Test; |
| 31 | +import org.openqa.selenium.bidi.Network; |
| 32 | +import org.openqa.selenium.environment.webserver.AppServer; |
| 33 | +import org.openqa.selenium.environment.webserver.NettyAppServer; |
| 34 | +import org.openqa.selenium.testing.JupiterTestBase; |
| 35 | +import org.openqa.selenium.testing.NotYetImplemented; |
| 36 | + |
| 37 | +class AddInterceptParametersTest extends JupiterTestBase { |
| 38 | + |
| 39 | + private AppServer server; |
| 40 | + |
| 41 | + @BeforeEach |
| 42 | + public void setUp() { |
| 43 | + server = new NettyAppServer(); |
| 44 | + server.start(); |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + @NotYetImplemented(SAFARI) |
| 49 | + @NotYetImplemented(IE) |
| 50 | + @NotYetImplemented(EDGE) |
| 51 | + @NotYetImplemented(FIREFOX) |
| 52 | + void canAddInterceptPhase() { |
| 53 | + try (Network network = new Network(driver)) { |
| 54 | + String intercept = |
| 55 | + network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT)); |
| 56 | + assertThat(intercept).isNotNull(); |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + @NotYetImplemented(SAFARI) |
| 62 | + @NotYetImplemented(IE) |
| 63 | + @NotYetImplemented(EDGE) |
| 64 | + @NotYetImplemented(FIREFOX) |
| 65 | + void canAddInterceptPhases() { |
| 66 | + try (Network network = new Network(driver)) { |
| 67 | + String intercept = |
| 68 | + network.addIntercept( |
| 69 | + new AddInterceptParameters( |
| 70 | + List.of(InterceptPhase.BEFORE_REQUEST_SENT, InterceptPhase.RESPONSE_STARTED))); |
| 71 | + assertThat(intercept).isNotNull(); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + @NotYetImplemented(SAFARI) |
| 77 | + @NotYetImplemented(IE) |
| 78 | + @NotYetImplemented(EDGE) |
| 79 | + @NotYetImplemented(FIREFOX) |
| 80 | + void canAddStringUrlPattern() { |
| 81 | + try (Network network = new Network(driver)) { |
| 82 | + String intercept = |
| 83 | + network.addIntercept( |
| 84 | + new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT) |
| 85 | + .urlStringPattern("http://localhost:4444/basicAuth")); |
| 86 | + assertThat(intercept).isNotNull(); |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + @NotYetImplemented(SAFARI) |
| 92 | + @NotYetImplemented(IE) |
| 93 | + @NotYetImplemented(EDGE) |
| 94 | + @NotYetImplemented(FIREFOX) |
| 95 | + void canAddStringUrlPatterns() { |
| 96 | + try (Network network = new Network(driver)) { |
| 97 | + String intercept = |
| 98 | + network.addIntercept( |
| 99 | + new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT) |
| 100 | + .urlStringPatterns( |
| 101 | + List.of( |
| 102 | + "http://localhost:4444/basicAuth", |
| 103 | + "http://localhost:4445/logEntryAdded"))); |
| 104 | + assertThat(intercept).isNotNull(); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + @NotYetImplemented(SAFARI) |
| 110 | + @NotYetImplemented(IE) |
| 111 | + @NotYetImplemented(EDGE) |
| 112 | + @NotYetImplemented(FIREFOX) |
| 113 | + void canAddUrlPattern() { |
| 114 | + try (Network network = new Network(driver)) { |
| 115 | + UrlPattern pattern = |
| 116 | + new UrlPattern() |
| 117 | + .hostname("localhost") |
| 118 | + .pathname("/logEntryAdded") |
| 119 | + .port("4444") |
| 120 | + .protocol("http") |
| 121 | + .search(""); |
| 122 | + |
| 123 | + String intercept = |
| 124 | + network.addIntercept( |
| 125 | + new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT).urlPattern(pattern)); |
| 126 | + assertThat(intercept).isNotNull(); |
| 127 | + } |
| 128 | + } |
| 129 | + |
| 130 | + @Test |
| 131 | + @NotYetImplemented(SAFARI) |
| 132 | + @NotYetImplemented(IE) |
| 133 | + @NotYetImplemented(EDGE) |
| 134 | + @NotYetImplemented(FIREFOX) |
| 135 | + void canAddUrlPatterns() { |
| 136 | + try (Network network = new Network(driver)) { |
| 137 | + UrlPattern pattern1 = |
| 138 | + new UrlPattern() |
| 139 | + .hostname("localhost") |
| 140 | + .pathname("/logEntryAdded") |
| 141 | + .port("4444") |
| 142 | + .protocol("http") |
| 143 | + .search(""); |
| 144 | + |
| 145 | + UrlPattern pattern2 = |
| 146 | + new UrlPattern() |
| 147 | + .hostname("localhost") |
| 148 | + .pathname("/basicAuth") |
| 149 | + .port("4445") |
| 150 | + .protocol("https") |
| 151 | + .search("auth"); |
| 152 | + |
| 153 | + String intercept = |
| 154 | + network.addIntercept( |
| 155 | + new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT) |
| 156 | + .urlPatterns(List.of(pattern1, pattern2))); |
| 157 | + assertThat(intercept).isNotNull(); |
| 158 | + } |
| 159 | + } |
| 160 | + |
| 161 | + @AfterEach |
| 162 | + public void quitDriver() { |
| 163 | + if (driver != null) { |
| 164 | + driver.quit(); |
| 165 | + } |
| 166 | + safelyCall(server::stop); |
| 167 | + } |
| 168 | +} |
0 commit comments