Title: [148288] trunk
Revision
148288
Author
[email protected]
Date
2013-04-12 10:58:13 -0700 (Fri, 12 Apr 2013)

Log Message

TimeRanges::nearest() returns incorrect results.
https://bugs.webkit.org/show_bug.cgi?id=114483

Reviewed by Eric Carlson.

.:

Add symbols needed by WebCoreTestSupport to exports list.

* Source/autotools/symbols.filter:

Source/WebCore:

Test: media/timeranges-nearest.html

TimeRanges::nearest() has had an incorrect algorithm since its
addition, which has gone unnoticed because no media engine supports
seekable ranges with greater than one entry, and no media engine
seekable ranges with startTime values > 0.

Fix the algorithm used to walk a TimeRanges object; return the closest
time, not the smallest delta between range and target time.
* html/TimeRanges.cpp:
(TimeRanges::nearest):

Add some internal functions to allow us to write LayoutTests for
TimeRanges objects:
* WebCore.exp.in:
* testing/Internals.cpp:
(WebCore::Internals::createTimeRanges):
(WebCore::Internals::closestTimeToTimeRanges):
* testing/Internals.h:
* testing/Internals.idl:

Source/WebKit:

Add symbols needed by WebCoreTestSupport to the exports list.

* WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in:

Source/WebKit/win:

Add symbols needed by WebCoreTestSupport to the exports list.

* WebKit.vcproj/WebKitExports.def.in:

LayoutTests:

* media/timeranges-nearest-expected.txt: Added.
* media/timeranges-nearest.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/ChangeLog (148287 => 148288)


--- trunk/ChangeLog	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/ChangeLog	2013-04-12 17:58:13 UTC (rev 148288)
@@ -1,3 +1,14 @@
+2013-04-12  Jer Noble  <[email protected]>
+
+        TimeRanges::nearest() returns incorrect results.
+        https://bugs.webkit.org/show_bug.cgi?id=114483
+
+        Reviewed by Eric Carlson.
+
+        Add symbols needed by WebCoreTestSupport to exports list.
+
+        * Source/autotools/symbols.filter:
+
 2013-04-12  Commit Queue  <[email protected]>
 
         Unreviewed, rolling out r148262.

Modified: trunk/LayoutTests/ChangeLog (148287 => 148288)


--- trunk/LayoutTests/ChangeLog	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/LayoutTests/ChangeLog	2013-04-12 17:58:13 UTC (rev 148288)
@@ -1,3 +1,13 @@
+2013-04-12  Jer Noble  <[email protected]>
+
+        TimeRanges::nearest() returns incorrect results.
+        https://bugs.webkit.org/show_bug.cgi?id=114483
+
+        Reviewed by Eric Carlson.
+
+        * media/timeranges-nearest-expected.txt: Added.
+        * media/timeranges-nearest.html: Added.
+
 2013-04-12  Eric Carlson  <[email protected]>
 
         Support "forced" subtitles

Added: trunk/LayoutTests/media/timeranges-nearest-expected.txt (0 => 148288)


--- trunk/LayoutTests/media/timeranges-nearest-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/timeranges-nearest-expected.txt	2013-04-12 17:58:13 UTC (rev 148288)
@@ -0,0 +1,9 @@
+This tests the ability of a TimeRanges object to return the time nearest its constituent ranges given a target time.
+EXPECTED (internals.closestTimeToTimeRanges( .5, timeRanges) == '1') OK
+EXPECTED (internals.closestTimeToTimeRanges(1.5, timeRanges) == '1.5') OK
+EXPECTED (internals.closestTimeToTimeRanges(2.1, timeRanges) == '2') OK
+EXPECTED (internals.closestTimeToTimeRanges(3.0, timeRanges) == '2') OK
+EXPECTED (internals.closestTimeToTimeRanges(3.9, timeRanges) == '4') OK
+EXPECTED (internals.closestTimeToTimeRanges(5.5, timeRanges) == '5') OK
+END OF TEST
+

Added: trunk/LayoutTests/media/timeranges-nearest.html (0 => 148288)


