| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
| 8 #include "content/public/browser/browser_thread.h" | 8 #include "content/public/browser/browser_thread.h" |
| 9 #include "device/serial/serial_device_enumerator.h" | 9 #include "device/serial/serial_device_enumerator.h" |
| 10 #include "device/serial/serial_service_impl.h" | 10 #include "device/serial/serial_service_impl.h" |
| 11 #include "device/serial/test_serial_io_handler.h" | 11 #include "device/serial/test_serial_io_handler.h" |
| 12 #include "extensions/browser/api/serial/serial_api.h" | 12 #include "extensions/browser/api/serial/serial_api.h" |
| 13 #include "extensions/browser/api/serial/serial_connection.h" | 13 #include "extensions/browser/api/serial/serial_connection.h" |
| 14 #include "extensions/browser/api/serial/serial_service_factory.h" |
| 14 #include "extensions/browser/extension_function.h" | 15 #include "extensions/browser/extension_function.h" |
| 15 #include "extensions/common/api/serial.h" | 16 #include "extensions/common/api/serial.h" |
| 16 #include "extensions/common/switches.h" | 17 #include "extensions/common/switches.h" |
| 17 #include "extensions/test/result_catcher.h" | 18 #include "extensions/test/result_catcher.h" |
| 18 #include "extensions/test/test_service_registration_manager.h" | |
| 19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 20 | 20 |
| 21 using testing::_; | 21 using testing::_; |
| 22 using testing::Return; | 22 using testing::Return; |
| 23 | 23 |
| 24 namespace extensions { | 24 namespace extensions { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 class FakeSerialGetDevicesFunction : public AsyncExtensionFunction { | 27 class FakeSerialGetDevicesFunction : public AsyncExtensionFunction { |
| 28 public: | 28 public: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 class SerialApiTest : public ExtensionApiTest, | 103 class SerialApiTest : public ExtensionApiTest, |
| 104 public testing::WithParamInterface<bool> { | 104 public testing::WithParamInterface<bool> { |
| 105 public: | 105 public: |
| 106 SerialApiTest() {} | 106 SerialApiTest() {} |
| 107 | 107 |
| 108 void SetUpCommandLine(base::CommandLine* command_line) override { | 108 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 109 ExtensionApiTest::SetUpCommandLine(command_line); | 109 ExtensionApiTest::SetUpCommandLine(command_line); |
| 110 if (GetParam()) | 110 if (GetParam()) |
| 111 command_line->AppendSwitch(switches::kEnableMojoSerialService); | 111 command_line->AppendSwitch(switches::kEnableMojoSerialService); |
| 112 test_service_registration_manager_.reset( | 112 } |
| 113 new TestServiceRegistrationManager); | 113 |
| 114 void TearDownOnMainThread() override { |
| 115 SetSerialServiceFactoryForTest(nullptr); |
| 116 ExtensionApiTest::TearDownOnMainThread(); |
| 114 } | 117 } |
| 115 | 118 |
| 116 protected: | 119 protected: |
| 117 scoped_ptr<TestServiceRegistrationManager> test_service_registration_manager_; | 120 base::Callback<void(mojo::InterfaceRequest<device::serial::SerialService>)> |
| 121 serial_service_factory_; |
| 118 }; | 122 }; |
| 119 | 123 |
| 120 ExtensionFunction* FakeSerialGetDevicesFunctionFactory() { | 124 ExtensionFunction* FakeSerialGetDevicesFunctionFactory() { |
| 121 return new FakeSerialGetDevicesFunction(); | 125 return new FakeSerialGetDevicesFunction(); |
| 122 } | 126 } |
| 123 | 127 |
| 124 ExtensionFunction* FakeSerialConnectFunctionFactory() { | 128 ExtensionFunction* FakeSerialConnectFunctionFactory() { |
| 125 return new FakeSerialConnectFunction(); | 129 return new FakeSerialConnectFunction(); |
| 126 } | 130 } |
| 127 | 131 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // on the virtual serial port at 57600 bps. An example is at | 172 // on the virtual serial port at 57600 bps. An example is at |
| 169 // chrome/test/data/extensions/api_test/serial/api/serial_arduino_test.ino. | 173 // chrome/test/data/extensions/api_test/serial/api/serial_arduino_test.ino. |
| 170 // | 174 // |
| 171 #define SIMULATE_SERIAL_PORTS (1) | 175 #define SIMULATE_SERIAL_PORTS (1) |
| 172 IN_PROC_BROWSER_TEST_P(SerialApiTest, SerialFakeHardware) { | 176 IN_PROC_BROWSER_TEST_P(SerialApiTest, SerialFakeHardware) { |
| 173 ResultCatcher catcher; | 177 ResultCatcher catcher; |
| 174 catcher.RestrictToBrowserContext(browser()->profile()); | 178 catcher.RestrictToBrowserContext(browser()->profile()); |
| 175 | 179 |
| 176 #if SIMULATE_SERIAL_PORTS | 180 #if SIMULATE_SERIAL_PORTS |
| 177 if (GetParam()) { | 181 if (GetParam()) { |
| 178 test_service_registration_manager_->OverrideServiceFactoryForTest( | 182 serial_service_factory_ = base::Bind(&CreateTestSerialService); |
| 179 base::Bind(&CreateTestSerialService)); | 183 SetSerialServiceFactoryForTest(&serial_service_factory_); |
| 180 } else { | 184 } else { |
| 181 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( | 185 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( |
| 182 "serial.getDevices", FakeSerialGetDevicesFunctionFactory)); | 186 "serial.getDevices", FakeSerialGetDevicesFunctionFactory)); |
| 183 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( | 187 ASSERT_TRUE(ExtensionFunctionDispatcher::OverrideFunction( |
| 184 "serial.connect", FakeSerialConnectFunctionFactory)); | 188 "serial.connect", FakeSerialConnectFunctionFactory)); |
| 185 } | 189 } |
| 186 #endif | 190 #endif |
| 187 | 191 |
| 188 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; | 192 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; |
| 189 } | 193 } |
| 190 | 194 |
| 191 IN_PROC_BROWSER_TEST_P(SerialApiTest, SerialRealHardware) { | 195 IN_PROC_BROWSER_TEST_P(SerialApiTest, SerialRealHardware) { |
| 192 ResultCatcher catcher; | 196 ResultCatcher catcher; |
| 193 catcher.RestrictToBrowserContext(browser()->profile()); | 197 catcher.RestrictToBrowserContext(browser()->profile()); |
| 194 | 198 |
| 195 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; | 199 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; |
| 196 } | 200 } |
| 197 | 201 |
| 198 INSTANTIATE_TEST_CASE_P(SerialApiTest, SerialApiTest, testing::Bool()); | 202 INSTANTIATE_TEST_CASE_P(SerialApiTest, SerialApiTest, testing::Bool()); |
| 199 | 203 |
| 200 } // namespace extensions | 204 } // namespace extensions |
| OLD | NEW |