Skip to content

Commit

Permalink
Generalize dialog and notification tests from Max layout to all layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
kynikos authored and flacjacket committed Apr 26, 2017
1 parent d4c2f36 commit 4aacd56
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 107 deletions.
121 changes: 121 additions & 0 deletions test/layouts/test__common.py
Expand Up @@ -274,6 +274,127 @@ def test_remove(qtile):
assert qtile.c.window.info()['name'] in qtile.c.layout.info()['clients']


@each_layout_config
def test_remove_floating(qtile):
one = qtile.testWindow("one")
two = qtile.testWindow("two")
float1 = qtile.testDialog("float1")
assertFocused(qtile, "float1")
assert set(qtile.c.layout.info()['clients']) == {"one", "two"}
assert qtile.c.group.info()['focusHistory'] == ["one", "two", "float1"]

# Removing a focused floating window must focus the one that was focused before
qtile.kill_window(float1)
assertFocused(qtile, "two")
assert qtile.c.group.info()['focusHistory'] == ["one", "two"]

float2 = qtile.testDialog("float2")
assertFocused(qtile, "float2")
assert qtile.c.group.info()['focusHistory'] == ["one", "two", "float2"]

# Removing a non-focused floating window must not change the current focus
qtile.c.group.focus_by_name("two")
qtile.kill_window(float2)
assertFocused(qtile, "two")
assert qtile.c.group.info()['focusHistory'] == ["one", "two"]

# Add more windows and shuffle the focus order
three = qtile.testWindow("three")
float3 = qtile.testDialog("float3")
qtile.c.group.focus_by_name("one")
float4 = qtile.testDialog("float4")
float5 = qtile.testDialog("float5")
qtile.c.group.focus_by_name("three")
qtile.c.group.focus_by_name("float3")
assert qtile.c.group.info()['focusHistory'] == ["two", "one", "float4",
"float5", "three", "float3"]

qtile.kill_window(one)
assertFocused(qtile, "float3")
assert qtile.c.group.info()['focusHistory'] == ["two", "float4",
"float5", "three", "float3"]

qtile.kill_window(float5)
assertFocused(qtile, "float3")
assert qtile.c.group.info()['focusHistory'] == ["two", "float4", "three", "float3"]

# The focus must be given to the previous window even if it's floating
qtile.c.group.focus_by_name("float4")
assert qtile.c.group.info()['focusHistory'] == ["two", "three", "float3", "float4"]
qtile.kill_window(float4)
assertFocused(qtile, "float3")
assert qtile.c.group.info()['focusHistory'] == ["two", "three", "float3"]

four = qtile.testWindow("four")
float6 = qtile.testDialog("float6")
five = qtile.testWindow("five")
qtile.c.group.focus_by_name("float3")
assert qtile.c.group.info()['focusHistory'] == ["two", "three", "four",
"float6", "five", "float3"]

# Killing several unfocused windows before the current one, and then
# killing the current window, must focus the remaining most recently
# focused window
qtile.kill_window(five)
qtile.kill_window(four)
qtile.kill_window(float6)
assert qtile.c.group.info()['focusHistory'] == ["two", "three", "float3"]
qtile.kill_window(float3)
assertFocused(qtile, "three")
assert qtile.c.group.info()['focusHistory'] == ["two", "three"]


@each_layout_config
def test_desktop_notifications(qtile):
# Unlike normal floating windows such as dialogs, notifications don't steal
# focus when they spawn, so test them separately

# A notification fired in an empty group must not take focus
notif1 = qtile.testNotification("notif1")
assert qtile.c.group.info()['focus'] is None
qtile.kill_window(notif1)

# A window is spawned while a notification is displayed
notif2 = qtile.testNotification("notif2")
one = qtile.testWindow("one")
assert qtile.c.group.info()['focusHistory'] == ["one"]
qtile.kill_window(notif2)

# Another notification is fired, but the focus must not change
notif3 = qtile.testNotification("notif3")
assertFocused(qtile, 'one')
qtile.kill_window(notif3)

# Complicate the scenario with multiple windows and notifications

dialog1 = qtile.testDialog("dialog1")
two = qtile.testWindow("two")
notif4 = qtile.testNotification("notif4")
notif5 = qtile.testNotification("notif5")
assert qtile.c.group.info()['focusHistory'] == ["one", "dialog1", "two"]

dialog2 = qtile.testDialog("dialog2")
qtile.kill_window(notif5)
three = qtile.testWindow("three")
qtile.kill_window(one)
qtile.c.group.focus_by_name("two")
notif6 = qtile.testNotification("notif6")
notif7 = qtile.testNotification("notif7")
qtile.kill_window(notif4)
notif8 = qtile.testNotification("notif8")
assert qtile.c.group.info()['focusHistory'] == ["dialog1", "dialog2",
"three", "two"]

