1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 base.require('ui.overlay');
8 base.require('ui.dom_helpers');
10 base.unittest.testSuite('ui.overlay', function() {
11 function addShowButtonForDialog(dlg) {
12 var btn = document.createElement('button');
13 btn.textContent = 'Launch Overlay';
14 btn.addEventListener('click', function(e) {
19 this.addHTMLOutput(btn);
22 function makeButton(title) {
23 var btn = document.createElement('button');
24 btn.textContent = title;
28 function makeCloseButton(dlg) {
29 var btn = makeButton('close');
30 btn.addEventListener('click', function(e) {
36 test('instantiate', function() {
37 var dlg = new ui.Overlay();
38 dlg.classList.add('example-overlay');
39 dlg.title = 'ExampleOverlay';
40 dlg.innerHTML = 'hello';
41 dlg.leftButtons.appendChild(makeButton('i am a button'));
42 dlg.leftButtons.appendChild(makeCloseButton(dlg));
43 dlg.rightButtons.appendChild(ui.createSpan({textContent: 'i am a span'}));
44 addShowButtonForDialog.call(this, dlg);
47 test('instantiate_noButtons', function() {
48 var dlg = new ui.Overlay();
49 dlg.classList.add('example-overlay');
50 dlg.title = 'ExampleOverlay';
51 dlg.innerHTML = 'hello';
52 addShowButtonForDialog.call(this, dlg);
55 test('instantiate_disableUserClose', function() {
56 var dlg = new ui.Overlay();
57 dlg.classList.add('example-overlay');
58 dlg.userCanClose = false;
59 dlg.title = 'Unclosable';
60 dlg.innerHTML = 'This has no close X button.';
61 dlg.leftButtons.appendChild(makeCloseButton(dlg));
62 addShowButtonForDialog.call(this, dlg);
65 test('instantiateTall', function() {
66 var dlg = new ui.Overlay();
67 dlg.title = 'TallContent';
68 var contentEl = document.createElement('div');
69 contentEl.style.overflowY = 'auto';
70 dlg.appendChild(contentEl);
72 for (var i = 0; i < 1000; i++) {
73 var el = document.createElement('div');
74 el.textContent = 'line ' + i;
75 contentEl.appendChild(el);
79 dlg.leftButtons.appendChild(makeButton('i am a button'));
80 addShowButtonForDialog.call(this, dlg);
83 test('instantiateTallWithManyDirectChildren', function() {
84 var dlg = new ui.Overlay();
85 dlg.title = 'TallContent';
86 for (var i = 0; i < 100; i++) {
87 var el = document.createElement('div');
88 el.style.webkitFlex = '1 0 auto';
89 el.textContent = 'line ' + i;
93 dlg.leftButtons.appendChild(makeButton('i am a button'));
94 addShowButtonForDialog.call(this, dlg);
97 test('closeclickEvent', function() {
98 var dlg = new ui.Overlay();
99 dlg.title = 'Test closeclick event';
100 var closeBtn = makeCloseButton(dlg);
101 dlg.leftButtons.appendChild(closeBtn);
103 var closeClicked = false;
104 dlg.addEventListener('closeclick', function() {
108 return new Promise(function(resolver) {
109 function pressClose() {
114 resolver.reject(new Error('closeclick event is not dispatched'));
117 setTimeout(pressClose, 60);