Skip to content

Commit

Permalink
Add reflected IDL property for popup [popup 3/N]
Browse files Browse the repository at this point in the history
This CL just adds a Reflected `popup` IDL attribute for the
`popup` content attribute, plus associated testing.

Note: some existing web_tests/WPTs had to be modified slightly, to avoid
a namespace collision between global event handler content attributes
that called a function called "popup()", and the new 'popup' content
attribute. In those cases, the inline event handler runs with |this|
set to the element, so 'popup()' evaluates to 'this.popup()' which is
(now) an error due to the new 'popup' attribute. This might bode poorly
for general web compat - we'll see.

Bug: 1307772
Change-Id: I0218a1aa56f63c4965835b6457b3655bdf78aedd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3556371
Auto-Submit: Mason Freed <masonf@chromium.org>
Reviewed-by: David Baron <dbaron@chromium.org>
Commit-Queue: David Baron <dbaron@chromium.org>
Cr-Commit-Position: refs/heads/main@{#987017}
  • Loading branch information
Mason Freed authored and Chromium LUCI CQ committed Mar 30, 2022
1 parent 5ebce23 commit 765f2ba
Show file tree
Hide file tree
Showing 13 changed files with 77 additions and 28 deletions.
1 change: 1 addition & 0 deletions third_party/blink/renderer/core/dom/element.idl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ callback ScrollStateCallback = void (ScrollState scrollState);
// The Popup API
[MeasureAs=ElementShowPopup,RuntimeEnabled=HTMLPopupAttribute] void showPopup();
[MeasureAs=ElementHidePopup,RuntimeEnabled=HTMLPopupAttribute] void hidePopup();
[RuntimeEnabled=HTMLPopupAttribute,Reflect] attribute DOMString popup;

// Experimental accessibility API
[RuntimeEnabled=ComputedAccessibilityInfo] readonly attribute DOMString? computedRole;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@
assert_true(popupVisible(nonPopup, /*isPopup*/false));
}

function createPopup() {
const popup = document.createElement('div');
document.body.appendChild(popup);
popup.setAttribute('popup','popup');
return popup;
}

const popups = document.getElementById('popups').children;
for(let i=0;i<popups.length;++i) {
const popup = popups[i];
Expand All @@ -68,16 +61,49 @@
}, `The .showPopup() and .hidePopup() do NOT work on elements without a 'popup' attribute, case #${i}.`);
}

function createPopup() {
const popup = document.createElement('div');
document.body.appendChild(popup);
popup.setAttribute('popup','popup');
return popup;
}

test(() => {
const popup = createPopup();
assert_true(!!popup);
assert_false(popupVisible(popup, /*isPopup*/true));
assert_equals(popup.popup,'popup');
popup.setAttribute('popup','hint');
assert_equals(popup.popup,'hint');
popup.setAttribute('popup','invalid');
assert_equals(popup.popup,'invalid');
popup.setAttribute('popup','HiNt');
assert_equals(popup.popup,'HiNt');
popup.removeAttribute('popup');
assert_equals(popup.popup,'');
popup.popup='hint';
assert_equals(popup.getAttribute('popup'),'hint');
popup.popup='popup';
assert_equals(popup.getAttribute('popup'),'popup');
popup.popup='invalid';
assert_equals(popup.getAttribute('popup'),'invalid');
popup.popup='';
assert_equals(popup.getAttribute('popup'),'');
},'IDL attribute reflection')

test(() => {
const popup = createPopup();
assertIsFunctionalPopup(popup);

popup.setAttribute('popup','hint'); // Change popup type
assertIsFunctionalPopup(popup);

popup.setAttribute('popup','invalid'); // Change popup type to something invalid
assertNotAPopup(popup);

popup.popup = 'hint'; // Change popup type via IDL
assertIsFunctionalPopup(popup);

popup.popup = 'invalid'; // Make invalid via IDL
assertNotAPopup(popup);
},'Changing attribute values for popup should work')

