<commit_before><!doctype html>
<title>activation behavior</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="media-file.js"></script>
<div id="log"></div>
<script>
function activation_behavior_test(tagName, src)
{
    async_test(function(t)
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.src = src;
        e.preload = 'auto';
        e.oncanplay = t.step_func(function()
        {
            assert_greater_than(e.readyState, e.HAVE_CURRENT_DATA, 'element readyState');
            e.controller = new MediaController();
            assert_false(e.controller.paused, 'controller paused state before click');
            assert_true(e.paused, 'element paused state before click');
            e.click();
            assert_false(e.controller.paused, 'controller paused state after click');
            assert_false(e.paused, 'element paused state after click');
            t.done();
        });
    }, tagName + ' activation behavior for restrained media controller');

    async_test(function(t)
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.src = src;
        e.preload = 'auto';
        e.oncanplay = t.step_func(function()
        {
            e.pause(); // clears autoplaying flag
            assert_greater_than(e.readyState, e.HAVE_CURRENT_DATA, 'element readyState');
            e.controller = new MediaController();
            assert_false(e.controller.paused, 'controller paused state before click');
            assert_true(e.paused, 'element paused state before click');
            e.click();
            assert_false(e.controller.paused, 'controller paused state after click');
            assert_false(e.paused, 'element paused state after click');
            t.done();
        });
    }, tagName + ' activation behavior for restrained media controller (with non-autoplaying paused slave)');

    async_test(function(t)
    {
        var e1 = document.createElement(tagName);
        var e2 = document.createElement(tagName);
        e1.controls = true;
        e1.src = e2.src = src;
        e1.preload = e2.preload = 'auto';
        var canplaycount = 0;
        e1.oncanplay = e2.oncanplay = t.step_func(function()
        {
            if (++canplaycount != 2) {
                return;
            }
            e1.play();
            assert_greater_than(e1.readyState, e1.HAVE_CURRENT_DATA, 'element 1 readyState');
            assert_greater_than(e2.readyState, e2.HAVE_CURRENT_DATA, 'element 2 readyState');
            e1.controller = new MediaController();
            e2.controller = e1.controller;
            assert_false(e1.controller.paused, 'controller paused state before click');
            assert_false(e1.paused, 'element 1 paused state before click');
            assert_true(e2.paused, 'element 2 paused state before click');
            e1.click();
            assert_false(e1.controller.paused, 'controller paused state after click');
            assert_false(e1.paused, 'element 1 paused state after click');
            assert_false(e2.paused, 'element 2 paused state after click');
            t.done();
        });
    }, tagName + ' activation behavior for restrained media controller (with non-blocked playing and autoplaying-and-paused slaves)');

    test(function()
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.controller = new MediaController();
        e.controller.pause();
        assert_true(e.controller.paused, 'controller paused state before click');
        assert_true(e.paused, 'element paused state before click');
        e.click();
        assert_false(e.controller.paused, 'controller paused state after click');
        assert_true(e.paused, 'element paused state after click');
    }, tagName + ' activation behavior for paused media controller');

    async_test(function(t)
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.src = src;
        e.preload = 'auto';
        e.oncanplay = t.step_func(function()
        {
            assert_greater_than(e.readyState, e.HAVE_CURRENT_DATA, 'element readyState');
            e.controller = new MediaController();
            e.controller.pause();
            assert_true(e.controller.paused, 'controller paused state before click');
            assert_true(e.paused, 'element paused state before click');
            e.click();
            assert_false(e.controller.paused, 'controller paused state after click');
            assert_true(e.paused, 'element paused state after click');
            t.done();
        });
    }, tagName + ' activation behavior for paused media controller (with non-blocked paused slave)');

    test(function()
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.controller = new MediaController();
        e.controller.play();
        assert_false(e.controller.paused, 'controller paused state before click');
        assert_false(e.paused, 'element paused state before click');
        e.click();
        assert_true(e.controller.paused, 'controller paused state after click');
        assert_false(e.paused, 'element paused state after click');
    }, tagName + ' activation behavior for playing media controller');

    async_test(function(t)
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.src = src;
        e.preload = 'auto';
        e.oncanplay = t.step_func(function()
        {
            e.play();
            assert_greater_than(e.readyState, e.HAVE_CURRENT_DATA, 'element readyState');
            e.controller = new MediaController();
            assert_false(e.controller.paused, 'controller paused state before click');
            assert_false(e.paused, 'element paused state before click');
            e.click();
            assert_true(e.controller.paused, 'controller paused state after click');
            assert_false(e.paused, 'element paused state after click');
            t.done();
        });
    }, tagName + ' activation behavior for playing media controller (with non-blocked playing slave)');

    async_test(function(t)
    {
        var e1 = document.createElement(tagName);
        var e2 = document.createElement(tagName);
        e1.controls = true;
        e1.src = src;
        e1.preload = 'auto';
        e1.oncanplay = t.step_func(function()
        {
            assert_greater_than(e1.readyState, e1.HAVE_CURRENT_DATA, 'element 1 readyState');
            assert_equals(e2.readyState, e2.HAVE_NOTHING, 'element 2 readyState');
            e1.controller = new MediaController();
            e2.controller = e1.controller;
            assert_false(e1.controller.paused, 'controller paused state before click');
            assert_true(e1.paused, 'element 1 paused state before click');
            assert_true(e2.paused, 'element 2 paused state before click');
            e1.click();
            assert_true(e1.controller.paused, 'controller paused state after click');
            assert_true(e1.paused, 'element 1 paused state after click');<commit_msg>Make media element sources unique to investigate flaky test<commit_after><!doctype html>
<title>activation behavior</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="media-file.js"></script>
<div id="log"></div>
<script>
var uniqueSrcCounter = 0;

function activation_behavior_test(tagName, src)
{
    // FIXME: hack used to investigate http://crbug.com/355489
    function uniqueSrc()
    {
        return src + '?activation-behavior-' + ++uniqueSrcCounter;
    }

    async_test(function(t)
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.src = uniqueSrc();
        e.preload = 'auto';
        e.oncanplay = t.step_func(function()
        {
            assert_greater_than(e.readyState, e.HAVE_CURRENT_DATA, 'element readyState');
            e.controller = new MediaController();
            assert_false(e.controller.paused, 'controller paused state before click');
            assert_true(e.paused, 'element paused state before click');
            e.click();
            assert_false(e.controller.paused, 'controller paused state after click');
            assert_false(e.paused, 'element paused state after click');
            t.done();
        });
    }, tagName + ' activation behavior for restrained media controller');

    async_test(function(t)
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.src = uniqueSrc();
        e.preload = 'auto';
        e.oncanplay = t.step_func(function()
        {
            e.pause(); // clears autoplaying flag
            assert_greater_than(e.readyState, e.HAVE_CURRENT_DATA, 'element readyState');
            e.controller = new MediaController();
            assert_false(e.controller.paused, 'controller paused state before click');
            assert_true(e.paused, 'element paused state before click');
            e.click();
            assert_false(e.controller.paused, 'controller paused state after click');
            assert_false(e.paused, 'element paused state after click');
            t.done();
        });
    }, tagName + ' activation behavior for restrained media controller (with non-autoplaying paused slave)');

    async_test(function(t)
    {
        var e1 = document.createElement(tagName);
        var e2 = document.createElement(tagName);
        e1.controls = true;
        e1.src = uniqueSrc();
        e2.src = uniqueSrc();
        e1.preload = e2.preload = 'auto';
        var canplaycount = 0;
        e1.oncanplay = e2.oncanplay = t.step_func(function()
        {
            if (++canplaycount != 2) {
                return;
            }
            e1.play();
            assert_greater_than(e1.readyState, e1.HAVE_CURRENT_DATA, 'element 1 readyState');
            assert_greater_than(e2.readyState, e2.HAVE_CURRENT_DATA, 'element 2 readyState');
            e1.controller = new MediaController();
            e2.controller = e1.controller;
            assert_false(e1.controller.paused, 'controller paused state before click');
            assert_false(e1.paused, 'element 1 paused state before click');
            assert_true(e2.paused, 'element 2 paused state before click');
            e1.click();
            assert_false(e1.controller.paused, 'controller paused state after click');
            assert_false(e1.paused, 'element 1 paused state after click');
            assert_false(e2.paused, 'element 2 paused state after click');
            t.done();
        });
    }, tagName + ' activation behavior for restrained media controller (with non-blocked playing and autoplaying-and-paused slaves)');

    test(function()
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.controller = new MediaController();
        e.controller.pause();
        assert_true(e.controller.paused, 'controller paused state before click');
        assert_true(e.paused, 'element paused state before click');
        e.click();
        assert_false(e.controller.paused, 'controller paused state after click');
        assert_true(e.paused, 'element paused state after click');
    }, tagName + ' activation behavior for paused media controller');

    async_test(function(t)
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.src = uniqueSrc();
        e.preload = 'auto';
        e.oncanplay = t.step_func(function()
        {
            assert_greater_than(e.readyState, e.HAVE_CURRENT_DATA, 'element readyState');
            e.controller = new MediaController();
            e.controller.pause();
            assert_true(e.controller.paused, 'controller paused state before click');
            assert_true(e.paused, 'element paused state before click');
            e.click();
            assert_false(e.controller.paused, 'controller paused state after click');
            assert_true(e.paused, 'element paused state after click');
            t.done();
        });
    }, tagName + ' activation behavior for paused media controller (with non-blocked paused slave)');

    test(function()
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.controller = new MediaController();
        e.controller.play();
        assert_false(e.controller.paused, 'controller paused state before click');
        assert_false(e.paused, 'element paused state before click');
        e.click();
        assert_true(e.controller.paused, 'controller paused state after click');
        assert_false(e.paused, 'element paused state after click');
    }, tagName + ' activation behavior for playing media controller');

    async_test(function(t)
    {
        var e = document.createElement(tagName);
        e.controls = true;
        e.src = uniqueSrc();
        e.preload = 'auto';
        e.oncanplay = t.step_func(function()
        {
            e.play();
            assert_greater_than(e.readyState, e.HAVE_CURRENT_DATA, 'element readyState');
            e.controller = new MediaController();
            assert_false(e.controller.paused, 'controller paused state before click');
            assert_false(e.paused, 'element paused state before click');
            e.click();
            assert_true(e.controller.paused, 'controller paused state after click');
            assert_false(e.paused, 'element paused state after click');
            t.done();
        });
    }, tagName + ' activation behavior for playing media controller (with non-blocked playing slave)');

    async_test(function(t)
    {
        var e1 = document.createElement(tagName);
        var e2 = document.createElement(tagName);
        e1.controls = true;
        e1.src = uniqueSrc();
        e1.preload = 'auto';
        e1.oncanplay = t.step_func(function()
        {
            assert_greater_than(e1.readyState, e1.HAVE_CURRENT_DATA, 'element 1 readyState');
            assert_equals(e2.readyState, e2.HAVE_NOTHING, 'element 2 readyState');
            e1.controller = new MediaController();
            e2.controller = e1.controller;
            assert_false(e1.controller.paused, 'controller paused state before click');
            assert_true(e1.paused, 'element 1 paused state before click');
            assert_true(e2.paused, 'element 2 paused state before click');
            e1.click();
            assert_true(e1.controller.paused, 'controller paused state after click');
            assert_true(e1.paused, 'element 1 paused state after click');
{'fraction_non_alphanumeric': 0.11340136054421769, 'fraction_numerical': 0.008095238095238095, 'mean_word_length': 2.469671937691763, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1202813', 'n_tokens_mistral': 4142, 'n_tokens_neox': 3971, 'n_words': 995}