| 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', function() { | 5 cr.define('settings_search', function() { |
| 6 /** | 6 /** |
| 7 * A test version of SearchEnginesBrowserProxy. Provides helper methods | 7 * A test version of SearchEnginesBrowserProxy. Provides helper methods |
| 8 * for allowing tests to know when a method was called, as well as | 8 * for allowing tests to know when a method was called, as well as |
| 9 * specifying mock responses. | 9 * specifying mock responses. |
| 10 * | 10 * |
| 11 * @constructor | 11 * @constructor |
| 12 * @implements {settings.SearchEnginesBrowserProxy} | 12 * @implements {settings.SearchEnginesBrowserProxy} |
| 13 * @extends {settings.TestBrowserProxy} | 13 * @extends {settings.TestBrowserProxy} |
| 14 */ | 14 */ |
| 15 var TestSearchEnginesBrowserProxy = function() { | 15 var TestSearchEnginesBrowserProxy = function() { |
| 16 settings.TestBrowserProxy.call(this, [ | 16 settings.TestBrowserProxy.call(this, [ |
| 17 'getSearchEnginesList', | 17 'getSearchEnginesList', |
| 18 'removeSearchEngine', | 18 'removeSearchEngine', |
| 19 'searchEngineEditCancelled', | 19 'searchEngineEditCancelled', |
| 20 'searchEngineEditCompleted', | 20 'searchEngineEditCompleted', |
| 21 'searchEngineEditStarted', | 21 'searchEngineEditStarted', |
| 22 'setDefaultSearchEngine', | 22 'setDefaultSearchEngine', |
| 23 'validateSearchEngineInput', | 23 'validateSearchEngineInput', |
| 24 'getHotwordInfo', |
| 25 'setHotwordSearchEnabled', |
| 24 ]); | 26 ]); |
| 25 | 27 |
| 28 /** @type {boolean} */ |
| 29 this.hotwordSearchEnabled = false; |
| 30 |
| 26 /** @private {!SearchEnginesInfo} */ | 31 /** @private {!SearchEnginesInfo} */ |
| 27 this.searchEnginesInfo_ = {defaults: [], others: [], extensions: []}; | 32 this.searchEnginesInfo_ = {defaults: [], others: [], extensions: []}; |
| 33 |
| 34 /** @private {!SearchPageHotwordInfo} */ |
| 35 this.hotwordInfo_ = { |
| 36 allowed: true, |
| 37 enabled: false, |
| 38 alwaysOn: true, |
| 39 errorMessage: '', |
| 40 userName: 'user@test.org', |
| 41 historyEnabled: false, |
| 42 }; |
| 28 }; | 43 }; |
| 29 | 44 |
| 30 TestSearchEnginesBrowserProxy.prototype = { | 45 TestSearchEnginesBrowserProxy.prototype = { |
| 31 __proto__: settings.TestBrowserProxy.prototype, | 46 __proto__: settings.TestBrowserProxy.prototype, |
| 32 | 47 |
| 33 /** @override */ | 48 /** @override */ |
| 34 setDefaultSearchEngine: function(modelIndex) { | 49 setDefaultSearchEngine: function(modelIndex) { |
| 35 this.methodCalled('setDefaultSearchEngine', modelIndex); | 50 this.methodCalled('setDefaultSearchEngine', modelIndex); |
| 36 }, | 51 }, |
| 37 | 52 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 48 /** @override */ | 63 /** @override */ |
| 49 searchEngineEditCancelled: function() { | 64 searchEngineEditCancelled: function() { |
| 50 this.methodCalled('searchEngineEditCancelled'); | 65 this.methodCalled('searchEngineEditCancelled'); |
| 51 }, | 66 }, |
| 52 | 67 |
| 53 /** @override */ | 68 /** @override */ |
| 54 searchEngineEditCompleted: function(searchEngine, keyword, queryUrl) { | 69 searchEngineEditCompleted: function(searchEngine, keyword, queryUrl) { |
| 55 this.methodCalled('searchEngineEditCompleted'); | 70 this.methodCalled('searchEngineEditCompleted'); |
| 56 }, | 71 }, |
| 57 | 72 |
| 58 /** | |
| 59 * Sets the response to be returned by |getSearchEnginesList|. | |
| 60 * @param {!SearchEnginesInfo} | |
| 61 */ | |
| 62 setSearchEnginesInfo: function(searchEnginesInfo) { | |
| 63 this.searchEnginesInfo_ = searchEnginesInfo; | |
| 64 }, | |
| 65 | |
| 66 /** @override */ | 73 /** @override */ |
| 67 getSearchEnginesList: function() { | 74 getSearchEnginesList: function() { |
| 68 this.methodCalled('getSearchEnginesList'); | 75 this.methodCalled('getSearchEnginesList'); |
| 69 return Promise.resolve(this.searchEnginesInfo_); | 76 return Promise.resolve(this.searchEnginesInfo_); |
| 70 }, | 77 }, |
| 71 | 78 |
| 72 /** @override */ | 79 /** @override */ |
| 73 validateSearchEngineInput: function(fieldName, fieldValue) { | 80 validateSearchEngineInput: function(fieldName, fieldValue) { |
| 74 this.methodCalled('validateSearchEngineInput'); | 81 this.methodCalled('validateSearchEngineInput'); |
| 75 return Promise.resolve(true); | 82 return Promise.resolve(true); |
| 76 }, | 83 }, |
| 84 |
| 85 /** @override */ |
| 86 getHotwordInfo: function() { |
| 87 this.methodCalled('getHotwordInfo'); |
| 88 return Promise.resolve(this.hotwordInfo_); |
| 89 }, |
| 90 |
| 91 /** @override */ |
| 92 setHotwordSearchEnabled: function(enabled) { |
| 93 this.hotwordSearchEnabled = enabled; |
| 94 this.hotwordInfo_.enabled = true; |
| 95 this.hotwordInfo_.historyEnabled = this.hotwordInfo_.alwaysOn; |
| 96 this.methodCalled('setHotwordSearchEnabled'); |
| 97 }, |
| 98 |
| 99 /** |
| 100 * Sets the response to be returned by |getSearchEnginesList|. |
| 101 * @param {!SearchEnginesInfo} searchEnginesInfo |
| 102 */ |
| 103 setSearchEnginesInfo: function(searchEnginesInfo) { |
| 104 this.searchEnginesInfo_ = searchEnginesInfo; |
| 105 }, |
| 106 |
| 107 /** |
| 108 * Sets the response to be returned by |getSearchEnginesList|. |
| 109 * @param {!SearchPageHotwordInfo} hotwordInfo |
| 110 */ |
| 111 setHotwordInfo: function(hotwordInfo) { |
| 112 this.hotwordInfo_ = hotwordInfo; |
| 113 cr.webUIListenerCallback('hotword-info-update', this.hotwordInfo_); |
| 114 }, |
| 77 }; | 115 }; |
| 78 | 116 |
| 79 /** | 117 /** |
| 80 * @param {boolean} canBeDefault | 118 * @param {boolean} canBeDefault |
| 81 * @param {boolean} canBeEdited | 119 * @param {boolean} canBeEdited |
| 82 * @param {boolean} canBeRemoved | 120 * @param {boolean} canBeRemoved |
| 83 * @return {!SearchEngine} | 121 * @return {!SearchEngine} |
| 84 */ | 122 */ |
| 85 function createSampleSearchEngine(canBeDefault, canBeEdited, canBeRemoved) { | 123 function createSampleSearchEngine(canBeDefault, canBeEdited, canBeRemoved) { |
| 86 return { | 124 return { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 97 url: "https://search.foo.com/search?p=%s", | 135 url: "https://search.foo.com/search?p=%s", |
| 98 urlLocked: false, | 136 urlLocked: false, |
| 99 }; | 137 }; |
| 100 } | 138 } |
| 101 | 139 |
| 102 return { | 140 return { |
| 103 createSampleSearchEngine: createSampleSearchEngine, | 141 createSampleSearchEngine: createSampleSearchEngine, |
| 104 TestSearchEnginesBrowserProxy: TestSearchEnginesBrowserProxy, | 142 TestSearchEnginesBrowserProxy: TestSearchEnginesBrowserProxy, |
| 105 }; | 143 }; |
| 106 }); | 144 }); |
| OLD | NEW |