Skip to content

Commit 00f7655

Browse files
authored
[java] Update extension in the tests to use the common extensions (#10398)
Related to #10266 Co-authored-by: Diego Molina <diemol@users.noreply.github.com> [skip ci]
1 parent 3dad508 commit 00f7655

File tree

12 files changed

+66
-83
lines changed

12 files changed

+66
-83
lines changed

‎common/extensions/BUILD.bazel

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,17 @@ filegroup(
66
]),
77
visibility = [
88
"//javascript/node/selenium-webdriver:__pkg__",
9+
"//java/test/org/openqa/selenium/chrome:__pkg__",
10+
"//java/test/org/openqa/selenium/edge:__pkg__",
11+
"//java/test/org/openqa/selenium/firefox:__pkg__",
12+
"//java/test/org/openqa/selenium/environment:__pkg__",
913
],
1014
)
15+
exports_files(
16+
[
17+
"webextensions-selenium-example.xpi"
18+
],
19+
visibility = [
20+
"//java/test/org/openqa/selenium/firefox:__pkg__",
21+
],
22+
)

‎java/test/org/openqa/selenium/chrome/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ java_selenium_test_suite(
99
"chrome",
1010
],
1111
data = [
12-
"//third_party/chrome_ext:backspace.crx",
12+
"//common/extensions",
1313
],
1414
javacopts = [
1515
"--release",

‎java/test/org/openqa/selenium/chrome/ChromeOptionsFunctionalTest.java

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,22 @@
1919

2020
import static org.assertj.core.api.Assertions.assertThat;
2121
import static org.openqa.selenium.remote.CapabilityType.ACCEPT_INSECURE_CERTS;
22-
import static org.openqa.selenium.support.ui.ExpectedConditions.titleIs;
2322

2423
import org.junit.After;
2524
import org.junit.Test;
2625
import org.openqa.selenium.By;
27-
import org.openqa.selenium.Keys;
28-
import org.openqa.selenium.support.ui.WebDriverWait;
26+
import org.openqa.selenium.WebElement;
2927
import org.openqa.selenium.build.InProject;
3028
import org.openqa.selenium.testing.JUnit4TestBase;
3129
import org.openqa.selenium.testing.TestUtilities;
3230

3331
import java.io.IOException;
3432
import java.nio.file.Files;
35-
import java.time.Duration;
3633
import java.util.Base64;
3734

3835
public class ChromeOptionsFunctionalTest extends JUnit4TestBase {
3936

40-
private static final String EXT_PATH = "third_party/chrome_ext/backspace.crx";
37+
private static final String EXT_PATH = "common/extensions/webextensions-selenium-example.crx";
4138

4239
private ChromeDriver driver = null;
4340

@@ -92,13 +89,12 @@ public void canAddExtensionFromFile() {
9289
options.addExtensions(InProject.locate(EXT_PATH).toFile());
9390
driver = new ChromeDriver(options);
9491

95-
driver.get(pages.clicksPage);
92+
driver.get(pages.echoPage);
9693

97-
driver.findElement(By.id("normal")).click();
98-
new WebDriverWait(driver, Duration.ofSeconds(10)).until(titleIs("XHTML Test Page"));
94+
WebElement footerElement = driver.findElement(By.id("webextensions-selenium-example"));
9995

100-
driver.findElement(By.tagName("body")).sendKeys(Keys.BACK_SPACE);
101-
new WebDriverWait(driver, Duration.ofSeconds(10)).until(titleIs("clicks"));
96+
String footText = footerElement.getText();
97+
assertThat(footText).isEqualTo("Content injected by webextensions-selenium-example");
10298
}
10399

104100
@Test
@@ -111,13 +107,12 @@ public void canAddExtensionFromStringEncodedInBase64() throws IOException {
111107
Files.readAllBytes(InProject.locate(EXT_PATH))));
112108
driver = new ChromeDriver(options);
113109

114-
driver.get(pages.clicksPage);
110+
driver.get(pages.echoPage);
115111

116-
driver.findElement(By.id("normal")).click();
117-
new WebDriverWait(driver, Duration.ofSeconds(10)).until(titleIs("XHTML Test Page"));
112+
WebElement footerElement = driver.findElement(By.id("webextensions-selenium-example"));
118113

119-
driver.findElement(By.tagName("body")).sendKeys(Keys.BACK_SPACE);
120-
new WebDriverWait(driver, Duration.ofSeconds(10)).until(titleIs("clicks"));
114+
String footText = footerElement.getText();
115+
assertThat(footText).isEqualTo("Content injected by webextensions-selenium-example");
121116
}
122117

123118
}

