| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "files/public/cpp/input_stream_file.h" | 5 #include "files/public/cpp/input_stream_file.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 got_request_data_ = false; | 67 got_request_data_ = false; |
| 68 got_on_closed_ = false; | 68 got_on_closed_ = false; |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Completes a pending callback. Note: |RequestData()| may be called again | 71 // Completes a pending callback. Note: |RequestData()| may be called again |
| 72 // "inside" this (i.e., "inside" the callback). | 72 // "inside" this (i.e., "inside" the callback). |
| 73 void RunRequestDataCallback(mojo::Array<uint8_t> data) { | 73 void RunRequestDataCallback(mojo::Array<uint8_t> data) { |
| 74 MOJO_CHECK(!callback_.is_null()); | 74 MOJO_CHECK(!callback_.is_null()); |
| 75 RequestDataCallback callback; | 75 RequestDataCallback callback; |
| 76 std::swap(callback, callback_); | 76 std::swap(callback, callback_); |
| 77 callback.Run(mojo::files::ERROR_OK, data.Pass()); | 77 callback.Run(mojo::files::Error::OK, data.Pass()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void set_data(mojo::Array<uint8_t> data) { | 80 void set_data(mojo::Array<uint8_t> data) { |
| 81 MOJO_CHECK(!data.is_null()); | 81 MOJO_CHECK(!data.is_null()); |
| 82 data_ = data.Pass(); | 82 data_ = data.Pass(); |
| 83 } | 83 } |
| 84 void set_complete_synchronously(bool complete_synchronously) { | 84 void set_complete_synchronously(bool complete_synchronously) { |
| 85 complete_synchronously_ = complete_synchronously; | 85 complete_synchronously_ = complete_synchronously; |
| 86 } | 86 } |
| 87 | 87 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 103 MOJO_CHECK(callback_.is_null()); | 103 MOJO_CHECK(callback_.is_null()); |
| 104 | 104 |
| 105 got_request_data_ = true; | 105 got_request_data_ = true; |
| 106 QuitMessageLoop(); | 106 QuitMessageLoop(); |
| 107 | 107 |
| 108 if (!complete_synchronously_) { | 108 if (!complete_synchronously_) { |
| 109 callback_ = callback; | 109 callback_ = callback; |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| 112 | 112 |
| 113 *error = mojo::files::ERROR_OK; | 113 *error = mojo::files::Error::OK; |
| 114 *data = data_.Clone(); | 114 *data = data_.Clone(); |
| 115 return true; | 115 return true; |
| 116 } | 116 } |
| 117 void OnClosed() override { | 117 void OnClosed() override { |
| 118 got_on_closed_ = true; | 118 got_on_closed_ = true; |
| 119 QuitMessageLoop(); | 119 QuitMessageLoop(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 mojo::Array<uint8_t> data_; | 122 mojo::Array<uint8_t> data_; |
| 123 bool complete_synchronously_; | 123 bool complete_synchronously_; |
| 124 | 124 |
| 125 bool got_request_data_; | 125 bool got_request_data_; |
| 126 bool got_on_closed_; | 126 bool got_on_closed_; |
| 127 | 127 |
| 128 RequestDataCallback callback_; | 128 RequestDataCallback callback_; |
| 129 | 129 |
| 130 MOJO_DISALLOW_COPY_AND_ASSIGN(TestClient); | 130 MOJO_DISALLOW_COPY_AND_ASSIGN(TestClient); |
| 131 }; | 131 }; |
| 132 | 132 |
| 133 void TestReadSync(mojo::files::File* file, | 133 void TestReadSync(mojo::files::File* file, |
| 134 TestClient* client, | 134 TestClient* client, |
| 135 const std::string& s) { | 135 const std::string& s) { |
| 136 bool read_cb_called = false; | 136 bool read_cb_called = false; |
| 137 mojo::files::Error error = mojo::files::ERROR_INTERNAL; | 137 mojo::files::Error error = mojo::files::Error::INTERNAL; |
| 138 mojo::Array<uint8_t> data; | 138 mojo::Array<uint8_t> data; |
| 139 file->Read(100u, 0, mojo::files::WHENCE_FROM_CURRENT, | 139 file->Read(100u, 0, mojo::files::Whence::FROM_CURRENT, |
| 140 [&read_cb_called, &error, &data](mojo::files::Error e, | 140 [&read_cb_called, &error, &data](mojo::files::Error e, |
| 141 mojo::Array<uint8_t> d) { | 141 mojo::Array<uint8_t> d) { |
| 142 read_cb_called = true; | 142 read_cb_called = true; |
| 143 error = e; | 143 error = e; |
| 144 data = d.Pass(); | 144 data = d.Pass(); |
| 145 QuitMessageLoop(); | 145 QuitMessageLoop(); |
| 146 }); | 146 }); |
| 147 if (client) { | 147 if (client) { |
| 148 // If there's a client, since we're running everything on one thread, the | 148 // If there's a client, since we're running everything on one thread, the |
| 149 // impl (which will call the client, which will quit the message loop) will | 149 // impl (which will call the client, which will quit the message loop) will |
| 150 // get called before the callback. | 150 // get called before the callback. |
| 151 client->Reset(); | 151 client->Reset(); |
| 152 client->set_data(StringToArray(s)); | 152 client->set_data(StringToArray(s)); |
| 153 RunMessageLoop(); | 153 RunMessageLoop(); |
| 154 EXPECT_TRUE(client->got_request_data()); | 154 EXPECT_TRUE(client->got_request_data()); |
| 155 EXPECT_FALSE(client->got_on_closed()); | 155 EXPECT_FALSE(client->got_on_closed()); |
| 156 EXPECT_FALSE(read_cb_called); | 156 EXPECT_FALSE(read_cb_called); |
| 157 // Spin the message loop again to get the callback. | 157 // Spin the message loop again to get the callback. |
| 158 client->Reset(); | 158 client->Reset(); |
| 159 RunMessageLoop(); | 159 RunMessageLoop(); |
| 160 EXPECT_FALSE(client->got_request_data()); | 160 EXPECT_FALSE(client->got_request_data()); |
| 161 EXPECT_FALSE(client->got_on_closed()); | 161 EXPECT_FALSE(client->got_on_closed()); |
| 162 EXPECT_TRUE(read_cb_called); | 162 EXPECT_TRUE(read_cb_called); |
| 163 EXPECT_EQ(mojo::files::ERROR_OK, error); | 163 EXPECT_EQ(mojo::files::Error::OK, error); |
| 164 EXPECT_EQ(s, ArrayToString(data)); | 164 EXPECT_EQ(s, ArrayToString(data)); |
| 165 } else { | 165 } else { |
| 166 // Otherwise, only the read callback will be called and quit the message | 166 // Otherwise, only the read callback will be called and quit the message |
| 167 // loop. | 167 // loop. |
| 168 RunMessageLoop(); | 168 RunMessageLoop(); |
| 169 EXPECT_TRUE(read_cb_called); | 169 EXPECT_TRUE(read_cb_called); |
| 170 EXPECT_EQ(mojo::files::ERROR_UNAVAILABLE, error); | 170 EXPECT_EQ(mojo::files::Error::UNAVAILABLE, error); |
| 171 EXPECT_TRUE(data.is_null()); | 171 EXPECT_TRUE(data.is_null()); |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 | 174 |
| 175 void TestReadAsync(mojo::files::File* file, | 175 void TestReadAsync(mojo::files::File* file, |
| 176 TestClient* client, | 176 TestClient* client, |
| 177 const std::string& s) { | 177 const std::string& s) { |
| 178 MOJO_CHECK(client); | 178 MOJO_CHECK(client); |
| 179 | 179 |
| 180 bool read_cb_called = false; | 180 bool read_cb_called = false; |
| 181 mojo::files::Error error = mojo::files::ERROR_INTERNAL; | 181 mojo::files::Error error = mojo::files::Error::INTERNAL; |
| 182 mojo::Array<uint8_t> data; | 182 mojo::Array<uint8_t> data; |
| 183 file->Read(100u, 0, mojo::files::WHENCE_FROM_CURRENT, | 183 file->Read(100u, 0, mojo::files::Whence::FROM_CURRENT, |
| 184 [&read_cb_called, &error, &data](mojo::files::Error e, | 184 [&read_cb_called, &error, &data](mojo::files::Error e, |
| 185 mojo::Array<uint8_t> d) { | 185 mojo::Array<uint8_t> d) { |
| 186 read_cb_called = true; | 186 read_cb_called = true; |
| 187 error = e; | 187 error = e; |
| 188 data = d.Pass(); | 188 data = d.Pass(); |
| 189 QuitMessageLoop(); | 189 QuitMessageLoop(); |
| 190 }); | 190 }); |
| 191 client->Reset(); | 191 client->Reset(); |
| 192 client->set_complete_synchronously(false); | 192 client->set_complete_synchronously(false); |
| 193 RunMessageLoop(); | 193 RunMessageLoop(); |
| 194 EXPECT_TRUE(client->got_request_data()); | 194 EXPECT_TRUE(client->got_request_data()); |
| 195 EXPECT_FALSE(client->got_on_closed()); | 195 EXPECT_FALSE(client->got_on_closed()); |
| 196 EXPECT_FALSE(read_cb_called); | 196 EXPECT_FALSE(read_cb_called); |
| 197 // The read callback won't get called until we tell the client to run its | 197 // The read callback won't get called until we tell the client to run its |
| 198 // callback. | 198 // callback. |
| 199 client->Reset(); | 199 client->Reset(); |
| 200 client->RunRequestDataCallback(StringToArray(s)); | 200 client->RunRequestDataCallback(StringToArray(s)); |
| 201 EXPECT_FALSE(client->got_request_data()); | 201 EXPECT_FALSE(client->got_request_data()); |
| 202 EXPECT_FALSE(client->got_on_closed()); | 202 EXPECT_FALSE(client->got_on_closed()); |
| 203 EXPECT_FALSE(read_cb_called); | 203 EXPECT_FALSE(read_cb_called); |
| 204 // Spin the message loop again to get the read callback. | 204 // Spin the message loop again to get the read callback. |
| 205 client->Reset(); | 205 client->Reset(); |
| 206 RunMessageLoop(); | 206 RunMessageLoop(); |
| 207 EXPECT_FALSE(client->got_request_data()); | 207 EXPECT_FALSE(client->got_request_data()); |
| 208 EXPECT_FALSE(client->got_on_closed()); | 208 EXPECT_FALSE(client->got_on_closed()); |
| 209 EXPECT_TRUE(read_cb_called); | 209 EXPECT_TRUE(read_cb_called); |
| 210 EXPECT_EQ(mojo::files::ERROR_OK, error); | 210 EXPECT_EQ(mojo::files::Error::OK, error); |
| 211 EXPECT_EQ(s, ArrayToString(data)); | 211 EXPECT_EQ(s, ArrayToString(data)); |
| 212 } | 212 } |
| 213 | 213 |
| 214 void TestClose(mojo::files::File* file, TestClient* client) { | 214 void TestClose(mojo::files::File* file, TestClient* client) { |
| 215 bool close_cb_called = false; | 215 bool close_cb_called = false; |
| 216 mojo::files::Error error = mojo::files::ERROR_INTERNAL; | 216 mojo::files::Error error = mojo::files::Error::INTERNAL; |
| 217 file->Close([&close_cb_called, &error](mojo::files::Error e) { | 217 file->Close([&close_cb_called, &error](mojo::files::Error e) { |
| 218 close_cb_called = true; | 218 close_cb_called = true; |
| 219 error = e; | 219 error = e; |
| 220 QuitMessageLoop(); | 220 QuitMessageLoop(); |
| 221 }); | 221 }); |
| 222 if (client) { | 222 if (client) { |
| 223 // (This is analogous to |TestReadSync()|.) | 223 // (This is analogous to |TestReadSync()|.) |
| 224 client->Reset(); | 224 client->Reset(); |
| 225 RunMessageLoop(); | 225 RunMessageLoop(); |
| 226 EXPECT_FALSE(client->got_request_data()); | 226 EXPECT_FALSE(client->got_request_data()); |
| 227 EXPECT_TRUE(client->got_on_closed()); | 227 EXPECT_TRUE(client->got_on_closed()); |
| 228 EXPECT_FALSE(close_cb_called); | 228 EXPECT_FALSE(close_cb_called); |
| 229 client->Reset(); | 229 client->Reset(); |
| 230 RunMessageLoop(); | 230 RunMessageLoop(); |
| 231 EXPECT_FALSE(client->got_request_data()); | 231 EXPECT_FALSE(client->got_request_data()); |
| 232 EXPECT_FALSE(client->got_on_closed()); | 232 EXPECT_FALSE(client->got_on_closed()); |
| 233 } else { | 233 } else { |
| 234 RunMessageLoop(); | 234 RunMessageLoop(); |
| 235 } | 235 } |
| 236 EXPECT_TRUE(close_cb_called); | 236 EXPECT_TRUE(close_cb_called); |
| 237 EXPECT_EQ(mojo::files::ERROR_OK, error); | 237 EXPECT_EQ(mojo::files::Error::OK, error); |
| 238 } | 238 } |
| 239 | 239 |
| 240 TEST_F(InputStreamFileTest, BasicSync) { | 240 TEST_F(InputStreamFileTest, BasicSync) { |
| 241 mojo::files::FilePtr file; | 241 mojo::files::FilePtr file; |
| 242 TestClient client; | 242 TestClient client; |
| 243 std::unique_ptr<InputStreamFile> file_impl = | 243 std::unique_ptr<InputStreamFile> file_impl = |
| 244 InputStreamFile::Create(&client, GetProxy(&file)); | 244 InputStreamFile::Create(&client, GetProxy(&file)); |
| 245 | 245 |
| 246 TestReadSync(file.get(), &client, "hello"); | 246 TestReadSync(file.get(), &client, "hello"); |
| 247 TestReadSync(file.get(), &client, "world"); | 247 TestReadSync(file.get(), &client, "world"); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 TestClientDestroysImplClient client(GetProxy(&file)); | 372 TestClientDestroysImplClient client(GetProxy(&file)); |
| 373 bool got_connection_error = false; | 373 bool got_connection_error = false; |
| 374 file.set_connection_error_handler([&got_connection_error]() { | 374 file.set_connection_error_handler([&got_connection_error]() { |
| 375 got_connection_error = true; | 375 got_connection_error = true; |
| 376 QuitMessageLoop(); | 376 QuitMessageLoop(); |
| 377 }); | 377 }); |
| 378 // If the impl is destroyed while trying to answer a read, it doesn't | 378 // If the impl is destroyed while trying to answer a read, it doesn't |
| 379 // respond. | 379 // respond. |
| 380 // TODO(vtl): I'm not sure if this is the best behavior. Maybe it should | 380 // TODO(vtl): I'm not sure if this is the best behavior. Maybe it should |
| 381 // respond with an error? | 381 // respond with an error? |
| 382 file->Read(100u, 0, mojo::files::WHENCE_FROM_CURRENT, | 382 file->Read(100u, 0, mojo::files::Whence::FROM_CURRENT, |
| 383 [](mojo::files::Error, mojo::Array<uint8_t>) { | 383 [](mojo::files::Error, mojo::Array<uint8_t>) { |
| 384 MOJO_CHECK(false) << "Not reached"; | 384 MOJO_CHECK(false) << "Not reached"; |
| 385 }); | 385 }); |
| 386 RunMessageLoop(); | 386 RunMessageLoop(); |
| 387 EXPECT_TRUE(got_connection_error); | 387 EXPECT_TRUE(got_connection_error); |
| 388 } | 388 } |
| 389 | 389 |
| 390 // Test destruction due to closing. | 390 // Test destruction due to closing. |
| 391 { | 391 { |
| 392 mojo::files::FilePtr file; | 392 mojo::files::FilePtr file; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 411 : file_impl_(InputStreamFile::Create(this, request.Pass())), | 411 : file_impl_(InputStreamFile::Create(this, request.Pass())), |
| 412 next_byte_(0u) {} | 412 next_byte_(0u) {} |
| 413 ~TestClientFifoSync() override {} | 413 ~TestClientFifoSync() override {} |
| 414 | 414 |
| 415 private: | 415 private: |
| 416 // InputStreamFile::Client|: | 416 // InputStreamFile::Client|: |
| 417 bool RequestData(size_t max_num_bytes, | 417 bool RequestData(size_t max_num_bytes, |
| 418 mojo::files::Error* error, | 418 mojo::files::Error* error, |
| 419 mojo::Array<uint8_t>* data, | 419 mojo::Array<uint8_t>* data, |
| 420 const RequestDataCallback& callback) override { | 420 const RequestDataCallback& callback) override { |
| 421 *error = mojo::files::ERROR_OK; | 421 *error = mojo::files::Error::OK; |
| 422 data->resize(1); | 422 data->resize(1); |
| 423 (*data)[0] = next_byte_++; | 423 (*data)[0] = next_byte_++; |
| 424 return true; | 424 return true; |
| 425 } | 425 } |
| 426 void OnClosed() override {} | 426 void OnClosed() override {} |
| 427 | 427 |
| 428 std::unique_ptr<InputStreamFile> file_impl_; | 428 std::unique_ptr<InputStreamFile> file_impl_; |
| 429 uint8_t next_byte_; | 429 uint8_t next_byte_; |
| 430 | 430 |
| 431 MOJO_DISALLOW_COPY_AND_ASSIGN(TestClientFifoSync); | 431 MOJO_DISALLOW_COPY_AND_ASSIGN(TestClientFifoSync); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 442 | 442 |
| 443 private: | 443 private: |
| 444 // InputStreamFile::Client|: | 444 // InputStreamFile::Client|: |
| 445 bool RequestData(size_t max_num_bytes, | 445 bool RequestData(size_t max_num_bytes, |
| 446 mojo::files::Error* error, | 446 mojo::files::Error* error, |
| 447 mojo::Array<uint8_t>* data, | 447 mojo::Array<uint8_t>* data, |
| 448 const RequestDataCallback& callback) override { | 448 const RequestDataCallback& callback) override { |
| 449 PostTaskToMessageLoop([this, callback]() { | 449 PostTaskToMessageLoop([this, callback]() { |
| 450 mojo::Array<uint8_t> data; | 450 mojo::Array<uint8_t> data; |
| 451 data.push_back(next_byte_++); | 451 data.push_back(next_byte_++); |
| 452 callback.Run(mojo::files::ERROR_OK, data.Pass()); | 452 callback.Run(mojo::files::Error::OK, data.Pass()); |
| 453 }); | 453 }); |
| 454 return false; | 454 return false; |
| 455 } | 455 } |
| 456 void OnClosed() override {} | 456 void OnClosed() override {} |
| 457 | 457 |
| 458 std::unique_ptr<InputStreamFile> file_impl_; | 458 std::unique_ptr<InputStreamFile> file_impl_; |
| 459 uint8_t next_byte_; | 459 uint8_t next_byte_; |
| 460 | 460 |
| 461 MOJO_DISALLOW_COPY_AND_ASSIGN(TestClientFifoAsync); | 461 MOJO_DISALLOW_COPY_AND_ASSIGN(TestClientFifoAsync); |
| 462 }; | 462 }; |
| 463 | 463 |
| 464 void TestFifo(mojo::files::File* file) { | 464 void TestFifo(mojo::files::File* file) { |
| 465 int expect_callback = 0; | 465 int expect_callback = 0; |
| 466 uint8_t expect_byte = 0; | 466 uint8_t expect_byte = 0; |
| 467 | 467 |
| 468 // Test a couple of zero-byte reads. | 468 // Test a couple of zero-byte reads. |
| 469 file->Read(0u, 0, mojo::files::WHENCE_FROM_CURRENT, | 469 file->Read(0u, 0, mojo::files::Whence::FROM_CURRENT, |
| 470 [&expect_callback](mojo::files::Error e, mojo::Array<uint8_t> a) { | 470 [&expect_callback](mojo::files::Error e, mojo::Array<uint8_t> a) { |
| 471 EXPECT_EQ(0, expect_callback++); | 471 EXPECT_EQ(0, expect_callback++); |
| 472 EXPECT_EQ(mojo::files::ERROR_OK, e); | 472 EXPECT_EQ(mojo::files::Error::OK, e); |
| 473 EXPECT_EQ(0u, a.size()); | 473 EXPECT_EQ(0u, a.size()); |
| 474 }); | 474 }); |
| 475 file->Read(0u, 0, mojo::files::WHENCE_FROM_CURRENT, | 475 file->Read(0u, 0, mojo::files::Whence::FROM_CURRENT, |
| 476 [&expect_callback](mojo::files::Error e, mojo::Array<uint8_t> a) { | 476 [&expect_callback](mojo::files::Error e, mojo::Array<uint8_t> a) { |
| 477 EXPECT_EQ(1, expect_callback++); | 477 EXPECT_EQ(1, expect_callback++); |
| 478 EXPECT_EQ(mojo::files::ERROR_OK, e); | 478 EXPECT_EQ(mojo::files::Error::OK, e); |
| 479 EXPECT_EQ(0u, a.size()); | 479 EXPECT_EQ(0u, a.size()); |
| 480 }); | 480 }); |
| 481 | 481 |
| 482 // Test a couple of non-zero-byte reads. | 482 // Test a couple of non-zero-byte reads. |
| 483 file->Read(100u, 0, mojo::files::WHENCE_FROM_CURRENT, | 483 file->Read(100u, 0, mojo::files::Whence::FROM_CURRENT, |
| 484 [&expect_callback, &expect_byte](mojo::files::Error e, | 484 [&expect_callback, &expect_byte](mojo::files::Error e, |
| 485 mojo::Array<uint8_t> a) { | 485 mojo::Array<uint8_t> a) { |
| 486 EXPECT_EQ(2, expect_callback++); | 486 EXPECT_EQ(2, expect_callback++); |
| 487 EXPECT_EQ(mojo::files::ERROR_OK, e); | 487 EXPECT_EQ(mojo::files::Error::OK, e); |
| 488 EXPECT_EQ(1u, a.size()); | 488 EXPECT_EQ(1u, a.size()); |
| 489 EXPECT_EQ(expect_byte++, a[0]); | 489 EXPECT_EQ(expect_byte++, a[0]); |
| 490 }); | 490 }); |
| 491 file->Read(100u, 0, mojo::files::WHENCE_FROM_CURRENT, | 491 file->Read(100u, 0, mojo::files::Whence::FROM_CURRENT, |
| 492 [&expect_callback, &expect_byte](mojo::files::Error e, | 492 [&expect_callback, &expect_byte](mojo::files::Error e, |
| 493 mojo::Array<uint8_t> a) { | 493 mojo::Array<uint8_t> a) { |
| 494 EXPECT_EQ(3, expect_callback++); | 494 EXPECT_EQ(3, expect_callback++); |
| 495 EXPECT_EQ(mojo::files::ERROR_OK, e); | 495 EXPECT_EQ(mojo::files::Error::OK, e); |
| 496 EXPECT_EQ(1u, a.size()); | 496 EXPECT_EQ(1u, a.size()); |
| 497 EXPECT_EQ(expect_byte++, a[0]); | 497 EXPECT_EQ(expect_byte++, a[0]); |
| 498 }); | 498 }); |
| 499 // Throw in a zero-byte read. | 499 // Throw in a zero-byte read. |
| 500 file->Read(0u, 0, mojo::files::WHENCE_FROM_CURRENT, | 500 file->Read(0u, 0, mojo::files::Whence::FROM_CURRENT, |
| 501 [&expect_callback](mojo::files::Error e, mojo::Array<uint8_t> a) { | 501 [&expect_callback](mojo::files::Error e, mojo::Array<uint8_t> a) { |
| 502 EXPECT_EQ(4, expect_callback++); | 502 EXPECT_EQ(4, expect_callback++); |
| 503 EXPECT_EQ(mojo::files::ERROR_OK, e); | 503 EXPECT_EQ(mojo::files::Error::OK, e); |
| 504 EXPECT_EQ(0u, a.size()); | 504 EXPECT_EQ(0u, a.size()); |
| 505 }); | 505 }); |
| 506 // And a final non-zero-byte read (we'll quit the message loop). | 506 // And a final non-zero-byte read (we'll quit the message loop). |
| 507 file->Read(100u, 0, mojo::files::WHENCE_FROM_CURRENT, | 507 file->Read(100u, 0, mojo::files::Whence::FROM_CURRENT, |
| 508 [&expect_callback, &expect_byte](mojo::files::Error e, | 508 [&expect_callback, &expect_byte](mojo::files::Error e, |
| 509 mojo::Array<uint8_t> a) { | 509 mojo::Array<uint8_t> a) { |
| 510 EXPECT_EQ(5, expect_callback++); | 510 EXPECT_EQ(5, expect_callback++); |
| 511 EXPECT_EQ(mojo::files::ERROR_OK, e); | 511 EXPECT_EQ(mojo::files::Error::OK, e); |
| 512 EXPECT_EQ(1u, a.size()); | 512 EXPECT_EQ(1u, a.size()); |
| 513 EXPECT_EQ(expect_byte++, a[0]); | 513 EXPECT_EQ(expect_byte++, a[0]); |
| 514 QuitMessageLoop(); | 514 QuitMessageLoop(); |
| 515 }); | 515 }); |
| 516 RunMessageLoop(); | 516 RunMessageLoop(); |
| 517 | 517 |
| 518 // Check that all the callbacks ran. | 518 // Check that all the callbacks ran. |
| 519 EXPECT_EQ(6, expect_callback); | 519 EXPECT_EQ(6, expect_callback); |
| 520 EXPECT_EQ(3u, expect_byte); | 520 EXPECT_EQ(3u, expect_byte); |
| 521 } | 521 } |
| 522 | 522 |
| 523 // Tests that if multiple reads are sent, they are completed in FIFO order. This | 523 // Tests that if multiple reads are sent, they are completed in FIFO order. This |
| 524 // tests the synchronous completion path. | 524 // tests the synchronous completion path. |
| 525 TEST_F(InputStreamFileTest, FifoSync) { | 525 TEST_F(InputStreamFileTest, FifoSync) { |
| 526 mojo::files::FilePtr file; | 526 mojo::files::FilePtr file; |
| 527 TestClientFifoSync client(GetProxy(&file)); | 527 TestClientFifoSync client(GetProxy(&file)); |
| 528 TestFifo(file.get()); | 528 TestFifo(file.get()); |
| 529 } | 529 } |
| 530 | 530 |
| 531 // Like |InputStreamFileTest.FifoSync|, but asynchronous. | 531 // Like |InputStreamFileTest.FifoSync|, but asynchronous. |
| 532 TEST_F(InputStreamFileTest, FifoAsync) { | 532 TEST_F(InputStreamFileTest, FifoAsync) { |
| 533 mojo::files::FilePtr file; | 533 mojo::files::FilePtr file; |
| 534 TestClientFifoAsync client(GetProxy(&file)); | 534 TestClientFifoAsync client(GetProxy(&file)); |
| 535 TestFifo(file.get()); | 535 TestFifo(file.get()); |
| 536 } | 536 } |
| 537 | 537 |
| 538 } // namespace | 538 } // namespace |
| 539 } // namespace files_impl | 539 } // namespace files_impl |
| OLD | NEW |