Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / browser / resources / media / disjoint_range_set_test.html
blob424fc65d3c5c63ba1ec5568505070fbed404f8ee
1 <!doctype html>
2 <html>
3 <!--
4 Copyright (c) 2011 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
7 -->
8 <head>
9 <title></title>
10 <script src="https://cdn.rawgit.com/google/closure-library/master/closure/goog/base.js"></script>
11 <script src="../../../../ui/webui/resources/js/cr.js"></script>
12 <script src="disjoint_range_set.js"></script>
13 <script>
14 goog.require('goog.testing.jsunit');
15 </script>
16 </head>
17 <body>
18 <script>
20 var range;
22 function assertRangeEquals(ranges) {
23 assertArrayEquals(
24 ranges, range.map(function(start, end) { return [start, end]; }));
27 function setUp() {
28 range = new media.DisjointRangeSet;
31 function testAdd() {
32 range.add(1, 6);
33 assertRangeEquals([[1, 6]]);
34 range.add(-5, -3);
35 assertRangeEquals([[-5, -3], [1, 6]]);
38 function testAddAdjacent() {
39 range.add(3, 6);
40 assertRangeEquals([[3, 6]]);
41 range.add(1, 2);
42 assertRangeEquals([[1, 6]]);
43 range.add(7, 9);
44 assertRangeEquals([[1, 9]]);
47 function testAddNotQuiteAdjacent() {
48 range.add(3, 6);
49 assertRangeEquals([[3, 6]]);
50 range.add(0, 1);
51 assertRangeEquals([[0, 1], [3, 6]]);
52 range.add(8, 9);
53 assertRangeEquals([[0, 1], [3, 6], [8, 9]]);
56 function testAddOverlapping() {
57 range.add(1, 6);
58 assertRangeEquals([[1, 6]]);
59 range.add(5, 8);
60 assertRangeEquals([[1, 8]]);
61 range.add(0, 1);
62 assertRangeEquals([[0, 8]]);
65 function testMax() {
66 assertNull(range.max());
67 range.add(1, 6);
68 assertEquals(range.max(), 6);
69 range.add(3, 8);
70 assertEquals(range.max(), 8);
71 range.remove(2, 3);
72 assertEquals(range.max(), 8);
73 range.remove(4, 10);
74 assertEquals(range.max(), 1);
75 range.remove(1, 1);
76 assertNull(range.max());
79 function testRemove() {
80 range.add(1, 20);
81 assertRangeEquals([[1, 20]]);
82 range.remove(0, 3);
83 assertRangeEquals([[4, 20]]);
84 range.remove(18, 20);
85 assertRangeEquals([[4, 17]]);
86 range.remove(5, 16);
87 assertRangeEquals([[4, 4], [17, 17]]);
90 function testStartsEmpty() {
91 assertRangeEquals([]);
94 </script>
95 </body>
96 </html>