Skip to content

Commit 78b07f8

Browse files
committed
Build the SynthesizedFirefoxDriver using Buck
This now means that tests run in IJ use Buck by default. That's a milestone for progress :)
1 parent 16a02ed commit 78b07f8

File tree

2 files changed

+36
-41
lines changed

2 files changed

+36
-41
lines changed

java/client/test/org/openqa/selenium/BuckBuild.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,13 @@ private void findBuck(Path projectRoot, ImmutableList.Builder<String> builder) t
118118

119119
private void downloadBuckPexIfNecessary(ImmutableList.Builder<String> builder)
120120
throws IOException {
121-
String buckVersion = new String(Files.readAllBytes(Paths.get(".buckversion"))).trim();
121+
Path projectRoot = InProject.locate("Rakefile").getParentFile().toPath();
122+
String buckVersion = new String(Files.readAllBytes(projectRoot.resolve(".buckversion"))).trim();
122123

123124
Path pex = Paths.get(
124125
StandardSystemProperty.USER_HOME.value(), ".crazyfun", "buck", buckVersion, "buck.pex");
125126

126-
String expectedHash = new String(Files.readAllBytes(Paths.get(".buckhash"))).trim();
127+
String expectedHash = new String(Files.readAllBytes(projectRoot.resolve(".buckhash"))).trim();
127128
HashCode md5 = Files.exists(pex) ?
128129
Hashing.md5().hashBytes(Files.readAllBytes(pex)) :
129130
HashCode.fromString("aa"); // So we have a non-null value

java/client/test/org/openqa/selenium/testing/drivers/SynthesizedFirefoxDriver.java

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,41 +17,43 @@
1717

1818
package org.openqa.selenium.testing.drivers;
1919

20-
import static org.junit.Assert.assertTrue;
21-
import static org.junit.Assert.fail;
2220
import static org.openqa.selenium.testing.DevMode.isInDevMode;
23-
import static org.openqa.selenium.testing.InProject.locate;
2421

2522
import com.google.common.collect.ImmutableMap;
26-
import com.google.common.io.Files;
2723

28-
import org.openqa.selenium.Build;
24+
import org.openqa.selenium.BuckBuild;
2925
import org.openqa.selenium.Capabilities;
3026
import org.openqa.selenium.firefox.FirefoxDriver;
3127
import org.openqa.selenium.firefox.FirefoxProfile;
3228
import org.openqa.selenium.remote.DesiredCapabilities;
29+
import org.openqa.selenium.testing.DevMode;
3330

3431
import java.io.File;
3532
import java.io.IOException;
33+
import java.io.InputStream;
34+
import java.net.URL;
35+
import java.nio.file.Files;
36+
import java.nio.file.Path;
3637

3738
public class SynthesizedFirefoxDriver extends FirefoxDriver {
3839

3940
private static boolean runBuild = true;
41+
private static File cachedExt = null;
4042

4143
public SynthesizedFirefoxDriver() {
4244
this(new DesiredCapabilities(), new DesiredCapabilities());
4345
}
4446

4547
public SynthesizedFirefoxDriver(FirefoxProfile profile) throws IOException {
46-
this(new DesiredCapabilities(), new DesiredCapabilities(ImmutableMap.of(PROFILE, profile)));
48+
this(new DesiredCapabilities(ImmutableMap.of(PROFILE, profile)), new DesiredCapabilities());
4749
}
4850

4951
public SynthesizedFirefoxDriver(Capabilities desiredCapabilities) {
5052
this(desiredCapabilities, null);
5153
}
5254

5355
public SynthesizedFirefoxDriver(Capabilities desiredCapabilities,
54-
Capabilities requiredCapabilities) {
56+
Capabilities requiredCapabilities) {
5557
super(tweakCapabilities(desiredCapabilities), requiredCapabilities);
5658
}
5759

@@ -103,54 +105,46 @@ private static FirefoxProfile createTemporaryProfile() {
103105
}
104106

105107
try {
106-
File prefs = locate("build/javascript/firefox-driver/webdriver_prefs.json");
107-
File noFocus = locate("build/cpp/i386/libnoblur.so");
108-
File ime = locate("build/cpp/i386/libimehandler.so");
109-
File noFocus64 = locate("build/cpp/amd64/libnoblur64.so");
110-
File ime64 = locate("build/cpp/amd64/libimehandler64.so");
111-
File dest = locate("java/client/build/production/org/openqa/selenium/firefox");
112-
Files.copy(prefs, new File(dest, "webdriver_prefs.json"));
113-
114-
File libDir = new File(dest, "x86");
115-
if (!libDir.exists()) {
116-
assertTrue("Cannot create x86 library directory", libDir.mkdir());
117-
}
118-
Files.copy(noFocus, new File(libDir, "x_ignore_nofocus.so"));
119-
Files.copy(ime, new File(libDir, "libibushandler.so"));
120-
121-
libDir = new File(dest, "amd64");
122-
if (!libDir.exists()) {
123-
assertTrue("Cannot create x86 library directory", libDir.mkdir());
124-
}
125-
Files.copy(noFocus64, new File(libDir, "x_ignore_nofocus.so"));
126-
Files.copy(ime64, new File(libDir, "libibushandler.so"));
127-
128108
FirefoxProfile profile = new FirefoxProfile();
129-
130109
if (Boolean.getBoolean("webdriver.debug")) {
110+
131111
Firebug.addTo(profile);
132112
}
133113

134114
profile.setEnableNativeEvents(Boolean.getBoolean("selenium.browser.native_events"));
135115
profile.setPreference("webdriver.log.file", "/dev/stdout");
136116

137117
return copyExtensionTo(profile);
138-
} catch (Exception e) {
118+
} catch (IOException e) {
139119
e.printStackTrace();
140-
fail(e.getMessage());
120+
throw new RuntimeException(e);
141121
}
142-
return null;
143122
}
144123

145124
private static FirefoxProfile copyExtensionTo(FirefoxProfile profile) throws IOException {
146-
File topDir = locate("Rakefile").getParentFile();
147-
File ext = new File(topDir,
148-
"build/javascript/firefox-driver/webdriver.xpi");
149-
if (!ext.exists() || runBuild) {
150-
ext.delete();
151-
new Build().of("//javascript/firefox-driver:webdriver").go();
125+
// Look for the xpi as a resource first.
126+
URL resource = FirefoxDriver.class.getResource("/org/openqa/selenium/firefox/webdriver.xpi");
127+
File ext;
128+
if (resource != null || !DevMode.isInDevMode()) {
129+
Path path = Files.createTempFile("syn-firefox", ".xpi");
130+
ext = path.toFile();
131+
ext.deleteOnExit();
132+
try (InputStream is = resource.openStream()) {
133+
Files.copy(is, path);
134+
}
135+
} else if (runBuild) {
136+
Path output = new BuckBuild().of("//javascript/firefox-driver:webdriver").go();
137+
ext = output.toFile();
138+
cachedExt = ext;
152139
runBuild = false;
140+
} else {
141+
ext = cachedExt;
153142
}
143+
144+
if (ext == null) {
145+
throw new RuntimeException("Cannot compile firefox extension");
146+
}
147+
154148
profile.addExtension(ext);
155149
return profile;
156150
}

0 commit comments

Comments
 (0)