Commit Graph

832 Commits

Author SHA1 Message Date
Elias Naur 2bee95358a .builds: run the cmd tests with and without -race
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-03 13:06:14 +01:00
Daniel Martí 2a4829d857 cmd/gogio: support running e2e with and without -race
Right now, we can only run the e2e gio app with -race, not without
-race, because the flag is hard-coded in the tests.

The reason for this change was that 'GOFLAGS=-race go test' would fail
with the JS test, since js/wasm doesn't support the race detector. Fix
that by skipping the JS test when -race is used.

Now, we can run multiple levels of -race:

	go test               # no -race at all
	go test -race         # -race for the tests, not the e2e gio app
	GOFLAGS=-race go test # -race for everything (best-effort)

To detect the race detector being on, we use a file with a build tag.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-03 13:05:06 +01:00
Elias Naur cc4b407647 .build,cmd: add -race to test programs
It's not possible to set GOFLAGS=-race because some programs are
built for webassembly where -race is not supported.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-03 12:09:02 +01:00
Elias Naur b3635c78ee .builds: add sway as dependency for Wayland end-to-end test
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-02 18:55:31 +01:00
Daniel Martí 12ce899bb5 cmd/gogio: first wayland end-to-end tests
Clicking doesn't quite work yet, but everything else does. We use a
custom sway config to ensure that it's a minimalist setup with no bar or
borders, like the other drivers.

The generic test now adapts to the window's real size when running in
non-headless mode, since tiling window managers resize some drivers like
sway. The default headless mode still expects the exact size that we
specify, as no real windows are at play.

While at it, clean up some now unused code from the x11 file.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-02 18:12:46 +01:00
Elias Naur 5eeaadccea app/internal/window: apply font scale to dp scaling on Wayland
As discussed in gio#53, Linux font scales conflate two settings: the fractional
UI scale and the user preference as a result of conditions such as impaired
vision. The former setting should apply to both dps and sps, while the latter
only to sps. However, with the assumption that more users presumable change the
font scale for the former reason rather than the latter, we should apply the
font scale to both dps and sps in Gio.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-02 17:58:56 +01:00
Elias Naur e2c29f96d9 app: fix reference to gioui.org/io/event
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-02 16:59:19 +01:00
Elias Naur 7182477f3c README.md: add supported platforms
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-02 16:32:47 +01:00
Elias Naur dde09b9d74 example,cmd: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-02 16:09:07 +01:00
Daniel Martí 97d13922dd cmd/gogio: remove sleeps in x11 e2e test
We can instead synchronize with the gio app via stdout. We need three
states, since we need to first invalidate a frame and then print when
the next frame is drawn.

This is not happening on the JS test yet, because stdout printing
crashes in that case. See the comment.

This change should make the X11 test a bit faster on fast machines,
while making it more stable in small or headless machines like CI.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-02 15:00:37 +01:00
Elias Naur 2a9361db65 Revert "gesture: add Active methods to gestures"
This reverts commit d829e56194.

We're not using the activity of gestures to track whether widgets
should behave as disabled or enabled anymore.
2019-11-02 14:49:33 +01:00
Elias Naur 4107485902 widget,widget/material: remove disabled drawing modes
Determining the enabled state of a widget from whether its Clicked method has
been called only works for button-like widgets. For example, it's not clear a
Clicked method is appropriate for a CheckBox.

Remove the feature for now, and let's find a better design in the future.

As a nice side effect, we can now process events in Layout methods, so that
buttons react to user input even when Clicked is not called.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-02 14:48:22 +01:00
Elias Naur 06aa0da2a2 .builds: add scrot to the linux image for the X11 end-to-end test
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-02 10:43:50 +01:00
Daniel Martí b8e996074b cmd/gogio: rip out cgo deps for x11
Instead rely on more tiny standalone tools. In this case, scrot lets us
take png screenshots, and works well.

On the plus side, we remove some large X Go deps, and we don't need
nearly as much code.

While at it, skip if any of the tools are missing, and actually defer
the cleanup funcs so that they run when we fail the test early.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-02 01:19:19 +01:00
Elias Naur 837b5f6bab .builds: install xdotool in the linux builder to satisfy the X11 test
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-01 22:27:42 +01:00
Daniel Martí 41402ce524 cmd/gogio: add clicks to the e2e tests
The test app now responds to mouse clicks; clicking on one of the four
sections of the app flips it to red color until clicked again.

