diff options
author | kevers@chromium.org <kevers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 09:42:31 +0000 |
---|---|---|
committer | kevers@chromium.org <kevers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-06-21 09:42:31 +0000 |
commit | 0a48dd73f9ca59956de61683fdd59f844b3963c7 (patch) | |
tree | c127f5bae761c9c2606e54d7023ca8e0b74c53a9 /ui | |
parent | e8745108509371775c26a68bc677228dcce23c0d (diff) | |
download | chromium_src-0a48dd73f9ca59956de61683fdd59f844b3963c7.zip chromium_src-0a48dd73f9ca59956de61683fdd59f844b3963c7.tar.gz chromium_src-0a48dd73f9ca59956de61683fdd59f844b3963c7.tar.bz2 |
Port passing closure tests for cr.ui framework to browser tests. This CL deals with porting closure tests that require minimal formatting changes to run as browser tests.
BUG=249104
TEST=WebUIResourceBrowserTest
Review URL: https://chromiumcodereview.appspot.com/17315020
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@207770 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/webui/resources/js/cr/event_target_test.html | 137 | ||||
-rw-r--r-- | ui/webui/resources/js/cr/ui/array_data_model_test.html | 92 | ||||
-rw-r--r-- | ui/webui/resources/js/cr/ui/grid_test.html | 98 | ||||
-rw-r--r-- | ui/webui/resources/js/cr/ui/position_util_test.html | 310 |
4 files changed, 0 insertions, 637 deletions
diff --git a/ui/webui/resources/js/cr/event_target_test.html b/ui/webui/resources/js/cr/event_target_test.html deleted file mode 100644 index ec5f2f6..0000000 --- a/ui/webui/resources/js/cr/event_target_test.html +++ /dev/null @@ -1,137 +0,0 @@ -<!DOCTYPE html> -<html> -<head> -<!-- TODO(arv): Check in Closue unit tests and make this run as part of the - tests --> -<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script> -<script src="../cr.js"></script> -<script src="event_target.js"></script> -<script> - -goog.require('goog.testing.jsunit'); - -</script> -</head> -<body> -<script> - -const EventTarget = cr.EventTarget; -const Event = cr.Event; - -function testFunctionListener() { - var fi = 0; - function f(e) { - fi++; - } - - var gi = 0; - function g(e) { - gi++; - } - - var et = new EventTarget; - et.addEventListener('f', f); - et.addEventListener('g', g); - - // Adding again should not cause it to be called twice - et.addEventListener('f', f); - et.dispatchEvent(new Event('f')); - assertEquals('Should have been called once', 1, fi); - assertEquals(0, gi); - - et.removeEventListener('f', f); - et.dispatchEvent(new Event('f')); - assertEquals('Should not have been called again', 1, fi); - - et.dispatchEvent(new Event('g')); - assertEquals('Should have been called once', 1, gi); -} - -function testHandleEvent() { - var fi = 0; - var f = { - handleEvent: function(e) { - fi++; - } - }; - - var gi = 0; - var g = { - handleEvent: function(e) { - gi++; - } - }; - - var et = new EventTarget; - et.addEventListener('f', f); - et.addEventListener('g', g); - - // Adding again should not cause it to be called twice - et.addEventListener('f', f); - et.dispatchEvent(new Event('f')); - assertEquals('Should have been called once', 1, fi); - assertEquals(0, gi); - - et.removeEventListener('f', f); - et.dispatchEvent(new Event('f')); - assertEquals('Should not have been called again', 1, fi); - - et.dispatchEvent(new Event('g')); - assertEquals('Should have been called once', 1, gi); -} - -function testPreventDefault() { - var i = 0; - function prevent(e) { - i++; - e.preventDefault(); - } - - var j = 0; - function pass(e) { - j++; - } - - var et = new EventTarget; - et.addEventListener('test', pass); - - assertTrue(et.dispatchEvent(new Event('test'))); - assertEquals(1, j); - - et.addEventListener('test', prevent); - - console.log('NOW'); - assertFalse(et.dispatchEvent(new Event('test'))); - assertEquals(2, j); - assertEquals(1, i); -} - - -function testReturnFalse() { - var i = 0; - function prevent(e) { - i++; - return false; - } - - var j = 0; - function pass(e) { - j++; - } - - var et = new EventTarget; - et.addEventListener('test', pass); - - assertTrue(et.dispatchEvent(new Event('test'))); - assertEquals(1, j); - - et.addEventListener('test', prevent); - - assertFalse(et.dispatchEvent(new Event('test'))); - assertEquals(2, j); - assertEquals(1, i); -} - -</script> -</body> -</html> diff --git a/ui/webui/resources/js/cr/ui/array_data_model_test.html b/ui/webui/resources/js/cr/ui/array_data_model_test.html deleted file mode 100644 index ed6e44f..0000000 --- a/ui/webui/resources/js/cr/ui/array_data_model_test.html +++ /dev/null @@ -1,92 +0,0 @@ -<!DOCTYPE html> -<html> -<head> -<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script> -<script src="../../cr.js"></script> -<script src="../event_target.js"></script> -<script src="array_data_model.js"></script> -<script> - -goog.require('goog.testing.jsunit'); - -</script> - -</head> -<body> - -<script> - -function testSlice() { - var m = new cr.ui.ArrayDataModel([0, 1, 2]); - assertArrayEquals([0, 1, 2], m.slice()); - assertArrayEquals([1, 2], m.slice(1)); - assertArrayEquals([1], m.slice(1, 2)); -} - -function testPush() { - var m = new cr.ui.ArrayDataModel([0, 1, 2]); - - var count = 0; - m.addEventListener('splice', function(e) { - count++; - assertEquals(3, e.index); - assertArrayEquals([], e.removed); - assertArrayEquals([3, 4], e.added); - }); - - assertEquals(5, m.push(3, 4)); - var a = m.slice(); - assertArrayEquals([0, 1, 2, 3, 4], a); - - assertEquals('The splice event should only fire once', 1, count); -} - -function testSplice() { - function compare(array, args) { - var m = new cr.ui.ArrayDataModel(array.slice()); - var expected = array.slice(); - var result = expected.splice.apply(expected, args); - assertArrayEquals(result, m.splice.apply(m, args)); - assertArrayEquals(expected, m.slice()); - } - - compare([1, 2, 3], []); - compare([1, 2, 3], [0, 0]); - compare([1, 2, 3], [0, 1]); - compare([1, 2, 3], [1, 1]); - compare([1, 2, 3], [0, 3]); - compare([1, 2, 3], [0, 1, 5]); - compare([1, 2, 3], [0, 3, 1, 2, 3]); - compare([1, 2, 3], [5, 3, 1, 2, 3]); -} - -function testPermutation() { - function doTest(sourceArray, spliceArgs) { - var m = new cr.ui.ArrayDataModel(sourceArray.slice()); - var permutation; - m.addEventListener('permuted', function(event) { - permutation = event.permutation; - }); - m.splice.apply(m, spliceArgs); - var deleted = 0; - for (var i = 0; i < sourceArray.length; i++) { - if (permutation[i] == -1) - deleted++; - else - assertEquals(sourceArray[i], m.item(permutation[i])); - } - assertEquals(deleted, spliceArgs[1]); - } - - doTest([1, 2, 3], [0, 0]); - doTest([1, 2, 3], [0, 1]); - doTest([1, 2, 3], [1, 1]); - doTest([1, 2, 3], [0, 3]); - doTest([1, 2, 3], [0, 1, 5]); - doTest([1, 2, 3], [0, 3, 1, 2, 3]); -} - -</script> - -</body> -</html> diff --git a/ui/webui/resources/js/cr/ui/grid_test.html b/ui/webui/resources/js/cr/ui/grid_test.html deleted file mode 100644 index d3bfd1d..0000000 --- a/ui/webui/resources/js/cr/ui/grid_test.html +++ /dev/null @@ -1,98 +0,0 @@ -<!DOCTYPE html> -<html> -<head> -<title></title> -<style> - -</style> -<script src= - "http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"> -</script> -<script src="../../cr.js"></script> -<script src="../event_target.js"></script> -<script src="../ui.js"></script> -<script src="array_data_model.js"></script> -<script src="list_selection_model.js"></script> -<script src="list_selection_controller.js"></script> -<script src="list_item.js"></script> -<script src="list.js"></script> -<script src="grid.js"></script> -<script> - -goog.require('goog.testing.jsunit'); - -</script> - -</head> -<body> - -<script> - -function testGetColumnCount() { - var g = cr.ui.Grid.prototype; - g.measured_ = { - height: 8, - marginTop: 0, - marginBottom: 0, - width: 10, - marginLeft: 0, - marginRight: 0 - }; - var columns = g.getColumnCount_(); - g.measured_.width = 0; - columns = g.getColumnCount_(); - // Item width equals 0. - assertEquals(0, columns); - - g.measured_.width = 10; - columns = g.getColumnCount_(); - // No item in the list. - assertEquals(0, columns); - - g.dataModel_ = new cr.ui.ArrayDataModel([0, 1, 2]); - g.clientWidthWithoutScrollbar_ = 8; - columns = g.getColumnCount_(); - // Client width is smaller than item width. - assertEquals(0, columns); - - g.clientWidthWithoutScrollbar_ = 20; - // Client height can fit two rows. - g.clientHeight_ = 16; - columns = g.getColumnCount_(); - assertEquals(2, columns); - - // Client height can not fit two rows. A scroll bar is needed. - g.clientHeight_ = 15; - g.clientWidthWithScrollbar_ = 18; - columns = g.getColumnCount_(); - // Can not fit two columns due to the scroll bar. - assertEquals(1, columns); - - g.clientHeight_ = 16; - g.measured_.marginTop = 1; - columns = g.getColumnCount_(); - // Can fit two columns due to uncollapse margin. - assertEquals(2, columns); - - g.measured_.marginBottom = 1; - columns = g.getColumnCount_(); - // Can not fit two columns due to margin. - assertEquals(1, columns); - - g.measured_.marginTop = 0; - g.measured_.marginBottom = 0; - g.measured_.marginLeft = 1; - columns = g.getColumnCount_(); - // Can fit two columns due to uncollapse margin. - assertEquals(2, columns); - - g.measured_.marginRight = 1; - columns = g.getColumnCount_(); - // Can not fit two columns due to margin on left and right side. - assertEquals(1, columns); -} - -</script> - -</body> -</html> diff --git a/ui/webui/resources/js/cr/ui/position_util_test.html b/ui/webui/resources/js/cr/ui/position_util_test.html deleted file mode 100644 index 5fcc6c1..0000000 --- a/ui/webui/resources/js/cr/ui/position_util_test.html +++ /dev/null @@ -1,310 +0,0 @@ -<!DOCTYPE html> -<html> -<head> -<!-- TODO(arv): Check in Closue unit tests and make this run as part of the - tests --> -<script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script> -<script src="../../cr.js"></script> -<script src="position_util.js"></script> -<script> - -goog.require('goog.testing.PropertyReplacer'); -goog.require('goog.testing.jsunit'); - -</script> -<style> - -html, body { - margin: 0; - width: 100%; - height: 100%; -} - -#anchor { - position: absolute; - width: 10px; - height: 10px; - background: green; -} - -#popup { - position: absolute; - top: 0; - left: 0; - width: 100px; - height: 100px; - background: red; -} - -</style> -</head> -<body> - -<div id=anchor></div> -<div id=popup></div> - -<script> - -var anchor = document.getElementById('anchor'); -var popup = document.getElementById('popup'); -var anchorParent = anchor.offsetParent; -var pr = new goog.testing.PropertyReplacer; -var availRect; - -function MockRect(w, h) { - this.width = w; - this.height = h; - this.right = this.left + w; - this.bottom = this.top + h; -} -MockRect.prototype = { - left: 0, - top: 0 -}; - -function setUp() { - anchor.style.top = '100px'; - anchor.style.left = '100px'; - availRect = new MockRect(200, 200); - pr.set(anchorParent, 'getBoundingClientRect', function() { - return availRect; - }); -} - -function tearDown() { - document.documentElement.dir = 'ltr'; - pr.reset(); -} - -function testAbovePrimary() { - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE); - - assertEquals('auto', popup.style.top); - assertEquals('100px', popup.style.bottom); - - anchor.style.top = '90px'; - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE); - assertEquals('100px', popup.style.top); - assertEquals('auto', popup.style.bottom); -} - -function testBelowPrimary() { - // ensure enough below - anchor.style.top = '90px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW); - - assertEquals('100px', popup.style.top); - assertEquals('auto', popup.style.bottom); - - // ensure not enough below - anchor.style.top = '100px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW); - assertEquals('auto', popup.style.top); - assertEquals('100px', popup.style.bottom); -} - -function testBeforePrimary() { - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BEFORE); - - assertEquals('auto', popup.style.left); - assertEquals('100px', popup.style.right); - - anchor.style.left = '90px'; - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BEFORE); - assertEquals('100px', popup.style.left); - assertEquals('auto', popup.style.right); -} - -function testBeforePrimaryRtl() { - document.documentElement.dir = 'rtl'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER); - - assertEquals('auto', popup.style.left); - assertEquals('100px', popup.style.right); - - anchor.style.left = '90px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER); - assertEquals('100px', popup.style.left); - assertEquals('auto', popup.style.right); -} - -function testAfterPrimary() { - // ensure enough to the right - anchor.style.left = '90px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER); - - assertEquals('100px', popup.style.left); - assertEquals('auto', popup.style.right); - - // ensure not enough below - anchor.style.left = '100px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER); - assertEquals('auto', popup.style.left); - assertEquals('100px', popup.style.right); -} - -function testAfterPrimaryRtl() { - document.documentElement.dir = 'rtl'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER); - - assertEquals('auto', popup.style.left); - assertEquals('100px', popup.style.right); - - // ensure not enough below - anchor.style.left = '90px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER); - assertEquals('100px', popup.style.left); - assertEquals('auto', popup.style.right); -} - -function testAboveSecondary() { - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE); - - assertEquals('100px', popup.style.left); - assertEquals('auto', popup.style.right); - - anchor.style.left = '110px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE); - - assertEquals('auto', popup.style.left); - assertEquals('80px', popup.style.right); -} - -function testAboveSecondaryRtl() { - document.documentElement.dir = 'rtl'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE); - - assertEquals('auto', popup.style.left); - assertEquals('90px', popup.style.right); - - anchor.style.left = '80px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE); - - assertEquals('80px', popup.style.left); - assertEquals('auto', popup.style.right); -} - -function testAboveSecondarySwappedAlign() { - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE, true); - - assertEquals('auto', popup.style.left); - assertEquals('90px', popup.style.right); - - anchor.style.left = '80px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.ABOVE, true); - - assertEquals('80px', popup.style.left); - assertEquals('auto', popup.style.right); -} - -function testBelowSecondary() { - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW); - - assertEquals('100px', popup.style.left); - assertEquals('auto', popup.style.right); - - anchor.style.left = '110px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW); - - assertEquals('auto', popup.style.left); - assertEquals('80px', popup.style.right); -} - -function testBelowSecondaryRtl() { - document.documentElement.dir = 'rtl'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW); - - assertEquals('auto', popup.style.left); - assertEquals('90px', popup.style.right); - - anchor.style.left = '80px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW); - - assertEquals('80px', popup.style.left); - assertEquals('auto', popup.style.right); -} - -function testBelowSecondarySwappedAlign() { - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW, true); - - assertEquals('auto', popup.style.left); - assertEquals('90px', popup.style.right); - - anchor.style.left = '80px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BELOW, true); - - assertEquals('80px', popup.style.left); - assertEquals('auto', popup.style.right); -} - -function testBeforeSecondary() { - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BEFORE); - - assertEquals('100px', popup.style.top); - assertEquals('auto', popup.style.bottom); - - anchor.style.top = '110px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.BEFORE); - - assertEquals('auto', popup.style.top); - assertEquals('80px', popup.style.bottom); -} - -function testAfterSecondary() { - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER); - - assertEquals('100px', popup.style.top); - assertEquals('auto', popup.style.bottom); - - anchor.style.top = '110px'; - - cr.ui.positionPopupAroundElement(anchor, popup, cr.ui.AnchorType.AFTER); - - assertEquals('auto', popup.style.top); - assertEquals('80px', popup.style.bottom); -} - -function testPositionAtPoint() { - cr.ui.positionPopupAtPoint(100, 100, popup); - - assertEquals('100px', popup.style.left); - assertEquals('100px', popup.style.top); - assertEquals('auto', popup.style.right); - assertEquals('auto', popup.style.bottom); - - cr.ui.positionPopupAtPoint(100, 150, popup); - - assertEquals('100px', popup.style.left); - assertEquals('auto', popup.style.top); - assertEquals('auto', popup.style.right); - assertEquals('50px', popup.style.bottom); - - cr.ui.positionPopupAtPoint(150, 150, popup); - - assertEquals('auto', popup.style.left); - assertEquals('auto', popup.style.top); - assertEquals('50px', popup.style.right); - assertEquals('50px', popup.style.bottom); -} - -</script> - -</body> -</html> |