browser_rules_edit-value-after-name_04.js (2320B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Tests that clicking on a property's value URL while editing the property name 7 // will open the link in a new tab. See also Bug 1248274. 8 9 const TEST_URI = ` 10 <style type="text/css"> 11 #testid { 12 background: url("https://example.com/browser/devtools/client/inspector/rules/test/doc_test_image.png"), linear-gradient(white, #F06 400px); 13 } 14 </style> 15 <div id="testid">Styled Node</div> 16 `; 17 18 add_task(async function () { 19 await addTab("data:text/html;charset=utf-8," + encodeURIComponent(TEST_URI)); 20 const { inspector, view } = await openRuleView(); 21 22 info("Test click on background-image url while editing property name"); 23 24 await selectNode("#testid", inspector); 25 const ruleEditor = getRuleViewRuleEditor(view, 1); 26 const propEditor = ruleEditor.rule.textProps[0].editor; 27 const anchor = propEditor.valueSpan.querySelector( 28 ".ruleview-propertyvalue .theme-link" 29 ); 30 31 info("Focus the background name span"); 32 await focusEditableField(view, propEditor.nameSpan); 33 const editor = inplaceEditor(propEditor.doc.activeElement); 34 35 info( 36 "Modify the property to background to trigger the " + 37 "property-value-updated event" 38 ); 39 editor.input.value = "background-image"; 40 41 const onRuleViewChanged = view.once("ruleview-changed"); 42 const onPropertyValueUpdate = view.once("property-value-updated"); 43 const onTabOpened = waitForTab(); 44 45 info("blur propEditor.nameSpan by clicking on the link"); 46 // The url can be wrapped across multiple lines, and so we click the lower left corner 47 // of the anchor to make sure to target the link. 48 const rect = anchor.getBoundingClientRect(); 49 EventUtils.synthesizeMouse( 50 anchor, 51 2, 52 rect.height - 2, 53 {}, 54 propEditor.doc.defaultView 55 ); 56 57 info( 58 "wait for ruleview-changed event to be triggered to prevent pending requests" 59 ); 60 await onRuleViewChanged; 61 62 info("wait for the property value to be updated"); 63 await onPropertyValueUpdate; 64 65 info("wait for the image to be open in a new tab"); 66 const tab = await onTabOpened; 67 ok(true, "A new tab opened"); 68 69 is( 70 tab.linkedBrowser.currentURI.spec, 71 anchor.href, 72 "The URL for the new tab is correct" 73 ); 74 75 gBrowser.removeTab(tab); 76 });