| 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 ]).then(function([frameInterfaces, adapter, device, bindings]) { | 54 'mojo/public/js/connection', |
| 55 ]).then(function([frameInterfaces, adapter, device, bindings, |
| 56 connection]) { |
| 55 /** | 57 /** |
| 56 * A test adapter factory proxy for the chrome://bluetooth-internals | 58 * A test adapter factory proxy for the chrome://bluetooth-internals |
| 57 * page. | 59 * page. |
| 58 * | 60 * |
| 59 * @constructor | 61 * @constructor |
| 60 * @extends {TestBrowserProxyBase} | 62 * @extends {TestBrowserProxyBase} |
| 61 */ | 63 */ |
| 62 var TestAdapterFactoryProxy = function() { | 64 var TestAdapterFactoryProxy = function() { |
| 63 settings.TestBrowserProxy.call(this, [ | 65 settings.TestBrowserProxy.call(this, [ |
| 64 'getAdapter', | 66 'getAdapter', |
| 65 ]); | 67 ]); |
| 66 | 68 |
| 67 this.binding = new bindings.Binding(adapter.AdapterFactory, this); | |
| 68 this.adapter = new TestAdapter(); | 69 this.adapter = new TestAdapter(); |
| 69 this.adapterBinding_ = new bindings.Binding(adapter.Adapter, | 70 this.adapterBinding_ = new bindings.Binding(adapter.Adapter, |
| 70 this.adapter); | 71 this.adapter); |
| 71 }; | 72 }; |
| 72 | 73 |
| 73 TestAdapterFactoryProxy.prototype = { | 74 TestAdapterFactoryProxy.prototype = { |
| 74 __proto__: settings.TestBrowserProxy.prototype, | 75 __proto__: settings.TestBrowserProxy.prototype, |
| 75 getAdapter: function() { | 76 getAdapter: function() { |
| 76 this.methodCalled('getAdapter'); | 77 this.methodCalled('getAdapter'); |
| 77 | 78 |
| 78 // Create message pipe bound to TestAdapter. | 79 // Create message pipe bound to TestAdapter. |
| 79 return Promise.resolve({ | 80 return Promise.resolve({ |
| 80 adapter: this.adapterBinding_.createInterfacePtrAndBind(), | 81 adapter: this.adapterBinding_.createInterfacePtrAndBind(), |
| 81 }); | 82 }); |
| 82 } | 83 } |
| 83 }; | 84 }; |
| 84 | 85 |
| 85 /** | 86 /** |
| 86 * A test adapter for the chrome://bluetooth-internals page. | 87 * A test adapter for the chrome://bluetooth-internals page. |
| 87 * Must be used to create message pipe handle from test code. | 88 * Must be used to create message pipe handle from test code. |
| 88 * | 89 * |
| 89 * @constructor | 90 * @constructor |
| 91 * @extends {adapter.Adapter.stubClass} |
| 90 */ | 92 */ |
| 91 var TestAdapter = function() { | 93 var TestAdapter = function() { |
| 92 this.proxy = new TestAdapterProxy(); | 94 this.proxy = new TestAdapterProxy(); |
| 93 }; | 95 }; |
| 94 | 96 |
| 95 TestAdapter.prototype = { | 97 TestAdapter.prototype = { |
| 98 __proto__: adapter.Adapter.stubClass.prototype, |
| 96 getInfo: function() { return this.proxy.getInfo(); }, | 99 getInfo: function() { return this.proxy.getInfo(); }, |
| 97 getDevices: function() { return this.proxy.getDevices(); }, | 100 getDevices: function() { return this.proxy.getDevices(); }, |
| 98 setClient: function(client) { return this.proxy.setClient(client); } | 101 setClient: function(client) { return this.proxy.setClient(client); } |
| 99 }; | 102 }; |
| 100 | 103 |
| 101 /** | 104 /** |
| 102 * A test adapter proxy for the chrome://bluetooth-internals page. | 105 * A test adapter proxy for the chrome://bluetooth-internals page. |
| 103 * | 106 * |
| 104 * @constructor | 107 * @constructor |
| 105 * @extends {TestBrowserProxyBase} | 108 * @extends {TestBrowserProxyBase} |
| (...skipping 30 matching lines...) Expand all Loading... |
| 136 this.adapterInfo_ = adapterInfo; | 139 this.adapterInfo_ = adapterInfo; |
| 137 }, | 140 }, |
| 138 | 141 |
| 139 setTestDevices: function(devices) { | 142 setTestDevices: function(devices) { |
| 140 this.devices_ = devices; | 143 this.devices_ = devices; |
| 141 } | 144 } |
| 142 }; | 145 }; |
| 143 | 146 |
| 144 frameInterfaces.addInterfaceOverrideForTesting( | 147 frameInterfaces.addInterfaceOverrideForTesting( |
| 145 adapter.AdapterFactory.name, function(handle) { | 148 adapter.AdapterFactory.name, function(handle) { |
| 149 var stub = connection.bindHandleToStub( |
| 150 handle, adapter.AdapterFactory); |
| 151 |
| 146 this.adapterFactory = new TestAdapterFactoryProxy(); | 152 this.adapterFactory = new TestAdapterFactoryProxy(); |
| 147 this.adapterFactory.binding.bind(handle); | |
| 148 | 153 |
| 149 this.adapterFactory.adapter.proxy.setTestDevices([ | 154 this.adapterFactory.adapter.proxy.setTestDevices([ |
| 150 this.fakeDeviceInfo1(), | 155 this.fakeDeviceInfo1(), |
| 151 this.fakeDeviceInfo2(), | 156 this.fakeDeviceInfo2(), |
| 152 ]); | 157 ]); |
| 153 this.adapterFactory.adapter.proxy.setTestAdapter( | 158 this.adapterFactory.adapter.proxy.setTestAdapter( |
| 154 this.fakeAdapterInfo()); | 159 this.fakeAdapterInfo()); |
| 155 | 160 |
| 161 bindings.StubBindings(stub).delegate = this.adapterFactory; |
| 162 |
| 156 this.setupResolver.resolve(); | 163 this.setupResolver.resolve(); |
| 157 }.bind(this)); | 164 }.bind(this)); |
| 158 | 165 |
| 159 }.bind(this)); | 166 }.bind(this)); |
| 160 }.bind(this); | 167 }.bind(this); |
| 161 }, | 168 }, |
| 162 | 169 |
| 163 /** | 170 /** |
| 164 * Returns a copy of fake adapter info object. | 171 * Returns a copy of fake adapter info object. |
| 165 * @return {!Object} | 172 * @return {!Object} |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 // Multiple calls to close shouldn't change the state. | 463 // Multiple calls to close shouldn't change the state. |
| 457 sidebarObj.close(); | 464 sidebarObj.close(); |
| 458 sidebarObj.close(); | 465 sidebarObj.close(); |
| 459 expectFalse(sidebarNode.classList.contains('open')); | 466 expectFalse(sidebarNode.classList.contains('open')); |
| 460 }); | 467 }); |
| 461 }); | 468 }); |
| 462 | 469 |
| 463 // Run all registered tests. | 470 // Run all registered tests. |
| 464 mocha.run(); | 471 mocha.run(); |
| 465 }); | 472 }); |
| OLD | NEW |