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 <queue> | 5 #include <queue> |
6 | 6 |
7 #include "device/serial/data_source_sender.h" | 7 #include "device/serial/data_source_sender.h" |
8 #include "device/serial/data_stream.mojom.h" | 8 #include "device/serial/data_stream.mojom.h" |
9 #include "extensions/renderer/api_test_base.h" | 9 #include "extensions/renderer/api_test_base.h" |
10 #include "grit/extensions_renderer_resources.h" | 10 #include "grit/extensions_renderer_resources.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 env()->RegisterModule("data_receiver", IDR_DATA_RECEIVER_JS); | 22 env()->RegisterModule("data_receiver", IDR_DATA_RECEIVER_JS); |
23 env()->RegisterModule("device/serial/data_stream.mojom", | 23 env()->RegisterModule("device/serial/data_stream.mojom", |
24 IDR_DATA_STREAM_MOJOM_JS); | 24 IDR_DATA_STREAM_MOJOM_JS); |
25 service_provider()->AddService(base::Bind( | 25 service_provider()->AddService(base::Bind( |
26 &DataReceiverTest::CreateDataSource, base::Unretained(this))); | 26 &DataReceiverTest::CreateDataSource, base::Unretained(this))); |
27 } | 27 } |
28 | 28 |
29 virtual void TearDown() OVERRIDE { | 29 virtual void TearDown() OVERRIDE { |
30 if (sender_.get()) { | 30 if (sender_.get()) { |
31 sender_->ShutDown(); | 31 sender_->ShutDown(); |
32 sender_ = NULL; | 32 sender_ = nullptr; |
33 } | 33 } |
34 ApiTestBase::TearDown(); | 34 ApiTestBase::TearDown(); |
35 } | 35 } |
36 | 36 |
37 std::queue<int32_t> error_to_send_; | 37 std::queue<int32_t> error_to_send_; |
38 std::queue<std::string> data_to_send_; | 38 std::queue<std::string> data_to_send_; |
39 | 39 |
40 private: | 40 private: |
41 void CreateDataSource( | 41 void CreateDataSource( |
42 mojo::InterfaceRequest<device::serial::DataSource> request) { | 42 mojo::InterfaceRequest<device::serial::DataSource> request) { |
(...skipping 13 matching lines...) Expand all Loading... |
56 if (!data_to_send_.empty()) { | 56 if (!data_to_send_.empty()) { |
57 data = data_to_send_.front(); | 57 data = data_to_send_.front(); |
58 data_to_send_.pop(); | 58 data_to_send_.pop(); |
59 } | 59 } |
60 if (!error_to_send_.empty()) { | 60 if (!error_to_send_.empty()) { |
61 error = error_to_send_.front(); | 61 error = error_to_send_.front(); |
62 error_to_send_.pop(); | 62 error_to_send_.pop(); |
63 } | 63 } |
64 if (error == 2) { | 64 if (error == 2) { |
65 sender_->ShutDown(); | 65 sender_->ShutDown(); |
66 sender_ = NULL; | 66 sender_ = nullptr; |
67 return; | 67 return; |
68 } | 68 } |
69 DCHECK(buffer->GetSize() >= static_cast<uint32_t>(data.size())); | 69 DCHECK(buffer->GetSize() >= static_cast<uint32_t>(data.size())); |
70 memcpy(buffer->GetData(), data.c_str(), data.size()); | 70 memcpy(buffer->GetData(), data.c_str(), data.size()); |
71 if (error) | 71 if (error) |
72 buffer->DoneWithError(data.size(), error); | 72 buffer->DoneWithError(data.size(), error); |
73 else | 73 else |
74 buffer->Done(data.size()); | 74 buffer->Done(data.size()); |
75 } | 75 } |
76 | 76 |
(...skipping 25 matching lines...) Expand all Loading... |
102 error_to_send_.push(1); | 102 error_to_send_.push(1); |
103 RunTest("data_receiver_unittest.js", "testReceiveErrorThenData"); | 103 RunTest("data_receiver_unittest.js", "testReceiveErrorThenData"); |
104 } | 104 } |
105 | 105 |
106 TEST_F(DataReceiverTest, SourceShutdown) { | 106 TEST_F(DataReceiverTest, SourceShutdown) { |
107 error_to_send_.push(2); | 107 error_to_send_.push(2); |
108 RunTest("data_receiver_unittest.js", "testSourceShutdown"); | 108 RunTest("data_receiver_unittest.js", "testSourceShutdown"); |
109 } | 109 } |
110 | 110 |
111 } // namespace extensions | 111 } // namespace extensions |
OLD | NEW |