<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[160749] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/160749">160749</a></dd>
<dt>Author</dt> <dd>jer.noble@apple.com</dd>
<dt>Date</dt> <dd>2013-12-17 21:37:02 -0800 (Tue, 17 Dec 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix TimeRanges::intersectWith
https://bugs.webkit.org/show_bug.cgi?id=118802

Source/WebCore:

Test: TestWebKitAPI/Tests/WebCore/TimeRanges.cpp.

Reviewed by Eric Carlson.

* WebCore.exp.in:
* WebCore.xcodeproj/project.pbxproj:
* html/TimeRanges.cpp:
(TimeRanges::invert):
(TimeRanges::intersectWith):

Merge
https://chromium.googlesource.com/chromium/blink/+/f557582b6c6283a8b165514f52d01cfd98130e85

Tools:

Reviewed by Eric Carlson.

Add unit tests for WebCore/TimeRanges.

* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
* TestWebKitAPI/Tests/WebCore/TimeRanges.cpp: Added.
(TestWebKitAPI::ToString):
(TestWebKitAPI::TEST):</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCoreexpin">trunk/Source/WebCore/WebCore.exp.in</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorehtmlTimeRangescpp">trunk/Source/WebCore/html/TimeRanges.cpp</a></li>
<li><a href="#trunkToolsChangeLog">trunk/Tools/ChangeLog</a></li>
<li><a href="#trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj">trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkToolsTestWebKitAPITestsWebCoreTimeRangescpp">trunk/Tools/TestWebKitAPI/Tests/WebCore/TimeRanges.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (160748 => 160749)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2013-12-18 04:32:23 UTC (rev 160748)
+++ trunk/Source/WebCore/ChangeLog        2013-12-18 05:37:02 UTC (rev 160749)
</span><span class="lines">@@ -1,3 +1,21 @@
</span><ins>+2013-12-17  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        Fix TimeRanges::intersectWith
+        https://bugs.webkit.org/show_bug.cgi?id=118802
+
+        Test: TestWebKitAPI/Tests/WebCore/TimeRanges.cpp.
+
+        Reviewed by Eric Carlson.
+
+        * WebCore.exp.in:
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/TimeRanges.cpp:
+        (TimeRanges::invert):
+        (TimeRanges::intersectWith):
+
+        Merge
+        https://chromium.googlesource.com/chromium/blink/+/f557582b6c6283a8b165514f52d01cfd98130e85        
+
</ins><span class="cx"> 2013-12-17  Eric Carlson  &lt;eric.carlson@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         ASSERT setting pseudoID with registered DOMSubtreeModified listener
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCoreexpin"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.exp.in (160748 => 160749)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.exp.in        2013-12-18 04:32:23 UTC (rev 160748)
+++ trunk/Source/WebCore/WebCore.exp.in        2013-12-18 05:37:02 UTC (rev 160749)
</span><span class="lines">@@ -1386,6 +1386,8 @@
</span><span class="cx"> __ZN7WebCore9plainTextEPKNS_5RangeENS_20TextIteratorBehaviorEb
</span><span class="cx"> __ZN7WebCore9toElementEN3JSC7JSValueE
</span><span class="cx"> __ZN7WebCore9unionRectERKN3WTF6VectorINS_9FloatRectELm0ENS0_15CrashOnOverflowEEE
</span><ins>+__ZN7WebCore10TimeRanges13intersectWithEPKS0_
+__ZN7WebCore10TimeRangesC1Edd
</ins><span class="cx"> __ZNK3JSC8Bindings10RootObject12globalObjectEv
</span><span class="cx"> __ZNK3WTF6String14createCFStringEv
</span><span class="cx"> __ZNK7WebCore10Credential11hasPasswordEv
</span><span class="lines">@@ -1418,6 +1420,9 @@
</span><span class="cx"> __ZNK7WebCore10StorageMap6lengthEv
</span><span class="cx"> __ZNK7WebCore10StorageMap7getItemERKN3WTF6StringE
</span><span class="cx"> __ZNK7WebCore10StorageMap8containsERKN3WTF6StringE
</span><ins>+__ZNK7WebCore10TimeRanges3endEjRi
+__ZNK7WebCore10TimeRanges4copyEv
+__ZNK7WebCore10TimeRanges5startEjRi
</ins><span class="cx"> __ZNK7WebCore11FrameLoader10isCompleteEv
</span><span class="cx"> __ZNK7WebCore11FrameLoader14cancelledErrorERKNS_15ResourceRequestE
</span><span class="cx"> __ZNK7WebCore11FrameLoader14frameHasLoadedEv
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (160748 => 160749)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2013-12-18 04:32:23 UTC (rev 160748)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2013-12-18 05:37:02 UTC (rev 160749)
</span><span class="lines">@@ -5786,7 +5786,7 @@
</span><span class="cx">                 E44613AB0CD6331000FADA75 /* HTMLVideoElement.h in Headers */ = {isa = PBXBuildFile; fileRef = E44613990CD6331000FADA75 /* HTMLVideoElement.h */; };
</span><span class="cx">                 E44613AD0CD6331000FADA75 /* MediaError.h in Headers */ = {isa = PBXBuildFile; fileRef = E446139B0CD6331000FADA75 /* MediaError.h */; };
</span><span class="cx">                 E44613AF0CD6331000FADA75 /* TimeRanges.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E446139D0CD6331000FADA75 /* TimeRanges.cpp */; };
</span><del>-                E44613B00CD6331000FADA75 /* TimeRanges.h in Headers */ = {isa = PBXBuildFile; fileRef = E446139E0CD6331000FADA75 /* TimeRanges.h */; };
</del><ins>+                E44613B00CD6331000FADA75 /* TimeRanges.h in Headers */ = {isa = PBXBuildFile; fileRef = E446139E0CD6331000FADA75 /* TimeRanges.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 E44613B60CD6344E00FADA75 /* VoidCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = E44613B40CD6344E00FADA75 /* VoidCallback.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 E44613E30CD6819F00FADA75 /* MediaPlayer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E4B41E0C0CBF90BD00AF2ECE /* MediaPlayer.cpp */; };
</span><span class="cx">                 E44613E40CD681A200FADA75 /* MediaPlayer.h in Headers */ = {isa = PBXBuildFile; fileRef = E4B41E0D0CBF90BD00AF2ECE /* MediaPlayer.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span></span></pre></div>
<a id="trunkSourceWebCorehtmlTimeRangescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/html/TimeRanges.cpp (160748 => 160749)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/html/TimeRanges.cpp        2013-12-18 04:32:23 UTC (rev 160748)
+++ trunk/Source/WebCore/html/TimeRanges.cpp        2013-12-18 05:37:02 UTC (rev 160749)
</span><span class="lines">@@ -58,13 +58,15 @@
</span><span class="cx">     if (!m_ranges.size())
</span><span class="cx">         inverted-&gt;add(negInf, posInf);
</span><span class="cx">     else {
</span><del>-        if (double start = m_ranges.first().m_start != negInf)
</del><ins>+        double start = m_ranges.first().m_start;
+        if (start != negInf)
</ins><span class="cx">             inverted-&gt;add(negInf, start);
</span><span class="cx"> 
</span><span class="cx">         for (size_t index = 0; index + 1 &lt; m_ranges.size(); ++index)
</span><span class="cx">             inverted-&gt;add(m_ranges[index].m_end, m_ranges[index + 1].m_start);
</span><span class="cx"> 
</span><del>-        if (double end = m_ranges.last().m_end != posInf)
</del><ins>+        double end = m_ranges.last().m_end;
+        if (end != posInf)
</ins><span class="cx">             inverted-&gt;add(end, posInf);
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="lines">@@ -74,12 +76,16 @@
</span><span class="cx"> void TimeRanges::intersectWith(const TimeRanges* other)
</span><span class="cx"> {
</span><span class="cx">     ASSERT(other);
</span><del>-    RefPtr&lt;TimeRanges&gt; inverted = copy();
</del><ins>+
+    if (other == this)
+        return;
+
</ins><span class="cx">     RefPtr&lt;TimeRanges&gt; invertedOther = other-&gt;copy();
</span><del>-    inverted-&gt;unionWith(invertedOther.get());
-    inverted-&gt;invert();
</del><ins>+    invertedOther-&gt;invert();
</ins><span class="cx"> 
</span><del>-    m_ranges.swap(inverted-&gt;m_ranges);
</del><ins>+    invert();
+    unionWith(invertedOther.get());
+    invert();
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void TimeRanges::unionWith(const TimeRanges* other)
</span></span></pre></div>
<a id="trunkToolsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Tools/ChangeLog (160748 => 160749)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/ChangeLog        2013-12-18 04:32:23 UTC (rev 160748)
+++ trunk/Tools/ChangeLog        2013-12-18 05:37:02 UTC (rev 160749)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2013-12-17  Jer Noble  &lt;jer.noble@apple.com&gt;
+
+        Fix TimeRanges::intersectWith
+        https://bugs.webkit.org/show_bug.cgi?id=118802
+
+        Reviewed by Eric Carlson.
+
+        Add unit tests for WebCore/TimeRanges.
+
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+        * TestWebKitAPI/Tests/WebCore/TimeRanges.cpp: Added.
+        (TestWebKitAPI::ToString):
+        (TestWebKitAPI::TEST):
+
</ins><span class="cx"> 2013-12-17  Alexey Proskuryakov  &lt;ap@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Botwatcher's dashboard ceases to update itself after a while
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestWebKitAPIxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (160748 => 160749)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2013-12-18 04:32:23 UTC (rev 160748)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj        2013-12-18 05:37:02 UTC (rev 160749)
</span><span class="lines">@@ -227,6 +227,7 @@
</span><span class="cx">                 CD5393C81757BA9700C07123 /* MD5.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD5393C71757BA9700C07123 /* MD5.cpp */; };
</span><span class="cx">                 CD5393CA1757BAC400C07123 /* SHA1.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD5393C91757BAC400C07123 /* SHA1.cpp */; };
</span><span class="cx">                 CD5497B415857F0C00B5BC30 /* MediaTime.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD5497B315857F0C00B5BC30 /* MediaTime.cpp */; };
</span><ins>+                CDC2C71517970DDB00E627FB /* TimeRanges.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDC2C7141797089D00E627FB /* TimeRanges.cpp */; };
</ins><span class="cx">                 CE14F1A4181873B0001C2705 /* WillPerformClientRedirectToURLCrash.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = CE14F1A2181873B0001C2705 /* WillPerformClientRedirectToURLCrash.html */; };
</span><span class="cx">                 CE32C7C818184C4900CD8C28 /* WillPerformClientRedirectToURLCrash.mm in Sources */ = {isa = PBXBuildFile; fileRef = CE32C7C718184C4900CD8C28 /* WillPerformClientRedirectToURLCrash.mm */; };
</span><span class="cx">                 E1220DA0155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = E1220D9F155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm */; };
</span><span class="lines">@@ -575,6 +576,7 @@
</span><span class="cx">                 CD5393C71757BA9700C07123 /* MD5.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MD5.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD5393C91757BAC400C07123 /* SHA1.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SHA1.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CD5497B315857F0C00B5BC30 /* MediaTime.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MediaTime.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                CDC2C7141797089D00E627FB /* TimeRanges.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TimeRanges.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 CE14F1A2181873B0001C2705 /* WillPerformClientRedirectToURLCrash.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = WillPerformClientRedirectToURLCrash.html; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 CE32C7C718184C4900CD8C28 /* WillPerformClientRedirectToURLCrash.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WillPerformClientRedirectToURLCrash.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E1220D9F155B25480013E2FC /* MemoryCacheDisableWithinResourceLoadDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MemoryCacheDisableWithinResourceLoadDelegate.mm; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -685,6 +687,7 @@
</span><span class="cx">                 440A1D3614A01000008A66F2 /* WebCore */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                CDC2C7141797089D00E627FB /* TimeRanges.cpp */,
</ins><span class="cx">                                 440A1D3814A0103A008A66F2 /* URL.cpp */,
</span><span class="cx">                                 14464012167A8305000BD218 /* LayoutUnit.cpp */,
</span><span class="cx">                         );
</span><span class="lines">@@ -1251,6 +1254,7 @@
</span><span class="cx">                                 261516D615B0E60500A2C201 /* SetAndUpdateCacheModel.mm in Sources */,
</span><span class="cx">                                 52B8CF9615868CF000281053 /* SetDocumentURI.mm in Sources */,
</span><span class="cx">                                 7C8DDAAB1735DEEE00EA5AC0 /* CloseThenTerminate.cpp in Sources */,
</span><ins>+                                CDC2C71517970DDB00E627FB /* TimeRanges.cpp in Sources */,
</ins><span class="cx">                                 51FCF79A1534AC6D00104491 /* ShouldGoToBackForwardListItem.cpp in Sources */,
</span><span class="cx">                                 C540F776152E4DA000A40C8C /* SimplifyMarkup.mm in Sources */,
</span><span class="cx">                                 C02B77F2126612140026BF0F /* SpacebarScrolling.cpp in Sources */,
</span></span></pre></div>
<a id="trunkToolsTestWebKitAPITestsWebCoreTimeRangescpp"></a>
<div class="addfile"><h4>Added: trunk/Tools/TestWebKitAPI/Tests/WebCore/TimeRanges.cpp (0 => 160749)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Tools/TestWebKitAPI/Tests/WebCore/TimeRanges.cpp                                (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebCore/TimeRanges.cpp        2013-12-18 05:37:02 UTC (rev 160749)
</span><span class="lines">@@ -0,0 +1,292 @@
</span><ins>+/*
+ * Copyright (c) 2013, Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following disclaimer
+ * in the documentation and/or other materials provided with the
+ * distribution.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &lt;WebCore/TimeRanges.h&gt;
+
+#include &lt;WebCore/ExceptionCodePlaceholder.h&gt;
+
+using namespace WebCore;
+
+namespace TestWebKitAPI {
+
+static std::string ToString(const TimeRanges&amp; ranges)
+{
+    std::stringstream ss;
+    ss &lt;&lt; &quot;{&quot;;
+    for (unsigned i = 0; i &lt; ranges.length(); ++i)
+        ss &lt;&lt; &quot; [&quot; &lt;&lt; ranges.start(i, IGNORE_EXCEPTION) &lt;&lt; &quot;,&quot; &lt;&lt; ranges.end(i, IGNORE_EXCEPTION) &lt;&lt; &quot;)&quot;;
+    ss &lt;&lt; &quot; }&quot;;
+
+    return ss.str();
+}
+
+#define ASSERT_RANGE(expected, range) EXPECT_EQ(expected, ToString(*range))
+
+TEST(TimeRanges, Empty)
+{
+    ASSERT_RANGE(&quot;{ }&quot;, TimeRanges::create());
+}
+
+TEST(TimeRanges, SingleRange)
+{
+    ASSERT_RANGE(&quot;{ [1,2) }&quot;, TimeRanges::create(1, 2));
+}
+
+TEST(TimeRanges, AddOrder)
+{
+    RefPtr&lt;TimeRanges&gt; rangeA = TimeRanges::create();
+    RefPtr&lt;TimeRanges&gt; rangeB = TimeRanges::create();
+
+    rangeA-&gt;add(0, 2);
+    rangeA-&gt;add(3, 4);
+    rangeA-&gt;add(5, 100);
+
+    std::string expected = &quot;{ [0,2) [3,4) [5,100) }&quot;;
+    ASSERT_RANGE(expected, rangeA);
+
+    // Add the values in rangeA to rangeB in reverse order.
+    for (int i = rangeA-&gt;length() - 1; i &gt;= 0; --i)
+        rangeB-&gt;add(rangeA-&gt;start(i, IGNORE_EXCEPTION), rangeA-&gt;end(i, IGNORE_EXCEPTION));
+
+    ASSERT_RANGE(expected, rangeB);
+}
+
+TEST(TimeRanges, OverlappingAdds)
+{
+    RefPtr&lt;TimeRanges&gt; ranges = TimeRanges::create();
+
+    ranges-&gt;add(0, 2);
+    ranges-&gt;add(10, 11);
+    ASSERT_RANGE(&quot;{ [0,2) [10,11) }&quot;, ranges);
+
+    ranges-&gt;add(0, 2);
+    ASSERT_RANGE(&quot;{ [0,2) [10,11) }&quot;, ranges);
+
+    ranges-&gt;add(2, 3);
+    ASSERT_RANGE(&quot;{ [0,3) [10,11) }&quot;, ranges);
+
+    ranges-&gt;add(2, 6);
+    ASSERT_RANGE(&quot;{ [0,6) [10,11) }&quot;, ranges);
+
+    ranges-&gt;add(9, 10);
+    ASSERT_RANGE(&quot;{ [0,6) [9,11) }&quot;, ranges);
+
+    ranges-&gt;add(8, 10);
+    ASSERT_RANGE(&quot;{ [0,6) [8,11) }&quot;, ranges);
+
+    ranges-&gt;add(-1, 7);
+    ASSERT_RANGE(&quot;{ [-1,7) [8,11) }&quot;, ranges);
+
+    ranges-&gt;add(6, 9);
+    ASSERT_RANGE(&quot;{ [-1,11) }&quot;, ranges);
+}
+
+TEST(TimeRanges, IntersectWith_Self)
+{
+    RefPtr&lt;TimeRanges&gt; ranges = TimeRanges::create(0, 2);
+
+    ASSERT_RANGE(&quot;{ [0,2) }&quot;, ranges);
+
+    ranges-&gt;intersectWith(ranges.get());
+
+    ASSERT_RANGE(&quot;{ [0,2) }&quot;, ranges);
+}
+
+TEST(TimeRanges, IntersectWith_IdenticalRange)
+{
+    RefPtr&lt;TimeRanges&gt; rangesA = TimeRanges::create(0, 2);
+    RefPtr&lt;TimeRanges&gt; rangesB = rangesA-&gt;copy();
+
+    ASSERT_RANGE(&quot;{ [0,2) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [0,2) }&quot;, rangesB);
+
+    rangesA-&gt;intersectWith(rangesB.get());
+
+    ASSERT_RANGE(&quot;{ [0,2) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [0,2) }&quot;, rangesB);
+}
+
+TEST(TimeRanges, IntersectWith_Empty)
+{
+    RefPtr&lt;TimeRanges&gt; rangesA = TimeRanges::create(0, 2);
+    RefPtr&lt;TimeRanges&gt; rangesB = TimeRanges::create();
+
+    ASSERT_RANGE(&quot;{ [0,2) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ }&quot;, rangesB);
+
+    rangesA-&gt;intersectWith(rangesB.get());
+
+    ASSERT_RANGE(&quot;{ }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ }&quot;, rangesB);
+}
+
+TEST(TimeRanges, IntersectWith_DisjointRanges1)
+{
+    RefPtr&lt;TimeRanges&gt; rangesA = TimeRanges::create();
+    RefPtr&lt;TimeRanges&gt; rangesB = TimeRanges::create();
+
+    rangesA-&gt;add(0, 1);
+    rangesA-&gt;add(4, 5);
+
+    rangesB-&gt;add(2, 3);
+    rangesB-&gt;add(6, 7);
+
+    ASSERT_RANGE(&quot;{ [0,1) [4,5) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [2,3) [6,7) }&quot;, rangesB);
+
+    rangesA-&gt;intersectWith(rangesB.get());
+
+    ASSERT_RANGE(&quot;{ }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [2,3) [6,7) }&quot;, rangesB);
+}
+
+TEST(TimeRanges, IntersectWith_DisjointRanges2)
+{
+    RefPtr&lt;TimeRanges&gt; rangesA = TimeRanges::create();
+    RefPtr&lt;TimeRanges&gt; rangesB = TimeRanges::create();
+
+    rangesA-&gt;add(0, 1);
+    rangesA-&gt;add(4, 5);
+
+    rangesB-&gt;add(1, 4);
+    rangesB-&gt;add(5, 7);
+
+    ASSERT_RANGE(&quot;{ [0,1) [4,5) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [1,4) [5,7) }&quot;, rangesB);
+
+    rangesA-&gt;intersectWith(rangesB.get());
+
+    ASSERT_RANGE(&quot;{ }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [1,4) [5,7) }&quot;, rangesB);
+}
+
+TEST(TimeRanges, IntersectWith_CompleteOverlap1)
+{
+    RefPtr&lt;TimeRanges&gt; rangesA = TimeRanges::create();
+    RefPtr&lt;TimeRanges&gt; rangesB = TimeRanges::create();
+
+    rangesA-&gt;add(1, 3);
+    rangesA-&gt;add(4, 5);
+    rangesA-&gt;add(6, 9);
+
+    rangesB-&gt;add(0, 10);
+
+    ASSERT_RANGE(&quot;{ [1,3) [4,5) [6,9) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [0,10) }&quot;, rangesB);
+
+    rangesA-&gt;intersectWith(rangesB.get());
+
+    ASSERT_RANGE(&quot;{ [1,3) [4,5) [6,9) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [0,10) }&quot;, rangesB);
+}
+
+TEST(TimeRanges, IntersectWith_CompleteOverlap2)
+{
+    RefPtr&lt;TimeRanges&gt; rangesA = TimeRanges::create();
+    RefPtr&lt;TimeRanges&gt; rangesB = TimeRanges::create();
+
+    rangesA-&gt;add(1, 3);
+    rangesA-&gt;add(4, 5);
+    rangesA-&gt;add(6, 9);
+
+    rangesB-&gt;add(1, 9);
+
+    ASSERT_RANGE(&quot;{ [1,3) [4,5) [6,9) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [1,9) }&quot;, rangesB);
+
+    rangesA-&gt;intersectWith(rangesB.get());
+
+    ASSERT_RANGE(&quot;{ [1,3) [4,5) [6,9) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [1,9) }&quot;, rangesB);
+}
+
+TEST(TimeRanges, IntersectWith_Gaps1)
+{
+    RefPtr&lt;TimeRanges&gt; rangesA = TimeRanges::create();
+    RefPtr&lt;TimeRanges&gt; rangesB = TimeRanges::create();
+
+    rangesA-&gt;add(0, 2);
+    rangesA-&gt;add(4, 6);
+
+    rangesB-&gt;add(1, 5);
+
+    ASSERT_RANGE(&quot;{ [0,2) [4,6) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [1,5) }&quot;, rangesB);
+
+    rangesA-&gt;intersectWith(rangesB.get());
+
+    ASSERT_RANGE(&quot;{ [1,2) [4,5) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [1,5) }&quot;, rangesB);
+}
+
+TEST(TimeRanges, IntersectWith_Gaps2)
+{
+    RefPtr&lt;TimeRanges&gt; rangesA = TimeRanges::create();
+    RefPtr&lt;TimeRanges&gt; rangesB = TimeRanges::create();
+
+    rangesA-&gt;add(0, 2);
+    rangesA-&gt;add(4, 6);
+    rangesA-&gt;add(8, 10);
+
+    rangesB-&gt;add(1, 9);
+
+    ASSERT_RANGE(&quot;{ [0,2) [4,6) [8,10) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [1,9) }&quot;, rangesB);
+
+    rangesA-&gt;intersectWith(rangesB.get());
+
+    ASSERT_RANGE(&quot;{ [1,2) [4,6) [8,9) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [1,9) }&quot;, rangesB);
+}
+
+TEST(TimeRanges, IntersectWith_Gaps3)
+{
+    RefPtr&lt;TimeRanges&gt; rangesA = TimeRanges::create();
+    RefPtr&lt;TimeRanges&gt; rangesB = TimeRanges::create();
+
+    rangesA-&gt;add(0, 2);
+    rangesA-&gt;add(4, 7);
+    rangesA-&gt;add(8, 10);
+
+    rangesB-&gt;add(1, 5);
+    rangesB-&gt;add(6, 9);
+
+    ASSERT_RANGE(&quot;{ [0,2) [4,7) [8,10) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [1,5) [6,9) }&quot;, rangesB);
+
+    rangesA-&gt;intersectWith(rangesB.get());
+
+    ASSERT_RANGE(&quot;{ [1,2) [4,5) [6,7) [8,9) }&quot;, rangesA);
+    ASSERT_RANGE(&quot;{ [1,5) [6,9) }&quot;, rangesB);
+}
+
+}
+
</ins></span></pre>
</div>
</div>

</body>
</html>