‎java/test/org/openqa/selenium/edge/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ java_selenium_test_suite(
99
"edge",
1010
],
1111
data = [
12-
"//third_party/chrome_ext:backspace.crx",
12+
"//common/extensions",
1313
],
1414
javacopts = [
1515
"--release",

‎java/test/org/openqa/selenium/edge/EdgeOptionsFunctionalTest.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.openqa.selenium.JavascriptExecutor;
2929
import org.openqa.selenium.Keys;
3030
import org.openqa.selenium.WebDriver;
31+
import org.openqa.selenium.WebElement;
3132
import org.openqa.selenium.build.InProject;
3233
import org.openqa.selenium.support.ui.WebDriverWait;
3334
import org.openqa.selenium.testing.JUnit4TestBase;
@@ -41,7 +42,7 @@
4142

4243
public class EdgeOptionsFunctionalTest extends JUnit4TestBase {
4344

44-
private static final String EXT_PATH = "third_party/chrome_ext/backspace.crx";
45+
private static final String EXT_PATH = "common/extensions/webextensions-selenium-example.crx";
4546

4647
private WebDriver edgeDriver = null;
4748

@@ -89,13 +90,13 @@ public void canAddExtensionFromFile() {
8990
options.addExtensions(InProject.locate(EXT_PATH).toFile());
9091
edgeDriver = new WebDriverBuilder().get(options);
9192

92-
edgeDriver.get(pages.clicksPage);
93+
edgeDriver.get(pages.echoPage);
9394

94-
edgeDriver.findElement(By.id("normal")).click();
95-
new WebDriverWait(edgeDriver, Duration.ofSeconds(10)).until(titleIs("XHTML Test Page"));
95+
WebElement footerElement = driver.findElement(By.id("webextensions-selenium-example"));
96+
97+
String footText = footerElement.getText();
98+
assertThat(footText).isEqualTo("Content injected by webextensions-selenium-example");
9699

97-
edgeDriver.findElement(By.tagName("body")).sendKeys(Keys.BACK_SPACE);
98-
new WebDriverWait(edgeDriver, Duration.ofSeconds(10)).until(titleIs("clicks"));
99100
}
100101

101102
@Test
@@ -106,13 +107,12 @@ public void canAddExtensionFromStringEncodedInBase64() throws IOException {
106107
Files.readAllBytes(InProject.locate(EXT_PATH))));
107108
edgeDriver = new WebDriverBuilder().get(options);
108109

109-
edgeDriver.get(pages.clicksPage);
110+
edgeDriver.get(pages.echoPage);
110111

111-
edgeDriver.findElement(By.id("normal")).click();
112-
new WebDriverWait(edgeDriver, Duration.ofSeconds(10)).until(titleIs("XHTML Test Page"));
112+
WebElement footerElement = driver.findElement(By.id("webextensions-selenium-example"));
113113

114-
edgeDriver.findElement(By.tagName("body")).sendKeys(Keys.BACK_SPACE);
115-
new WebDriverWait(edgeDriver, Duration.ofSeconds(10)).until(titleIs("clicks"));
114+
String footText = footerElement.getText();
115+
assertThat(footText).isEqualTo("Content injected by webextensions-selenium-example");
116116
}
117117

118118
}

