From 726270ab2d8413bc008ece2fe7d72b8e7a2de750 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 23 Nov 2019 19:36:52 +0000 Subject: [PATCH] cmd: remove js runtime workaround MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The js/wasm bug meant that printing to stdout in the e2e app would crash the runtime, so we couldn't synchronize with the app like in the other drivers. Now that the bug is fixed, we can do the same as the other drivers just fine. Signed-off-by: Daniel Martí --- cmd/gogio/js_test.go | 22 +++++++++++++++++----- cmd/gogio/testdata/red.go | 8 -------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/cmd/gogio/js_test.go b/cmd/gogio/js_test.go index 1459e8ac..f01fd6fa 100644 --- a/cmd/gogio/js_test.go +++ b/cmd/gogio/js_test.go @@ -15,7 +15,6 @@ import ( "os/exec" "strings" "testing" - "time" "github.com/chromedp/cdproto/runtime" "github.com/chromedp/chromedp" @@ -26,11 +25,14 @@ import ( type JSTestDriver struct { t *testing.T + frameNotifs chan bool + // ctx is the chromedp context. ctx context.Context } func (d *JSTestDriver) Start(t_ *testing.T, path string, width, height int) { + d.frameNotifs = make(chan bool, 1) d.t = t_ if raceEnabled { @@ -92,6 +94,14 @@ func (d *JSTestDriver) Start(t_ *testing.T, path string, width, height int) { chromedp.ListenTarget(ctx, func(ev interface{}) { switch ev := ev.(type) { case *runtime.EventConsoleAPICalled: + if ev.Type == "log" && len(ev.Args) == 1 && + // Note that the argument values are JSON. + string(ev.Args[0].Value) == `"frame ready"` { + + d.frameNotifs <- true + // These logs are expected. Don't show them. + break + } switch ev.Type { case "log", "info", "warning", "error": var args strings.Builder @@ -123,8 +133,9 @@ func (d *JSTestDriver) Start(t_ *testing.T, path string, width, height int) { ); err != nil { d.t.Fatal(err) } - // TODO(mvdan): synchronize with the app instead - time.Sleep(200 * time.Millisecond) + + // Wait for the gio app to render. + <-d.frameNotifs } func (d *JSTestDriver) Screenshot() image.Image { @@ -147,6 +158,7 @@ func (d *JSTestDriver) Click(x, y int) { ); err != nil { d.t.Fatal(err) } - // TODO(mvdan): synchronize with the app instead - time.Sleep(200 * time.Millisecond) + + // Wait for the gio app to render after this click. + <-d.frameNotifs } diff --git a/cmd/gogio/testdata/red.go b/cmd/gogio/testdata/red.go index 2964a563..f6730ca1 100644 --- a/cmd/gogio/testdata/red.go +++ b/cmd/gogio/testdata/red.go @@ -8,7 +8,6 @@ import ( "image" "image/color" "log" - "runtime" "gioui.org/app" "gioui.org/f32" @@ -82,13 +81,6 @@ func loop(w *app.Window) error { e.Frame(gtx.Ops) - if runtime.GOOS == "js" { - // TODO(mvdan): Unfortunately, printing to - // stdout crashes the js/wasm port. Use the - // prints once the issue is fixed: - // https://github.com/golang/go/issues/35256 - break - } switch notify { case notifyInvalidate: notify = notifyPrint