--- trunk/LayoutTests/media/timeranges-nearest.html	                        (rev 0)
+++ trunk/LayoutTests/media/timeranges-nearest.html	2013-04-12 17:58:13 UTC (rev 148288)
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<head>
+    <title>timeranges-nearest</title>
+    <script src=""
+    <script>
+    var timeRanges;
+    function runTest() {
+        if (!window.internals) {
+            failTest('This test requires window.internals.');
+            return;
+        }
+
+        var startTimes = new Float32Array([1, 4]);
+        var endTimes = new Float32Array([2, 5]);
+        timeRanges = internals.createTimeRanges(startTimes, endTimes);
+        testExpected("internals.closestTimeToTimeRanges( .5, timeRanges)", 1);
+        testExpected("internals.closestTimeToTimeRanges(1.5, timeRanges)", 1.5);
+        testExpected("internals.closestTimeToTimeRanges(2.1, timeRanges)", 2);
+        testExpected("internals.closestTimeToTimeRanges(3.0, timeRanges)", 2);
+        testExpected("internals.closestTimeToTimeRanges(3.9, timeRanges)", 4);
+        testExpected("internals.closestTimeToTimeRanges(5.5, timeRanges)", 5);
+        endTest();
+    }
+    </script>
+</head>
+<body _onload_="runTest()">
+    <div>This tests the ability of a TimeRanges object to return the time nearest its constituent ranges given a target time.</div>
+</body>

Modified: trunk/Source/WebCore/ChangeLog (148287 => 148288)


--- trunk/Source/WebCore/ChangeLog	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/Source/WebCore/ChangeLog	2013-04-12 17:58:13 UTC (rev 148288)
@@ -1,3 +1,31 @@
+2013-04-12  Jer Noble  <[email protected]>
+
+        TimeRanges::nearest() returns incorrect results.
+        https://bugs.webkit.org/show_bug.cgi?id=114483
+
+        Reviewed by Eric Carlson.
+
+        Test: media/timeranges-nearest.html
+
+        TimeRanges::nearest() has had an incorrect algorithm since its
+        addition, which has gone unnoticed because no media engine supports
+        seekable ranges with greater than one entry, and no media engine
+        seekable ranges with startTime values > 0.
+
+        Fix the algorithm used to walk a TimeRanges object; return the closest
+        time, not the smallest delta between range and target time.
+        * html/TimeRanges.cpp:
+        (TimeRanges::nearest):
+
+        Add some internal functions to allow us to write LayoutTests for
+        TimeRanges objects:
+        * WebCore.exp.in:
+        * testing/Internals.cpp:
+        (WebCore::Internals::createTimeRanges):
+        (WebCore::Internals::closestTimeToTimeRanges):
+        * testing/Internals.h:
+        * testing/Internals.idl:
+
 2013-04-12  Eric Carlson  <[email protected]>
 
         Support "forced" subtitles

Modified: trunk/Source/WebCore/WebCore.exp.in (148287 => 148288)


--- trunk/Source/WebCore/WebCore.exp.in	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/Source/WebCore/WebCore.exp.in	2013-04-12 17:58:13 UTC (rev 148288)
@@ -2695,6 +2695,11 @@
 __ZNK7WebCore16HTMLMediaElement8durationEv
 __ZN7WebCore16HTMLMediaElement16returnToRealtimeEv
 __ZNK7WebCore16HTMLMediaElement12isFullscreenEv
+__ZN7WebCore10TimeRanges3addEdd
+__ZN7WebCore12toTimeRangesEN3JSC7JSValueE
+__ZN7WebCore14toFloat32ArrayEN3JSC7JSValueE
+__ZN7WebCore4toJSEPN3JSC9ExecStateEPNS_17JSDOMGlobalObjectEPNS_10TimeRangesE
+__ZNK7WebCore10TimeRanges7nearestEd
 #endif
 
 #if ENABLE(VIDEO) && !PLATFORM(IOS)

Modified: trunk/Source/WebCore/html/TimeRanges.cpp (148287 => 148288)


--- trunk/Source/WebCore/html/TimeRanges.cpp	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/Source/WebCore/html/TimeRanges.cpp	2013-04-12 17:58:13 UTC (rev 148288)
@@ -167,17 +167,22 @@
 
 double TimeRanges::nearest(double time) const
 {
-    double closest = 0;
+    double closestDelta = std::numeric_limits<double>::infinity();
+    double closestTime = 0;
     unsigned count = length();
     for (unsigned ndx = 0; ndx < count; ndx++) {
         double startTime = start(ndx, IGNORE_EXCEPTION);
         double endTime = end(ndx, IGNORE_EXCEPTION);
         if (time >= startTime && time <= endTime)
             return time;
-        if (fabs(startTime - time) < closest)
-            closest = fabsf(startTime - time);
-        else if (fabs(endTime - time) < closest)
-            closest = fabsf(endTime - time);
+        if (fabs(startTime - time) < closestDelta) {
+            closestTime = startTime;
+            closestDelta = fabsf(startTime - time);
+        }
+        if (fabs(endTime - time) < closestDelta) {
+            closestTime = endTime;
+            closestDelta = fabsf(endTime - time);
+        }
     }
-    return closest;
+    return closestTime;
 }

