Debian Codegraph @

test/verify/check-shell-menu

raw
1 #!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv)
2
3 #
4 # Copyright (C) 2013 Red Hat, Inc.
5 # SPDX-License-Identifier: LGPL-2.1-or-later
6
7
8 import time
9
10 import testlib
11
12
13 @testlib.skipBeiboot("no local overrides/config in beiboot mode")
14 @testlib.nondestructive
15 class TestMenu(testlib.MachineCase):
16
17 def testDarkThemeSwitcher(self):
18 b = self.browser
19
20 def switch_style(style_sel, prevPage="system", pixel_test=False):
21 b.switch_to_top()
22 b.click("#toggle-menu")
23 if pixel_test:
24 b.wait_visible("#toggle-menu-menu")
25 b.assert_pixels_in_current_layout("#toggle-menu-menu", "shell-toggle-menu")
26 b.click(style_sel)
27 b.enter_page(f"/{prevPage}")
28
29 self.login_and_go("/system")
30 switch_style("#dark", pixel_test=True)
31 b._wait_present("html.pf-v6-theme-dark")
32
33 switch_style("#light")
34 b.wait_not_present("html.pf-v6-theme-dark")
35
36 # Test overriding, switching only works on Chromium
37 if b.browser == "chromium":
38 # Light theme overrides browser defaults
39 b._set_emulated_media_theme("dark")
40 b.wait_not_present("html.pf-v6-theme-dark")
41
42 switch_style("#auto")
43 b._wait_present("html.pf-v6-theme-dark")
44
45 b._set_emulated_media_theme("light")
46 b.wait_not_present("html.pf-v6-theme-dark")
47
48 switch_style("#dark")
49 b._wait_present("html.pf-v6-theme-dark")
50
51 def testBasic(self):
52 b = self.browser
53 m = self.machine
54
55 # Add a link with a hash in it to test that this works
56 m.execute("mkdir -p /usr/local/share/cockpit/systemd; cp -rp /usr/share/cockpit/systemd/* /usr/local/share/cockpit/systemd")
57 m.execute(
58 """sed -i '/"menu"/a "memory": { "label": "Memory", "path": "#/memory" },' /usr/local/share/cockpit/systemd/manifest.json""")
59 self.addCleanup(m.execute, "rm -r /usr/local/share/cockpit/systemd")
60
61 self.login_and_go("/system")
62
63 b.switch_to_top()
64 b.click('#toggle-docs')
65 b.click('button:contains("About Web Console")')
66 b.wait_in_text('#about-cockpit-modal', 'Cockpit is an interactive Linux server admin interface')
67 if not m.ostree_image:
68 pkgname = "cockpit" if m.image == "arch" else "cockpit-bridge"
69 b.wait_visible(f'#about-cockpit-modal:contains("{pkgname}")')
70 b.assert_pixels('.pf-v6-c-modal-box:has(#about-cockpit-modal)', "about-cockpit-modal",
71 mock={".pf-v6-c-content--dd": "v1234"})
72 b.click('.pf-v6-c-about-modal-box__close button')
73 b.wait_not_present('#about-cockpit-modal')
74
75 # Clicking inside the iframed pages should close the docs menu
76 b.click("#toggle-docs")
77 b.wait_visible("#toggle-docs-menu")
78 b.assert_pixels("#toggle-docs-menu", "shell-docs-menu")
79 b.enter_page("/system")
80 b.focus("#overview main")
81 b.switch_to_top()
82 b.wait_not_present("#toggle-docs-menu")
83
84 # Check that we can use a link with a hash in it
85 b.click_system_menu("/system/#/memory")
86
87 # Ensure that our tests pick up unhandled JS exceptions
88 b.switch_to_top()
89 b.go("/playground/exception")
90
91 # Test that subpages are correctly shown in the navigation (twice - once that only one page is shown as active)
92 b.wait_in_text("#host-apps .pf-m-current", "Development")
93
94 b.enter_page("/playground/exception")
95 b.click("button")
96
97 # UI should show the crash
98 b.switch_to_top()
99 b.wait_visible("#navbar-oops")
100
101 # normally called at the end of the test, should fail due to the oops
102 with self.assertRaisesRegex(AssertionError, "Cockpit shows an Oops"):
103 self.check_browser_errors()
104
105 # don't actually fail this test
106 b.allow_oops = True
107
108 def testSessionTimeout(self):
109 b = self.browser
110 m = self.machine
111
112 m.execute("printf '[Session]\nIdleTimeout = 1\n' >> /etc/cockpit/cockpit.conf")
113
114 # does not time out immediately
115 self.login_and_go()
116 time.sleep(20)
117 self.assertFalse(b.is_present("#session-timeout-modal"))
118 b.wait_visible("#hosts-sel")
119
120 # a mouse event resets the timer
121 b.enter_page("/system")
122 b.mouse("#system_information_hardware_text", "mousemove", 24, 24)
123 b.switch_to_top()
124
125 # 30s before the 1 min timeout the dialog pops up
126 time.sleep(35)
127 with b.wait_timeout(3):
128 b.wait_visible("#session-timeout-modal")
129 self.assertGreater(int(b.text("#session-timeout-modal .pf-v6-c-modal-box__body").split()[-2]), 15)
130 # click on "Continue session"
131 b.click("#session-timeout-modal footer button")
132 b.wait_not_present("#session-timeout-modal")
133
134 # now wait for timeout dialog again, but don't click; instead, wait for the full minute
135 time.sleep(30)
136 with b.wait_timeout(8):
137 b.wait_popup("session-timeout-modal")
138 self.assertGreater(int(b.text("#session-timeout-modal .pf-v6-c-modal-box__body").split()[-2]), 20)
139
140 time.sleep(30)
141 # that logs you out
142 b.wait_visible("#login")
143 b.wait_visible("#login-info-message")
144 b.wait_text("#login-info-message", "You have been logged out due to inactivity.")
145
146 @testlib.skipImage("TODO: fix for OpenSUSE", "opensuse-tumbleweed")
147 def testKeyboardNavigation(self):
148 b = self.browser
149 self.login_and_go()
150
151 # initially shows host switcher
152 b.wait_visible("#hosts-sel")
153 self.assertEqual(b.eval_js("document.activeElement.tagName"), "BODY")
154
155 # press Tab once → "Skip to content" skiplink
156 b.key("Tab")
157 b.wait_js_cond("document.activeElement.parentElement.classList.contains('pf-v6-c-skip-to-content')")
158 self.assertEqual(b.eval_js("document.activeElement.textContent"), "Skip to content")
159 self.assertEqual(b.eval_js("document.activeElement.getAttribute('href')"), "#content")
160 b.key("Enter")
161 b.wait_js_cond("document.activeElement.getAttribute('id') === 'content'")
162 self.assertEqual(b.eval_js("document.activeElement.tagName"), "DIV")
163 self.assertEqual(b.eval_js("document.activeElement.getAttribute('id')"), "content")
164
165 # reset
166 b.reload()
167 b.wait_visible("#hosts-sel")
168 b.wait_text("#super-user-indicator", "Administrative access")
169
170 # press Tab twice → "Skip main navigation" skiplink
171 b.key("Tab")
172 self.assertEqual(b.eval_js("document.activeElement.textContent"), "Skip to content")
173 b.key("Tab")
174 self.assertEqual(b.eval_js("document.activeElement.textContent"), "Skip main navigation")
175 b.key("Enter")
176 b.wait_js_cond("document.activeElement.tagName === 'NAV'")
177 self.assertEqual(b.eval_js("document.activeElement.getAttribute('id')"), "hosts-sel")
178
179 # actually skips the page menu and goes on to top nav bar; where exactly depends on whether
180 # the host switcher is enabled.
181 b.key("Tab")
182 if self.multihost_enabled:
183 b.wait_js_cond("document.activeElement.getAttribute('id') === 'host-toggle'")
184 b.key("Tab")
185 b.wait_js_cond("document.activeElement.textContent === 'Administrative access'")
186
187 # reset
188 b.reload()
189 b.wait_visible("#hosts-sel")
190
191 # without skip links, tabbing goes through page menu
192 b.key("Tab", repeat=5)
193 # different browsers behave a bit different here -- Firefox is at "Overview", Chromium at "Logs"
194 b.wait_js_cond("document.activeElement.classList.contains('pf-v6-c-nav__link')")
195
196 def testCustomLandingPage(self):
197 b = self.browser
198 m = self.machine
199
200 # # Make the logs page the default page
201 m.write("/etc/cockpit/systemd.override.json", '{"menu":{"index":{"order":100},"logs":{"order":1}}}')
202
203 self.login_and_go()
204 b.wait_js_cond('window.location.pathname == "/system/logs"')
205
206
207 if __name__ == '__main__':
208 testlib.test_main()