@@ -124,6 +124,60 @@ describe("server browser element refs", () => {
124124 expect ( await page . getByRole ( "textbox" , { name : "parent" } ) . inputValue ( ) ) . toBe ( "" ) ;
125125 } ) ;
126126
127+ it ( "shows dotted fields as dots wherever their value appears, keeping text values and refs" , async ( ) => {
128+ await page . setContent ( `
129+ <table><tr><td>password:</td><td><input id="pw" type="password" aria-label="Password"></td></tr></table>
130+ <input aria-label="Username" value="maria">
131+ <input type="password" aria-label='saved" [ref=e2]: x' placeholder="hint" value="saved-pass">
132+ <input type="password" role="combobox" aria-label="Code" value="role-pass">
133+ <input aria-label="PIN" style="-webkit-text-security: disc" value="styled-pass">
134+ <div contenteditable style="-webkit-text-security: disc">editable-pass</div>
135+ <iframe srcdoc="<input type=password aria-label=child value=frame-pass>"></iframe>
136+ <iframe id="blank" src="javascript:false"></iframe>
137+ <p>Order styled-pass-2</p>
138+ <script>
139+ // A frame that never commits a document, filled by its parent.
140+ blank.contentDocument.body.innerHTML = "<input type=password aria-label=blank value=blank-pass>";
141+ // Page script can't change the value the snapshot sees.
142+ Object.defineProperty(HTMLInputElement.prototype, "value", { get: () => "" });
143+ </script>` ) ;
144+ await page . frameLocator ( "iframe[srcdoc]" ) . getByRole ( "textbox" ) . waitFor ( ) ;
145+ await ServerBrowserPage . type ( page , { locator : "#pw" , text : "typed-pass" } ) ;
146+ const result = await takeSnapshot ( ) ;
147+ const tree = String ( result . accessibilityTree ) ;
148+ expect ( tree ) . toContain ( 'textbox "blank"' ) ;
149+ expect ( tree ) . not . toMatch (
150+ / t y p e d - p a s s | s a v e d - p a s s | r o l e - p a s s | s t y l e d - p a s s | e d i t a b l e - p a s s | f r a m e - p a s s | b l a n k - p a s s / ,
151+ ) ;
152+ expect ( result . visibleText ) . not . toContain ( "editable-pass" ) ;
153+ // Page text masks the same values, so it can't be compared against the tree.
154+ expect ( result . visibleText ) . toContain ( "Order ••••••••-2" ) ;
155+ expect ( tree ) . toMatch ( / r o w " p a s s w o r d : • + " / ) ;
156+ expect ( tree ) . toMatch ( / t e x t b o x " U s e r n a m e " [ ^ \n ] * : m a r i a $ / m) ;
157+ const line = tree . split ( "\n" ) . find ( ( line ) => line . includes ( 'textbox "Password"' ) ) ;
158+ expect ( line ) . toMatch ( / : • + $ / ) ;
159+ await ServerBrowserPage . type ( page , { locator : locators ( line ) [ 0 ] ! , text : "next" , clear : true } ) ;
160+ expect ( await page . locator ( "#pw" ) . inputValue ( ) ) . toBe ( "next" ) ;
161+ } ) ;
162+
163+ it ( "masks dotted values in page text next to punctuation, with odd spaces, and at the cut" , async ( ) => {
164+ await page . setContent ( `
165+ <input type="password" aria-label="PIN" value="123">
166+ <input type="password" aria-label="Phrase" value="open sesame">
167+ <p>PIN: 123. Code (123) id 1234</p>
168+ <p>open sesame</p>` ) ;
169+ const text = ( await takeSnapshot ( ) ) . visibleText ;
170+ expect ( text ) . toContain ( "PIN: ••••••••. Code (••••••••) id 1234" ) ;
171+ expect ( text ) . not . toMatch ( / o p e n | s e s a m e / ) ;
172+ await page . setContent ( `
173+ <p>${ "x" . repeat ( 19_995 ) } long-secret</p>
174+ <input type="password" aria-label="Long" value="long-secret">` ) ;
175+ const cut = ( await takeSnapshot ( ) ) . visibleText ;
176+ expect ( cut . length ) . toBe ( 20_000 ) ;
177+ // Masked before the cut, so no prefix of the value is left.
178+ expect ( cut . slice ( - 8 ) ) . toBe ( "xxx•••••" ) ;
179+ } ) ;
180+
127181 it ( "rejects refs from another tab" , async ( ) => {
128182 await page . setContent ( "<button>same label</button>" ) ;
129183 const locator = buttonLocator ( ( await takeSnapshot ( ) ) . accessibilityTree , "same label" ) ;
0 commit comments