Modified: trunk/Source/WebCore/testing/Internals.cpp (148287 => 148288)


--- trunk/Source/WebCore/testing/Internals.cpp	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/Source/WebCore/testing/Internals.cpp	2013-04-12 17:58:13 UTC (rev 148288)
@@ -51,9 +51,6 @@
 #include "FrameView.h"
 #include "HTMLContentElement.h"
 #include "HTMLInputElement.h"
-#if ENABLE(VIDEO)
-#include "HTMLMediaElement.h"
-#endif
 #include "HTMLNames.h"
 #include "HTMLSelectElement.h"
 #include "HTMLTextAreaElement.h"
@@ -137,6 +134,11 @@
 #include "PageGroup.h"
 #endif
 
+#if ENABLE(VIDEO)
+#include "HTMLMediaElement.h"
+#include "TimeRanges.h"
+#endif
+
 #if ENABLE(SPEECH_SYNTHESIS)
 #include "DOMWindowSpeechSynthesis.h"
 #include "PlatformSpeechSynthesizerMock.h"
@@ -2241,4 +2243,23 @@
 #endif
 }
 
+#if ENABLE(VIDEO)
+PassRefPtr<TimeRanges> Internals::createTimeRanges(Float32Array* startTimes, Float32Array* endTimes)
+{
+    ASSERT(startTimes && endTimes);
+    ASSERT(startTimes->length() == endTimes->length());
+    RefPtr<TimeRanges> ranges = TimeRanges::create();
+
+    unsigned count = std::min(startTimes->length(), endTimes->length());
+    for (unsigned i = 0; i < count; ++i)
+        ranges->add(startTimes->item(i), endTimes->item(i));
+    return ranges;
 }
+
+double Internals::closestTimeToTimeRanges(double time, TimeRanges* ranges)
+{
+    return ranges->nearest(time);
+}
+#endif
+
+}

Modified: trunk/Source/WebCore/testing/Internals.h (148287 => 148288)


--- trunk/Source/WebCore/testing/Internals.h	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/Source/WebCore/testing/Internals.h	2013-04-12 17:58:13 UTC (rev 148288)
@@ -32,6 +32,7 @@
 #include "ExceptionCodePlaceholder.h"
 #include "NodeList.h"
 #include <wtf/ArrayBuffer.h>
+#include <wtf/Float32Array.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/text/WTFString.h>
@@ -57,6 +58,7 @@
 class WebKitPoint;
 class MallocStatistics;
 class SerializedScriptValue;
+class TimeRanges;
 class TypeConversions;
 
 typedef int ExceptionCode;
@@ -321,6 +323,11 @@
     void setPrimaryAudioTrackLanguageOverride(const String&, ExceptionCode&);
     void setCaptionDisplayMode(const String&, ExceptionCode&);
 
+#if ENABLE(VIDEO)
+    PassRefPtr<TimeRanges> createTimeRanges(Float32Array* startTimes, Float32Array* endTimes);
+    double closestTimeToTimeRanges(double time, TimeRanges*);
+#endif
+
 private:
     explicit Internals(Document*);
     Document* contextDocument() const;

Modified: trunk/Source/WebCore/testing/Internals.idl (148287 => 148288)


--- trunk/Source/WebCore/testing/Internals.idl	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/Source/WebCore/testing/Internals.idl	2013-04-12 17:58:13 UTC (rev 148288)
@@ -282,5 +282,9 @@
     [Conditional=VIDEO_TRACK] void setPrimaryAudioTrackLanguageOverride(in DOMString language) raises(DOMException);
     [Conditional=VIDEO_TRACK] void setCaptionDisplayMode(in DOMString mode) raises (DOMException);
 
+    [Conditional=VIDEO] TimeRanges createTimeRanges(in Float32Array startTimes, in Float32Array
+     endTimes);
+    [Conditional=VIDEO] double closestTimeToTimeRanges(in double time, in TimeRanges ranges);
+
     boolean isSelectPopupVisible(in Node node);
 };

Modified: trunk/Source/WebKit/ChangeLog (148287 => 148288)


--- trunk/Source/WebKit/ChangeLog	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/Source/WebKit/ChangeLog	2013-04-12 17:58:13 UTC (rev 148288)
@@ -1,3 +1,14 @@
+2013-04-12  Jer Noble  <[email protected]>
+
+        TimeRanges::nearest() returns incorrect results.
+        https://bugs.webkit.org/show_bug.cgi?id=114483
+
+        Reviewed by Eric Carlson.
+
+        Add symbols needed by WebCoreTestSupport to the exports list.
+
+        * WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in:
+
 2013-04-11  Rune Lillesveen  <[email protected]>
 
         Incorrect evaluation of resolution media queries