Add a Click method to the TestDriver interface, and implement it in both
of the current drivers. Unfortunately, I failed at implementing it in
X11 with the xdg library, after a few wasted hours. Instead, start
relying on more external tools which are simple to use and not heavy to
install.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-11-01 22:24:26 +01:00
Elias Naur 5b948ceece app/internal/window: tweak minimum pixels per dp/sp
To keep text legible on low DPI monitors, the number of pixels
per dp or sp is not is not allowed to go below minDensity. However,
a minimum density of 1.25 leads to too big text and widgets on a
baseline ~96 DPI monitor. Lower the minimum to 1.0, where text is still
legible.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-01 22:13:42 +01:00
Elias Naur 835714d44e app/internal/window: apply monitorScale to sp values on Wayland
macOS and Windows already applies monitorScale to sp values. Wayland
didn't apply the monitorScale when font scale detection fails. Do that.

Run gofmt -s -w . as well.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-01 21:36:15 +01:00
Elias Naur c646827c0f example: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-01 20:53:08 +01:00
Elias Naur 9a6bdee813 widget/material: adjust Button insets to match Android
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-01 20:51:16 +01:00
Elias Naur 9126da41f4 app: accept pending frame before reporting error
If creating a GPU instance fails for some reason, we need to
receive the incoming frame from the application before reporting
the error in a DestroyEvent. If we don't, the a deadlock will occur
where the app is waiting for FrameEvent.Frame to complete, while
the Window waits for the app the receive a DestroyEvent.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-01 19:38:13 +01:00
Elias Naur 15e34e9ca2 app/internal/window: add note about ANGLE when failing to load it
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-01 19:30:52 +01:00
Greg Pomerantz af353822fa cmd/gogio: add permissions system for Android
Search for imports of the form gioui.org/app/permission/* and add
required permissions to AndroidManifest.xml.

Signed-off-by: Greg Pomerantz <gmp.gio@wow.st>
2019-11-01 18:58:13 +01:00
Elias Naur f418684c0e .builds: set GOFLAGS=-mod=readonly to catch stale go.mod files
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-11-01 18:00:28 +01:00
Greg Pomerantz 3cd633ee44 cmd/gogio: Android: include jar files from dependencies
On Android, in addition to adding jar files found in the source
directory of the program being compiled, cmd/gogio also searches
every dependency for jar files to include in the output APK.

Signed-off-by: Greg Pomerantz <gmp.gio@wow.st>
2019-11-01 17:59:49 +01:00
Daniel Martí 4e71f195ab cmd/gogio: start using layout.Flex in the e2e app
This vastly simplifies our code, and saves us the ugly math.

While at it, establish that a TestDriver must have a white background,
which is already satisfied by both existing implementations.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-31 21:06:34 +01:00
Elias Naur 3a341a3daf cmd/gogio: add -tags nowayland to avoid Wayland in the X11 end-to-end test
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-31 20:57:36 +01:00
Elias Naur f9a3d35184 cmd/gogio/testdate: gofmt -s -w
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-31 14:31:55 +01:00
Elias Naur 34bbf59efa cmd/gogio: double sleep to ensure X11 output is available
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-31 14:24:34 +01:00
Daniel Martí f20c0cc0a6 cmd/gogio: add four colors to the e2e tests
The e2e app now splits the window into four rectangles and paints them
differently.

The first advantage is that we now test that we see the entire Gio app.
Before, with a solid background color, we could be seeing a small part
of the window and we wouldn't tell the difference.

The second advantage is that we test more colors. In particular, the
fourth color includes a different alpha value, which renders the same on
JS and X11.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-31 14:06:05 +01:00
Daniel Martí b3d4da6229 cmd/gogio: start using a TestDriver e2e interface
Now we implement the "red background" end-to-end test exactly once.

While at it, start using a 800x600 window size, which is a bit more
realistic than 600x600, and will catch if we got either dimension wrong.

The interface only has two methods for now, but it will be expanded in
the future to also support input such as clicks.

Keeping state in the test driver, such as a context or a connection, is
a bit awkward but necessary so that we don't have to repeat arguments
over and over. The same applies to testing.T.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-30 23:10:49 +01:00
Elias Naur ff8879ddce example,cmd: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 20:43:45 +01:00
Elias Naur b53c2a7c9d app/internal/window: introduce and use nilEGLDisplay
Updates gio#52

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 20:41:20 +01:00
Daniel Martí d6f5902c5e cmd/gogio: send all e2e logs to t.Logf
chromedp was defaulting to log.Printf, which is not good for tests.

The xgb and xgbutil logs were suppressed if -v wasn't given, but they
were sent straight to os.Stderr otherwise:

	=== RUN   TestX11
	=== PAUSE TestX11
	=== CONT  TestX11
	XGB: conn.go:47: Could not get authority info: EOF
	XGB: conn.go:48: Trying connection without authority info...
	--- PASS: TestX11 (0.87s)

Instead, direct their loggers to an io.Writer implementation that sends
its output to t.Logf:

	=== RUN   TestX11
	=== PAUSE TestX11
	=== CONT  TestX11
	    TestX11: x11_test.go:187: XGB: conn.go:47: Could not get authority info: EOF
	    TestX11: x11_test.go:187: XGB: conn.go:48: Trying connection without authority info...
	--- PASS: TestX11 (0.86s)

We do end up with duplicate log prefixes, but at least we don't write
straight to stderr, which will be a problem as we add more concurrent
tests.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-30 17:30:58 +01:00
Elias Naur dc7af8fba3 cmd/gogio: use a more difficult color for end-to-end tests
RGB 0xff0000 is too easy to get right by accident.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 14:56:37 +01:00
Elias Naur d74be30a90 cmd/gogio: ignore alpha in end-to-end tests
On FreeBSD the X11 test seems to succeed except for the alpha
value:

	--- FAIL: TestX11 (2.04s)
	    js_test.go:138: got 0xffff000000000000 at (5,5), want 0xffff00000000ffff
	    js_test.go:138: got 0xffff000000000000 at (595,595), want 0xffff00000000ffff
	FAIL

Ignore alpha values for now.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 14:45:05 +01:00
Elias Naur 6bbfe288aa .builds: remove go fmt test from freebsd image
There is no reason to run platform independent tests on FreeBSD.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 14:11:24 +01:00
Elias Naur 3945302b4f example,cmd: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 14:05:56 +01:00
Elias Naur 3425b25ecc app/internal: add FreeBSD support
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 14:01:02 +01:00
Elias Naur 1cc1fb1c72 app/internal/window: replace ppoll with poll
We're about to add FreeBSD where ppoll is not supported.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 13:44:59 +01:00
Elias Naur c131a7f423 .builds: remove existing $PATH from PATH settings
$PATH is not expanded anyway, and it's better to be explicit.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 11:49:44 +01:00
Elias Naur 7939f142bd .builds: remove unused path from PATH
It was left over from when the builds didn't use the distro version
of Go.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 11:41:24 +01:00
Elias Naur 6d9dccdbaa cmd,example: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 00:58:35 +01:00
Elias Naur 2e605f2dcb app: ensure the previous frame is complete before accepting another
It matters for end-to-end tests that rely on the window contents.

Before this change, tests had to wait for 2 extra frames. This change
ensures that the first completed FrameEvent.Frame call guarantees
the previous frame is complete.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-30 00:53:21 +01:00
Daniel Martí d31a129bf9 cmd/gogio: fix a couple of x11 e2e TODOs
First, pick a random display number between 1 and 100,000. The pool is
large enough that we don't need to think about collisions for now.

Second, wait for the X server to expose its socket for up to 1s, instead
of doing a single static sleep of 200ms. The average time we actually
need to sleep on my laptop is around 5ms, so this gives a noticeable
speed-up.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-30 00:35:47 +01:00
Elias Naur fe54f3df4e .builds: add xvfb package to the linux builder for X11 end-to-end test
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-29 20:04:47 +01:00
Daniel Martí cea8dc374b cmd/gogio: add the first end-to-end X11 test
Right now it's very similar to the JS test on Chrome. Like it, this one
just runs the "red.go" gio app, takes a screenshot, and expects to see
red.

It also supports the -headless flag; when true, Xvfb is used and it's
entirely headless and hidden. Otherwise, Xephyr is used and once can see
the test in action. If the tool isn't installed, the test is skipped.

We need to add xgb as a dependency, so that we can connect to the X
server and interact with it, like taking screenshots.

Finally, this is an initial version, and a number of TODOs are left for
a later time. They'll get fixed in follow-up patches.

While at it, start making all tests parallel, since the end-to-end tests
take about a second each and neither are very cpu-intensive.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-29 20:01:52 +01:00
Elias Naur b8edf2ee04 .builds: switch from fedora/latest to debian/testing
Fedora builds kept failing at package installation. See
~sircmpwn/builds.sr.ht#220.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-29 17:48:12 +01:00
Daniel Martí 95c47aba55 cmd/gogio: clarify the need for --use-gl=egl in the e2e tests
After some investigation, it turns out that both Alpine and Arch suffer
from the same bug - their packages completely lack SwiftShader.

The current workaround is still the best that we have right now. But at
least we can actually provide a good explanation why, and a TODO to
improve this once the issues filed with the distros are fixed.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
2019-10-29 15:35:23 +01:00
Elias Naur 4793faeadd cmd,example: update gio version
Signed-off-by: Elias Naur <mail@eliasnaur.com>
2019-10-29 14:08:38 +01:00