| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 cr.define('settings_search_page', function() { | 5 cr.define('settings_search_page', function() { |
| 6 function generateSearchEngineInfo() { | 6 function generateSearchEngineInfo() { |
| 7 var searchEngines0 = settings_search.createSampleSearchEngine( | 7 var searchEngines0 = settings_search.createSampleSearchEngine( |
| 8 true, false, false); | 8 true, false, false); |
| 9 searchEngines0.default = true; | 9 searchEngines0.default = true; |
| 10 var searchEngines1 = settings_search.createSampleSearchEngine( | 10 var searchEngines1 = settings_search.createSampleSearchEngine( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 PolymerTest.clearBody(); | 35 PolymerTest.clearBody(); |
| 36 page = document.createElement('settings-search-page'); | 36 page = document.createElement('settings-search-page'); |
| 37 document.body.appendChild(page); | 37 document.body.appendChild(page); |
| 38 }); | 38 }); |
| 39 | 39 |
| 40 teardown(function() { page.remove(); }); | 40 teardown(function() { page.remove(); }); |
| 41 | 41 |
| 42 // Tests that the page is querying and displaying search engine info on | 42 // Tests that the page is querying and displaying search engine info on |
| 43 // startup. | 43 // startup. |
| 44 test('Initialization', function() { | 44 test('Initialization', function() { |
| 45 var listboxElement = page.$$('paper-listbox'); | 45 var selectElement = page.$$('select'); |
| 46 | 46 |
| 47 return browserProxy.whenCalled('getSearchEnginesList').then(function() { | 47 return browserProxy.whenCalled('getSearchEnginesList').then(function() { |
| 48 assertEquals(0, listboxElement.selected); | 48 Polymer.dom.flush(); |
| 49 assertEquals(0, selectElement.selectedIndex); |
| 49 | 50 |
| 50 // Simulate a user initiated change of the default search engine. | 51 // Simulate a user initiated change of the default search engine. |
| 51 listboxElement.selected = 1; | 52 selectElement.selectedIndex = 1; |
| 53 selectElement.dispatchEvent(new CustomEvent('change')); |
| 52 return browserProxy.whenCalled('setDefaultSearchEngine'); | 54 return browserProxy.whenCalled('setDefaultSearchEngine'); |
| 53 }).then(function() { | 55 }).then(function() { |
| 54 assertEquals(1, listboxElement.selected); | 56 assertEquals(1, selectElement.selectedIndex); |
| 55 | 57 |
| 56 // Simulate a change that happened in a different tab. | 58 // Simulate a change that happened in a different tab. |
| 57 var searchEnginesInfo = generateSearchEngineInfo(); | 59 var searchEnginesInfo = generateSearchEngineInfo(); |
| 58 searchEnginesInfo.defaults[0].default = false; | 60 searchEnginesInfo.defaults[0].default = false; |
| 59 searchEnginesInfo.defaults[1].default = false; | 61 searchEnginesInfo.defaults[1].default = false; |
| 60 searchEnginesInfo.defaults[2].default = true; | 62 searchEnginesInfo.defaults[2].default = true; |
| 61 | 63 |
| 62 browserProxy.resetResolver('setDefaultSearchEngine'); | 64 browserProxy.resetResolver('setDefaultSearchEngine'); |
| 63 cr.webUIListenerCallback('search-engines-changed', searchEnginesInfo); | 65 cr.webUIListenerCallback('search-engines-changed', searchEnginesInfo); |
| 64 assertEquals(2, listboxElement.selected); | 66 Polymer.dom.flush(); |
| 67 assertEquals(2, selectElement.selectedIndex); |
| 65 | 68 |
| 66 browserProxy.whenCalled('setDefaultSearchEngine').then(function() { | 69 browserProxy.whenCalled('setDefaultSearchEngine').then(function() { |
| 67 // Since the change happened in a different tab, there should be no | 70 // Since the change happened in a different tab, there should be no |
| 68 // new call to |setDefaultSearchEngine|. | 71 // new call to |setDefaultSearchEngine|. |
| 69 assertNotReached('Should not call setDefaultSearchEngine again'); | 72 assertNotReached('Should not call setDefaultSearchEngine again'); |
| 70 }); | 73 }); |
| 71 }); | 74 }); |
| 72 }); | 75 }); |
| 73 }); | 76 }); |
| 74 } | 77 } |
| 75 | 78 |
| 76 return { | 79 return { |
| 77 registerTests: registerTests, | 80 registerTests: registerTests, |
| 78 }; | 81 }; |
| 79 }); | 82 }); |
| OLD | NEW |