Changeset 79949 in webkit


Ignore:
Timestamp:
Feb 28, 2011 5:31:35 PM (13 years ago)
Author:
tonyg@chromium.org
Message:

2011-02-28 Tony Gentilcore <tonyg@chromium.org>

Reviewed by Darin Adler.

Fix race condition in 4 media tests
https://bugs.webkit.org/show_bug.cgi?id=55414

The parser may yield and give events a chance to dispatch between any two tokens. So
it is possible that the loadstart event fires immediately after the video tag is
inserted into the document but before the subsequent script is parsed. This is very
rare in the layout test environment since these small files are loaded from disk.

This patch eliminates that race condition by allowing waitForEvent to register for
events that bubble up to the document from any element. Then the registration can
happen before before the element is inserted into the document.

  • media/video-source-media.html:
  • media/video-source-none-supported.html:
  • media/video-source-type-params.html:
  • media/video-source-type.html:
  • media/video-test.js: (waitForEvent): (waitForEventAndTest):
Location:
trunk/LayoutTests
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r79944 r79949  
     12011-02-28  Tony Gentilcore  <tonyg@chromium.org>
     2
     3        Reviewed by Darin Adler.
     4
     5        Fix race condition in 4 media tests
     6        https://bugs.webkit.org/show_bug.cgi?id=55414
     7
     8        The parser may yield and give events a chance to dispatch between any two tokens. So
     9        it is possible that the loadstart event fires immediately after the video tag is
     10        inserted into the document but before the subsequent script is parsed. This is very
     11        rare in the layout test environment since these small files are loaded from disk.
     12
     13        This patch eliminates that race condition by allowing waitForEvent to register for
     14        events that bubble up to the document from any element. Then the registration can
     15        happen before before the element is inserted into the document.
     16
     17        * media/video-source-media.html:
     18        * media/video-source-none-supported.html:
     19        * media/video-source-type-params.html:
     20        * media/video-source-type.html:
     21        * media/video-test.js:
     22        (waitForEvent):
     23        (waitForEventAndTest):
     24
    1252011-02-28  Tony Gentilcore  <tonyg@chromium.org>
    226
  • trunk/LayoutTests/media/video-source-media.html

    r79630 r79949  
    11<body>
    22<script src=video-test.js></script>
     3<script>
     4    waitForEvent('loadstart', function () {
     5        video = mediaElement = document.getElementsByTagName('video')[0];
     6        testExpected("relativeURL(video.currentSrc)", "content/test.mp4");
     7        endTest();
     8    } );
     9</script>
    310<video controls>
    411    <source src=content/error.mpeg media="print">
     
    613    <source src=content/test.mp4 media="screen and (min-device-width: 100px)">
    714</video>
    8 <script>
    9     video = mediaElement = document.getElementsByTagName('video')[0];
    10     waitForEvent('loadstart', function () {
    11         testExpected("relativeURL(video.currentSrc)", "content/test.mp4");
    12         endTest();
    13     } );
    14 
    15 </script>
  • trunk/LayoutTests/media/video-source-none-supported.html

    r79630 r79949  
    55    <script src=video-test.js></script>
    66    <script>
    7 
    8         function setup()
    9         {
    10             findMediaElement();
    11             document.addEventListener("error", errorEvent, true);
    12         }
     7        document.addEventListener("error", errorEvent, true);
    138
    149        function errorEvent(evt)
    1510        {
     11            findMediaElement();
    1612            consoleWrite("++ ERROR, src = " + relativeURL(event.target.src) + ", type = \"" + event.target.type + "\"");
    1713            testExpected("event.target.tagName", "SOURCE", "==");
     
    4945    <p>1. Test that no usable &lt;source&gt; element leaves the media element with
    5046    networkState == NETWORK_NO_SOURCE</p>
    51 
    52     <script>setup();</script>
    5347</body>
    5448</html>
  • trunk/LayoutTests/media/video-source-type-params.html

    r79630 r79949  
    22<script src=media-file.js></script>
    33<script src=video-test.js></script>
     4<script>
     5    waitForEvent('loadstart', function () {
     6        video = mediaElement = document.getElementsByTagName('video')[0];
     7        testExpected("stripExtension(relativeURL(video.currentSrc))", stripExtension(findMediaFile("video", "content/test")));
     8        endTest();
     9    } );
     10</script>
    411<video controls>
    512    <source src=content/bogus.mpeg type="video/blahblah">
     
    815    <source src=content/error2.mpeg type=video/mpeg>
    916</video>
    10 <script>
    11     video = mediaElement = document.getElementsByTagName('video')[0];
    12     waitForEvent('loadstart', function () {
    13         testExpected("stripExtension(relativeURL(video.currentSrc))", stripExtension(findMediaFile("video", "content/test")));
    14         endTest();
    15     } );
    16 </script>
  • trunk/LayoutTests/media/video-source-type.html

    r79630 r79949  
    77    <script src=video-test.js></script>
    88    <script>
    9         function setup()
    10         {
     9        waitForEvent("loadstart", function () {
    1110            video = mediaElement = document.getElementsByTagName('video')[0];
    12        
    13             waitForEvent("loadstart", function () {
    14                 testExpected("stripExtension(relativeURL(video.currentSrc))", stripExtension(findMediaFile("video", "content/test")));
    15                 endTest();
    16             });
    17         }
     11            testExpected("stripExtension(relativeURL(video.currentSrc))", stripExtension(findMediaFile("video", "content/test")));
     12            endTest();
     13        });
    1814    </script>
    1915</head>
     
    2723        <source src=content/error2.mpeg type=video/mpeg>
    2824    </video>
    29     <script>setup();</script>
    3025</body>
    3126</html>
  • trunk/LayoutTests/media/video-test.js

    r79630 r79949  
    11
    22var video = null;
    3 var mediaElement = null;
     3var mediaElement = document; // If not set, an event from any element will trigger a waitForEvent() callback.
    44var console = null;
    55var printFullTestDetails = true; // This is optionaly switched of by test whose tested values can differ. (see disableFullTestDetailsPrinting())
     
    141141    }
    142142
    143     mediaElement.addEventListener(eventName, _eventCallback);
     143    mediaElement.addEventListener(eventName, _eventCallback, true);
    144144}
    145145
     
    163163    }
    164164
    165     mediaElement.addEventListener(eventName, _eventCallback);
     165    mediaElement.addEventListener(eventName, _eventCallback, true);
    166166}
    167167
Note: See TracChangeset for help on using the changeset viewer.