| 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 "mojo/fetcher/data_fetcher.h" | 5 #include "mojo/fetcher/data_fetcher.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 EXPECT_EQ(expected_status_code, response->status_code); | 75 EXPECT_EQ(expected_status_code, response->status_code); |
| 76 | 76 |
| 77 if (expected_status_code != 200) | 77 if (expected_status_code != 200) |
| 78 return; | 78 return; |
| 79 | 79 |
| 80 ASSERT_TRUE(response->body.is_valid()); | 80 ASSERT_TRUE(response->body.is_valid()); |
| 81 EXPECT_EQ(expected_mime_type, response->mime_type); | 81 EXPECT_EQ(expected_mime_type, response->mime_type); |
| 82 | 82 |
| 83 uint32_t num_bytes = 0; | 83 uint32_t num_bytes = 0; |
| 84 Handle body_handle = response->body.release(); | 84 Handle body_handle = response->body.release(); |
| 85 |
| 86 MojoHandleSignalsState hss; |
| 87 ASSERT_EQ(MOJO_RESULT_OK, |
| 88 MojoWait(body_handle.value(), MOJO_HANDLE_SIGNAL_READABLE, |
| 89 MOJO_DEADLINE_INDEFINITE, &hss)); |
| 90 |
| 85 MojoResult result = MojoReadData(body_handle.value(), nullptr, &num_bytes, | 91 MojoResult result = MojoReadData(body_handle.value(), nullptr, &num_bytes, |
| 86 MOJO_READ_DATA_FLAG_QUERY); | 92 MOJO_READ_DATA_FLAG_QUERY); |
| 87 ASSERT_EQ(MOJO_RESULT_OK, result); | 93 ASSERT_EQ(MOJO_RESULT_OK, result); |
| 88 | 94 |
| 89 scoped_ptr<char[]> body(new char[num_bytes]); | 95 scoped_ptr<char[]> body(new char[num_bytes]); |
| 90 result = MojoReadData(body_handle.value(), body.get(), &num_bytes, | 96 result = MojoReadData(body_handle.value(), body.get(), &num_bytes, |
| 91 MOJO_READ_DATA_FLAG_ALL_OR_NONE); | 97 MOJO_READ_DATA_FLAG_ALL_OR_NONE); |
| 92 ASSERT_EQ(MOJO_RESULT_OK, result); | 98 ASSERT_EQ(MOJO_RESULT_OK, result); |
| 93 EXPECT_EQ(expected_body, std::string(body.get(), num_bytes)); | 99 EXPECT_EQ(expected_body, std::string(body.get(), num_bytes)); |
| 94 } | 100 } |
| 95 | 101 |
| 96 private: | 102 private: |
| 97 base::MessageLoop loop_; | 103 base::MessageLoop loop_; |
| 98 | 104 |
| 99 DISALLOW_COPY_AND_ASSIGN(DataFetcherTest); | 105 DISALLOW_COPY_AND_ASSIGN(DataFetcherTest); |
| 100 }; | 106 }; |
| 101 | 107 |
| 102 TEST_F(DataFetcherTest, BasicSuccess) { | 108 TEST_F(DataFetcherTest, BasicSuccess) { |
| 103 TestFetchURL("data:text/html,Hello world", 200, "text/html", "Hello world"); | 109 TestFetchURL("data:text/html,Hello world", 200, "text/html", "Hello world"); |
| 104 } | 110 } |
| 105 | 111 |
| 106 TEST_F(DataFetcherTest, BasicFailure) { | 112 TEST_F(DataFetcherTest, BasicFailure) { |
| 107 TestFetchURL("about:blank", 400, std::string(), std::string()); | 113 TestFetchURL("about:blank", 400, std::string(), std::string()); |
| 108 TestFetchURL("data:;base64,aGVs_-_-", 400, std::string(), std::string()); | 114 TestFetchURL("data:;base64,aGVs_-_-", 400, std::string(), std::string()); |
| 109 } | 115 } |
| 110 | 116 |
| 111 } // namespace | 117 } // namespace |
| 112 } // namespace fetcher | 118 } // namespace fetcher |
| 113 } // namespace mojo | 119 } // namespace mojo |
| OLD | NEW |