Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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. | |
| 4 | |
| 5 /** @fileoverview Suite of tests for cr elements. */ | |
| 6 | |
| 7 /** @const {string} Path to source root. */ | |
| 8 var ROOT_PATH = '../../../../'; | |
| 9 | |
| 10 // Polymer BrowserTest fixture. | |
| 11 GEN_INCLUDE( | |
| 12 [ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']); | |
| 13 | |
| 14 /** | |
| 15 * Test fixture for cr elements | |
| 16 * @constructor | |
| 17 * @extends {PolymerTest} | |
| 18 */ | |
| 19 function CrElementsBrowserTest() {} | |
| 20 | |
| 21 CrElementsBrowserTest.prototype = { | |
| 22 __proto__: PolymerTest.prototype, | |
| 23 extraLibraries: PolymerTest.getLibraries(ROOT_PATH), | |
| 24 }; | |
| 25 | |
| 26 TEST_F('CrElementsBrowserTest', 'CrToolbarSearchFieldTest', function() { | |
| 27 suite('cr-toolbar-search-field', function() { | |
| 28 /** @type {CrToolbarSearchFieldElement} */ | |
| 29 var field; | |
| 30 /** @type {Array<string>} */ | |
| 31 var searches; | |
|
dpapad
2016/05/26 21:43:36
How about making this field a member variable of t
tsergeant
2016/05/27 01:20:13
Done.
| |
| 32 | |
| 33 /** @param {string} term */ | |
| 34 function mockSearch(term) { | |
|
dpapad
2016/05/26 21:43:37
"mock" is an overloaded term IMO. Personally I thi
tsergeant
2016/05/27 01:20:13
Done.
| |
| 35 field.$.searchInput.bindValue = term; | |
| 36 field.onSearchTermSearch_(); | |
| 37 } | |
| 38 | |
| 39 /** | |
| 40 * @constructor | |
| 41 * @implements {SearchFieldDelegate} | |
| 42 */ | |
| 43 function MockSearchFieldDelegate() { | |
|
dpapad
2016/05/26 21:43:36
/**
* @constructor
* @implements {SearchFieldD
dpapad
2016/05/26 21:44:47
Small correction on my previous suggestion:
this.s
tsergeant
2016/05/27 01:20:13
Done.
| |
| 44 } | |
| 45 | |
| 46 MockSearchFieldDelegate.prototype = { | |
| 47 onSearchTermSearch: function(term) { | |
| 48 searches.push(term); | |
| 49 } | |
| 50 }; | |
| 51 | |
| 52 suiteSetup(function() { | |
| 53 return PolymerTest.importHtml( | |
| 54 'chrome://resources/cr_elements/cr_toolbar/' + | |
| 55 'cr_toolbar_search_field.html'); | |
| 56 }); | |
| 57 | |
| 58 setup(function() { | |
| 59 PolymerTest.clearBody(); | |
| 60 searches = []; | |
|
dpapad
2016/05/26 21:43:36
// no need to instantiate both "searches" and a ne
tsergeant
2016/05/27 01:20:13
Done.
| |
| 61 field = document.createElement('cr-toolbar-search-field'); | |
| 62 document.body.appendChild(field); | |
| 63 field.setDelegate(new MockSearchFieldDelegate()); | |
|
dpapad
2016/05/26 21:43:36
field.setDelegate(delegate);
tsergeant
2016/05/27 01:20:13
Done.
| |
| 64 }); | |
|
dpapad
2016/05/26 21:43:36
It is generally good practice to have tearDown und
tsergeant
2016/05/27 01:20:13
Done.
| |
| 65 | |
| 66 test('opens and closes correctly', function() { | |
| 67 return Promise.resolve().then(function() { | |
|
dpapad
2016/05/26 21:43:36
Why are you using a Promise here? This test does n
tsergeant
2016/05/27 01:20:13
CrSearchFieldBehavior.focus_() was previously asyn
| |
| 68 assertFalse(field.showingSearch); | |
| 69 MockInteractions.tap(field); | |
| 70 assertTrue(field.showingSearch); | |
| 71 }).then(function() { | |
|
dpapad
2016/05/26 21:43:36
Same here (and below). Why is starting a new funct
tsergeant
2016/05/27 01:20:14
See above.
| |
| 72 assertEquals(field.$.searchInput, field.root.activeElement); | |
| 73 | |
| 74 MockInteractions.blur(field.$.searchInput); | |
| 75 assertFalse(field.showingSearch); | |
| 76 | |
| 77 MockInteractions.tap(field); | |
| 78 }).then(function() { | |
| 79 assertEquals(field.$.searchInput, field.root.activeElement); | |
| 80 MockInteractions.pressAndReleaseKeyOn( | |
| 81 field.$.searchInput, 27, '', 'Escape'); | |
| 82 assertFalse(field.showingSearch, 'Pressing escape closes field.'); | |
| 83 }).then(function() { | |
| 84 assertNotEquals(field.$.searchInput, field.root.activeElement); | |
| 85 }); | |
| 86 }); | |
| 87 | |
| 88 test('passes searches correctly', function() { | |
| 89 MockInteractions.tap(field); | |
| 90 mockSearch('test'); | |
| 91 assertEquals('test', field.getValue()); | |
| 92 | |
| 93 MockInteractions.tap(field.$.clearSearch); | |
| 94 assertFalse(field.showingSearch); | |
| 95 assertEquals('', field.getValue()); | |
| 96 | |
| 97 assertEquals(2, searches.length); | |
| 98 assertEquals('test', searches[0]); | |
| 99 assertEquals('', searches[1]); | |
| 100 }); | |
| 101 | |
| 102 test('blur does not close field when a search is active', function() { | |
| 103 MockInteractions.tap(field); | |
| 104 mockSearch('test'); | |
| 105 MockInteractions.blur(field.$.searchInput); | |
| 106 | |
| 107 assertTrue(field.showingSearch); | |
| 108 }); | |
| 109 }); | |
| 110 | |
| 111 mocha.run(); | |
| 112 }); | |
| OLD | NEW |