Skip to content

Commit c4d3bfa

Browse files
fix(tests): dispatch logout callback without protocol prompts
- Windows: extract logout returnTo and write deep-link to registry so Unity receives the callback even if the OS blocks immutablerunner:// - macOS: remove Selenium/ChromeDriver dependency from logout helper; trigger returnTo via `open` using URL captured from Player.log
1 parent dc755d5 commit c4d3bfa

2 files changed

Lines changed: 32 additions & 27 deletions

File tree

sample/Tests/test/test_mac_helpers.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
import os
44
import re
55
from pathlib import Path
6-
from selenium import webdriver
7-
from selenium.webdriver.chrome.options import Options
86

97
def get_app_name():
108
"""Get the app name from environment variable, falling back to default"""
@@ -67,22 +65,15 @@ def get_logout_url_from_unity_logs():
6765
return None
6866

6967
def logout_with_controlled_browser():
70-
"""Handle logout using the controlled browser instance instead of letting Unity open its own browser."""
68+
"""Handle logout without relying on Selenium/ChromeDriver.
69+
70+
The Unity sample app already opens the logout URL in the system browser when LogoutBtn is tapped.
71+
Here we monitor Unity logs to capture that logout URL, extract its `returnTo` deep-link, and
72+
trigger it via `open` so Unity receives the callback deterministically.
73+
"""
7174
print("Starting controlled logout process...")
72-
73-
# Set up Chrome WebDriver options to connect to the existing browser instance
74-
chrome_options = Options()
75-
chrome_options.add_experimental_option("debuggerAddress", "localhost:9222")
76-
77-
# Brave binary location on macOS
78-
brave_path = "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser"
79-
chrome_options.binary_location = brave_path
80-
75+
8176
try:
82-
# Connect to the existing browser instance
83-
driver = webdriver.Chrome(options=chrome_options)
84-
print("Connected to existing browser for logout")
85-
8677
# Monitor Unity logs for logout URL
8778
print("Monitoring Unity logs for logout URL...")
8879
logout_url = None
@@ -93,17 +84,8 @@ def logout_with_controlled_browser():
9384
time.sleep(1)
9485

9586
if logout_url:
96-
print(f"Navigating controlled browser to logout URL: {logout_url}")
97-
driver.get(logout_url)
98-
99-
# Wait for logout page to load
100-
time.sleep(3)
101-
print("Logout completed in controlled browser")
102-
103-
# Check final page
104-
current_url = driver.current_url
105-
print(f"Final logout URL: {current_url}")
106-
87+
print(f"Captured logout URL from Unity logs: {logout_url}")
88+
10789
# Extract the deep-link from the redirect
10890
# Look for immutablerunner://logout in the response or extract from returnTo parameter
10991
if 'returnTo=' in logout_url:
@@ -118,6 +100,10 @@ def logout_with_controlled_browser():
118100
print(f"Triggering deep-link manually: {return_to}")
119101
subprocess.run(['open', return_to], check=False)
120102
time.sleep(2)
103+
else:
104+
print("Warning: returnTo parameter present but could not be parsed.")
105+
else:
106+
print("Warning: logout URL did not include returnTo; cannot trigger deep-link callback.")
121107

122108
else:
123109
print("Could not find logout URL in Unity logs - logout may complete without browser interaction")

sample/Tests/test/test_windows_helpers.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,25 @@ def logout_with_controlled_browser():
377377
# Check final page
378378
current_url = driver.current_url
379379
print(f"Final logout URL: {current_url}")
380+
381+
# Fallback: dispatch returnTo deep-link via registry so Unity can process it even when
382+
# Windows shows "Get an app to open this 'immutablerunner' link" and blocks the protocol.
383+
try:
384+
if "returnTo=" in logout_url:
385+
import re
386+
from urllib.parse import unquote
387+
388+
match = re.search(r"returnTo=([^&]+)", logout_url)
389+
if match:
390+
return_to = unquote(match.group(1))
391+
print(f"Extracted returnTo deep-link: {return_to}")
392+
if _write_deeplink_registry(return_to):
393+
print("Wrote logout returnTo deep-link to registry (fallback).")
394+
time.sleep(2)
395+
else:
396+
print("Warning: returnTo parameter present but could not be parsed.")
397+
except Exception as dispatch_err:
398+
print(f"Warning: failed to dispatch logout deep-link via registry: {dispatch_err}")
380399

381400
else:
382401
print("Could not find logout URL in Unity logs - logout may complete without browser interaction")

0 commit comments

Comments
 (0)