Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(267)

Side by Side Diff: chrome/browser/extensions/api/serial/serial_apitest.cc

Issue 22804008: Adds Serial API to set data bits, parity, stop bits. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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> 5 #include <deque>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/extensions/api/serial/serial_api.h" 10 #include "chrome/browser/extensions/api/serial/serial_api.h"
11 #include "chrome/browser/extensions/api/serial/serial_connection.h" 11 #include "chrome/browser/extensions/api/serial/serial_connection.h"
12 #include "chrome/browser/extensions/extension_apitest.h" 12 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/browser/extensions/extension_function.h" 13 #include "chrome/browser/extensions/extension_function.h"
14 #include "chrome/browser/extensions/extension_function_test_utils.h" 14 #include "chrome/browser/extensions/extension_function_test_utils.h"
15 #include "chrome/browser/extensions/extension_test_message_listener.h" 15 #include "chrome/browser/extensions/extension_test_message_listener.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
18 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 19
20 using testing::_; 20 using testing::_;
21 using testing::Return; 21 using testing::Return;
22 22
23 using content::BrowserThread; 23 using content::BrowserThread;
24 24
25 namespace serial = extensions::api::serial;
26
25 namespace { 27 namespace {
26 28
27 class SerialApiTest : public ExtensionApiTest { 29 class SerialApiTest : public ExtensionApiTest {
28 public: 30 public:
29 SerialApiTest() {} 31 SerialApiTest() {}
30 }; 32 };
31 33
32 } // namespace 34 } // namespace
33 35
34 namespace extensions { 36 namespace extensions {
(...skipping 10 matching lines...) Expand all
45 } 47 }
46 protected: 48 protected:
47 virtual ~FakeSerialGetPortsFunction() {} 49 virtual ~FakeSerialGetPortsFunction() {}
48 }; 50 };
49 51
50 class FakeEchoSerialConnection : public SerialConnection { 52 class FakeEchoSerialConnection : public SerialConnection {
51 public: 53 public:
52 explicit FakeEchoSerialConnection( 54 explicit FakeEchoSerialConnection(
53 const std::string& port, 55 const std::string& port,
54 int bitrate, 56 int bitrate,
57 serial::DataBit databit,
58 serial::ParityBit parity,
59 serial::StopBit stopbit,
55 const std::string& owner_extension_id) 60 const std::string& owner_extension_id)
56 : SerialConnection(port, bitrate, owner_extension_id), 61 : SerialConnection(port, bitrate, databit, parity, stopbit,
62 owner_extension_id),
57 opened_(true) { 63 opened_(true) {
58 Flush(); 64 Flush();
59 opened_ = false; 65 opened_ = false;
60 } 66 }
61 67
62 virtual ~FakeEchoSerialConnection() { 68 virtual ~FakeEchoSerialConnection() {
63 } 69 }
64 70
65 virtual bool Open() { 71 virtual bool Open() {
66 DCHECK(!opened_); 72 DCHECK(!opened_);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 std::deque<char> buffer_; 117 std::deque<char> buffer_;
112 118
113 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialConnection); 119 DISALLOW_COPY_AND_ASSIGN(FakeEchoSerialConnection);
114 }; 120 };
115 121
116 class FakeSerialOpenFunction : public SerialOpenFunction { 122 class FakeSerialOpenFunction : public SerialOpenFunction {
117 protected: 123 protected:
118 virtual SerialConnection* CreateSerialConnection( 124 virtual SerialConnection* CreateSerialConnection(
119 const std::string& port, 125 const std::string& port,
120 int bitrate, 126 int bitrate,
127 serial::DataBit databit,
128 serial::ParityBit parity,
129 serial::StopBit stopbit,
121 const std::string& owner_extension_id) OVERRIDE { 130 const std::string& owner_extension_id) OVERRIDE {
122 FakeEchoSerialConnection* serial_connection = 131 FakeEchoSerialConnection* serial_connection =
123 new FakeEchoSerialConnection(port, bitrate, owner_extension_id); 132 new FakeEchoSerialConnection(port, bitrate, databit, parity, stopbit,
133 owner_extension_id);
124 EXPECT_CALL(*serial_connection, GetControlSignals(_)). 134 EXPECT_CALL(*serial_connection, GetControlSignals(_)).
125 Times(1).WillOnce(Return(true)); 135 Times(1).WillOnce(Return(true));
126 EXPECT_CALL(*serial_connection, SetControlSignals(_)). 136 EXPECT_CALL(*serial_connection, SetControlSignals(_)).
127 Times(1).WillOnce(Return(true)); 137 Times(1).WillOnce(Return(true));
128 return serial_connection; 138 return serial_connection;
129 } 139 }
130 virtual bool DoesPortExist(const std::string& port) OVERRIDE { 140 virtual bool DoesPortExist(const std::string& port) OVERRIDE {
131 return true; 141 return true;
132 } 142 }
133 143
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 190
181 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_; 191 ASSERT_TRUE(RunExtensionTest("serial/api")) << message_;
182 } 192 }
183 193
184 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) { 194 IN_PROC_BROWSER_TEST_F(SerialApiTest, SerialRealHardware) {
185 ResultCatcher catcher; 195 ResultCatcher catcher;
186 catcher.RestrictToProfile(browser()->profile()); 196 catcher.RestrictToProfile(browser()->profile());
187 197
188 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_; 198 ASSERT_TRUE(RunExtensionTest("serial/real_hardware")) << message_;
189 } 199 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/serial/serial_api.cc ('k') | chrome/browser/extensions/api/serial/serial_connection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698