test(() => {
Expand All @@ -90,5 +116,10 @@
popup.removeAttribute('popup');
popup.setAttribute('PoPuP','PoPuP');
assertIsFunctionalPopup(popup);
// Via IDL also
popup.popup = 'popup';
assertIsFunctionalPopup(popup);
popup.popup = 'PoPuP';
assertIsFunctionalPopup(popup);
},'Popup attribute value should be case insensitive')
</script>
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
CONSOLE MESSAGE: Found a 'popup' attribute with an invalid value.
This test passes if it does not crash.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
<body>
<button id="button1" onclick="testButton1()">Click Here</button>
<button id="button2" onclick="testButton2()">Click Here Too</button>
<button id="test" onclick="popup()" style="display:none"></button>
<button id="test" onclick="openPopup()" style="display:none"></button>
<script>
setup({explicit_done: true});

var testNum = 0;
var win;

function popup() {
function openPopup() {
win = window.open("about:blank", "blank");
assert_not_equals(win, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
Test that only a single popup is allowed in response to a single
user action. The test passes if only one popup is created.
</p>
<button id="button" onclick="popup()">Click Here</button>
<button id="button" onclick="openPopup()">Click Here</button>
<div id="console"></div>
<script>
function popup() {
function openPopup() {
window.open("about:blank", "window1");
window.open("about:blank", "window2");
if (window.testRunner) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<html>
<html>
<head>
<script src="../../resources/testharness.js"></script>
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<button id="test" onclick="popup()" style="display:none"></button>
<button id="test" onclick="openPopup()" style="display:none"></button>
<div id="console"></div>
<script>
<script>
var win;
function popup() {
function openPopup() {
win = window.open("about:blank", "blank");
assert_equals(win, null);
}

if (window.testRunner) {
testRunner.setPopupBlockingEnabled(true);
}

test(() => document.getElementById("test").click(), 'Fake button click');
</script>
</body>
</script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<script src="../../resources/testharnessreport.js"></script>
</head>
<body>
<textarea id="test" width="100" onfocus="popup()" onblur="popup()"></textarea>
<textarea id="test" width="100" onfocus="openPopup()" onblur="openPopup()"></textarea>

<script>
var win;
function popup() {
function openPopup() {
win = window.open("about:blank", "blank");
assert_equals(win, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Test that a forwarded user gesture that is consumed before the
time fires is resurrected.
</p>
<button id="button" onclick="popup()">Click Here</button>
<button id="button" onclick="openPopup()">Click Here</button>
<div id="console"></div>
<script>
function timer() {
Expand All @@ -21,7 +21,7 @@
}
}

function popup() {
function openPopup() {
setTimeout(timer, 0);
window.open("about:blank", "window1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Test that a forwarded user gesture can be consumed by any timeout,
not just the first.
</p>
<button id="button" onclick="popup()">Click Here</button>
<button id="button" onclick="openPopup()">Click Here</button>
<div id="console"></div>
<script>
function timer1() {
Expand All @@ -22,7 +22,7 @@
testRunner.notifyDone();
}

function popup() {
function openPopup() {
setTimeout(timer1, 0);
setTimeout(timer2, 10);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ Harness status: OK

Rerun

Found 3 tests
Found 4 tests

3 Pass
4 Pass
Details
Result Test Name Message
Pass Basic tests
Expand All @@ -19,3 +19,6 @@ Asserts run

Pass popup_attribute should be HTMLUnknownElement and should be stylable/visible
Asserts run

Pass The popup IDL attribute should not be present on Element
Asserts run
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,13 @@
assert_not_equals(window.getComputedStyle(el).display,'none');
},`${el.id} should be HTMLUnknownElement and should be stylable/visible`);
}

function supportsPopup() {
return Element.prototype.hasOwnProperty("popup");
}

test(() => {
assert_false(supportsPopup());
},`The popup IDL attribute should not be present on Element`);

</script>
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ namespace http://www.w3.org/1999/xhtml
property parentElement
property parentNode
property part
property popup
property prefix
property prepend
property previousElementSibling
Expand Down Expand Up @@ -1509,6 +1510,7 @@ namespace http://www.w3.org/2000/svg
property parentElement
property parentNode
property part
property popup
property prefix
property prepend
property previousElementSibling
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,7 @@ interface Element : Node
getter onwebkitfullscreenerror
getter outerHTML
getter part
getter popup
getter prefix
getter previousElementSibling
getter role
Expand Down Expand Up @@ -2382,6 +2383,7 @@ interface Element : Node
setter onwebkitfullscreenerror
setter outerHTML
setter part
setter popup
setter role
setter scrollLeft
setter scrollTop
Expand Down

0 comments on commit 765f2ba

Please sign in to comment.