Skip to content

Commit

Permalink
Got all races fixed, I think
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacalz committed Jan 13, 2025
1 parent b926697 commit 8ed292a
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 44 deletions.
35 changes: 21 additions & 14 deletions internal/driver/glfw/canvas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,28 @@ func TestGlCanvas_ChildMinSizeChangesInDifferentScrollAffectAncestorsUpToScroll(
w.Resize(oldCanvasSize)
repaintWindow(w)

oldLeftColSize := leftCol.Size()
oldLeftScrollSize := leftColScroll.Size()
oldRightColSize := rightCol.Size()
oldRightScrollSize := rightColScroll.Size()
leftObj2.SetMinSize(fyne.NewSize(50, 100))
rightObj2.SetMinSize(fyne.NewSize(50, 200))
var oldLeftColSize, oldLeftScrollSize, oldRightColSize, oldRightScrollSize fyne.Size
runOnMain(func() {
oldLeftColSize = leftCol.Size()
oldLeftScrollSize = leftColScroll.Size()
oldRightColSize = rightCol.Size()
oldRightScrollSize = rightColScroll.Size()
leftObj2.SetMinSize(fyne.NewSize(50, 100))
rightObj2.SetMinSize(fyne.NewSize(50, 200))
})
c.Refresh(leftObj2)
c.Refresh(rightObj2)
repaintWindow(w)

assert.Equal(t, oldCanvasSize, c.Size())
assert.Equal(t, oldLeftScrollSize, leftColScroll.Size())
assert.Equal(t, oldRightScrollSize, rightColScroll.Size())
expectedLeftColSize := oldLeftColSize.Add(fyne.NewSize(0, 50))
assert.Equal(t, expectedLeftColSize, leftCol.Size())
expectedRightColSize := oldRightColSize.Add(fyne.NewSize(0, 150))
assert.Equal(t, expectedRightColSize, rightCol.Size())
runOnMain(func() {
assert.Equal(t, oldCanvasSize, c.Size())
assert.Equal(t, oldLeftScrollSize, leftColScroll.Size())
assert.Equal(t, oldRightScrollSize, rightColScroll.Size())
expectedLeftColSize := oldLeftColSize.Add(fyne.NewSize(0, 50))
assert.Equal(t, expectedLeftColSize, leftCol.Size())
expectedRightColSize := oldRightColSize.Add(fyne.NewSize(0, 150))
assert.Equal(t, expectedRightColSize, rightCol.Size())
})
}

func TestGlCanvas_Content(t *testing.T) {
Expand Down Expand Up @@ -417,7 +422,9 @@ func TestGlCanvas_ResizeWithOtherOverlay(t *testing.T) {
})

size = fyne.NewSize(200, 100)
assert.NotEqual(t, size, content.Size())
runOnMain(func() {
assert.NotEqual(t, size, content.Size())
})

w.Resize(size)
ensureCanvasSize(t, w, size)
Expand Down
86 changes: 56 additions & 30 deletions internal/driver/glfw/window_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ func TestWindow_MinSize_Fixed(t *testing.T) {
assertCanvasSize(t, w, minSizePlusPadding)

w = createWindow("Test")
r.SetMinSize(fyne.NewSize(100, 100))
runOnMain(func() {
r.SetMinSize(fyne.NewSize(100, 100))
})
w.SetFixedSize(true)
w.SetContent(r)
assertCanvasSize(t, w, minSizePlusPadding)
Expand Down Expand Up @@ -272,8 +274,10 @@ func TestWindow_HandleHoverable(t *testing.T) {
w.Resize(fyne.NewSize(30, 20))

repaintWindow(w)
require.Equal(t, fyne.NewPos(0, 0), h1.Position())
require.Equal(t, fyne.NewPos(14, 0), h2.Position())
runOnMain(func() {
require.Equal(t, fyne.NewPos(0, 0), h1.Position())
require.Equal(t, fyne.NewPos(14, 0), h2.Position())
})

runOnMain(func() {
w.mouseMoved(w.viewport, 9, 9)
Expand Down Expand Up @@ -1054,7 +1058,9 @@ func TestWindow_DragEndWithoutTappedEvent(t *testing.T) {
w.SetContent(do)

repaintWindow(w)
require.Equal(t, fyne.NewPos(4, 4), do.Position())
runOnMain(func() {
require.Equal(t, fyne.NewPos(4, 4), do.Position())
})

runOnMain(func() {
w.mouseMoved(w.viewport, 11, 11)
Expand Down Expand Up @@ -1447,16 +1453,24 @@ func TestWindow_SetPadded(t *testing.T) {
ensureCanvasSize(t, w, oldCanvasSize)

repaintWindow(w)
contentSize := content.Size()
expectedCanvasSize := contentSize.
Add(fyne.NewSize(2*tt.expectedPad, 2*tt.expectedPad)).
Add(fyne.NewSize(0, tt.expectedMenuHeight))

var contentSize, expectedCanvasSize fyne.Size
runOnMain(func() {
contentSize = content.Size()
expectedCanvasSize = contentSize.
Add(fyne.NewSize(2*tt.expectedPad, 2*tt.expectedPad)).
Add(fyne.NewSize(0, tt.expectedMenuHeight))
})

w.SetPadded(tt.padding)
repaintWindow(w)
assert.Equal(t, contentSize, content.Size())
assert.Equal(t, fyne.NewPos(tt.expectedPad, tt.expectedPad+tt.expectedMenuHeight), content.Position())
assert.Equal(t, expectedCanvasSize, w.Canvas().Size())

canvas := w.Canvas()
runOnMain(func() {
assert.Equal(t, contentSize, content.Size())
assert.Equal(t, fyne.NewPos(tt.expectedPad, tt.expectedPad+tt.expectedMenuHeight), content.Position())
assert.Equal(t, expectedCanvasSize, canvas.Size())
})
})
}
}
Expand Down Expand Up @@ -1564,33 +1578,45 @@ func TestWindow_ManualFocus(t *testing.T) {
w.SetContent(content)
repaintWindow(w)

w.mouseMoved(w.viewport, 9, 9)
w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Press, 0)
w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Release, 0)
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 0, content.unfocusedTimes)
runOnMain(func() {
w.mouseMoved(w.viewport, 9, 9)
w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Press, 0)
w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Release, 0)
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 0, content.unfocusedTimes)

w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Press, 0)
w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Release, 0)
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 0, content.unfocusedTimes)
w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Press, 0)
w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Release, 0)
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 0, content.unfocusedTimes)
})

w.Canvas().Focus(content)
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 0, content.unfocusedTimes)

runOnMain(func() {
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 0, content.unfocusedTimes)
})

w.Canvas().Unfocus()
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 1, content.unfocusedTimes)

content.Disable()
runOnMain(func() {
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 1, content.unfocusedTimes)

content.Disable()
})

w.Canvas().Focus(content)
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 1, content.unfocusedTimes)

w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Press, 0)
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 1, content.unfocusedTimes)
runOnMain(func() {
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 1, content.unfocusedTimes)

w.mouseClicked(w.viewport, glfw.MouseButton1, glfw.Press, 0)
assert.Equal(t, 1, content.focusedTimes)
assert.Equal(t, 1, content.unfocusedTimes)
})
}

func TestWindow_ClipboardCopy_DisabledEntry(t *testing.T) {
Expand Down

0 comments on commit 8ed292a

Please sign in to comment.