From 08f5c42639275f7070c371f0bbdaf57f088bef91 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 18 Jul 2014 22:30:07 -0400 Subject: [PATCH] Added a test case for Window.Close(). --- redo/zz_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/redo/zz_test.go b/redo/zz_test.go index c916252..8b87312 100644 --- a/redo/zz_test.go +++ b/redo/zz_test.go @@ -5,23 +5,39 @@ package ui // This file is called zz_test.go to keep it separate from the other files in this package (and because go test won't accept just test.go) import ( + "flag" "testing" ) +var closeOnClick = flag.Bool("close", false, "close on click") + // because Cocoa hates being run off the main thread, even if it's run exclusively off the main thread func init() { + flag.Parse() go func() { w := GetNewWindow(Do, "Hello", 320, 240) b := GetNewButton(Do, "There") Wait(Do, w.SetControl(b)) + if *closeOnClick { + Wait(Do, b.SetText("Click to Close")) + } done := make(chan struct{}) Wait(Do, w.OnClosing(func(c Doer) bool { + if *closeOnClick { + panic("window closed normally in close on click mode (should not happen)") + } + println("window close event received") Stop() done <- struct{}{} return true })) Wait(Do, b.OnClicked(func(c Doer) { println("in OnClicked()") + if *closeOnClick { + Wait(c, w.Close()) + Stop() + done <- struct{}{} + } })) Wait(Do, w.Show()) <-done