Skip to content

Commit f5a89c1

Browse files
committed
Sign out through the drawer's account menu with the page's own controls, and look at the drawer's title through the DOM and a software path
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012xYtaUjbkB1hwLtK4TEzhq
1 parent d9a670a commit f5a89c1

3 files changed

Lines changed: 94 additions & 32 deletions

File tree

‎android-shell/app/src/androidTest/java/ai/openbot/shell/test/WebNavTest.kt‎

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,47 @@ open class WebNavTest : ShellTestBase() {
1919

2020
protected val homeText = "Start a conversation"
2121

22+
/** Opens the drawer with a real tap on the web app's toggle. */
2223
protected fun openDrawer(moment: String): Boolean {
2324
if (!check(tapWeb("Show sidebar"), "$moment: no 'Show sidebar' toggle")) return false
2425
return check(waitForState("overlay=1", 5_000), "$moment: the drawer did not open (the app saw no overlay): ${debugState()}")
2526
}
2627

27-
/** The web app's account button: "Account" in the phone app, else the person's name at the strip's foot. */
28+
/** The web app's account menu: the avatar at the foot of the drawer's rail, named after the person. */
2829
protected fun openAccountMenu(moment: String): Boolean {
29-
if (tapWeb("Account", 3_000)) return true
30-
if (!openDrawer(moment)) return false
30+
if (!drawer(moment)) return false
3131
sleep(600)
32-
return check(tapWeb("Sam Rivera", 5_000), "$moment: no account button in the drawer")
32+
return check(clickInPage("Sam Rivera"), "$moment: no account button in the drawer")
3333
}
3434

35+
/**
36+
* Clicks the page's own control named `text` (aria-label, or the smallest element whose text starts with
37+
* it) in the page: on the recording's busy emulator, a tap at a place read a moment earlier missed
38+
* menus that were still sliding in.
39+
*/
40+
protected fun clickInPage(text: String, timeoutMs: Long = 8_000): Boolean {
41+
val deadline = System.currentTimeMillis() + timeoutMs
42+
do {
43+
val done = pageString(
44+
"(function(t){var best=null;var all=document.querySelectorAll('a,button,[role=button],[role=menuitem],[role=link],[role=tab],span,div');" +
45+
"for(var i=0;i<all.length;i++){var e=all[i];var s=(e.innerText||'').trim();var al=e.getAttribute('aria-label');" +
46+
"if(al===t||s===t||(al&&al.indexOf(t)===0)||s.indexOf(t)===0){var r=e.getBoundingClientRect();if(r.width>0&&r.height>0&&(!best||r.width*r.height<best.a))best={a:r.width*r.height,e:e};}}" +
47+
"if(!best)return 'no';var c=best.e.closest('a,button,[role=button],[role=menuitem],[role=link],[role=tab]')||best.e;c.click();return 'yes';})(" +
48+
org.json.JSONObject.quote(text) + ")",
49+
)
50+
if (done == "yes") return true
51+
sleep(400)
52+
} while (System.currentTimeMillis() < deadline)
53+
note("tour: no '$text' to click")
54+
return false
55+
}
56+
57+
protected fun drawer(moment: String): Boolean {
58+
clickInPage("Show sidebar")
59+
return check(waitForState("overlay=1", 6_000), "$moment: the drawer did not open: ${debugState()}")
60+
}
61+
62+
3563
@Test
3664
fun testSignInToTheWebAppsOwnNavigation() {
3765
launch(MOCK_A, "web-nav")
@@ -111,7 +139,8 @@ open class WebNavTest : ShellTestBase() {
111139
if (!openAccountMenu("sign-out")) return
112140
sleep(800)
113141
screenshot("1-account-menu")
114-
if (!check(tapWeb("Sign out"), "no Sign out in the account menu")) return
142+
sleep(600)
143+
if (!check(clickInPage("Sign out"), "no Sign out in the account menu")) return
115144
check(waitFor("sign_in_button", 20_000) != null, "Sign out did not return to the native first screen: ${debugState()}")
116145
screenshot("2-first-screen")
117146
if (!check(signInThroughCustomTab("again", shots = false), "signing in again did not reach the web app")) return
@@ -136,4 +165,63 @@ open class WebNavTest : ShellTestBase() {
136165
checkEquals("Try again", find("retry_button")?.text, "Try again")
137166
screenshot("lock")
138167
}
168+
169+
/**
170+
* Is the drawer's damaged title (a grey block over "Conversations", "Bots" missing) the page or
171+
* the emulator's drawing? The DOM's own headings and boxes, then the same settled screen drawn on
172+
* a software canvas and with a software layer (test only), against the GPU screenshot.
173+
*/
174+
@Test
175+
fun testDrawerTitleRendering() {
176+
if (!launchSignedIn("drawer-render")) return
177+
check(waitPageText(homeText, 30_000), "no Home")
178+
sleep(800)
179+
for (panel in listOf("Conversations", "Bots")) {
180+
if (!drawer("render-$panel")) return
181+
if (panel == "Bots") clickInPage("Bots")
182+
sleep(2_500)
183+
screenshot("$panel-1-gpu")
184+
val dom = pageString(
185+
"(function(t){var d=document.querySelector('[role=dialog][data-open]');if(!d)return 'no drawer';" +
186+
"var hits=Array.prototype.filter.call(d.querySelectorAll('h1,h2,h3,[role=heading]'),function(e){return (e.innerText||'').trim()===t;});" +
187+
"return JSON.stringify({headings: hits.length, boxes: hits.map(function(e){var r=e.getBoundingClientRect();var c=getComputedStyle(e);" +
188+
"return {top:Math.round(r.top),left:Math.round(r.left),w:Math.round(r.width),h:Math.round(r.height),opacity:c.opacity,visibility:c.visibility,color:c.color};})," +
189+
"backdrop: Array.prototype.filter.call(d.querySelectorAll('*'),function(e){var c=getComputedStyle(e);return c.backdropFilter&&c.backdropFilter!=='none';}).length," +
190+
"drawerBackdrop: getComputedStyle(d).backdropFilter, overlayBackdrop: (function(){var o=document.querySelector('[data-slot=sheet-overlay]');return o?getComputedStyle(o).backdropFilter:null;})()});})(" +
191+
org.json.JSONObject.quote(panel) + ")",
192+
)
193+
note("drawer $panel: DOM $dom")
194+
check(dom.contains("\"headings\":1"), "$panel: the drawer does not have exactly 1 '$panel' heading: $dom")
195+
val web = find("openbot_webview")
196+
var view: android.webkit.WebView? = null
197+
instrumentation.runOnMainSync {
198+
val activity = androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry.getInstance()
199+
.getActivitiesInStage(androidx.test.runner.lifecycle.Stage.RESUMED).firstOrNull()
200+
fun walk(v: android.view.View) {
201+
if (view != null) return
202+
if (v is android.webkit.WebView) view = v
203+
if (v is android.view.ViewGroup) for (k in 0 until v.childCount) walk(v.getChildAt(k))
204+
}
205+
activity?.window?.decorView?.let { walk(it) }
206+
}
207+
val wv = view
208+
if (web != null && wv != null) {
209+
val file = java.io.File(instrumentation.targetContext.getExternalFilesDir(null), "drawer-$panel-software-canvas.png")
210+
instrumentation.runOnMainSync {
211+
val bitmap = android.graphics.Bitmap.createBitmap(wv.width, wv.height, android.graphics.Bitmap.Config.ARGB_8888)
212+
wv.draw(android.graphics.Canvas(bitmap))
213+
java.io.FileOutputStream(file).use { bitmap.compress(android.graphics.Bitmap.CompressFormat.PNG, 100, it) }
214+
}
215+
shell("cp ${file.absolutePath} $SHOTS/${testName}--$panel-2-software-canvas.png")
216+
instrumentation.runOnMainSync { wv.setLayerType(android.view.View.LAYER_TYPE_SOFTWARE, null) }
217+
sleep(2_500)
218+
screenshot("$panel-3-software-layer")
219+
instrumentation.runOnMainSync { wv.setLayerType(android.view.View.LAYER_TYPE_NONE, null) }
220+
sleep(1_000)
221+
}
222+
device.pressBack()
223+
waitForState("overlay=0", 5_000)
224+
sleep(800)
225+
}
226+
}
139227
}

‎android-shell/app/src/androidTest/java/ai/openbot/shell/test/WebNavTourTest.kt‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,6 @@ import org.junit.runner.RunWith
1313
class WebNavTourTest : WebNavTest() {
1414
private fun pause(ms: Long = 1_000) = sleep(ms)
1515

16-
/**
17-
* Clicks the page's own control named `text` (aria-label, or the smallest element whose text starts with
18-
* it) in the page: on the recording's busy emulator, a tap at a place read a moment earlier missed
19-
* menus that were still sliding in.
20-
*/
21-
private fun clickInPage(text: String, timeoutMs: Long = 8_000): Boolean {
22-
val deadline = System.currentTimeMillis() + timeoutMs
23-
do {
24-
val done = pageString(
25-
"(function(t){var best=null;var all=document.querySelectorAll('a,button,[role=button],[role=menuitem],[role=link],[role=tab],span,div');" +
26-
"for(var i=0;i<all.length;i++){var e=all[i];var s=(e.innerText||'').trim();var al=e.getAttribute('aria-label');" +
27-
"if(al===t||s===t||(al&&al.indexOf(t)===0)||s.indexOf(t)===0){var r=e.getBoundingClientRect();if(r.width>0&&r.height>0&&(!best||r.width*r.height<best.a))best={a:r.width*r.height,e:e};}}" +
28-
"if(!best)return 'no';var c=best.e.closest('a,button,[role=button],[role=menuitem],[role=link],[role=tab]')||best.e;c.click();return 'yes';})(" +
29-
org.json.JSONObject.quote(text) + ")",
30-
)
31-
if (done == "yes") return true
32-
sleep(400)
33-
} while (System.currentTimeMillis() < deadline)
34-
note("tour: no '$text' to click")
35-
return false
36-
}
37-
38-
private fun drawer(moment: String): Boolean {
39-
clickInPage("Show sidebar")
40-
return check(waitForState("overlay=1", 6_000), "$moment: the drawer did not open: ${debugState()}")
41-
}
42-
4316
@Test
4417
fun testWebNavTour() {
4518
mark("start")

‎android-shell/ci/run_tests.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
"WebNavTest#testSignOutAndRelaunch",
109109
"WebNavTest#testSignOutAndRelaunch_2_relaunch",
110110
"WebNavTest#testLockScreen",
111+
"WebNavTest#testDrawerTitleRendering",
111112
]
112113
# On mock stack A, in the lighter shard ("other") to keep the two shards even.
113114
HARDENING = [

0 commit comments

Comments
 (0)