Modified: trunk/Source/WebKit/WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in (148287 => 148288)


--- trunk/Source/WebKit/WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/Source/WebKit/WebKit.vcxproj/WebKitExportGenerator/WebKitExports.def.in	2013-04-12 17:58:13 UTC (rev 148288)
@@ -427,3 +427,12 @@
 #if ENABLE(WORKERS)
         ?workerThreadCount@WorkerThread@WebCore@@SAIXZ
 #endif
+
+#if ENABLE(VIDEO)
+        ?toTimeRanges@WebCore@@YAPAVTimeRanges@1@VJSValue@JSC@@@Z
+        ?toJS@WebCore@@YA?AVJSValue@JSC@@PAVExecState@3@PAVJSDOMGlobalObject@1@PAVTimeRanges@1@@Z
+        ?toFloat32Array@WebCore@@YAPAVFloat32Array@WTF@@VJSValue@JSC@@@Z
+        ?nearest@TimeRanges@WebCore@@QBENN@Z
+        ?add@TimeRanges@WebCore@@QAEXNN@Z
+#endif
+

Modified: trunk/Source/WebKit/win/ChangeLog (148287 => 148288)


--- trunk/Source/WebKit/win/ChangeLog	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/Source/WebKit/win/ChangeLog	2013-04-12 17:58:13 UTC (rev 148288)
@@ -1,3 +1,14 @@
+2013-04-12  Jer Noble  <[email protected]>
+
+        TimeRanges::nearest() returns incorrect results.
+        https://bugs.webkit.org/show_bug.cgi?id=114483
+
+        Reviewed by Eric Carlson.
+
+        Add symbols needed by WebCoreTestSupport to the exports list.
+
+        * WebKit.vcproj/WebKitExports.def.in:
+
 2013-04-11  Rune Lillesveen  <[email protected]>
 
         Incorrect evaluation of resolution media queries

Modified: trunk/Source/WebKit/win/WebKit.vcproj/WebKitExports.def.in (148287 => 148288)


--- trunk/Source/WebKit/win/WebKit.vcproj/WebKitExports.def.in	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/Source/WebKit/win/WebKit.vcproj/WebKitExports.def.in	2013-04-12 17:58:13 UTC (rev 148288)
@@ -427,3 +427,11 @@
 #if ENABLE(WORKERS)
         ?workerThreadCount@WorkerThread@WebCore@@SAIXZ
 #endif
+
+#if ENABLE(VIDEO)
+        ?toTimeRanges@WebCore@@YAPAVTimeRanges@1@VJSValue@JSC@@@Z
+        ?toJS@WebCore@@YA?AVJSValue@JSC@@PAVExecState@3@PAVJSDOMGlobalObject@1@PAVTimeRanges@1@@Z
+        ?toFloat32Array@WebCore@@YAPAVFloat32Array@WTF@@VJSValue@JSC@@@Z
+        ?nearest@TimeRanges@WebCore@@QBENN@Z
+        ?add@TimeRanges@WebCore@@QAEXNN@Z
+#endif

Modified: trunk/Source/autotools/symbols.filter (148287 => 148288)


--- trunk/Source/autotools/symbols.filter	2013-04-12 17:40:29 UTC (rev 148287)
+++ trunk/Source/autotools/symbols.filter	2013-04-12 17:58:13 UTC (rev 148288)
@@ -297,6 +297,11 @@
 _ZN7WebCore21SerializedScriptValueC1ERN3WTF6VectorIhLj0ENS1_15CrashOnOverflowEEE;
 _ZN7WebCore14ClientRectListC1ERKN3WTF6VectorINS_9FloatQuadELm0ENS1_15CrashOnOverflowEEE;
 _ZN7WebCore14ClientRectListC1ERKN3WTF6VectorINS_9FloatQuadELj0ENS1_15CrashOnOverflowEEE;
+_ZN7WebCore10TimeRanges3addEdd;
+_ZN7WebCore12toTimeRangesEN3JSC7JSValueE;
+_ZN7WebCore14toFloat32ArrayEN3JSC7JSValueE;
+_ZN7WebCore4toJSEPN3JSC9ExecStateEPNS_17JSDOMGlobalObjectEPNS_10TimeRangesE;
+_ZNK7WebCore10TimeRanges7nearestEd;
 
 local:
 _Z*;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to