‎java/test/org/openqa/selenium/environment/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ java_library(
2828
data = [
2929
"webserver/keystore",
3030
"//common/src/web",
31+
"//common/extensions",
3132
"//javascript/atoms",
3233
"//javascript/atoms:deps",
3334
"//third_party/closure/goog",

‎java/test/org/openqa/selenium/firefox/BUILD.bazel

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ java_test_suite(
2020
exclude = LARGE_TESTS + REMOTE_TESTS,
2121
),
2222
data = [
23-
":firebug_xpi",
24-
"//third_party/firebug:firebug-1.5.0-fx.xpi",
25-
"//third_party/firebug:mooltipass-1.1.87.xpi",
23+
":webextensions_selenium_example",
24+
"//common/extensions",
2625
],
2726
tags = [
2827
"requires-network",
@@ -48,14 +47,10 @@ java_selenium_test_suite(
4847
"firefox",
4948
],
5049
data = [
51-
"//third_party/firebug:favourite_colour-1.1-an+fx.xpi",
52-
"//third_party/firebug:firebug-1.5.0-fx.xpi",
53-
"//third_party/firebug:mooltipass-1.1.87.xpi",
50+
"//common/extensions",
5451
],
5552
resources = [
56-
"//third_party/firebug:favourite_colour-1.1-an+fx.xpi",
57-
"//third_party/firebug:firebug-1.5.0-fx.xpi",
58-
"//third_party/firebug:mooltipass-1.1.87.xpi",
53+
"//common/extensions",
5954
],
6055
deps = [
6156
"//java/src/org/openqa/selenium/firefox",
@@ -81,14 +76,10 @@ java_selenium_test_suite(
8176
"firefox",
8277
],
8378
data = [
84-
"//third_party/firebug:favourite_colour-1.1-an+fx.xpi",
85-
"//third_party/firebug:firebug-1.5.0-fx.xpi",
86-
"//third_party/firebug:mooltipass-1.1.87.xpi",
79+
"//common/extensions"
8780
],
8881
resources = [
89-
"//third_party/firebug:favourite_colour-1.1-an+fx.xpi",
90-
"//third_party/firebug:firebug-1.5.0-fx.xpi",
91-
"//third_party/firebug:mooltipass-1.1.87.xpi",
82+
"//common/extensions"
9283
],
9384
tags = [
9485
"selenium-remote",
@@ -106,7 +97,7 @@ java_selenium_test_suite(
10697
)
10798

10899
copy_file(
109-
name = "firebug_xpi",
110-
src = "//third_party/firebug:firebug-1.5.0-fx.xpi",
111-
out = "firebug-1.5.0-fx.xpi",
100+
name = "webextensions_selenium_example",
101+
src = "//common/extensions:webextensions-selenium-example.xpi",
102+
out = "webextensions-selenium-example.xpi",
112103
)

‎java/test/org/openqa/selenium/firefox/FirefoxDriverTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777

7878
public class FirefoxDriverTest extends JUnit4TestBase {
7979

80+
private static final String EXT_PATH = "common/extensions/webextensions-selenium-example.xpi";
8081
private static char[] CHARS =
8182
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!\"§$%&/()+*~#',.-_:;\\"
8283
.toCharArray();
@@ -529,10 +530,10 @@ public void testFirefoxCanNativelyClickOverlappingElements() {
529530

530531
@Test
531532
public void canAddRemoveExtensions() {
532-
Path extension = InProject.locate("third_party/firebug/favourite_colour-1.1-an+fx.xpi");
533+
Path extension = InProject.locate(EXT_PATH);
533534

534535
String id = ((HasExtensions) driver).installExtension(extension);
535-
assertThat(id).isEqualTo("favourite-colour-examples@mozilla.org");
536+
assertThat(id).isEqualTo("webextensions-selenium-example@example.com");
536537

537538
try {
538539
((HasExtensions) driver).uninstallExtension(id);
@@ -543,10 +544,10 @@ public void canAddRemoveExtensions() {
543544

544545
@Test
545546
public void canAddRemoveTempExtensions() {
546-
Path extension = InProject.locate("third_party/firebug/favourite_colour-1.1-an+fx.xpi");
547+
Path extension = InProject.locate(EXT_PATH);
547548

548549
String id = ((HasExtensions) driver).installExtension(extension, true);
549-
assertThat(id).isEqualTo("favourite-colour-examples@mozilla.org");
550+
assertThat(id).isEqualTo("webextensions-selenium-example@example.com");
550551

551552
try {
552553
((HasExtensions) driver).uninstallExtension(id);

‎java/test/org/openqa/selenium/firefox/FirefoxProfileTest.java

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@
4444

4545
@Category(UnitTests.class)
4646
public class FirefoxProfileTest {
47-
private static final String FIREBUG_PATH = "third_party/firebug/firebug-1.5.0-fx.xpi";
48-
private static final String FIREBUG_RESOURCE_PATH =
49-
"java/test/org/openqa/selenium/firefox/firebug-1.5.0-fx.xpi";
50-
private static final String MOOLTIPASS_PATH = "third_party/firebug/mooltipass-1.1.87.xpi";
47+
private static final String EXT_PATH = "common/extensions/webextensions-selenium-example.xpi";
48+
private static final String EXT_RESOURCE_PATH =
49+
"java/test/org/openqa/selenium/firefox/webextensions-selenium-example.xpi";
5150

5251
private FirefoxProfile profile;
5352

@@ -137,48 +136,29 @@ public void shouldAllowSettingFrozenPreferences() throws Exception {
137136
assertPreferenceValueEquals("network.http.phishy-userpass-length", 1024);
138137
}
139138

140-
@Test
141-
@Ignore("Need to replace the extension")
142-
public void shouldInstallExtensionFromZip() {
143-
profile.addExtension(InProject.locate(FIREBUG_PATH).toFile());
144-
File profileDir = profile.layoutOnDisk();
145-
File extensionFile = new File(profileDir, "extensions/firebug@software.joehewitt.com.xpi");
146-
assertThat(extensionFile).exists().isFile();
147-
}
148-
149139
@Test
150140
public void shouldInstallWebExtensionFromZip() {
151-
profile.addExtension(InProject.locate(MOOLTIPASS_PATH).toFile());
141+
profile.addExtension(InProject.locate(EXT_PATH).toFile());
152142
File profileDir = profile.layoutOnDisk();
153-
File extensionFile = new File(profileDir, "extensions/MooltipassExtension@1.1.87.xpi");
143+
File extensionFile = new File(profileDir, "extensions/webextensions-selenium-example@example.com.xpi");
154144
assertThat(extensionFile).exists().isFile();
155145
}
156146

157-
@Test
158-
public void shouldInstallExtensionFromDirectory() throws IOException {
159-
File extension = InProject.locate(FIREBUG_PATH).toFile();
160-
File unzippedExtension = Zip.unzipToTempDir(new FileInputStream(extension), "unzip", "stream");
161-
profile.addExtension(unzippedExtension);
162-
File profileDir = profile.layoutOnDisk();
163-
File extensionDir = new File(profileDir, "extensions/firebug@software.joehewitt.com");
164-
assertThat(extensionDir).exists().isDirectory();
165-
}
166-
167147
@Test
168148
public void shouldInstallWebExtensionFromDirectory() throws IOException {
169-
File extension = InProject.locate(MOOLTIPASS_PATH).toFile();
149+
File extension = InProject.locate(EXT_PATH).toFile();
170150
File unzippedExtension = Zip.unzipToTempDir(new FileInputStream(extension), "unzip", "stream");
171151
profile.addExtension(unzippedExtension);
172152
File profileDir = profile.layoutOnDisk();
173-
File extensionDir = new File(profileDir, "extensions/MooltipassExtension@1.1.87");
153+
File extensionDir = new File(profileDir, "extensions/webextensions-selenium-example@example.com");
174154
assertThat(extensionDir).exists();
175155
}
176156

177157
@Test
178158
public void shouldInstallExtensionUsingClasspath() {
179-
profile.addExtension(FirefoxProfileTest.class, FIREBUG_RESOURCE_PATH);
159+
profile.addExtension(FirefoxProfileTest.class, EXT_RESOURCE_PATH);
180160
File profileDir = profile.layoutOnDisk();
181-
File extensionDir = new File(profileDir, "extensions/firebug@software.joehewitt.com.xpi");
161+
File extensionDir = new File(profileDir, "extensions/webextensions-selenium-example@example.com.xpi");
182162
assertThat(extensionDir).exists();
183163
}
184164

‎java/test/org/openqa/selenium/firefox/MarionetteTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
public class MarionetteTest extends JUnit4TestBase {
4141

42-
private static final String MOOLTIPASS_PATH = "third_party/firebug/mooltipass-1.1.87.xpi";
42+
private static final String EXT_PATH = "common/extensions/webextensions-selenium-example.xpi";
4343

4444
private FirefoxDriver localDriver;
4545

@@ -233,8 +233,9 @@ public void canStartHeadless() {
233233
public void canInstallAndUninstallExtensionsOnTheFly() {
234234
assumeTrue(driver instanceof FirefoxDriver);
235235
FirefoxDriver localDriver = (FirefoxDriver) driver;
236-
Path extension = InProject.locate(MOOLTIPASS_PATH);
236+
Path extension = InProject.locate(EXT_PATH);
237237
String extId = localDriver.installExtension(extension);
238+
assertThat(extId).isEqualTo("webextensions-selenium-example@example.com");
238239
localDriver.uninstallExtension(extId);
239240
}
240241

‎java/test/org/openqa/selenium/firefox/RemoteFirefoxDriverTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public class RemoteFirefoxDriverTest extends JUnit4TestBase {
3939
@Test
4040
@NoDriverAfterTest
4141
public void shouldAllowRemoteWebDriverBuilderToUseHasExtensions() {
42-
Path extension = InProject.locate("third_party/firebug/favourite_colour-1.1-an+fx.xpi");
42+
Path extension = InProject.locate("common/extensions/webextensions-selenium-example.xpi");
4343
String id = ((HasExtensions) driver).installExtension(extension);
44-
assertThat(id).isEqualTo("favourite-colour-examples@mozilla.org");
44+
assertThat(id).isEqualTo("webextensions-selenium-example@example.com");
4545

4646
try {
4747
((HasExtensions) driver).uninstallExtension(id);

‎java/test/org/openqa/selenium/testing/Pages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class Pages {
3838
public String droppableItems;
3939
public String dynamicallyModifiedPage;
4040
public String dynamicPage;
41+
public String echoPage;
4142
public String errorsPage;
4243
public String formPage;
4344
public String formSelectionPage;
@@ -98,6 +99,7 @@ public Pages(AppServer appServer) {
9899
documentWrite = appServer.whereIs("document_write_in_onload.html");
99100
dynamicallyModifiedPage = appServer.whereIs("dynamicallyModifiedPage.html");
100101
dynamicPage = appServer.whereIs("dynamic.html");
102+
echoPage = appServer.whereIs("echo");
101103
errorsPage = appServer.whereIs("errors.html");
102104
xhtmlFormPage = appServer.whereIs("xhtmlFormPage.xhtml");
103105
formPage = appServer.whereIs("formPage.html");

0 commit comments

Comments
 (0)