| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 suite('<bookmarks-toast-manager>', function() { | 5 suite('<bookmarks-toast-manager>', function() { |
| 6 var toastManager; | 6 var toastManager; |
| 7 var store; | 7 var store; |
| 8 | 8 |
| 9 setup(function() { | 9 setup(function() { |
| 10 toastManager = document.createElement('bookmarks-toast-manager'); | 10 toastManager = document.createElement('bookmarks-toast-manager'); |
| 11 replaceBody(toastManager); | 11 replaceBody(toastManager); |
| 12 }); | 12 }); |
| 13 | 13 |
| 14 test('simple show/hide', function() { | 14 test('simple show/hide', function() { |
| 15 toastManager.show('test', false); | 15 toastManager.show('test', false); |
| 16 assertTrue(toastManager.open_); | 16 assertTrue(toastManager.open_); |
| 17 assertEquals('test', toastManager.$.content.textContent); | 17 assertEquals('test', toastManager.$.content.textContent); |
| 18 assertTrue(toastManager.$$('paper-button').hidden); | 18 assertTrue(toastManager.$$('paper-button').hidden); |
| 19 | 19 |
| 20 toastManager.hide(); | 20 toastManager.hide(); |
| 21 assertFalse(toastManager.open_); | 21 assertFalse(toastManager.open_); |
| 22 | 22 |
| 23 toastManager.show('test', true); | 23 toastManager.show('test', true); |
| 24 assertFalse(toastManager.$$('paper-button').hidden); | 24 assertFalse(toastManager.$$('paper-button').hidden); |
| 25 }); | 25 }); |
| 26 | 26 |
| 27 test('auto hide', function() { | 27 test('auto hide', function() { |
| 28 var timerProxy = new bookmarks.TestTimerProxy(); |
| 29 timerProxy.immediatelyResolveTimeouts = false; |
| 30 toastManager.timerProxy_ = timerProxy; |
| 31 |
| 28 toastManager.duration = 100; | 32 toastManager.duration = 100; |
| 29 | 33 |
| 30 var timeoutFunc = null; | |
| 31 var timeoutCounter = 0; | |
| 32 var clearedTimeout = null; | |
| 33 toastManager.setTimeout_ = function(f) { | |
| 34 timeoutFunc = f; | |
| 35 return timeoutCounter++; | |
| 36 }; | |
| 37 toastManager.clearTimeout_ = function(n) { | |
| 38 clearedTimeout = n; | |
| 39 }; | |
| 40 | |
| 41 toastManager.show('test', false); | 34 toastManager.show('test', false); |
| 42 assertEquals(0, toastManager.hideTimeout_); | 35 assertEquals(0, toastManager.hideTimeoutId_); |
| 43 assertTrue(toastManager.open_); | 36 assertTrue(toastManager.open_); |
| 44 | 37 |
| 45 timeoutFunc(); | 38 timerProxy.runTimeoutFn(0); |
| 46 assertEquals(null, toastManager.hideTimeout_); | 39 assertEquals(null, toastManager.hideTimeoutId_); |
| 47 assertFalse(toastManager.open_); | 40 assertFalse(toastManager.open_); |
| 48 | 41 |
| 49 // Check that multiple shows reset the timeout. | 42 // Check that multiple shows reset the timeout. |
| 50 toastManager.show('test', false); | 43 toastManager.show('test', false); |
| 51 assertEquals(1, toastManager.hideTimeout_); | 44 assertEquals(1, toastManager.hideTimeoutId_); |
| 52 assertTrue(toastManager.open_); | 45 assertTrue(toastManager.open_); |
| 53 | 46 |
| 54 toastManager.show('test2', false); | 47 toastManager.show('test2', false); |
| 55 assertEquals(1, clearedTimeout); | 48 assertFalse(timerProxy.hasTimeout(1)); |
| 56 assertEquals(2, toastManager.hideTimeout_); | 49 assertEquals(2, toastManager.hideTimeoutId_); |
| 57 assertTrue(toastManager.open_); | 50 assertTrue(toastManager.open_); |
| 58 }); | 51 }); |
| 59 }); | 52 }); |
| OLD | NEW |