<!doctype html>
<html>
    <head>
        <title>touch-action: parent: none + two embedded children</title>
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" type="text/css" href="pointerevent_styles.css">
        <script src="/resources/testharness.js"></script>
        <script src="/resources/testharnessreport.js"></script>
        <script src="/resources/testdriver.js"></script>
        <script src="/resources/testdriver-actions.js"></script>
        <script src="/resources/testdriver-vendor.js"></script>
        <script src="pointerevent_support.js"></script>
        <style>
            #divParent {
            touch-action: none;
            }
        </style>
    </head>
    <body onload="run()">
        <h1>Pointer Events touch-action attribute support</h1>
        <h4 id="desc">Test Description: Try to scroll text DOWN inside blue rectangle. Wait for description update. Expected: pan enabled</h4>
        <p>Note: this test is for touch-devices only</p>
        <div id="divParent">
            <div class="scroller" id="target0">
                <div id="scrollTarget">
                    <p>
                        Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem
                        nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat.
                        Ut wisis enim ad minim veniam, quis nostrud exerci tution ullamcorper suscipit
                        lobortis nisl ut aliquip ex ea commodo consequat.
                    </p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>
                        Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem
                        nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat.
                        Ut wisis enim ad minim veniam, quis nostrud exerci tution ullamcorper suscipit
                        lobortis nisl ut aliquip ex ea commodo consequat.
                    </p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>
                        Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem
                        nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat.
                        Ut wisis enim ad minim veniam, quis nostrud exerci tution ullamcorper suscipit
                        lobortis nisl ut aliquip ex ea commodo consequat.
                    </p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>
                        Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diem
                        nonummy nibh euismod tincidunt ut lacreet dolore magna aliguam erat volutpat.
                        Ut wisis enim ad minim veniam, quis nostrud exerci tution ullamcorper suscipit
                        lobortis nisl ut aliquip ex ea commodo consequat.
                    </p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                    <p>Lorem ipsum dolor sit amet...</p>
                </div>
            </div>
        </div>
        <script type='text/javascript'>
            var detected_pointertypes = {};

            var xScrollIsReceived = false;
            var yScrollIsReceived = false;
            var xScr0, yScr0, xScr1, yScr1;

            add_completion_callback(showPointerTypes);
            add_completion_callback(enableScrolling);

            function run() {
                var target0 = document.getElementById("target0");

                var test_touchaction = async_test("touch-action attribute test");
                var actions_promise;

                xScr0 = target0.scrollLeft;
                yScr0 = target0.scrollTop;

                on_event(target0, 'pointerdown', function(event) {
                    detected_pointertypes[event.pointerType] = true;
                });

                // Check if touch-action attribute works properly for embedded divs
                //
                // TA: 15.
                on_event(target0, 'scroll', function(event) {
                    xScr1 = target0.scrollLeft;
                    yScr1 = target0.scrollTop;

                    if(xScr1 != xScr0) {
                        xScrollIsReceived = true;
                    }

                    if(yScr1 != yScr0) {
                        yScrollIsReceived = true;
                        updateDescriptionNextStep();
                    }

                    if(xScrollIsReceived && yScrollIsReceived) {
                        // Make sure the test finishes after all the input actions are completed.
                        actions_promise.then( () => {
                            test_touchaction.done();
                        });
                        updateDescriptionComplete();
                    }
                });

                // Inject touch inputs and wait for all the actions finish to end the test.
                actions_promise = touchScrollInTarget(target0, 'down').then(function() {
                    return touchScrollInTarget(target0, 'right');
                });
            }

            function enableScrolling() {
                document.getElementById('divParent').setAttribute('style', 'touch-action: auto');
            }
        </script>
        <h1>behaviour: auto</h1>
        <div id="complete-notice">
            <p>The following pointer types were detected: <span id="pointertype-log"></span>.</p>
        </div>
        <div id="log"></div>
    </body>
</html>