0
Files
src/testing/xvfb_unittest.py
Tom Anderson b936950aa0 Remove complex GPU->Browser IPC for obtaining GL-compatible visuals
When GLVisualPickerGLX was written, the only way of obtaining
GL-compatible visuals was with libGLX, which loads the GPU driver.
This forced us to rely on the GPU process sending the visuals to the
browser process, which comes with a significant amount of complexity.
Now that we've switched to XProto, we can use x11::Glx to obtain the
visuals, which doesn't require loading the GPU driver.  This allows
us to simplify the visual loading code.

In addition, now that the transparent visual is available early, it
can be used as the visual for browser windows.  This can allow us to
remove usage of the XShape extension which we were using to "cut off"
a few pixels around the corners to give the appearance of rounded
corners.  This solution is not ideal since it:
  1. causes a performance hit on some environments (GNOME/Mutter)
  2. prevents the WM from drawing a shadow on the window
  3. doesn't antialias the corners
Using a transparent visual will solve all 3 issues.  However, we'll
have to draw client-side shadows (just like GTK does).

R=sky

Bug: 650494,811515,1198080
Change-Id: Ie518dfe489d3ba0af9ca73c80cc10792a4214838
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2895228
Reviewed-by: Dirk Pranke <dpranke@google.com>
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Emily Stark <estark@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Commit-Queue: Emily Stark <estark@chromium.org>
Auto-Submit: Thomas Anderson <thomasanderson@chromium.org>
Cr-Commit-Position: refs/heads/master@{#884257}
2021-05-19 01:06:40 +00:00

105 lines
2.9 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright (c) 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unit tests for xvfb.py functionality.
Each unit test is launching xvfb_test_script.py
through xvfb.py as a subprocess, then tests its expected output.
"""
import os
import signal
import subprocess
import sys
import time
import unittest
TEST_FILE = __file__.replace('.pyc', '.py')
XVFB = TEST_FILE.replace('_unittest', '')
XVFB_TEST_SCRIPT = TEST_FILE.replace('_unittest', '_test_script')
def launch_process(args):
"""Launches a sub process to run through xvfb.py."""
return subprocess.Popen(
[XVFB, XVFB_TEST_SCRIPT] + args, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, env=os.environ.copy())
def read_subprocess_message(proc, starts_with):
"""Finds the value after first line prefix condition."""
for line in proc.stdout:
if line.startswith(starts_with):
return line.rstrip().replace(starts_with, '')
def send_signal(proc, sig, sleep_time=0.3):
"""Sends a signal to subprocess."""
time.sleep(sleep_time) # gives process time to launch.
os.kill(proc.pid, sig)
proc.wait()
class XvfbLinuxTest(unittest.TestCase):
def setUp(self):
super(XvfbLinuxTest, self).setUp()
if sys.platform != 'linux2':
self.skipTest('linux only test')
def test_no_xvfb_display(self):
proc = launch_process(['--no-xvfb'])
proc.wait()
display = read_subprocess_message(proc, 'Display :')
self.assertEqual(display, os.environ.get('DISPLAY', 'None'))
def test_xvfb_display(self):
proc = launch_process([])
proc.wait()
display = read_subprocess_message(proc, 'Display :')
self.assertIsNotNone(display)
self.assertNotEqual(display, os.environ.get('DISPLAY', 'None'))
def test_no_xvfb_flag(self):
proc = launch_process(['--no-xvfb'])
proc.wait()
def test_xvfb_flag(self):
proc = launch_process([])
proc.wait()
def test_xvfb_race_condition(self):
proc_list = [launch_process([]) for _ in range(15)]
for proc in proc_list:
proc.wait()
display_list = [read_subprocess_message(p, 'Display :') for p in proc_list]
for display in display_list:
self.assertIsNotNone(display)
self.assertNotEqual(display, os.environ.get('DISPLAY', 'None'))
class XvfbTest(unittest.TestCase):
def setUp(self):
super(XvfbTest, self).setUp()
if sys.platform == 'win32':
self.skipTest('non-win32 test')
def test_send_sigint(self):
proc = launch_process(['--sleep'])
send_signal(proc, signal.SIGINT, 1)
sig = read_subprocess_message(proc, 'Signal :')
self.assertEqual(sig, str(signal.SIGINT))
def test_send_sigterm(self):
proc = launch_process(['--sleep'])
send_signal(proc, signal.SIGTERM, 1)
sig = read_subprocess_message(proc, 'Signal :')
self.assertEqual(sig, str(signal.SIGTERM))
if __name__ == '__main__':
unittest.main()