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 cr.define('settings_search', function() { |
| 6 /** |
| 7 * A test version of SearchEnginesBrowserProxy. Provides helper methods |
| 8 * for allowing tests to know when a method was called, as well as |
| 9 * specifying mock responses. |
| 10 * |
| 11 * @constructor |
| 12 * @implements {settings.SearchEnginesBrowserProxy} |
| 13 * @extends {settings.TestBrowserProxy} |
| 14 */ |
| 15 var TestSearchEnginesBrowserProxy = function() { |
| 16 settings.TestBrowserProxy.call(this, [ |
| 17 'getSearchEnginesList', |
| 18 'removeSearchEngine', |
| 19 'searchEngineEditCancelled', |
| 20 'searchEngineEditCompleted', |
| 21 'searchEngineEditStarted', |
| 22 'setDefaultSearchEngine', |
| 23 'validateSearchEngineInput', |
| 24 'manageExtension', |
| 25 'disableExtension', |
| 26 ]); |
| 27 |
| 28 /** @private {!SearchEnginesInfo} */ |
| 29 this.searchEnginesInfo_ = {defaults: [], others: [], extensions: []}; |
| 30 }; |
| 31 |
| 32 TestSearchEnginesBrowserProxy.prototype = { |
| 33 __proto__: settings.TestBrowserProxy.prototype, |
| 34 |
| 35 /** @override */ |
| 36 setDefaultSearchEngine: function(modelIndex) { |
| 37 this.methodCalled('setDefaultSearchEngine', modelIndex); |
| 38 }, |
| 39 |
| 40 /** @override */ |
| 41 removeSearchEngine: function(modelIndex) { |
| 42 this.methodCalled('removeSearchEngine', modelIndex); |
| 43 }, |
| 44 |
| 45 /** @override */ |
| 46 searchEngineEditStarted: function(modelIndex) { |
| 47 this.methodCalled('searchEngineEditStarted', modelIndex); |
| 48 }, |
| 49 |
| 50 /** @override */ |
| 51 searchEngineEditCancelled: function() { |
| 52 this.methodCalled('searchEngineEditCancelled'); |
| 53 }, |
| 54 |
| 55 /** @override */ |
| 56 searchEngineEditCompleted: function(searchEngine, keyword, queryUrl) { |
| 57 this.methodCalled('searchEngineEditCompleted'); |
| 58 }, |
| 59 |
| 60 /** |
| 61 * Sets the response to be returned by |getSearchEnginesList|. |
| 62 * @param {!SearchEnginesInfo} |
| 63 */ |
| 64 setSearchEnginesInfo: function(searchEnginesInfo) { |
| 65 this.searchEnginesInfo_ = searchEnginesInfo; |
| 66 }, |
| 67 |
| 68 /** @override */ |
| 69 getSearchEnginesList: function() { |
| 70 this.methodCalled('getSearchEnginesList'); |
| 71 return Promise.resolve(this.searchEnginesInfo_); |
| 72 }, |
| 73 |
| 74 /** @override */ |
| 75 validateSearchEngineInput: function(fieldName, fieldValue) { |
| 76 this.methodCalled('validateSearchEngineInput'); |
| 77 return Promise.resolve(true); |
| 78 }, |
| 79 |
| 80 /** @override */ |
| 81 manageExtension: function(extensionId) { |
| 82 this.methodCalled('manageExtension', extensionId); |
| 83 }, |
| 84 |
| 85 /** @override */ |
| 86 disableExtension: function(extensionId) { |
| 87 this.methodCalled('disableExtension', extensionId); |
| 88 }, |
| 89 }; |
| 90 |
| 91 /** |
| 92 * @param {boolean} canBeDefault |
| 93 * @param {boolean} canBeEdited |
| 94 * @param {boolean} canBeRemoved |
| 95 * @return {!SearchEngine} |
| 96 */ |
| 97 function createSampleSearchEngine(canBeDefault, canBeEdited, canBeRemoved) { |
| 98 return { |
| 99 canBeDefault: canBeDefault, |
| 100 canBeEdited: canBeEdited, |
| 101 canBeRemoved: canBeRemoved, |
| 102 default: false, |
| 103 displayName: "Google", |
| 104 iconURL: "http://www.google.com/favicon.ico", |
| 105 isOmniboxExtension: false, |
| 106 keyword: "google.com", |
| 107 modelIndex: 0, |
| 108 name: "Google", |
| 109 url: "https://search.foo.com/search?p=%s", |
| 110 urlLocked: false, |
| 111 }; |
| 112 } |
| 113 |
| 114 return { |
| 115 createSampleSearchEngine: createSampleSearchEngine, |
| 116 TestSearchEnginesBrowserProxy: TestSearchEnginesBrowserProxy, |
| 117 }; |
| 118 }); |
OLD | NEW |