Skip to content

Commit 6041098

Browse files
fix(tests): dispatch logout deep-link and fix browser lifecycle
Windows: - Extract returnTo deep-link from logout URL - Write deep-link to Windows Registry for Unity to process - Fixes app crash by ensuring logout callback is received macOS: - Kill existing Brave processes before launching with debugging port - Prevents 'cannot connect to chrome at localhost:9222' error - Ensures controlled logout can connect to browser Both platforms now properly dispatch immutablerunner://logout deep-link back to Unity after browser logout completes.
1 parent dc755d5 commit 6041098

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

sample/Tests/test/test_mac.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,19 @@ def tearDownClass(cls):
4040
@classmethod
4141
def launch_browser(cls):
4242
print("Starting Browser...")
43+
44+
# First, ensure no Brave instances are running
45+
print("Checking for existing Brave processes...")
46+
try:
47+
result = subprocess.run(["pgrep", "-f", "Brave Browser"],
48+
capture_output=True, text=True)
49+
if result.returncode == 0:
50+
print("Found existing Brave processes, closing them first...")
51+
cls.stop_browser()
52+
time.sleep(2)
53+
except Exception as e:
54+
print(f"Could not check for existing Brave processes: {e}")
55+
4356
browser_paths = [
4457
"/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
4558
]
@@ -54,6 +67,7 @@ def launch_browser(cls):
5467
print("Brave Browser executable not found.")
5568
exit(1)
5669

70+
print(f"Launching Brave with debugging port from: {browser_path}")
5771
subprocess.Popen([
5872
browser_path,
5973
"--remote-debugging-port=9222",

sample/Tests/test/test_windows_helpers.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,35 @@ def logout_with_controlled_browser():
370370
print(f"Navigating controlled browser to logout URL: {logout_url}")
371371
driver.get(logout_url)
372372

373-
# Wait for logout to complete (protocol is already configured, no dialogs expected)
373+
# Wait for logout page to load
374374
time.sleep(3)
375375
print("Logout completed in controlled browser")
376376

377377
# Check final page
378378
current_url = driver.current_url
379379
print(f"Final logout URL: {current_url}")
380380

381+
# Extract and dispatch the returnTo deep-link
382+
import re
383+
if 'returnTo=' in logout_url:
384+
from urllib.parse import unquote
385+
match = re.search(r'returnTo=([^&]+)', logout_url)
386+
if match:
387+
return_to = unquote(match.group(1))
388+
print(f"Extracted returnTo deep-link: {return_to}")
389+
390+
# Capture the deep-link and write to registry (same as login flow)
391+
print(f"Writing deep-link to Windows Registry: {return_to}")
392+
try:
393+
import winreg
394+
# Write the deep-link URL to the registry key that Unity monitors
395+
with winreg.CreateKey(winreg.HKEY_CURRENT_USER, r"Software\Immutable\UnityDeepLink") as key:
396+
winreg.SetValueEx(key, "deeplink", 0, winreg.REG_SZ, return_to)
397+
print("Deep-link written to registry successfully")
398+
time.sleep(2) # Give Unity time to read from registry
399+
except Exception as reg_err:
400+
print(f"Warning: Could not write to registry: {reg_err}")
401+
381402
else:
382403
print("Could not find logout URL in Unity logs - logout may complete without browser interaction")
383404

0 commit comments

Comments
 (0)