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

Side by Side Diff: extensions/renderer/api/serial/serial_api_unittest.cc

Issue 1527183003: Change mojo enums to be scoped enums in the generated C++ bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mojo-binding-equals
Patch Set: rebase Created 4 years, 11 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
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 }; 182 };
183 183
184 class ConfigurePortTestIoHandler : public TestIoHandlerBase { 184 class ConfigurePortTestIoHandler : public TestIoHandlerBase {
185 public: 185 public:
186 ConfigurePortTestIoHandler() {} 186 ConfigurePortTestIoHandler() {}
187 bool ConfigurePortImpl() override { 187 bool ConfigurePortImpl() override {
188 static const device::serial::ConnectionOptions expected_options[] = { 188 static const device::serial::ConnectionOptions expected_options[] = {
189 // Each JavaScript call to chrome.serial.update only modifies a single 189 // Each JavaScript call to chrome.serial.update only modifies a single
190 // property of the connection however this function can only check the 190 // property of the connection however this function can only check the
191 // final value of all options. The modified option is marked with "set". 191 // final value of all options. The modified option is marked with "set".
192 GenerateConnectionOptions(9600, 192 GenerateConnectionOptions(9600, device::serial::DataBits::EIGHT,
193 device::serial::DATA_BITS_EIGHT, 193 device::serial::ParityBit::NO,
194 device::serial::PARITY_BIT_NO, 194 device::serial::StopBits::ONE,
195 device::serial::STOP_BITS_ONE,
196 OPTIONAL_VALUE_FALSE), 195 OPTIONAL_VALUE_FALSE),
197 GenerateConnectionOptions(57600, // set 196 GenerateConnectionOptions(
198 device::serial::DATA_BITS_EIGHT, 197 57600, // set
199 device::serial::PARITY_BIT_NO, 198 device::serial::DataBits::EIGHT, device::serial::ParityBit::NO,
200 device::serial::STOP_BITS_ONE, 199 device::serial::StopBits::ONE, OPTIONAL_VALUE_FALSE),
200 GenerateConnectionOptions(57600,
201 device::serial::DataBits::SEVEN, // set
202 device::serial::ParityBit::NO,
203 device::serial::StopBits::ONE,
201 OPTIONAL_VALUE_FALSE), 204 OPTIONAL_VALUE_FALSE),
202 GenerateConnectionOptions(57600, 205 GenerateConnectionOptions(57600,
203 device::serial::DATA_BITS_SEVEN, // set 206 device::serial::DataBits::EIGHT, // set
204 device::serial::PARITY_BIT_NO, 207 device::serial::ParityBit::NO,
205 device::serial::STOP_BITS_ONE, 208 device::serial::StopBits::ONE,
206 OPTIONAL_VALUE_FALSE), 209 OPTIONAL_VALUE_FALSE),
207 GenerateConnectionOptions(57600, 210 GenerateConnectionOptions(57600, device::serial::DataBits::EIGHT,
208 device::serial::DATA_BITS_EIGHT, // set 211 device::serial::ParityBit::NO, // set
209 device::serial::PARITY_BIT_NO, 212 device::serial::StopBits::ONE,
210 device::serial::STOP_BITS_ONE,
211 OPTIONAL_VALUE_FALSE), 213 OPTIONAL_VALUE_FALSE),
212 GenerateConnectionOptions(57600, 214 GenerateConnectionOptions(57600, device::serial::DataBits::EIGHT,
213 device::serial::DATA_BITS_EIGHT, 215 device::serial::ParityBit::ODD, // set
214 device::serial::PARITY_BIT_NO, // set 216 device::serial::StopBits::ONE,
215 device::serial::STOP_BITS_ONE,
216 OPTIONAL_VALUE_FALSE), 217 OPTIONAL_VALUE_FALSE),
217 GenerateConnectionOptions(57600, 218 GenerateConnectionOptions(57600, device::serial::DataBits::EIGHT,
218 device::serial::DATA_BITS_EIGHT, 219 device::serial::ParityBit::EVEN, // set
219 device::serial::PARITY_BIT_ODD, // set 220 device::serial::StopBits::ONE,
220 device::serial::STOP_BITS_ONE,
221 OPTIONAL_VALUE_FALSE), 221 OPTIONAL_VALUE_FALSE),
222 GenerateConnectionOptions(57600, 222 GenerateConnectionOptions(57600, device::serial::DataBits::EIGHT,
223 device::serial::DATA_BITS_EIGHT, 223 device::serial::ParityBit::EVEN,
224 device::serial::PARITY_BIT_EVEN, // set 224 device::serial::StopBits::ONE, // set
225 device::serial::STOP_BITS_ONE,
226 OPTIONAL_VALUE_FALSE), 225 OPTIONAL_VALUE_FALSE),
227 GenerateConnectionOptions(57600, 226 GenerateConnectionOptions(57600, device::serial::DataBits::EIGHT,
228 device::serial::DATA_BITS_EIGHT, 227 device::serial::ParityBit::EVEN,
229 device::serial::PARITY_BIT_EVEN, 228 device::serial::StopBits::TWO, // set
230 device::serial::STOP_BITS_ONE, // set
231 OPTIONAL_VALUE_FALSE), 229 OPTIONAL_VALUE_FALSE),
232 GenerateConnectionOptions(57600, 230 GenerateConnectionOptions(57600, device::serial::DataBits::EIGHT,
233 device::serial::DATA_BITS_EIGHT, 231 device::serial::ParityBit::EVEN,
234 device::serial::PARITY_BIT_EVEN, 232 device::serial::StopBits::TWO,
235 device::serial::STOP_BITS_TWO, // set
236 OPTIONAL_VALUE_FALSE),
237 GenerateConnectionOptions(57600,
238 device::serial::DATA_BITS_EIGHT,
239 device::serial::PARITY_BIT_EVEN,
240 device::serial::STOP_BITS_TWO,
241 OPTIONAL_VALUE_FALSE), // set 233 OPTIONAL_VALUE_FALSE), // set
242 GenerateConnectionOptions(57600, 234 GenerateConnectionOptions(57600, device::serial::DataBits::EIGHT,
243 device::serial::DATA_BITS_EIGHT, 235 device::serial::ParityBit::EVEN,
244 device::serial::PARITY_BIT_EVEN, 236 device::serial::StopBits::TWO,
245 device::serial::STOP_BITS_TWO,
246 OPTIONAL_VALUE_TRUE), // set 237 OPTIONAL_VALUE_TRUE), // set
247 }; 238 };
248 239
249 if (!TestIoHandlerBase::ConfigurePortImpl()) { 240 if (!TestIoHandlerBase::ConfigurePortImpl()) {
250 return false; 241 return false;
251 } 242 }
252 243
253 if (num_calls() >= arraysize(expected_options)) { 244 if (num_calls() >= arraysize(expected_options)) {
254 return false; 245 return false;
255 } 246 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 class FixedDataReceiveTestIoHandler : public TestIoHandlerBase { 330 class FixedDataReceiveTestIoHandler : public TestIoHandlerBase {
340 public: 331 public:
341 explicit FixedDataReceiveTestIoHandler(const std::string& data) 332 explicit FixedDataReceiveTestIoHandler(const std::string& data)
342 : data_(data) {} 333 : data_(data) {}
343 334
344 void ReadImpl() override { 335 void ReadImpl() override {
345 if (pending_read_buffer_len() < data_.size()) 336 if (pending_read_buffer_len() < data_.size())
346 return; 337 return;
347 memcpy(pending_read_buffer(), data_.c_str(), data_.size()); 338 memcpy(pending_read_buffer(), data_.c_str(), data_.size());
348 QueueReadCompleted(static_cast<uint32_t>(data_.size()), 339 QueueReadCompleted(static_cast<uint32_t>(data_.size()),
349 device::serial::RECEIVE_ERROR_NONE); 340 device::serial::ReceiveError::NONE);
350 } 341 }
351 342
352 private: 343 private:
353 ~FixedDataReceiveTestIoHandler() override {} 344 ~FixedDataReceiveTestIoHandler() override {}
354 345
355 const std::string data_; 346 const std::string data_;
356 347
357 DISALLOW_COPY_AND_ASSIGN(FixedDataReceiveTestIoHandler); 348 DISALLOW_COPY_AND_ASSIGN(FixedDataReceiveTestIoHandler);
358 }; 349 };
359 350
(...skipping 11 matching lines...) Expand all
371 362
372 DISALLOW_COPY_AND_ASSIGN(ReceiveErrorTestIoHandler); 363 DISALLOW_COPY_AND_ASSIGN(ReceiveErrorTestIoHandler);
373 }; 364 };
374 365
375 class SendDataWithErrorIoHandler : public TestIoHandlerBase { 366 class SendDataWithErrorIoHandler : public TestIoHandlerBase {
376 public: 367 public:
377 SendDataWithErrorIoHandler() : sent_error_(false) {} 368 SendDataWithErrorIoHandler() : sent_error_(false) {}
378 void WriteImpl() override { 369 void WriteImpl() override {
379 if (sent_error_) { 370 if (sent_error_) {
380 WriteCompleted(pending_write_buffer_len(), 371 WriteCompleted(pending_write_buffer_len(),
381 device::serial::SEND_ERROR_NONE); 372 device::serial::SendError::NONE);
382 return; 373 return;
383 } 374 }
384 sent_error_ = true; 375 sent_error_ = true;
385 // We expect the JS test code to send a 4 byte buffer. 376 // We expect the JS test code to send a 4 byte buffer.
386 ASSERT_LT(2u, pending_write_buffer_len()); 377 ASSERT_LT(2u, pending_write_buffer_len());
387 WriteCompleted(2, device::serial::SEND_ERROR_SYSTEM_ERROR); 378 WriteCompleted(2, device::serial::SendError::SYSTEM_ERROR);
388 } 379 }
389 380
390 private: 381 private:
391 ~SendDataWithErrorIoHandler() override {} 382 ~SendDataWithErrorIoHandler() override {}
392 383
393 bool sent_error_; 384 bool sent_error_;
394 385
395 DISALLOW_COPY_AND_ASSIGN(SendDataWithErrorIoHandler); 386 DISALLOW_COPY_AND_ASSIGN(SendDataWithErrorIoHandler);
396 }; 387 };
397 388
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 RunTest("serial_unittest.js", "testDisableSendTimeout"); 564 RunTest("serial_unittest.js", "testDisableSendTimeout");
574 } 565 }
575 566
576 TEST_F(SerialApiTest, PausedReceive) { 567 TEST_F(SerialApiTest, PausedReceive) {
577 io_handler_ = new FixedDataReceiveTestIoHandler("data"); 568 io_handler_ = new FixedDataReceiveTestIoHandler("data");
578 RunTest("serial_unittest.js", "testPausedReceive"); 569 RunTest("serial_unittest.js", "testPausedReceive");
579 } 570 }
580 571
581 TEST_F(SerialApiTest, PausedReceiveError) { 572 TEST_F(SerialApiTest, PausedReceiveError) {
582 io_handler_ = 573 io_handler_ =
583 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DEVICE_LOST); 574 new ReceiveErrorTestIoHandler(device::serial::ReceiveError::DEVICE_LOST);
584 RunTest("serial_unittest.js", "testPausedReceiveError"); 575 RunTest("serial_unittest.js", "testPausedReceiveError");
585 } 576 }
586 577
587 TEST_F(SerialApiTest, ReceiveTimeout) { 578 TEST_F(SerialApiTest, ReceiveTimeout) {
588 RunTest("serial_unittest.js", "testReceiveTimeout"); 579 RunTest("serial_unittest.js", "testReceiveTimeout");
589 } 580 }
590 581
591 TEST_F(SerialApiTest, ReceiveTimeoutAfterSerialization) { 582 TEST_F(SerialApiTest, ReceiveTimeoutAfterSerialization) {
592 RunTest("serial_unittest.js", "testReceiveTimeoutAfterSerialization"); 583 RunTest("serial_unittest.js", "testReceiveTimeoutAfterSerialization");
593 } 584 }
594 585
595 TEST_F(SerialApiTest, DisableReceiveTimeout) { 586 TEST_F(SerialApiTest, DisableReceiveTimeout) {
596 RunTest("serial_unittest.js", "testDisableReceiveTimeout"); 587 RunTest("serial_unittest.js", "testDisableReceiveTimeout");
597 } 588 }
598 589
599 TEST_F(SerialApiTest, ReceiveErrorDisconnected) { 590 TEST_F(SerialApiTest, ReceiveErrorDisconnected) {
600 io_handler_ = 591 io_handler_ =
601 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DISCONNECTED); 592 new ReceiveErrorTestIoHandler(device::serial::ReceiveError::DISCONNECTED);
602 RunTest("serial_unittest.js", "testReceiveErrorDisconnected"); 593 RunTest("serial_unittest.js", "testReceiveErrorDisconnected");
603 } 594 }
604 595
605 TEST_F(SerialApiTest, ReceiveErrorDeviceLost) { 596 TEST_F(SerialApiTest, ReceiveErrorDeviceLost) {
606 io_handler_ = 597 io_handler_ =
607 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DEVICE_LOST); 598 new ReceiveErrorTestIoHandler(device::serial::ReceiveError::DEVICE_LOST);
608 RunTest("serial_unittest.js", "testReceiveErrorDeviceLost"); 599 RunTest("serial_unittest.js", "testReceiveErrorDeviceLost");
609 } 600 }
610 601
611 TEST_F(SerialApiTest, ReceiveErrorBreak) { 602 TEST_F(SerialApiTest, ReceiveErrorBreak) {
612 io_handler_ = 603 io_handler_ =
613 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_BREAK); 604 new ReceiveErrorTestIoHandler(device::serial::ReceiveError::BREAK);
614 RunTest("serial_unittest.js", "testReceiveErrorBreak"); 605 RunTest("serial_unittest.js", "testReceiveErrorBreak");
615 } 606 }
616 607
617 TEST_F(SerialApiTest, ReceiveErrorFrameError) { 608 TEST_F(SerialApiTest, ReceiveErrorFrameError) {
618 io_handler_ = 609 io_handler_ =
619 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_FRAME_ERROR); 610 new ReceiveErrorTestIoHandler(device::serial::ReceiveError::FRAME_ERROR);
620 RunTest("serial_unittest.js", "testReceiveErrorFrameError"); 611 RunTest("serial_unittest.js", "testReceiveErrorFrameError");
621 } 612 }
622 613
623 TEST_F(SerialApiTest, ReceiveErrorOverrun) { 614 TEST_F(SerialApiTest, ReceiveErrorOverrun) {
624 io_handler_ = 615 io_handler_ =
625 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_OVERRUN); 616 new ReceiveErrorTestIoHandler(device::serial::ReceiveError::OVERRUN);
626 RunTest("serial_unittest.js", "testReceiveErrorOverrun"); 617 RunTest("serial_unittest.js", "testReceiveErrorOverrun");
627 } 618 }
628 619
629 TEST_F(SerialApiTest, ReceiveErrorBufferOverflow) { 620 TEST_F(SerialApiTest, ReceiveErrorBufferOverflow) {
630 io_handler_ = new ReceiveErrorTestIoHandler( 621 io_handler_ = new ReceiveErrorTestIoHandler(
631 device::serial::RECEIVE_ERROR_BUFFER_OVERFLOW); 622 device::serial::ReceiveError::BUFFER_OVERFLOW);
632 RunTest("serial_unittest.js", "testReceiveErrorBufferOverflow"); 623 RunTest("serial_unittest.js", "testReceiveErrorBufferOverflow");
633 } 624 }
634 625
635 TEST_F(SerialApiTest, ReceiveErrorParityError) { 626 TEST_F(SerialApiTest, ReceiveErrorParityError) {
636 io_handler_ = 627 io_handler_ =
637 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_PARITY_ERROR); 628 new ReceiveErrorTestIoHandler(device::serial::ReceiveError::PARITY_ERROR);
638 RunTest("serial_unittest.js", "testReceiveErrorParityError"); 629 RunTest("serial_unittest.js", "testReceiveErrorParityError");
639 } 630 }
640 631
641 TEST_F(SerialApiTest, ReceiveErrorSystemError) { 632 TEST_F(SerialApiTest, ReceiveErrorSystemError) {
642 io_handler_ = 633 io_handler_ =
643 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_SYSTEM_ERROR); 634 new ReceiveErrorTestIoHandler(device::serial::ReceiveError::SYSTEM_ERROR);
644 RunTest("serial_unittest.js", "testReceiveErrorSystemError"); 635 RunTest("serial_unittest.js", "testReceiveErrorSystemError");
645 } 636 }
646 637
647 TEST_F(SerialApiTest, SendErrorDisconnected) { 638 TEST_F(SerialApiTest, SendErrorDisconnected) {
648 io_handler_ = 639 io_handler_ =
649 new SendErrorTestIoHandler(device::serial::SEND_ERROR_DISCONNECTED); 640 new SendErrorTestIoHandler(device::serial::SendError::DISCONNECTED);
650 RunTest("serial_unittest.js", "testSendErrorDisconnected"); 641 RunTest("serial_unittest.js", "testSendErrorDisconnected");
651 } 642 }
652 643
653 TEST_F(SerialApiTest, SendErrorSystemError) { 644 TEST_F(SerialApiTest, SendErrorSystemError) {
654 io_handler_ = 645 io_handler_ =
655 new SendErrorTestIoHandler(device::serial::SEND_ERROR_SYSTEM_ERROR); 646 new SendErrorTestIoHandler(device::serial::SendError::SYSTEM_ERROR);
656 RunTest("serial_unittest.js", "testSendErrorSystemError"); 647 RunTest("serial_unittest.js", "testSendErrorSystemError");
657 } 648 }
658 649
659 TEST_F(SerialApiTest, DisconnectUnknownConnectionId) { 650 TEST_F(SerialApiTest, DisconnectUnknownConnectionId) {
660 RunTest("serial_unittest.js", "testDisconnectUnknownConnectionId"); 651 RunTest("serial_unittest.js", "testDisconnectUnknownConnectionId");
661 } 652 }
662 653
663 TEST_F(SerialApiTest, GetInfoUnknownConnectionId) { 654 TEST_F(SerialApiTest, GetInfoUnknownConnectionId) {
664 RunTest("serial_unittest.js", "testGetInfoUnknownConnectionId"); 655 RunTest("serial_unittest.js", "testGetInfoUnknownConnectionId");
665 } 656 }
(...skipping 28 matching lines...) Expand all
694 TEST_F(SerialApiTest, DISABLED_StashAndRestoreDuringEcho) { 685 TEST_F(SerialApiTest, DISABLED_StashAndRestoreDuringEcho) {
695 ASSERT_NO_FATAL_FAILURE(RunTest("serial_unittest.js", "testSendAndStash")); 686 ASSERT_NO_FATAL_FAILURE(RunTest("serial_unittest.js", "testSendAndStash"));
696 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment()); 687 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment());
697 ApiTestEnvironment new_api_test_env(new_env.get()); 688 ApiTestEnvironment new_api_test_env(new_env.get());
698 PrepareEnvironment(&new_api_test_env, stash_backend_.get()); 689 PrepareEnvironment(&new_api_test_env, stash_backend_.get());
699 new_api_test_env.RunTest("serial_unittest.js", "testRestoreAndReceive"); 690 new_api_test_env.RunTest("serial_unittest.js", "testRestoreAndReceive");
700 } 691 }
701 692
702 TEST_F(SerialApiTest, DISABLED_StashAndRestoreDuringEchoError) { 693 TEST_F(SerialApiTest, DISABLED_StashAndRestoreDuringEchoError) {
703 io_handler_ = 694 io_handler_ =
704 new ReceiveErrorTestIoHandler(device::serial::RECEIVE_ERROR_DEVICE_LOST); 695 new ReceiveErrorTestIoHandler(device::serial::ReceiveError::DEVICE_LOST);
705 ASSERT_NO_FATAL_FAILURE( 696 ASSERT_NO_FATAL_FAILURE(
706 RunTest("serial_unittest.js", "testRestoreAndReceiveErrorSetUp")); 697 RunTest("serial_unittest.js", "testRestoreAndReceiveErrorSetUp"));
707 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment()); 698 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment());
708 ApiTestEnvironment new_api_test_env(new_env.get()); 699 ApiTestEnvironment new_api_test_env(new_env.get());
709 PrepareEnvironment(&new_api_test_env, stash_backend_.get()); 700 PrepareEnvironment(&new_api_test_env, stash_backend_.get());
710 new_api_test_env.RunTest("serial_unittest.js", "testRestoreAndReceiveError"); 701 new_api_test_env.RunTest("serial_unittest.js", "testRestoreAndReceiveError");
711 } 702 }
712 703
713 TEST_F(SerialApiTest, StashAndRestoreNoConnections) { 704 TEST_F(SerialApiTest, StashAndRestoreNoConnections) {
714 ASSERT_NO_FATAL_FAILURE( 705 ASSERT_NO_FATAL_FAILURE(
715 RunTest("serial_unittest.js", "testStashNoConnections")); 706 RunTest("serial_unittest.js", "testStashNoConnections"));
716 io_handler_ = nullptr; 707 io_handler_ = nullptr;
717 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment()); 708 scoped_ptr<ModuleSystemTestEnvironment> new_env(CreateEnvironment());
718 ApiTestEnvironment new_api_test_env(new_env.get()); 709 ApiTestEnvironment new_api_test_env(new_env.get());
719 PrepareEnvironment(&new_api_test_env, stash_backend_.get()); 710 PrepareEnvironment(&new_api_test_env, stash_backend_.get());
720 new_api_test_env.RunTest("serial_unittest.js", "testRestoreNoConnections"); 711 new_api_test_env.RunTest("serial_unittest.js", "testRestoreNoConnections");
721 } 712 }
722 713
723 } // namespace extensions 714 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/serial/serial_connection.cc ('k') | mandoline/ui/desktop_ui/browser_window.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698