diff --git a/container/innerwindow_test.go b/container/innerwindow_test.go index 463844f2fa..55d1436ded 100644 --- a/container/innerwindow_test.go +++ b/container/innerwindow_test.go @@ -14,7 +14,7 @@ import ( func TestInnerWindow_Close(t *testing.T) { w := NewInnerWindow("Thing", widget.NewLabel("Content")) - outer := test.NewWindow(w) + outer := test.NewTempWindow(t, w) outer.SetPadded(false) outer.Resize(w.MinSize()) assert.True(t, w.Visible()) diff --git a/container/tabs_test.go b/container/tabs_test.go index 87647193c8..1c3b93caf6 100644 --- a/container/tabs_test.go +++ b/container/tabs_test.go @@ -32,7 +32,7 @@ func TestTab_ThemeChange(t *testing.T) { tabs := NewAppTabs( NewTabItem("a", widget.NewLabel("a")), NewTabItem("b", widget.NewLabel("b"))) - w := test.NewWindow(tabs) + w := test.NewTempWindow(t, tabs) w.Resize(fyne.NewSize(180, 120)) initial := w.Canvas().Capture() diff --git a/dialog/color_button_test.go b/dialog/color_button_test.go index bb7e240922..356421440f 100644 --- a/dialog/color_button_test.go +++ b/dialog/color_button_test.go @@ -32,12 +32,10 @@ func Test_colorButton_Layout(t *testing.T) { color.MouseIn(nil) } - window := test.NewWindow(container.NewCenter(color)) + window := test.NewTempWindow(t, container.NewCenter(color)) window.Resize(color.MinSize().Max(fyne.NewSize(50, 50))) test.AssertRendersToImage(t, "color/button_layout_"+name+".png", window.Canvas()) - - window.Close() }) } } diff --git a/dialog/color_channel_test.go b/dialog/color_channel_test.go index 053d871e48..19c92bf9c1 100644 --- a/dialog/color_channel_test.go +++ b/dialog/color_channel_test.go @@ -35,11 +35,9 @@ func Test_colorChannel_Layout(t *testing.T) { color := newColorChannel(tt.name, min, max, tt.value, nil) color.Resize(size) - window := test.NewWindow(color) + window := test.NewTempWindow(t, color) test.AssertRendersToImage(t, "color/channel_layout_"+name+".png", window.Canvas()) - - window.Close() }) } } diff --git a/dialog/color_picker_test.go b/dialog/color_picker_test.go index f475f1ad15..6d87b9e7e1 100644 --- a/dialog/color_picker_test.go +++ b/dialog/color_picker_test.go @@ -14,12 +14,10 @@ func Test_colorGreyscalePicker_Layout(t *testing.T) { color := newColorGreyscalePicker(nil) - window := test.NewWindow(container.NewCenter(color)) + window := test.NewTempWindow(t, container.NewCenter(color)) window.Resize(color.MinSize().Max(fyne.NewSize(360, 60))) test.AssertRendersToImage(t, "color/picker_layout_greyscale.png", window.Canvas()) - - window.Close() } func Test_colorBasicPicker_Layout(t *testing.T) { @@ -27,12 +25,10 @@ func Test_colorBasicPicker_Layout(t *testing.T) { color := newColorBasicPicker(nil) - window := test.NewWindow(container.NewCenter(color)) + window := test.NewTempWindow(t, container.NewCenter(color)) window.Resize(color.MinSize().Max(fyne.NewSize(360, 60))) test.AssertRendersToImage(t, "color/picker_layout_basic.png", window.Canvas()) - - window.Close() } func Test_colorRecentPicker_Layout(t *testing.T) { @@ -43,12 +39,10 @@ func Test_colorRecentPicker_Layout(t *testing.T) { color := newColorRecentPicker(nil) - window := test.NewWindow(container.NewCenter(color)) + window := test.NewTempWindow(t, container.NewCenter(color)) window.Resize(color.MinSize().Max(fyne.NewSize(360, 60))) test.AssertRendersToImage(t, "color/picker_layout_recent.png", window.Canvas()) - - window.Close() } func Test_colorAdvancedPicker_Layout(t *testing.T) { @@ -58,10 +52,8 @@ func Test_colorAdvancedPicker_Layout(t *testing.T) { color.Refresh() - window := test.NewWindow(container.NewCenter(color)) + window := test.NewTempWindow(t, container.NewCenter(color)) window.Resize(color.MinSize().Max(fyne.NewSize(200, 200))) test.AssertRendersToImage(t, "color/picker_layout_advanced.png", window.Canvas()) - - window.Close() } diff --git a/dialog/color_preview_test.go b/dialog/color_preview_test.go index a9bb5a13d4..dfcdde4987 100644 --- a/dialog/color_preview_test.go +++ b/dialog/color_preview_test.go @@ -14,11 +14,9 @@ func Test_colorPreview_Color(t *testing.T) { preview := newColorPreview(color.RGBA{53, 113, 233, 255}) preview.SetColor(color.RGBA{90, 206, 80, 180}) - window := test.NewWindow(preview) + window := test.NewTempWindow(t, preview) padding := theme.Padding() * 2 window.Resize(fyne.NewSize(128+padding, 64+padding)) test.AssertRendersToImage(t, "color/preview_color.png", window.Canvas()) - - window.Close() } diff --git a/dialog/color_test.go b/dialog/color_test.go index 820aba89a0..b60eed07a5 100644 --- a/dialog/color_test.go +++ b/dialog/color_test.go @@ -15,7 +15,7 @@ import ( func TestColorDialog_Theme(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(1000, 800)) d := NewColorPicker("Color Picker", "Pick a Color", nil, w) @@ -35,8 +35,6 @@ func TestColorDialog_Theme(t *testing.T) { test.ApplyTheme(t, test.NewTheme()) test.AssertRendersToImage(t, "color/dialog_expanded_theme_ugly.png", w.Canvas()) - - w.Close() } func TestColorDialog_Recents(t *testing.T) { @@ -44,7 +42,7 @@ func TestColorDialog_Recents(t *testing.T) { // Inject recent preferences a.Preferences().SetString("color_recents", "#2196f3,#4caf50,#f44336") - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(800, 600)) d := NewColorPicker("Color Picker", "Pick a Color", nil, w) @@ -56,13 +54,11 @@ func TestColorDialog_Recents(t *testing.T) { test.ApplyTheme(t, test.NewTheme()) test.AssertRendersToImage(t, "color/dialog_recents_theme_ugly.png", w.Canvas()) - - w.Close() } func TestColorDialog_SetColor(t *testing.T) { - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(800, 600)) col := color.RGBA{70, 210, 200, 255} @@ -95,13 +91,12 @@ func TestColorDialog_SetColor(t *testing.T) { assert.Equal(t, 244, d.picker.Alpha) d.Show() - w.Close() } func TestColorDialogSimple_Theme(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(600, 400)) d := NewColorPicker("Color Picker", "Pick a Color", nil, w) @@ -111,8 +106,6 @@ func TestColorDialogSimple_Theme(t *testing.T) { test.ApplyTheme(t, test.NewTheme()) test.AssertRendersToImage(t, "color/dialog_simple_theme_ugly.png", w.Canvas()) - - w.Close() } func TestColorDialogSimple_Recents(t *testing.T) { @@ -121,7 +114,7 @@ func TestColorDialogSimple_Recents(t *testing.T) { // Inject recent preferences a.Preferences().SetString("color_recents", "#2196f3,#4caf50,#f44336") - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(600, 400)) d := NewColorPicker("Color Picker", "Pick a Color", nil, w) @@ -131,8 +124,6 @@ func TestColorDialogSimple_Recents(t *testing.T) { test.ApplyTheme(t, test.NewTheme()) test.AssertRendersToImage(t, "color/dialog_simple_recents_theme_ugly.png", w.Canvas()) - - w.Close() } func Test_recent_color(t *testing.T) { diff --git a/dialog/color_wheel_test.go b/dialog/color_wheel_test.go index 481c096d1c..b11503a160 100644 --- a/dialog/color_wheel_test.go +++ b/dialog/color_wheel_test.go @@ -12,11 +12,9 @@ func Test_colorWheel_Layout(t *testing.T) { wheel := newColorWheel(nil) wheel.SetHSLA(180, 100, 50, 255) - window := test.NewWindow(wheel) + window := test.NewTempWindow(t, wheel) window.Resize(wheel.MinSize().Max(fyne.NewSize(100, 100))) test.AssertRendersToImage(t, "color/wheel_layout.png", window.Canvas()) test.AssertRendersToMarkup(t, "color/wheel_layout.xml", window.Canvas()) - - window.Close() } diff --git a/dialog/confirm_test.go b/dialog/confirm_test.go index 45a32fb745..43079d650e 100644 --- a/dialog/confirm_test.go +++ b/dialog/confirm_test.go @@ -17,7 +17,7 @@ func TestDialog_ConfirmDoubleCallback(t *testing.T) { ch := make(chan int) cnf := NewConfirm("Test", "Test", func(_ bool) { ch <- 42 - }, test.NewWindow(nil)) + }, test.NewTempWindow(t, nil)) cnf.SetDismissText("No") cnf.SetConfirmText("Yes") cnf.SetOnClosed(func() { @@ -34,7 +34,7 @@ func TestDialog_ConfirmDoubleCallback(t *testing.T) { func TestDialog_ConfirmCallbackOnlyOnClosed(t *testing.T) { ch := make(chan int) - cnf := NewConfirm("Test", "Test", nil, test.NewWindow(nil)) + cnf := NewConfirm("Test", "Test", nil, test.NewTempWindow(t, nil)) cnf.SetDismissText("No") cnf.SetConfirmText("Yes") cnf.SetOnClosed(func() { @@ -52,7 +52,7 @@ func TestDialog_ConfirmCallbackOnlyOnConfirm(t *testing.T) { ch := make(chan int) cnf := NewConfirm("Test", "Test", func(_ bool) { ch <- 42 - }, test.NewWindow(nil)) + }, test.NewTempWindow(t, nil)) cnf.SetDismissText("No") cnf.SetConfirmText("Yes") cnf.Show() @@ -65,8 +65,8 @@ func TestDialog_ConfirmCallbackOnlyOnConfirm(t *testing.T) { func TestConfirmDialog_Resize(t *testing.T) { window := test.NewWindow(nil) - window.Resize(fyne.NewSize(600, 400)) defer window.Close() + window.Resize(fyne.NewSize(600, 400)) d := NewConfirm("Test", "Test", nil, window) theDialog := d.dialog @@ -108,7 +108,7 @@ func TestConfirmDialog_Resize(t *testing.T) { func TestConfirm_Importance(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) diff --git a/dialog/custom_test.go b/dialog/custom_test.go index 51069e0890..c82da1285d 100644 --- a/dialog/custom_test.go +++ b/dialog/custom_test.go @@ -16,7 +16,7 @@ import ( func TestShowCustom_ApplyTheme(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) label := widget.NewLabel("Content") label.Alignment = fyne.TextAlignCenter @@ -35,7 +35,7 @@ func TestShowCustom_ApplyTheme(t *testing.T) { } func TestShowCustom_Resize(t *testing.T) { - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(300, 300)) label := widget.NewLabel("Content") @@ -50,7 +50,7 @@ func TestShowCustom_Resize(t *testing.T) { func TestCustom_ApplyThemeOnShow(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 300)) label := widget.NewLabel("Content") @@ -75,7 +75,7 @@ func TestCustom_ApplyThemeOnShow(t *testing.T) { func TestCustom_ResizeOnShow(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -96,7 +96,7 @@ func TestCustom_ResizeOnShow(t *testing.T) { func TestConfirm_SetButtons(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -118,7 +118,7 @@ func TestConfirm_SetButtons(t *testing.T) { func TestConfirmWithoutButtons(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -130,7 +130,7 @@ func TestConfirmWithoutButtons(t *testing.T) { func TestCustomConfirm_Importance(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) diff --git a/dialog/entry_test.go b/dialog/entry_test.go index 329ddb3977..d53e80fcdf 100644 --- a/dialog/entry_test.go +++ b/dialog/entry_test.go @@ -11,7 +11,7 @@ func TestEntryDialog_Confirm(t *testing.T) { value := "" ed := NewEntryDialog("Test", "message", func(v string) { value = v - }, test.NewWindow(nil)) + }, test.NewTempWindow(t, nil)) ed.Show() test.Type(ed.entry, "123") test.Tap(ed.confirm) @@ -23,7 +23,7 @@ func TestEntryDialog_Dismiss(t *testing.T) { value := "123" ed := NewEntryDialog("Test", "message", func(v string) { value = v - }, test.NewWindow(nil)) + }, test.NewTempWindow(t, nil)) ed.Show() test.Type(ed.entry, "XYZ") test.Tap(ed.cancel) diff --git a/dialog/file_test.go b/dialog/file_test.go index a81e329f39..36954edf87 100644 --- a/dialog/file_test.go +++ b/dialog/file_test.go @@ -108,7 +108,7 @@ func TestEffectiveStartingDir(t *testing.T) { } func TestFileDialogResize(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) win.Resize(fyne.NewSize(600, 400)) file := NewFileOpen(func(file fyne.URIReadCloser, err error) {}, win) file.SetFilter(storage.NewExtensionFileFilter([]string{".png"})) @@ -161,7 +161,7 @@ func TestFileDialogResize(t *testing.T) { func TestShowFileOpen(t *testing.T) { var chosen fyne.URIReadCloser var openErr error - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) d := NewFileOpen(func(file fyne.URIReadCloser, err error) { chosen = file openErr = err @@ -260,7 +260,7 @@ func TestHiddenFiles(t *testing.T) { t.Error("Failed to hide .hidden", err) } - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) d := NewFileOpen(func(file fyne.URIReadCloser, err error) { }, win) d.SetLocation(dir) @@ -310,7 +310,7 @@ func TestHiddenFiles(t *testing.T) { func TestShowFileSave(t *testing.T) { var chosen fyne.URIWriteCloser var saveErr error - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) saver := NewFileSave(func(file fyne.URIWriteCloser, err error) { chosen = file saveErr = err @@ -386,7 +386,7 @@ func TestShowFileSave(t *testing.T) { } func TestFileFilters(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) f := NewFileOpen(func(file fyne.URIReadCloser, err error) { }, win) @@ -449,7 +449,7 @@ func TestFileFilters(t *testing.T) { } func TestView(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { assert.Nil(t, err) @@ -506,7 +506,7 @@ func TestView(t *testing.T) { } func TestSetView(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) fyne.CurrentApp().Preferences().SetInt(viewLayoutKey, int(defaultView)) @@ -556,7 +556,7 @@ func TestSetView(t *testing.T) { } func TestSetViewPreferences(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) prefs := fyne.CurrentApp().Preferences() @@ -590,7 +590,7 @@ func TestSetViewPreferences(t *testing.T) { } func TestViewPreferences(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) prefs := fyne.CurrentApp().Preferences() @@ -631,7 +631,7 @@ func TestViewPreferences(t *testing.T) { } func TestFileFavorites(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) dlg := NewFileOpen(func(reader fyne.URIReadCloser, err error) { assert.Nil(t, err) @@ -676,7 +676,7 @@ func TestFileFavorites(t *testing.T) { } func TestSetFileNameBeforeShow(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) dSave := NewFileSave(func(fyne.URIWriteCloser, error) {}, win) dSave.SetFileName("testfile.zip") dSave.Show() @@ -694,7 +694,7 @@ func TestSetFileNameBeforeShow(t *testing.T) { func TestSetFileNameAfterShow(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) dSave := NewFileSave(func(fyne.URIWriteCloser, error) {}, win) dSave.Show() dSave.SetFileName("testfile.zip") @@ -711,7 +711,7 @@ func TestSetFileNameAfterShow(t *testing.T) { } func TestCreateNewFolderInDir(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) folderDialog := NewFolderOpen(func(lu fyne.ListableURI, err error) { assert.Nil(t, err) @@ -757,7 +757,7 @@ func TestCreateNewFolderInDir(t *testing.T) { } func TestSetOnClosedBeforeShow(t *testing.T) { - win := test.NewWindow(widget.NewLabel("Content")) + win := test.NewTempWindow(t, widget.NewLabel("Content")) d := NewFileSave(func(fyne.URIWriteCloser, error) {}, win) onClosedCalled := false d.SetOnClosed(func() { onClosedCalled = true }) diff --git a/dialog/folder_test.go b/dialog/folder_test.go index 08c4a4b0a8..7cbec1374e 100644 --- a/dialog/folder_test.go +++ b/dialog/folder_test.go @@ -16,7 +16,7 @@ import ( func TestShowFolderOpen(t *testing.T) { var chosen fyne.ListableURI var openErr error - win := test.NewWindow(widget.NewLabel("OpenDir")) + win := test.NewTempWindow(t, widget.NewLabel("OpenDir")) d := NewFolderOpen(func(file fyne.ListableURI, err error) { chosen = file openErr = err diff --git a/dialog/form_test.go b/dialog/form_test.go index 69f17f37f2..a908663941 100644 --- a/dialog/form_test.go +++ b/dialog/form_test.go @@ -25,7 +25,7 @@ const ( func TestFormDialog_Control(t *testing.T) { var result formDialogResult - fd := controlFormDialog(&result, test.NewWindow(nil)) + fd := controlFormDialog(&result, test.NewTempWindow(t, nil)) fd.Show() test.Tap(fd.confirm) @@ -34,7 +34,7 @@ func TestFormDialog_Control(t *testing.T) { func TestFormDialog_InvalidCannotSubmit(t *testing.T) { var result formDialogResult - fd := validatingFormDialog(&result, test.NewWindow(nil)) + fd := validatingFormDialog(&result, test.NewTempWindow(t, nil)) fd.Show() assert.False(t, fd.win.Hidden) @@ -46,7 +46,7 @@ func TestFormDialog_InvalidCannotSubmit(t *testing.T) { func TestFormDialog_ValidCanSubmit(t *testing.T) { var result formDialogResult - fd := validatingFormDialog(&result, test.NewWindow(nil)) + fd := validatingFormDialog(&result, test.NewTempWindow(t, nil)) fd.Show() assert.False(t, fd.win.Hidden) @@ -65,7 +65,7 @@ func TestFormDialog_ValidCanSubmit(t *testing.T) { func TestFormDialog_CanCancelInvalid(t *testing.T) { var result formDialogResult - fd := validatingFormDialog(&result, test.NewWindow(nil)) + fd := validatingFormDialog(&result, test.NewTempWindow(t, nil)) fd.Show() assert.False(t, fd.win.Hidden) @@ -76,7 +76,7 @@ func TestFormDialog_CanCancelInvalid(t *testing.T) { func TestFormDialog_CanCancelNoValidation(t *testing.T) { var result formDialogResult - fd := controlFormDialog(&result, test.NewWindow(nil)) + fd := controlFormDialog(&result, test.NewTempWindow(t, nil)) fd.Show() assert.False(t, fd.win.Hidden) @@ -89,7 +89,7 @@ func TestFormDialog_Hints(t *testing.T) { test.NewTempApp(t) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) - w := test.NewWindow(nil) + w := test.NewTempWindow(t, nil) w.SetFullScreen(true) var result formDialogResult @@ -135,7 +135,7 @@ func TestFormDialog_Submit(t *testing.T) { items := []*widget.FormItem{validatingItem} form := NewForm("Validating Form Dialog", "Submit", "Cancel", items, func(confirm bool) { confirmed = confirm - }, test.NewWindow(nil)) + }, test.NewTempWindow(t, nil)) form.Show() validatingEntry.SetText("cba") diff --git a/dialog/information_test.go b/dialog/information_test.go index c1fc2c4c76..285e4c187b 100644 --- a/dialog/information_test.go +++ b/dialog/information_test.go @@ -65,7 +65,7 @@ func TestDialog_Resize(t *testing.T) { } func TestDialog_TextWrapping(t *testing.T) { - window := test.NewWindow(nil) + window := test.NewTempWindow(t, nil) window.Resize(fyne.NewSize(600, 400)) d := NewInformation("Title", "This is a really really long message that will be used to test the dialog text wrapping capabilities", window) @@ -84,7 +84,7 @@ func TestDialog_TextWrapping(t *testing.T) { } func TestDialog_InformationCallback(t *testing.T) { - d := NewInformation("Information", "Hello World", test.NewWindow(nil)) + d := NewInformation("Information", "Hello World", test.NewTempWindow(t, nil)) tapped := false d.SetOnClosed(func() { tapped = true }) d.Show() @@ -98,7 +98,7 @@ func TestDialog_InformationCallback(t *testing.T) { func TestDialog_ErrorCallback(t *testing.T) { err := errors.New("Error message") - d := NewError(err, test.NewWindow(nil)) + d := NewError(err, test.NewTempWindow(t, nil)) tapped := false d.SetOnClosed(func() { tapped = true }) d.Show() diff --git a/internal/app/theme_test.go b/internal/app/theme_test.go index a628fbe3a9..4109be02de 100644 --- a/internal/app/theme_test.go +++ b/internal/app/theme_test.go @@ -9,7 +9,8 @@ import ( func TestApplySettings_BeforeContentSet(t *testing.T) { a := test.NewApp() - _ = a.NewWindow("NoContent") + w := a.NewWindow("NoContent") + defer w.Close() app.ApplySettings(a.Settings(), a) } diff --git a/internal/widget/simple_renderer_test.go b/internal/widget/simple_renderer_test.go index 6445ea097f..d738af19c0 100644 --- a/internal/widget/simple_renderer_test.go +++ b/internal/widget/simple_renderer_test.go @@ -14,7 +14,7 @@ func TestNewSimpleRenderer(t *testing.T) { r := canvas.NewRectangle(color.Transparent) o := &simpleWidget{obj: r} o.ExtendBaseWidget(o) - w := test.NewWindow(o) + w := test.NewTempWindow(t, o) w.Resize(fyne.NewSize(100, 100)) test.AssertRendersToMarkup(t, "simple_renderer.xml", w.Canvas()) diff --git a/test/window.go b/test/window.go index 17bba3b92c..36b17dc7e1 100644 --- a/test/window.go +++ b/test/window.go @@ -1,6 +1,8 @@ package test import ( + "testing" + "fyne.io/fyne/v2" ) @@ -18,6 +20,16 @@ type window struct { menu *fyne.MainMenu } +// NewTempWindow creates and registers a new window for test purposes. +// This window will get removed automatically once the running test ends. +// +// Since: 2.5 +func NewTempWindow(t testing.TB, content fyne.CanvasObject) fyne.Window { + window := NewWindow(content) + t.Cleanup(window.Close) + return window +} + // NewWindow creates and registers a new window for test purposes func NewWindow(content fyne.CanvasObject) fyne.Window { window := fyne.CurrentApp().NewWindow("") diff --git a/widget/accordion_test.go b/widget/accordion_test.go index fee7cec1aa..5e90560df9 100644 --- a/widget/accordion_test.go +++ b/widget/accordion_test.go @@ -206,12 +206,10 @@ func TestAccordion_Layout(t *testing.T) { accordion.Open(o) } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{accordion}}) + window := test.NewTempWindow(t, &fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{accordion}}) window.Resize(accordion.MinSize().Add(fyne.NewSquareSize(theme.Padding() * 2))) test.AssertRendersToMarkup(t, "accordion/layout_"+name+".xml", window.Canvas()) - - window.Close() }) } } @@ -324,12 +322,10 @@ func TestAccordion_Layout_Expanded(t *testing.T) { accordion.Open(o) } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{accordion}}) + window := test.NewTempWindow(t, &fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{accordion}}) window.Resize(accordion.MinSize().Max(fyne.NewSize(150, 280))) test.AssertRendersToMarkup(t, "accordion/layout_"+name+".xml", window.Canvas()) - - window.Close() }) } } diff --git a/widget/activity_internal_test.go b/widget/activity_internal_test.go index 23582d3d09..2d87e3da18 100644 --- a/widget/activity_internal_test.go +++ b/widget/activity_internal_test.go @@ -12,8 +12,8 @@ func TestActivity_Animation(t *testing.T) { a := NewActivity() w := test.NewWindow(a) - w.SetPadded(false) defer w.Close() + w.SetPadded(false) w.Resize(a.MinSize()) render := test.TempWidgetRenderer(t, a).(*activityRenderer) diff --git a/widget/card_test.go b/widget/card_test.go index 2e914e165d..f527813a6e 100644 --- a/widget/card_test.go +++ b/widget/card_test.go @@ -104,15 +104,13 @@ func TestCard_Layout(t *testing.T) { Content: tt.content, } - window := test.NewWindow(card) + window := test.NewTempWindow(t, card) size := card.MinSize().Max(fyne.NewSize(80, 0)) // give a little width for image only tests window.Resize(size.Add(fyne.NewSize(theme.InnerPadding(), theme.InnerPadding()))) if tt.content != nil { assert.Equal(t, float32(10), tt.content.Size().Height) } test.AssertRendersToMarkup(t, "card/layout_"+name+".xml", window.Canvas()) - - window.Close() }) } } @@ -128,7 +126,7 @@ func TestCard_MinSize(t *testing.T) { func TestCard_Refresh(t *testing.T) { text := widget.NewLabel("Test") card := widget.NewCard("", "", text) - w := test.NewWindow(card) + w := test.NewTempWindow(t, card) test.AssertRendersToMarkup(t, "card/content_label.xml", w.Canvas()) text.Text = "Changed" diff --git a/widget/check_group_test.go b/widget/check_group_test.go index 8605ccb806..584fde8572 100644 --- a/widget/check_group_test.go +++ b/widget/check_group_test.go @@ -154,12 +154,10 @@ func TestCheckGroup_Layout(t *testing.T) { check.Disable() } - window := test.NewWindow(check) + window := test.NewTempWindow(t, check) window.Resize(check.MinSize().Max(fyne.NewSize(150, 200))) test.AssertRendersToMarkup(t, "check_group/layout_"+name+".xml", window.Canvas()) - - window.Close() }) } } diff --git a/widget/check_test.go b/widget/check_test.go index 38351fb688..8ab9ce9b8c 100644 --- a/widget/check_test.go +++ b/widget/check_test.go @@ -71,12 +71,10 @@ func TestCheck_Layout(t *testing.T) { check.Disable() } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{check}}) + window := test.NewTempWindow(t, &fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{check}}) window.Resize(check.MinSize().Max(fyne.NewSize(150, 200))) test.AssertRendersToMarkup(t, "check/layout_"+name+".xml", window.Canvas()) - - window.Close() }) } } diff --git a/widget/entry_internal_test.go b/widget/entry_internal_test.go index 57313ca48f..8af9f2f617 100644 --- a/widget/entry_internal_test.go +++ b/widget/entry_internal_test.go @@ -346,6 +346,7 @@ func TestEntry_PasteFromClipboard(t *testing.T) { entry := NewEntry() w := test.NewApp().NewWindow("") + defer w.Close() w.SetContent(entry) testContent := "test" @@ -363,6 +364,7 @@ func TestEntry_PasteFromClipboard_MultilineWrapping(t *testing.T) { entry.Wrapping = fyne.TextWrapWord w := test.NewApp().NewWindow("") + defer w.Close() w.SetContent(entry) w.Resize(fyne.NewSize(108, 64)) @@ -391,7 +393,7 @@ func TestEntry_PlaceholderTextStyle(t *testing.T) { e := NewEntry() e.TextStyle = fyne.TextStyle{Bold: true, Italic: true} - w := test.NewWindow(e) + w := test.NewTempWindow(t, e) assert.Equal(t, e.TextStyle, e.placeholder.Segments[0].(*TextSegment).Style.TextStyle) w.Canvas().Focus(e) @@ -409,7 +411,7 @@ func TestEntry_Tab(t *testing.T) { assert.Equal(t, "a", r.Objects()[0].(*canvas.Text).Text) assert.Equal(t, "\tb", r.Objects()[1].(*canvas.Text).Text) - w := test.NewWindow(e) + w := test.NewTempWindow(t, e) w.Resize(fyne.NewSize(86, 86)) w.Canvas().Focus(e) test.AssertImageMatches(t, "entry/tab-content.png", w.Canvas().Capture()) @@ -428,7 +430,7 @@ func TestEntry_TabSelection(t *testing.T) { assert.Equal(t, "\tb", e.SelectedText()) - w := test.NewWindow(e) + w := test.NewTempWindow(t, e) w.Resize(fyne.NewSize(86, 86)) w.Canvas().Focus(e) test.AssertImageMatches(t, "entry/tab-select.png", w.Canvas().Capture()) diff --git a/widget/entry_password_extend_test.go b/widget/entry_password_extend_test.go index 558a4ddbb8..48227dd719 100644 --- a/widget/entry_password_extend_test.go +++ b/widget/entry_password_extend_test.go @@ -17,6 +17,7 @@ type extendEntry struct { func TestEntry_Password_Extended_CreateRenderer(t *testing.T) { a := test.NewTempApp(t) w := a.NewWindow("") + defer w.Close() entry := &extendEntry{} entry.ExtendBaseWidget(entry) entry.Password = true diff --git a/widget/entry_test.go b/widget/entry_test.go index 7cc0c9773b..241b7cc539 100644 --- a/widget/entry_test.go +++ b/widget/entry_test.go @@ -78,7 +78,6 @@ func TestEntry_Binding_Replace(t *testing.T) { func TestEntry_Clicked(t *testing.T) { entry, window := setupImageTest(t, true) - defer teardownImageTest(window) c := window.Canvas() entry.SetText("MMM\nWWW\n") @@ -284,7 +283,7 @@ func TestEntry_CursorColumn_Wrap2(t *testing.T) { entry.SetText("1234") entry.CursorColumn = 3 - w := test.NewWindow(entry) + w := test.NewTempWindow(t, entry) w.Resize(fyne.NewSize(72, 64)) test.Type(entry, "a") @@ -334,7 +333,6 @@ func TestEntry_CursorRow(t *testing.T) { func TestEntry_Disableable(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() assert.False(t, entry.Disabled()) @@ -375,7 +373,6 @@ func TestEntry_Disableable(t *testing.T) { func TestEntry_Disabled_TextSelection(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) entry.SetText("Testing") entry.Disable() c := window.Canvas() @@ -418,7 +415,6 @@ func TestEntry_EmptySelection(t *testing.T) { func TestEntry_Focus(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() entry.FocusGained() @@ -433,7 +429,6 @@ func TestEntry_Focus(t *testing.T) { func TestEntry_FocusWithPopUp(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() test.TapSecondaryAt(entry, fyne.NewPos(1, 1)) @@ -530,7 +525,6 @@ func TestEntryMultiline_SetMinRowsVisible(t *testing.T) { func TestEntry_MultilineSelect(t *testing.T) { e, window := setupSelection(t, false) - defer teardownImageTest(window) c := window.Canvas() // Extend the selection down one row @@ -849,7 +843,6 @@ func TestEntry_OnKeyDown_Insert(t *testing.T) { func TestEntry_OnKeyDown_Newline(t *testing.T) { entry, window := setupImageTest(t, true) - defer teardownImageTest(window) c := window.Canvas() entry.SetText("Hi") @@ -956,7 +949,6 @@ func TestEntry_OnPaste(t *testing.T) { func TestEntry_PageUpDown(t *testing.T) { t.Run("single line", func(*testing.T) { e, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() c.Focus(e) @@ -987,7 +979,6 @@ func TestEntry_PageUpDown(t *testing.T) { t.Run("page down single line", func(*testing.T) { e, window := setupImageTest(t, true) - defer teardownImageTest(window) c := window.Canvas() c.Focus(e) @@ -1053,8 +1044,8 @@ func TestEntry_Placeholder(t *testing.T) { entry.Text = "Text" entry.PlaceHolder = "Placehold" - window := test.NewWindow(entry) - defer teardownImageTest(window) + window := test.NewTempWindow(t, entry) + defer test.NewApp() c := window.Canvas() assert.Equal(t, "Text", entry.Text) @@ -1207,7 +1198,6 @@ func TestEntry_Select(t *testing.T) { } { t.Run(name, func(t *testing.T) { entry, window := setupSelection(t, tt.setupReverse) - defer teardownImageTest(window) c := window.Canvas() if tt.text != "" { @@ -1224,7 +1214,6 @@ func TestEntry_Select(t *testing.T) { func TestEntry_SelectAll(t *testing.T) { e, window := setupImageTest(t, true) - defer teardownImageTest(window) c := window.Canvas() c.Focus(e) @@ -1247,7 +1236,6 @@ func TestEntry_SelectAll_EmptyEntry(t *testing.T) { func TestEntry_SelectEndWithoutShift(t *testing.T) { e, window := setupSelection(t, false) - defer teardownImageTest(window) c := window.Canvas() // end after releasing shift @@ -1258,7 +1246,6 @@ func TestEntry_SelectEndWithoutShift(t *testing.T) { func TestEntry_SelectHomeEnd(t *testing.T) { e, window := setupSelection(t, false) - defer teardownImageTest(window) c := window.Canvas() // Hold shift to continue selection @@ -1277,7 +1264,6 @@ func TestEntry_SelectHomeEnd(t *testing.T) { func TestEntry_SelectHomeWithoutShift(t *testing.T) { e, window := setupSelection(t, false) - defer teardownImageTest(window) c := window.Canvas() // home after releasing shift @@ -1289,7 +1275,6 @@ func TestEntry_SelectHomeWithoutShift(t *testing.T) { func TestEntry_SelectSnapDown(t *testing.T) { // down snaps to end, but it also moves e, window := setupSelection(t, false) - defer teardownImageTest(window) c := window.Canvas() assert.Equal(t, 1, e.CursorRow) @@ -1304,7 +1289,6 @@ func TestEntry_SelectSnapDown(t *testing.T) { func TestEntry_SelectSnapLeft(t *testing.T) { e, window := setupSelection(t, false) - defer teardownImageTest(window) c := window.Canvas() assert.Equal(t, 1, e.CursorRow) @@ -1319,7 +1303,6 @@ func TestEntry_SelectSnapLeft(t *testing.T) { func TestEntry_SelectSnapRight(t *testing.T) { e, window := setupSelection(t, false) - defer teardownImageTest(window) c := window.Canvas() assert.Equal(t, 1, e.CursorRow) @@ -1335,7 +1318,6 @@ func TestEntry_SelectSnapRight(t *testing.T) { func TestEntry_SelectSnapUp(t *testing.T) { // up snaps to start, but it also moves e, window := setupSelection(t, false) - defer teardownImageTest(window) c := window.Canvas() assert.Equal(t, 1, e.CursorRow) @@ -1361,7 +1343,6 @@ func TestEntry_Select_TripleTap(t *testing.T) { func TestEntry_SelectedText(t *testing.T) { e, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() c.Focus(e) @@ -1394,7 +1375,6 @@ func TestEntry_SelectedText(t *testing.T) { func TestEntry_SelectionHides(t *testing.T) { e, window := setupSelection(t, false) - defer teardownImageTest(window) c := window.Canvas() c.Unfocus() @@ -1408,7 +1388,6 @@ func TestEntry_SelectionHides(t *testing.T) { func TestEntry_SetPlaceHolder(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() assert.Equal(t, 0, len(entry.Text)) @@ -1424,7 +1403,6 @@ func TestEntry_SetPlaceHolder(t *testing.T) { func TestEntry_SetPlaceHolder_ByField(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() assert.Equal(t, 0, len(entry.Text)) @@ -1454,7 +1432,6 @@ func TestEntry_Disable_KeyDown(t *testing.T) { func TestEntry_Disable_OnFocus(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() entry.Disable() @@ -1491,7 +1468,6 @@ func TestEntry_SetText_EmptyString(t *testing.T) { func TestEntry_SetText_Manual(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() entry.Text = "Test" @@ -1557,7 +1533,6 @@ func TestEntry_SetText_Overflow_Multiline(t *testing.T) { func TestEntry_SetTextStyle(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() entry.Text = "Styled Text" @@ -1697,7 +1672,6 @@ func TestTabable(t *testing.T) { func TestEntry_TappedSecondary(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() tapPos := fyne.NewPos(20, 10) @@ -1778,7 +1752,6 @@ func TestEntry_TextWrap(t *testing.T) { } { t.Run(name, func(t *testing.T) { e, window := setupImageTest(t, tt.multiLine) - defer teardownImageTest(window) c := window.Canvas() c.Focus(e) @@ -1796,7 +1769,6 @@ func TestEntry_TextWrap(t *testing.T) { func TestEntry_TextWrap_Changed(t *testing.T) { e, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() c.Focus(e) @@ -1856,8 +1828,7 @@ func TestPasswordEntry_ActionItemSizeAndPlacement(t *testing.T) { } func TestPasswordEntry_Disabled(t *testing.T) { - entry, window := setupPasswordTest(t) - defer teardownImageTest(window) + entry, _ := setupPasswordTest(t) entry.Disable() test.Tap(entry.ActionItem.(fyne.Tappable)) @@ -1877,7 +1848,6 @@ func TestPasswordEntry_NewlineIgnored(t *testing.T) { func TestPasswordEntry_Obfuscation(t *testing.T) { entry, window := setupPasswordTest(t) - defer teardownImageTest(window) c := window.Canvas() test.Type(entry, "Hié™שרה") @@ -1887,7 +1857,6 @@ func TestPasswordEntry_Obfuscation(t *testing.T) { func TestPasswordEntry_Placeholder(t *testing.T) { entry, window := setupPasswordTest(t) - defer teardownImageTest(window) c := window.Canvas() test.AssertRendersToMarkup(t, "password_entry/initial.xml", window.Canvas()) @@ -2008,7 +1977,7 @@ func TestEntry_CarriageReturn(t *testing.T) { entry.Wrapping = fyne.TextWrapOff entry.Scroll = container.ScrollNone entry.SetText("\r\n\r") - w := test.NewWindow(entry) + w := test.NewTempWindow(t, entry) w.Resize(fyne.NewSize(64, 64)) test.AssertImageMatches(t, "entry/carriage_return_empty.png", w.Canvas().Capture()) entry.SetText("\rH\re\rl\rl\ro\r\n\rW\ro\rr\rl\rd\r!\r") @@ -2018,7 +1987,6 @@ func TestEntry_CarriageReturn(t *testing.T) { func TestEntry_UndoRedo(t *testing.T) { e, window := setupImageTest(t, true) window.Resize(fyne.NewSize(128, 128)) - defer teardownImageTest(window) c := window.Canvas() c.Focus(e) @@ -2108,6 +2076,7 @@ func checkNewlineIgnored(t *testing.T, entry *widget.Entry) { func setupImageTest(t *testing.T, multiLine bool) (*widget.Entry, fyne.Window) { test.NewApp() + t.Cleanup(func() { test.NewApp() }) var entry *widget.Entry if multiLine { @@ -2115,7 +2084,7 @@ func setupImageTest(t *testing.T, multiLine bool) (*widget.Entry, fyne.Window) { } else { entry = &widget.Entry{Wrapping: fyne.TextWrapOff, Scroll: container.ScrollNone} } - w := test.NewWindow(entry) + w := test.NewTempWindow(t, entry) w.Resize(fyne.NewSize(150, 200)) if multiLine { @@ -2136,9 +2105,10 @@ func setupImageTest(t *testing.T, multiLine bool) (*widget.Entry, fyne.Window) { func setupPasswordTest(t *testing.T) (*widget.Entry, fyne.Window) { test.NewApp() + t.Cleanup(func() { test.NewApp() }) entry := widget.NewPasswordEntry() - w := test.NewWindow(entry) + w := test.NewTempWindow(t, entry) w.Resize(fyne.NewSize(150, 100)) entry.Resize(entry.MinSize().Max(fyne.NewSize(130, 0))) @@ -2173,11 +2143,6 @@ func setupSelection(t *testing.T, reverse bool) (*widget.Entry, fyne.Window) { return e, window } -func teardownImageTest(w fyne.Window) { - w.Close() - test.NewApp() -} - func waitForBinding() { time.Sleep(time.Millisecond * 100) // data resolves on background thread } diff --git a/widget/entry_validation_test.go b/widget/entry_validation_test.go index 2d0642e221..08bb9d9ff8 100644 --- a/widget/entry_validation_test.go +++ b/widget/entry_validation_test.go @@ -17,7 +17,6 @@ var validator = validation.NewRegexp(`^\d{4}-\d{2}-\d{2}$`, "Input is not a vali func TestEntry_DisabledHideValidation(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() entry.Validator = validator @@ -29,7 +28,6 @@ func TestEntry_DisabledHideValidation(t *testing.T) { func TestEntry_ValidatedEntry(t *testing.T) { entry, window := setupImageTest(t, false) - defer teardownImageTest(window) c := window.Canvas() r := validation.NewRegexp(`^\d{4}-\d{2}-\d{2}`, "Input is not a valid date") @@ -72,8 +70,7 @@ func TestEntry_NotEmptyValidator(t *testing.T) { } return nil } - w := test.NewWindow(entry) - defer w.Close() + w := test.NewTempWindow(t, entry) test.AssertRendersToMarkup(t, "entry/validator_not_empty_initial.xml", w.Canvas()) @@ -89,7 +86,6 @@ func TestEntry_NotEmptyValidator(t *testing.T) { func TestEntry_SetValidationError(t *testing.T) { entry, window := setupImageTest(t, false) test.ApplyTheme(t, internalTest.LightTheme(theme.DefaultTheme())) - defer teardownImageTest(window) c := window.Canvas() entry.Validator = validator diff --git a/widget/fileicon_test.go b/widget/fileicon_test.go index 5397398e67..1a8e0bf73c 100644 --- a/widget/fileicon_test.go +++ b/widget/fileicon_test.go @@ -26,7 +26,7 @@ func TestFileIcon_NewFileIcon_Rendered(t *testing.T) { icon := widget.NewFileIcon(nil) - w := test.NewWindow(icon) + w := test.NewTempWindow(t, icon) w.Resize(fyne.NewSize(150, 150)) test.AssertImageMatches(t, "fileicon/fileicon_nil.png", w.Canvas().Capture()) @@ -58,8 +58,6 @@ func TestFileIcon_NewFileIcon_Rendered(t *testing.T) { w.SetContent(icon5) w.Resize(fyne.NewSize(150, 150)) test.AssertImageMatches(t, "fileicon/fileicon_folder.png", w.Canvas().Capture()) - - w.Close() } func TestFileIcon_Icon(t *testing.T) { diff --git a/widget/form_test.go b/widget/form_test.go index 08088431e1..2f401847c6 100644 --- a/widget/form_test.go +++ b/widget/form_test.go @@ -207,12 +207,12 @@ func TestForm_Validation(t *testing.T) { test.Type(entry2, "not-") entry1.SetText("incorrect") - w = test.NewWindow(form) + w = test.NewTempWindow(t, form) test.AssertImageMatches(t, "form/validation_invalid.png", w.Canvas().Capture()) entry1.SetText("15-true") - w = test.NewWindow(form) + w = test.NewTempWindow(t, form) test.AssertImageMatches(t, "form/validation_valid.png", w.Canvas().Capture()) } @@ -245,13 +245,13 @@ func TestForm_EntryValidation_FirstTypeValid(t *testing.T) { test.Type(entry2, "L") entry1.focused = false entry1.Refresh() - w = test.NewWindow(form) + w = test.NewTempWindow(t, form) test.AssertImageMatches(t, "form/validation_entry_first_type_valid.png", w.Canvas().Capture()) entry1.SetText("") entry2.SetText("") - w = test.NewWindow(form) + w = test.NewTempWindow(t, form) test.AssertImageMatches(t, "form/validation_entry_first_type_invalid.png", w.Canvas().Capture()) } diff --git a/widget/hyperlink_test.go b/widget/hyperlink_test.go index 33104f1495..90d5ce5e2e 100644 --- a/widget/hyperlink_test.go +++ b/widget/hyperlink_test.go @@ -78,8 +78,8 @@ func TestHyperlink_Focus(t *testing.T) { hyperlink := &Hyperlink{Text: "Test"} w := test.NewWindow(hyperlink) - w.SetPadded(false) defer w.Close() + w.SetPadded(false) w.Resize(hyperlink.MinSize()) test.AssertImageMatches(t, "hyperlink/initial.png", w.Canvas().Capture()) @@ -173,8 +173,8 @@ func TestHyperlink_ThemeOverride(t *testing.T) { bg := canvas.NewRectangle(color.Gray{Y: 0xc0}) w := test.NewWindow(&fyne.Container{Layout: layout.NewStackLayout(), Objects: []fyne.CanvasObject{bg, hyperlink}}) - w.SetPadded(false) defer w.Close() + w.SetPadded(false) w.Resize(hyperlink.MinSize()) light := w.Canvas().Capture() diff --git a/widget/icon_test.go b/widget/icon_test.go index 5d12ce3f14..53ee5daa32 100644 --- a/widget/icon_test.go +++ b/widget/icon_test.go @@ -26,12 +26,10 @@ func TestIcon_Layout(t *testing.T) { Resource: tt.resource, } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{icon}}) + window := test.NewTempWindow(t, &fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{icon}}) window.Resize(icon.MinSize().Max(fyne.NewSize(150, 200))) test.AssertRendersToMarkup(t, "icon/layout_"+name+".xml", window.Canvas()) - - window.Close() }) } } diff --git a/widget/list_test.go b/widget/list_test.go index 64751ad080..a4a1a0ee4b 100644 --- a/widget/list_test.go +++ b/widget/list_test.go @@ -126,7 +126,7 @@ func TestList_SetItemHeight(t *testing.T) { assert.Equal(t, fyne.NewSize(10, 10*5+(4*theme.Padding())+40), lay.MinSize()) list.Select(2) - w := test.NewWindow(list) + w := test.NewTempWindow(t, list) w.Resize(fyne.NewSize(200, 200)) test.AssertImageMatches(t, "list/list_item_height.png", w.Canvas().Capture()) } @@ -160,7 +160,7 @@ func TestList_OffsetChange(t *testing.T) { test.NewTempApp(t) list := createList(1000) - w := test.NewWindow(list) + w := test.NewTempWindow(t, list) w.Resize(fyne.NewSize(200, 400)) assert.Equal(t, float32(0), list.offsetY) @@ -402,7 +402,7 @@ func TestList_SmallList(t *testing.T) { item.(*fyne.Container).Objects[1].(*Label).SetText(data[id]) }, ) - w := test.NewWindow(list) + w := test.NewTempWindow(t, list) w.Resize(fyne.NewSize(200, 400)) visibleCount := len(list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children) @@ -452,7 +452,7 @@ func TestList_RemoveItem(t *testing.T) { item.(*fyne.Container).Objects[1].(*Label).SetText(data[id]) }, ) - w := test.NewWindow(list) + w := test.NewTempWindow(t, list) w.Resize(fyne.NewSize(200, 400)) visibleCount := len(list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children) @@ -485,7 +485,7 @@ func TestList_ScrollThenShrink(t *testing.T) { item.(*Label).SetText(data[id]) }, ) - w := test.NewWindow(list) + w := test.NewTempWindow(t, list) w.Resize(fyne.NewSize(300, 300)) visibles := list.scroller.Content.(*fyne.Container).Layout.(*listLayout).children @@ -524,7 +524,7 @@ func TestList_ScrollThenResizeWindow(t *testing.T) { item.(*Label).SetText(data[id]) }, ) - w := test.NewWindow(list) + w := test.NewTempWindow(t, list) w.Resize(fyne.NewSize(300, 300)) list.scroller.ScrollToBottom() @@ -540,7 +540,7 @@ func TestList_ScrollThenResizeWindow(t *testing.T) { func TestList_NoFunctionsSet(t *testing.T) { list := &List{} - w := test.NewWindow(list) + w := test.NewTempWindow(t, list) w.Resize(fyne.NewSize(200, 400)) list.Refresh() } @@ -613,7 +613,7 @@ func changeData(list *List) { func setupList(t *testing.T) (*List, fyne.Window) { test.NewApp() list := createList(1000) - w := test.NewWindow(list) + w := test.NewTempWindow(t, list) w.Resize(fyne.NewSize(200, 400)) test.AssertRendersToMarkup(t, "list/initial.xml", w.Canvas()) return list, w @@ -622,6 +622,7 @@ func setupList(t *testing.T) (*List, fyne.Window) { func TestList_LimitUpdateItem(t *testing.T) { app := test.NewApp() w := app.NewWindow("") + defer w.Close() printOut := "" list := NewList( func() int { @@ -646,6 +647,7 @@ func TestList_LimitUpdateItem(t *testing.T) { func TestList_RefreshUpdatesAllItems(t *testing.T) { app := test.NewApp() w := app.NewWindow("") + defer w.Close() printOut := "" list := NewList( func() int { diff --git a/widget/menu_desktop_test.go b/widget/menu_desktop_test.go index f8138b332e..ded09605e8 100644 --- a/widget/menu_desktop_test.go +++ b/widget/menu_desktop_test.go @@ -341,6 +341,7 @@ func TestMenu_TriggerTraversedMenu(t *testing.T) { )) m.OnDismiss = func() { dismissed = true } w := fyne.CurrentApp().NewWindow("") + t.Cleanup(w.Close) w.SetContent(internalWidget.NewOverlayContainer(m, w.Canvas(), nil)) return m } diff --git a/widget/popup_menu_desktop_test.go b/widget/popup_menu_desktop_test.go index beddddfebe..98d756bfaa 100644 --- a/widget/popup_menu_desktop_test.go +++ b/widget/popup_menu_desktop_test.go @@ -14,8 +14,7 @@ import ( func TestPopUpMenu_KeyboardControl(t *testing.T) { var lastTriggered string - m, w := setupPopUpMenuWithSubmenusTest(func(triggered string) { lastTriggered = triggered }) - defer tearDownPopUpMenuTest(w) + m, w := setupPopUpMenuWithSubmenusTest(t, func(triggered string) { lastTriggered = triggered }) c := w.Canvas() m.ShowAtPosition(fyne.NewPos(13, 45)) diff --git a/widget/popup_menu_test.go b/widget/popup_menu_test.go index 36514f1b18..ce3e08c664 100644 --- a/widget/popup_menu_test.go +++ b/widget/popup_menu_test.go @@ -13,8 +13,7 @@ import ( ) func TestPopUpMenu_Move(t *testing.T) { - m, w := setupPopUpMenuTest() - defer tearDownPopUpMenuTest(w) + m, w := setupPopUpMenuTest(t) c := w.Canvas() m.Show() @@ -31,8 +30,7 @@ func TestPopUpMenu_Move(t *testing.T) { } func TestPopUpMenu_Resize(t *testing.T) { - m, w := setupPopUpMenuTest() - defer tearDownPopUpMenuTest(w) + m, w := setupPopUpMenuTest(t) c := w.Canvas() m.ShowAtPosition(fyne.NewPos(10, 10)) @@ -49,8 +47,7 @@ func TestPopUpMenu_Resize(t *testing.T) { } func TestPopUpMenu_Show(t *testing.T) { - m, w := setupPopUpMenuTest() - defer tearDownPopUpMenuTest(w) + m, w := setupPopUpMenuTest(t) c := w.Canvas() test.AssertRendersToMarkup(t, "popup_menu/hidden.xml", c) @@ -60,8 +57,7 @@ func TestPopUpMenu_Show(t *testing.T) { } func TestPopUpMenu_ShowAtPosition(t *testing.T) { - m, w := setupPopUpMenuTest() - defer tearDownPopUpMenuTest(w) + m, w := setupPopUpMenuTest(t) c := w.Canvas() test.AssertRendersToMarkup(t, "popup_menu/hidden.xml", c) @@ -92,10 +88,12 @@ func TestPopUpMenu_ShowAtPosition(t *testing.T) { assert.Equal(t, fyne.NewSize(menuSize.Width, areaSize.Height), m.Size(), "width is larger than canvas; height is limited by canvas (menu scrolls)") } -func setupPopUpMenuTest() (*widget.PopUpMenu, fyne.Window) { +func setupPopUpMenuTest(t *testing.T) (*widget.PopUpMenu, fyne.Window) { test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.NRGBA{G: 150, B: 150, A: 255})) + w := test.NewTempWindow(t, canvas.NewRectangle(color.NRGBA{G: 150, B: 150, A: 255})) + t.Cleanup(func() { test.NewApp() }) + w.Resize(fyne.NewSize(200, 200)) m := widget.NewPopUpMenu(fyne.NewMenu( "", @@ -105,10 +103,12 @@ func setupPopUpMenuTest() (*widget.PopUpMenu, fyne.Window) { return m, w } -func setupPopUpMenuWithSubmenusTest(callback func(string)) (*widget.PopUpMenu, fyne.Window) { +func setupPopUpMenuWithSubmenusTest(t *testing.T, callback func(string)) (*widget.PopUpMenu, fyne.Window) { test.NewApp() - w := test.NewWindow(canvas.NewRectangle(color.NRGBA{G: 150, B: 150, A: 255})) + w := test.NewTempWindow(t, canvas.NewRectangle(color.NRGBA{G: 150, B: 150, A: 255})) + t.Cleanup(func() { test.NewApp() }) + w.Resize(fyne.NewSize(800, 600)) itemA := fyne.NewMenuItem("Option A", func() { callback("Option A") }) itemB := fyne.NewMenuItem("Option B", func() { callback("Option B") }) @@ -121,8 +121,3 @@ func setupPopUpMenuWithSubmenusTest(callback func(string)) (*widget.PopUpMenu, f m := widget.NewPopUpMenu(fyne.NewMenu("", itemA, itemB), w.Canvas()) return m, w } - -func tearDownPopUpMenuTest(w fyne.Window) { - w.Close() - test.NewApp() -} diff --git a/widget/popup_test.go b/widget/popup_test.go index 020ef5466e..183a23a022 100644 --- a/widget/popup_test.go +++ b/widget/popup_test.go @@ -32,7 +32,7 @@ func TestNewPopUp(t *testing.T) { func TestShowPopUp(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 200)) require.Nil(t, w.Canvas().Overlays().Top()) @@ -68,8 +68,8 @@ func TestShowPopUpAtRelativePosition(t *testing.T) { label := NewLabel("Hi") parent1 := NewLabel("Parent1") parent2 := NewLabel("Parent2") - w := test.NewWindow( - &fyne.Container{Layout: layout.NewVBoxLayout(), Objects: []fyne.CanvasObject{parent1, parent2}}) + w := test.NewTempWindow( + t, &fyne.Container{Layout: layout.NewVBoxLayout(), Objects: []fyne.CanvasObject{parent1, parent2}}) w.Resize(fyne.NewSize(100, 200)) ShowPopUpAtRelativePosition(label, w.Canvas(), pos, parent2) @@ -85,7 +85,7 @@ func TestShowPopUpAtRelativePosition(t *testing.T) { func TestShowModalPopUp(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 199)) require.Nil(t, w.Canvas().Overlays().Top()) @@ -326,7 +326,7 @@ func TestPopUp_Layout(t *testing.T) { func TestPopUp_ApplyThemeOnShow(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 300)) pop := NewPopUp(NewLabel("Label"), w.Canvas()) @@ -349,7 +349,7 @@ func TestPopUp_ApplyThemeOnShow(t *testing.T) { func TestPopUp_ResizeOnShow(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -372,7 +372,7 @@ func TestPopUp_ResizeBeforeShow_CanvasSizeZero(t *testing.T) { // Simulate canvas size {0,0} rect := canvas.NewRectangle(color.Black) rect.SetMinSize(fyne.NewSize(0, 0)) - w := test.NewWindow(rect) + w := test.NewTempWindow(t, rect) w.SetPadded(false) w.Resize(fyne.NewSize(0, 0)) assert.Zero(t, w.Canvas().Size()) @@ -439,7 +439,7 @@ func TestModalPopUp_Resize(t *testing.T) { func TestModalPopUp_Resize_Constrained(t *testing.T) { label := NewLabel("Hi") - win := test.NewWindow(NewLabel("OK")) + win := test.NewTempWindow(t, NewLabel("OK")) win.Resize(fyne.NewSize(80, 80)) pop := NewModalPopUp(label, win.Canvas()) @@ -452,7 +452,7 @@ func TestModalPopUp_Resize_Constrained(t *testing.T) { func TestModalPopUp_ApplyThemeOnShow(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) w.Resize(fyne.NewSize(200, 300)) pop := NewModalPopUp(NewLabel("Label"), w.Canvas()) @@ -475,7 +475,7 @@ func TestModalPopUp_ApplyThemeOnShow(t *testing.T) { func TestModalPopUp_ResizeOnShow(t *testing.T) { test.NewTempApp(t) - w := test.NewWindow(canvas.NewRectangle(color.Transparent)) + w := test.NewTempWindow(t, canvas.NewRectangle(color.Transparent)) size := fyne.NewSize(200, 300) w.Resize(size) @@ -498,7 +498,7 @@ func TestModelPopUp_ResizeBeforeShow_CanvasSizeZero(t *testing.T) { // Simulate canvas size {0,0} rect := canvas.NewRectangle(color.Black) rect.SetMinSize(fyne.NewSize(0, 0)) - w := test.NewWindow(rect) + w := test.NewTempWindow(t, rect) w.SetPadded(false) w.Resize(fyne.NewSize(0, 0)) assert.Zero(t, w.Canvas().Size()) diff --git a/widget/radio_group_test.go b/widget/radio_group_test.go index a51639b29a..82606c709d 100644 --- a/widget/radio_group_test.go +++ b/widget/radio_group_test.go @@ -155,12 +155,10 @@ func TestRadioGroup_Layout(t *testing.T) { radio.Disable() } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{radio}}) + window := test.NewTempWindow(t, &fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{radio}}) window.Resize(radio.MinSize().Max(fyne.NewSize(150, 200))) test.AssertRendersToMarkup(t, "radio_group/layout_"+name+".xml", window.Canvas()) - - window.Close() }) } } diff --git a/widget/richtext_test.go b/widget/richtext_test.go index 11379a0a2b..0b4d9fca97 100644 --- a/widget/richtext_test.go +++ b/widget/richtext_test.go @@ -348,7 +348,7 @@ func TestText_Multiline(t *testing.T) { &TextSegment{Text: "line1\nli", Style: RichTextStyleStrong}, &TextSegment{Text: "ne2\nline3", Style: RichTextStyleInline}) - w := test.NewWindow(text) + w := test.NewTempWindow(t, text) w.Resize(fyne.NewSize(64, 90)) test.AssertImageMatches(t, "richtext/richtext_multiline.png", w.Canvas().Capture()) } diff --git a/widget/select_test.go b/widget/select_test.go index cd4fa75409..9503b36448 100644 --- a/widget/select_test.go +++ b/widget/select_test.go @@ -541,15 +541,13 @@ func TestSelect_Layout(t *testing.T) { Selected: tt.selected, } - window := test.NewWindow(&fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{combo}}) + window := test.NewTempWindow(t, &fyne.Container{Layout: layout.NewCenterLayout(), Objects: []fyne.CanvasObject{combo}}) if tt.expanded { test.Tap(combo) } window.Resize(combo.MinSize().Max(fyne.NewSize(150, 200))) assertRendersToPlatformMarkup(t, "select/%s/layout_"+name+".xml", window.Canvas()) - - window.Close() }) } } diff --git a/widget/slider_test.go b/widget/slider_test.go index 421e153dac..ebbb3c646c 100644 --- a/widget/slider_test.go +++ b/widget/slider_test.go @@ -293,7 +293,7 @@ func TestSlider_FocusDesktop(t *testing.T) { return } slider := NewSlider(0, 10) - win := test.NewWindow(slider) + win := test.NewTempWindow(t, slider) test.Tap(slider) assert.Equal(t, win.Canvas().Focused(), slider) diff --git a/widget/table_test.go b/widget/table_test.go index 649efa1576..e95a6cd750 100644 --- a/widget/table_test.go +++ b/widget/table_test.go @@ -312,7 +312,7 @@ func TestTable_Resize(t *testing.T) { }, func(TableCellID, fyne.CanvasObject) {}) - w := test.NewWindow(table) + w := test.NewTempWindow(t, table) w.Resize(fyne.NewSize(100, 100)) test.AssertImageMatches(t, "table/resize.png", w.Canvas().Capture()) } diff --git a/widget/tree_internal_test.go b/widget/tree_internal_test.go index f0a59a0d36..3a2ca484e3 100644 --- a/widget/tree_internal_test.go +++ b/widget/tree_internal_test.go @@ -875,8 +875,8 @@ func TestTree_RefreshItem(t *testing.T) { } tree.OpenBranch("foo") - c := test.NewWindow(tree) - c.Resize(fyne.NewSize(100, 100)) + w := test.NewTempWindow(t, tree) + w.Resize(fyne.NewSize(100, 100)) r := test.TempWidgetRenderer(t, tree.scroller.Content.(*treeContent)).(*treeContentRenderer) diff --git a/widget/widget_test.go b/widget/widget_test.go index 8a34b7cfe1..87cee8ed50 100644 --- a/widget/widget_test.go +++ b/widget/widget_test.go @@ -34,7 +34,7 @@ func (m *myWidget) CreateRenderer() fyne.WidgetRenderer { func TestApplyThemeCalled(t *testing.T) { widget := &myWidget{refreshed: make(chan bool)} - window := test.NewWindow(widget) + test.NewTempWindow(t, widget) fyne.CurrentApp().Settings().SetTheme(internalTest.LightTheme(theme.DefaultTheme())) func() { @@ -44,15 +44,13 @@ func TestApplyThemeCalled(t *testing.T) { assert.Fail(t, "Timed out waiting for theme apply") } }() - - window.Close() } func TestApplyThemeCalledChild(t *testing.T) { child := &myWidget{refreshed: make(chan bool)} parent := &fyne.Container{Layout: layout.NewVBoxLayout(), Objects: []fyne.CanvasObject{child}} - window := test.NewWindow(parent) + test.NewTempWindow(t, parent) fyne.CurrentApp().Settings().SetTheme(internalTest.LightTheme(theme.DefaultTheme())) func() { select { @@ -61,8 +59,6 @@ func TestApplyThemeCalledChild(t *testing.T) { assert.Fail(t, "Timed out waiting for child theme apply") } }() - - window.Close() } func TestSimpleRenderer(t *testing.T) {