OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 <deque> | |
6 #include <string> | 5 #include <string> |
7 #include <vector> | |
8 | 6 |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "chrome/browser/extensions/api/serial/serial_api.h" | |
11 #include "chrome/browser/extensions/api/serial/serial_connection.h" | |
12 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
13 #include "chrome/browser/extensions/extension_function_test_utils.h" | 8 #include "extensions/browser/api/serial/serial_api.h" |
14 #include "chrome/browser/extensions/extension_test_message_listener.h" | 9 #include "extensions/browser/api/serial/serial_connection.h" |
15 #include "chrome/browser/ui/browser.h" | |
16 #include "chrome/common/extensions/api/serial.h" | |
17 #include "content/public/browser/browser_thread.h" | |
18 #include "extensions/browser/extension_function.h" | 10 #include "extensions/browser/extension_function.h" |
| 11 #include "extensions/common/api/serial.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
20 | 13 |
21 using testing::_; | 14 using testing::_; |
22 using testing::Return; | 15 using testing::Return; |
23 | 16 |
24 using content::BrowserThread; | |
25 | |
26 namespace { | 17 namespace { |
27 | 18 |
28 class SerialApiTest : public ExtensionApiTest { | 19 class SerialApiTest : public ExtensionApiTest { |
29 public: | 20 public: |
30 SerialApiTest() {} | 21 SerialApiTest() {} |
31 }; | 22 }; |
32 | 23 |
33 } // namespace | 24 } // namespace |
34 | 25 |
35 namespace extensions { | 26 namespace extensions { |
36 | 27 |
37 class FakeSerialGetDevicesFunction : public AsyncExtensionFunction { | 28 class FakeSerialGetDevicesFunction : public AsyncExtensionFunction { |
38 public: | 29 public: |
39 virtual bool RunAsync() OVERRIDE { | 30 virtual bool RunAsync() OVERRIDE { |
40 base::ListValue* devices = new base::ListValue(); | 31 base::ListValue* devices = new base::ListValue(); |
41 base::DictionaryValue* device0 = new base::DictionaryValue(); | 32 base::DictionaryValue* device0 = new base::DictionaryValue(); |
42 device0->SetString("path", "/dev/fakeserial"); | 33 device0->SetString("path", "/dev/fakeserial"); |
43 base::DictionaryValue* device1 = new base::DictionaryValue(); | 34 base::DictionaryValue* device1 = new base::DictionaryValue(); |
44 device1->SetString("path", "\\\\COM800\\"); | 35 device1->SetString("path", "\\\\COM800\\"); |
45 devices->Append(device0); | 36 devices->Append(device0); |
46 devices->Append(device1); | 37 devices->Append(device1); |
47 SetResult(devices); | 38 SetResult(devices); |
48 SendResponse(true); | 39 SendResponse(true); |
49 return true; | 40 return true; |
50 } | 41 } |
| 42 |
51 protected: | 43 protected: |
52 virtual ~FakeSerialGetDevicesFunction() {} | 44 virtual ~FakeSerialGetDevicesFunction() {} |
53 }; | 45 }; |
54 | 46 |
55 class FakeEchoSerialIoHandler : public device::SerialIoHandler { | 47 class FakeEchoSerialIoHandler : public device::SerialIoHandler { |
56 public: | 48 public: |
57 explicit FakeEchoSerialIoHandler() : opened_(false) {} | 49 explicit FakeEchoSerialIoHandler() : opened_(false) {} |
58 | 50 |
59 virtual void Open(const std::string& port, | 51 virtual void Open(const std::string& port, |
60 const OpenCompleteCallback& callback) OVERRIDE { | 52 const OpenCompleteCallback& callback) OVERRIDE { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 111 |
120 protected: | 112 protected: |
121 virtual ~FakeEchoSerialIoHandler() {} | 113 virtual ~FakeEchoSerialIoHandler() {} |
122 | 114 |
123 private: | 115 private: |
124 bool opened_; | 116 bool opened_; |
125 | 117 |
126 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialIoHandler); | 118 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialIoHandler); |
127 }; | 119 }; |
128 | 120 |
129 class FakeSerialConnectFunction : public api::SerialConnectFunction { | 121 class FakeSerialConnectFunction : public core_api::SerialConnectFunction { |
130 protected: | 122 protected: |
131 virtual SerialConnection* CreateSerialConnection( | 123 virtual SerialConnection* CreateSerialConnection( |
132 const std::string& port, | 124 const std::string& port, |
133 const std::string& owner_extension_id) const OVERRIDE { | 125 const std::string& owner_extension_id) const OVERRIDE { |
134 scoped_refptr<FakeEchoSerialIoHandler> io_handler = | 126 scoped_refptr<FakeEchoSerialIoHandler> io_handler = |
135 new FakeEchoSerialIoHandler; | 127 new FakeEchoSerialIoHandler; |
136 EXPECT_CALL(*io_handler, SetControlSignals(_)).Times(1).WillOnce( | 128 EXPECT_CALL(*io_handler, SetControlSignals(_)).Times(1).WillOnce( |
137 Return(true)); | 129 Return(true)); |
138 SerialConnection* serial_connection = | 130 SerialConnection* serial_connection = |
139 new SerialConnection(port, owner_extension_id); | 131 new SerialConnection(port, owner_extension_id); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 | 180 |
189 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; | 181 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; |
190 } | 182 } |
191 | 183 |
192 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { | 184 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { |
193 ResultCatcher catcher; | 185 ResultCatcher catcher; |
194 catcher.RestrictToProfile(browser()->profile()); | 186 catcher.RestrictToProfile(browser()->profile()); |
195 | 187 |
196 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; | 188 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; |
197 } | 189 } |
OLD | NEW |