dialog3 = qtile.testDialog("dialog3")
qtile.kill_window(dialog1)
qtile.kill_window(dialog2)
qtile.kill_window(notif6)
qtile.c.group.focus_by_name("three")
qtile.kill_window(notif7)
qtile.kill_window(notif8)
assert qtile.c.group.info()['focusHistory'] == ["two", "dialog3", "three"]


@all_layouts_config
def test_cycle_layouts(qtile):
qtile.testWindow("one")
Expand Down
107 changes: 0 additions & 107 deletions test/layouts/test_max.py
Expand Up @@ -84,113 +84,6 @@ def test_max_remove(qtile):
assert qtile.c.layout.info()["clients"] == ["one"]


@max_config
def test_closing_dialog(qtile):
# Closing a floating window that has focus must return the focus to the
# window that was previously focused

# Start by testing a dialog that is the first open window in the group
dialog1 = qtile.testWindow("dialog1")
qtile.testWindow("one")
qtile.testWindow("two")
three = qtile.testWindow("three")
qtile.c.layout.down()
assert qtile.c.window.info()['name'] == "dialog1", qtile.c.window.info()['name']
qtile.c.window.toggle_floating()
qtile.kill_window(dialog1)
assert qtile.c.window.info()['name'] == "three", qtile.c.window.info()['name']

# Now test a dialog that is the last open window in the group
dialog2 = qtile.testWindow("dialog2")
qtile.c.window.toggle_floating()
qtile.kill_window(dialog2)
assert qtile.c.window.info()['name'] == "three", qtile.c.window.info()['name']

# Now test a dialog that is neither the first nor the last open window in
# the group
dialog3 = qtile.testWindow("dialog3")
four = qtile.testWindow("four")
qtile.testWindow("five")
qtile.testWindow("six")
# TODO: for a more generic test, find a way to focus 'five', then focus
# 'dialog3' skipping 'four', so that then, after closing 'dialog3', the
# focus must be returned to 'five', which better represents a generic
# window that wasn't necessarily opened immediately after the dialog
qtile.c.layout.up()
qtile.c.layout.up()
qtile.c.layout.up()
assert qtile.c.window.info()['name'] == "dialog3", qtile.c.window.info()['name']
qtile.c.window.toggle_floating()
qtile.kill_window(dialog3)
assert qtile.c.window.info()['name'] == "four", qtile.c.window.info()['name']

# Finally test a case in which the window that had focus previously is
# closed without stealing focus from the dialog, thus requiring to find the
# window that had focus even before that (this tests the history of focus)
dialog4 = qtile.testWindow("dialog4")
qtile.c.layout.up()
qtile.c.layout.up()
qtile.c.layout.up()
assert qtile.c.window.info()['name'] == "two", qtile.c.window.info()['name']
qtile.c.layout.down()
qtile.c.layout.down()
qtile.c.layout.down()
assert qtile.c.window.info()['name'] == "dialog4", qtile.c.window.info()['name']
qtile.c.window.toggle_floating()
qtile.kill_window(three)
qtile.kill_window(four)
qtile.kill_window(dialog4)
assert qtile.c.window.info()['name'] == "two", qtile.c.window.info()['name']


@max_config
def test_closing_notification(qtile):
# Closing a floating window that doesn't have focus must not change the
# currently focused window

# TODO: for more proper testing, the notification windows should be created
# without giving them focus

# Start by testing a notification that is the first open window in the
# group
notification1 = qtile.testWindow("notification1")
qtile.c.window.toggle_floating()
qtile.testWindow("one")
qtile.testWindow("two")
qtile.testWindow("three")
qtile.c.layout.up()
assert qtile.c.window.info()['name'] == "two", qtile.c.window.info()['name']
qtile.kill_window(notification1)
assert qtile.c.window.info()['name'] == "two", qtile.c.window.info()['name']

# Now test a notification that is the last open window in the group
qtile.c.layout.down()
notification2 = qtile.testWindow("notification2")
qtile.c.window.toggle_floating()
# Create and kill 'temp', otherwise qtile.c.layout.up() won't work
temp = qtile.testWindow("temp")
qtile.c.layout.up()
qtile.c.layout.up()
qtile.kill_window(temp)
assert qtile.c.window.info()['name'] == "two", qtile.c.window.info()['name']
qtile.kill_window(notification2)
assert qtile.c.window.info()['name'] == "two", qtile.c.window.info()['name']

# Now test a notification that is neither the first nor the last open
# window in the group
qtile.c.layout.down()
notification3 = qtile.testWindow("notification3")
qtile.c.window.toggle_floating()
four = qtile.testWindow("four")
five = qtile.testWindow("five")
qtile.c.layout.up()
qtile.c.layout.up()
qtile.c.layout.up()
assert qtile.c.window.info()['name'] == "two", qtile.c.window.info()['name']
qtile.kill_window(notification3)
assert qtile.c.window.info()['name'] == "two", qtile.c.window.info()['name']


@max_config
def test_max_window_focus_cycle(qtile):
# setup 3 tiled and two floating clients
Expand Down

0 comments on commit 4aacd56

Please sign in to comment.