| 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 /** | 5 /** |
| 6 * @fileoverview Tests for chrome://bluetooth-internals | 6 * @fileoverview Tests for chrome://bluetooth-internals |
| 7 */ | 7 */ |
| 8 | 8 |
| 9 /** @const {string} Path to source root. */ | 9 /** @const {string} Path to source root. */ |
| 10 var ROOT_PATH = '../../../../'; | 10 var ROOT_PATH = '../../../../'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 preLoad: function() { | 44 preLoad: function() { |
| 45 // A function that is called from chrome://bluetooth-internals to allow this | 45 // A function that is called from chrome://bluetooth-internals to allow this |
| 46 // test to replace the real Mojo browser proxy with a fake one, before any | 46 // test to replace the real Mojo browser proxy with a fake one, before any |
| 47 // other code runs. | 47 // other code runs. |
| 48 window.setupFn = function() { | 48 window.setupFn = function() { |
| 49 return importModules([ | 49 return importModules([ |
| 50 'content/public/renderer/frame_interfaces', | 50 'content/public/renderer/frame_interfaces', |
| 51 'device/bluetooth/public/interfaces/adapter.mojom', | 51 'device/bluetooth/public/interfaces/adapter.mojom', |
| 52 'device/bluetooth/public/interfaces/device.mojom', | 52 'device/bluetooth/public/interfaces/device.mojom', |
| 53 'mojo/public/js/bindings', | 53 'mojo/public/js/bindings', |
| 54 'mojo/public/js/connection', | 54 ]).then(function([frameInterfaces, adapter, device, bindings]) { |
| 55 ]).then(function([frameInterfaces, adapter, device, bindings, | |
| 56 connection]) { | |
| 57 /** | 55 /** |
| 58 * A test adapter factory proxy for the chrome://bluetooth-internals | 56 * A test adapter factory proxy for the chrome://bluetooth-internals |
| 59 * page. | 57 * page. |
| 60 * | 58 * |
| 61 * @constructor | 59 * @constructor |
| 62 * @extends {TestBrowserProxyBase} | 60 * @extends {TestBrowserProxyBase} |
| 63 */ | 61 */ |
| 64 var TestAdapterFactoryProxy = function() { | 62 var TestAdapterFactoryProxy = function() { |
| 65 settings.TestBrowserProxy.call(this, [ | 63 settings.TestBrowserProxy.call(this, [ |
| 66 'getAdapter', | 64 'getAdapter', |
| 67 ]); | 65 ]); |
| 68 | 66 |
| 67 this.binding = new bindings.Binding(adapter.AdapterFactory, this); |
| 69 this.adapter = new TestAdapter(); | 68 this.adapter = new TestAdapter(); |
| 70 this.adapterBinding_ = new bindings.Binding(adapter.Adapter, | 69 this.adapterBinding_ = new bindings.Binding(adapter.Adapter, |
| 71 this.adapter); | 70 this.adapter); |
| 72 }; | 71 }; |
| 73 | 72 |
| 74 TestAdapterFactoryProxy.prototype = { | 73 TestAdapterFactoryProxy.prototype = { |
| 75 __proto__: settings.TestBrowserProxy.prototype, | 74 __proto__: settings.TestBrowserProxy.prototype, |
| 76 getAdapter: function() { | 75 getAdapter: function() { |
| 77 this.methodCalled('getAdapter'); | 76 this.methodCalled('getAdapter'); |
| 78 | 77 |
| 79 // Create message pipe bound to TestAdapter. | 78 // Create message pipe bound to TestAdapter. |
| 80 return Promise.resolve({ | 79 return Promise.resolve({ |
| 81 adapter: this.adapterBinding_.createInterfacePtrAndBind(), | 80 adapter: this.adapterBinding_.createInterfacePtrAndBind(), |
| 82 }); | 81 }); |
| 83 } | 82 } |
| 84 }; | 83 }; |
| 85 | 84 |
| 86 /** | 85 /** |
| 87 * A test adapter for the chrome://bluetooth-internals page. | 86 * A test adapter for the chrome://bluetooth-internals page. |
| 88 * Must be used to create message pipe handle from test code. | 87 * Must be used to create message pipe handle from test code. |
| 89 * | 88 * |
| 90 * @constructor | 89 * @constructor |
| 91 * @extends {adapter.Adapter.stubClass} | |
| 92 */ | 90 */ |
| 93 var TestAdapter = function() { | 91 var TestAdapter = function() { |
| 94 this.proxy = new TestAdapterProxy(); | 92 this.proxy = new TestAdapterProxy(); |
| 95 }; | 93 }; |
| 96 | 94 |
| 97 TestAdapter.prototype = { | 95 TestAdapter.prototype = { |
| 98 __proto__: adapter.Adapter.stubClass.prototype, | |
| 99 getInfo: function() { return this.proxy.getInfo(); }, | 96 getInfo: function() { return this.proxy.getInfo(); }, |
| 100 getDevices: function() { return this.proxy.getDevices(); }, | 97 getDevices: function() { return this.proxy.getDevices(); }, |
| 101 setClient: function(client) { return this.proxy.setClient(client); } | 98 setClient: function(client) { return this.proxy.setClient(client); } |
| 102 }; | 99 }; |
| 103 | 100 |
| 104 /** | 101 /** |
| 105 * A test adapter proxy for the chrome://bluetooth-internals page. | 102 * A test adapter proxy for the chrome://bluetooth-internals page. |
| 106 * | 103 * |
| 107 * @constructor | 104 * @constructor |
| 108 * @extends {TestBrowserProxyBase} | 105 * @extends {TestBrowserProxyBase} |
| (...skipping 30 matching lines...) Expand all Loading... |
| 139 this.adapterInfo_ = adapterInfo; | 136 this.adapterInfo_ = adapterInfo; |
| 140 }, | 137 }, |
| 141 | 138 |
| 142 setTestDevices: function(devices) { | 139 setTestDevices: function(devices) { |
| 143 this.devices_ = devices; | 140 this.devices_ = devices; |
| 144 } | 141 } |
| 145 }; | 142 }; |
| 146 | 143 |
| 147 frameInterfaces.addInterfaceOverrideForTesting( | 144 frameInterfaces.addInterfaceOverrideForTesting( |
| 148 adapter.AdapterFactory.name, function(handle) { | 145 adapter.AdapterFactory.name, function(handle) { |
| 149 var stub = connection.bindHandleToStub( | |
| 150 handle, adapter.AdapterFactory); | |
| 151 | |
| 152 this.adapterFactory = new TestAdapterFactoryProxy(); | 146 this.adapterFactory = new TestAdapterFactoryProxy(); |
| 147 this.adapterFactory.binding.bind(handle); |
| 153 | 148 |
| 154 this.adapterFactory.adapter.proxy.setTestDevices([ | 149 this.adapterFactory.adapter.proxy.setTestDevices([ |
| 155 this.fakeDeviceInfo1(), | 150 this.fakeDeviceInfo1(), |
| 156 this.fakeDeviceInfo2(), | 151 this.fakeDeviceInfo2(), |
| 157 ]); | 152 ]); |
| 158 this.adapterFactory.adapter.proxy.setTestAdapter( | 153 this.adapterFactory.adapter.proxy.setTestAdapter( |
| 159 this.fakeAdapterInfo()); | 154 this.fakeAdapterInfo()); |
| 160 | 155 |
| 161 bindings.StubBindings(stub).delegate = this.adapterFactory; | |
| 162 | |
| 163 this.setupResolver.resolve(); | 156 this.setupResolver.resolve(); |
| 164 }.bind(this)); | 157 }.bind(this)); |
| 165 | 158 |
| 166 }.bind(this)); | 159 }.bind(this)); |
| 167 }.bind(this); | 160 }.bind(this); |
| 168 }, | 161 }, |
| 169 | 162 |
| 170 /** | 163 /** |
| 171 * Returns a copy of fake adapter info object. | 164 * Returns a copy of fake adapter info object. |
| 172 * @return {!Object} | 165 * @return {!Object} |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 snackbar3.addEventListener('dismissed', next); | 551 snackbar3.addEventListener('dismissed', next); |
| 559 | 552 |
| 560 snackbar.Snackbar.dismiss(true); | 553 snackbar.Snackbar.dismiss(true); |
| 561 }); | 554 }); |
| 562 }); | 555 }); |
| 563 | 556 |
| 564 | 557 |
| 565 // Run all registered tests. | 558 // Run all registered tests. |
| 566 mocha.run(); | 559 mocha.run(); |
| 567 }); | 560 }); |
| OLD | NEW |