Avi Drissman | e4714ce9 | 2022-09-12 21:41:58 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
dcheng | 0a6e80c | 2016-04-08 18:37:38 | [diff] [blame] | 5 | #include "chromeos/process_proxy/process_output_watcher.h" |
| 6 | |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 7 | #include <gtest/gtest.h> |
avi | 6e1a22d | 2015-12-21 03:43:20 | [diff] [blame] | 8 | #include <stddef.h> |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 9 | |
dcheng | 0a6e80c | 2016-04-08 18:37:38 | [diff] [blame] | 10 | #include <memory> |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 11 | #include <queue> |
| 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
thestig | b44bd35 | 2014-09-10 01:47:06 | [diff] [blame] | 15 | #include "base/files/file_util.h" |
Avi Drissman | 710fdab | 2023-01-11 04:37:36 | [diff] [blame] | 16 | #include "base/functional/bind.h" |
| 17 | #include "base/functional/callback.h" |
skyostil | 1472c84 | 2015-06-11 18:40:24 | [diff] [blame] | 18 | #include "base/location.h" |
Carlos Caballero | dd8bf7b0 | 2019-07-30 14:14:15 | [diff] [blame] | 19 | #include "base/message_loop/message_pump_type.h" |
brettw@chromium.org | 2025d00 | 2012-11-14 20:54:35 | [diff] [blame] | 20 | #include "base/posix/eintr_wrapper.h" |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 21 | #include "base/run_loop.h" |
| 22 | #include "base/strings/string_util.h" |
Patrick Monette | 643cdf6 | 2021-10-15 19:13:42 | [diff] [blame] | 23 | #include "base/task/single_thread_task_runner.h" |
Gabriel Charette | c710874 | 2019-08-23 03:31:40 | [diff] [blame] | 24 | #include "base/test/task_environment.h" |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 25 | #include "base/threading/thread.h" |
phajdan.jr@chromium.org | 3a01162b | 2013-03-12 20:22:48 | [diff] [blame] | 26 | |
| 27 | namespace chromeos { |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 28 | |
tbarzic | 6ca5055 | 2015-08-10 22:32:45 | [diff] [blame] | 29 | namespace { |
| 30 | |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 31 | struct TestCase { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 32 | TestCase(const std::string& input, bool send_terminating_null) |
| 33 | : input(input), |
| 34 | should_send_terminating_null(send_terminating_null), |
| 35 | expected_output(input) {} |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 36 | |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 37 | // Conctructor for cases where the output is not expected to be the same as |
| 38 | // input. |
| 39 | TestCase(const std::string& input, |
| 40 | bool send_terminating_null, |
| 41 | const std::string& expected_output) |
| 42 | : input(input), |
| 43 | should_send_terminating_null(send_terminating_null), |
| 44 | expected_output(expected_output) {} |
| 45 | |
| 46 | std::string input; |
| 47 | bool should_send_terminating_null; |
| 48 | std::string expected_output; |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | class ProcessWatcherExpectations { |
| 52 | public: |
Chris Watkins | 2c529d6 | 2017-11-29 02:14:41 | [diff] [blame] | 53 | ProcessWatcherExpectations() = default; |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 54 | |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 55 | void SetTestCase(const TestCase& test_case) { |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 56 | received_from_out_ = 0; |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 57 | |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 58 | out_expectations_ = test_case.expected_output; |
| 59 | if (test_case.should_send_terminating_null) |
| 60 | out_expectations_.append(std::string("", 1)); |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 61 | } |
| 62 | |
tbarzic@chromium.org | 6866c6b | 2012-04-09 21:38:18 | [diff] [blame] | 63 | bool CheckExpectations(const std::string& data, ProcessOutputType type) { |
| 64 | EXPECT_EQ(PROCESS_OUTPUT_TYPE_OUT, type); |
thakis@chromium.org | e2524b0 | 2013-07-22 17:51:28 | [diff] [blame] | 65 | if (type != PROCESS_OUTPUT_TYPE_OUT) |
tbarzic@chromium.org | 6866c6b | 2012-04-09 21:38:18 | [diff] [blame] | 66 | return false; |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 67 | |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 68 | if (out_expectations_.length() == 0 && data.length() == 0) |
| 69 | return true; |
| 70 | |
tbarzic@chromium.org | 6866c6b | 2012-04-09 21:38:18 | [diff] [blame] | 71 | EXPECT_LT(received_from_out_, out_expectations_.length()); |
| 72 | if (received_from_out_ >= out_expectations_.length()) |
| 73 | return false; |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 74 | |
tbarzic@chromium.org | 6866c6b | 2012-04-09 21:38:18 | [diff] [blame] | 75 | EXPECT_EQ(received_from_out_, |
| 76 | out_expectations_.find(data, received_from_out_)); |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 77 | if (received_from_out_ != out_expectations_.find(data, received_from_out_)) |
| 78 | return false; |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 79 | |
tbarzic@chromium.org | 6866c6b | 2012-04-09 21:38:18 | [diff] [blame] | 80 | received_from_out_ += data.length(); |
| 81 | return true; |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | bool IsDone() { |
tbarzic@chromium.org | 6866c6b | 2012-04-09 21:38:18 | [diff] [blame] | 85 | return received_from_out_ >= out_expectations_.length(); |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | private: |
| 89 | std::string out_expectations_; |
| 90 | size_t received_from_out_; |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 91 | }; |
| 92 | |
dcheng | 0a6e80c | 2016-04-08 18:37:38 | [diff] [blame] | 93 | void StopProcessOutputWatcher(std::unique_ptr<ProcessOutputWatcher> watcher) { |
tbarzic | 6ca5055 | 2015-08-10 22:32:45 | [diff] [blame] | 94 | // Just deleting |watcher| if sufficient. |
| 95 | } |
| 96 | |
| 97 | } // namespace |
| 98 | |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 99 | class ProcessOutputWatcherTest : public testing::Test { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 100 | public: |
| 101 | ProcessOutputWatcherTest() : output_watch_thread_started_(false), |
| 102 | failed_(false) { |
| 103 | } |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 104 | |
Chris Watkins | 2c529d6 | 2017-11-29 02:14:41 | [diff] [blame] | 105 | ~ProcessOutputWatcherTest() override = default; |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 106 | |
dcheng | ae98daa | 2015-01-21 20:30:49 | [diff] [blame] | 107 | void TearDown() override { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 108 | if (output_watch_thread_started_) |
| 109 | output_watch_thread_->Stop(); |
| 110 | } |
| 111 | |
Joel Hockey | 8d1d019 | 2022-07-29 02:38:35 | [diff] [blame] | 112 | void OnRead(ProcessOutputType type, const std::string& output) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 113 | ASSERT_FALSE(failed_); |
tbarzic | daf936a | 2015-07-29 21:05:14 | [diff] [blame] | 114 | // There may be an EXIT signal sent during test tear down (which is sent |
| 115 | // by process output watcher when master end of test pseudo-terminal is |
| 116 | // closed). If this happens, ignore it. If EXIT is seen before test |
| 117 | // expectations are met, fall through in order to fail the test. |
| 118 | if (type == PROCESS_OUTPUT_TYPE_EXIT && expectations_.IsDone()) { |
| 119 | ASSERT_TRUE(test_case_done_callback_.is_null()); |
| 120 | return; |
| 121 | } |
| 122 | |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 123 | failed_ = !expectations_.CheckExpectations(output, type); |
| 124 | if (failed_ || expectations_.IsDone()) { |
| 125 | ASSERT_FALSE(test_case_done_callback_.is_null()); |
Gabriel Charette | 694c3c33 | 2019-08-19 14:53:05 | [diff] [blame] | 126 | task_environment_.GetMainThreadTaskRunner()->PostTask( |
Reilly Grant | 65820a5 | 2019-11-19 20:45:11 | [diff] [blame] | 127 | FROM_HERE, std::move(test_case_done_callback_)); |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 128 | test_case_done_callback_.Reset(); |
| 129 | } |
tbarzic | 170f12c | 2016-01-08 05:15:29 | [diff] [blame] | 130 | |
Joel Hockey | 8d1d019 | 2022-07-29 02:38:35 | [diff] [blame] | 131 | output_watch_thread_->task_runner()->PostTask( |
| 132 | FROM_HERE, base::BindOnce(&ProcessOutputWatcher::AckOutput, |
| 133 | base::Unretained(output_watcher_.get()))); |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | protected: |
| 137 | std::string VeryLongString() { |
| 138 | std::string result = "0123456789"; |
| 139 | for (int i = 0; i < 8; i++) |
| 140 | result = result.append(result); |
| 141 | return result; |
| 142 | } |
| 143 | |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 144 | void RunTest(const std::vector<TestCase>& test_cases) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 145 | ASSERT_FALSE(output_watch_thread_started_); |
Peter Boström | 6b70182 | 2021-04-15 03:53:08 | [diff] [blame] | 146 | output_watch_thread_ = |
| 147 | std::make_unique<base::Thread>("ProcessOutpuWatchThread"); |
tbarzic | 6ca5055 | 2015-08-10 22:32:45 | [diff] [blame] | 148 | output_watch_thread_started_ = output_watch_thread_->StartWithOptions( |
Carlos Caballero | dd8bf7b0 | 2019-07-30 14:14:15 | [diff] [blame] | 149 | base::Thread::Options(base::MessagePumpType::IO, 0)); |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 150 | ASSERT_TRUE(output_watch_thread_started_); |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 151 | |
tbarzic | 6ca5055 | 2015-08-10 22:32:45 | [diff] [blame] | 152 | int pt_pipe[2]; |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 153 | ASSERT_FALSE(HANDLE_EINTR(pipe(pt_pipe))); |
tbarzic | 6ca5055 | 2015-08-10 22:32:45 | [diff] [blame] | 154 | |
Joel Hockey | 8d1d019 | 2022-07-29 02:38:35 | [diff] [blame] | 155 | output_watcher_ = std::make_unique<ProcessOutputWatcher>( |
Reilly Grant | 65820a5 | 2019-11-19 20:45:11 | [diff] [blame] | 156 | pt_pipe[0], base::BindRepeating(&ProcessOutputWatcherTest::OnRead, |
| 157 | base::Unretained(this))); |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 158 | |
skyostil | 1472c84 | 2015-06-11 18:40:24 | [diff] [blame] | 159 | output_watch_thread_->task_runner()->PostTask( |
tzik | c8fdd6c3 | 2018-04-11 04:02:40 | [diff] [blame] | 160 | FROM_HERE, base::BindOnce(&ProcessOutputWatcher::Start, |
Joel Hockey | 8d1d019 | 2022-07-29 02:38:35 | [diff] [blame] | 161 | base::Unretained(output_watcher_.get()))); |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 162 | |
| 163 | for (size_t i = 0; i < test_cases.size(); i++) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 164 | expectations_.SetTestCase(test_cases[i]); |
| 165 | |
| 166 | base::RunLoop run_loop; |
| 167 | ASSERT_TRUE(test_case_done_callback_.is_null()); |
| 168 | test_case_done_callback_ = run_loop.QuitClosure(); |
| 169 | |
| 170 | const std::string& test_str = test_cases[i].input; |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 171 | // Let's make inputs not NULL terminated, unless other is specified in |
| 172 | // the test case. |
| 173 | ssize_t test_size = test_str.length() * sizeof(*test_str.c_str()); |
| 174 | if (test_cases[i].should_send_terminating_null) |
| 175 | test_size += sizeof(*test_str.c_str()); |
Lei Zhang | c9e8a16 | 2021-05-14 09:33:52 | [diff] [blame] | 176 | EXPECT_TRUE(base::WriteFileDescriptor( |
| 177 | pt_pipe[1], base::StringPiece(test_str.c_str(), test_size))); |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 178 | |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 179 | run_loop.Run(); |
| 180 | EXPECT_TRUE(expectations_.IsDone()); |
| 181 | if (failed_) |
| 182 | break; |
| 183 | } |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 184 | |
tbarzic | 6ca5055 | 2015-08-10 22:32:45 | [diff] [blame] | 185 | output_watch_thread_->task_runner()->PostTask( |
| 186 | FROM_HERE, |
Joel Hockey | 8d1d019 | 2022-07-29 02:38:35 | [diff] [blame] | 187 | base::BindOnce(&StopProcessOutputWatcher, std::move(output_watcher_))); |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 188 | |
mark@chromium.org | d89eec8 | 2013-12-03 14:10:59 | [diff] [blame] | 189 | EXPECT_NE(-1, IGNORE_EINTR(close(pt_pipe[1]))); |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 190 | } |
| 191 | |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 192 | private: |
Reilly Grant | 65820a5 | 2019-11-19 20:45:11 | [diff] [blame] | 193 | base::OnceClosure test_case_done_callback_; |
Gabriel Charette | 58ea6de8b | 2019-09-07 13:18:33 | [diff] [blame] | 194 | base::test::SingleThreadTaskEnvironment task_environment_; |
dcheng | 0a6e80c | 2016-04-08 18:37:38 | [diff] [blame] | 195 | std::unique_ptr<base::Thread> output_watch_thread_; |
Joel Hockey | 8d1d019 | 2022-07-29 02:38:35 | [diff] [blame] | 196 | bool output_watch_thread_started_ = false; |
| 197 | std::unique_ptr<ProcessOutputWatcher> output_watcher_; |
| 198 | bool failed_ = false; |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 199 | ProcessWatcherExpectations expectations_; |
| 200 | std::vector<TestCase> exp; |
| 201 | }; |
| 202 | |
Sergey Ulanov | c7ddfb6c | 2022-12-13 05:04:02 | [diff] [blame] | 203 | TEST_F(ProcessOutputWatcherTest, DISABLED_OutputWatcher) { |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 204 | std::vector<TestCase> test_cases; |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 205 | test_cases.push_back(TestCase("t", false)); |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 206 | test_cases.push_back(TestCase("testing output\n", false)); |
| 207 | test_cases.push_back(TestCase("testing error\n", false)); |
| 208 | test_cases.push_back(TestCase("testing error1\n", false)); |
| 209 | test_cases.push_back(TestCase("testing output1\n", false)); |
| 210 | test_cases.push_back(TestCase("testing output2\n", false)); |
| 211 | test_cases.push_back(TestCase("testing output3\n", false)); |
| 212 | test_cases.push_back(TestCase(VeryLongString(), false)); |
| 213 | test_cases.push_back(TestCase("testing error2\n", false)); |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 214 | |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 215 | RunTest(test_cases); |
thestig | b44bd35 | 2014-09-10 01:47:06 | [diff] [blame] | 216 | } |
tbarzic@chromium.org | 8f42798 | 2011-12-13 23:40:23 | [diff] [blame] | 217 | |
Sergey Ulanov | c7ddfb6c | 2022-12-13 05:04:02 | [diff] [blame] | 218 | TEST_F(ProcessOutputWatcherTest, DISABLED_SplitUTF8Character) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 219 | std::vector<TestCase> test_cases; |
| 220 | test_cases.push_back(TestCase("test1\xc2", false, "test1")); |
| 221 | test_cases.push_back(TestCase("\xb5test1", false, "\xc2\xb5test1")); |
| 222 | |
| 223 | RunTest(test_cases); |
| 224 | } |
| 225 | |
Sergey Ulanov | c7ddfb6c | 2022-12-13 05:04:02 | [diff] [blame] | 226 | TEST_F(ProcessOutputWatcherTest, DISABLED_SplitSoleUTF8Character) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 227 | std::vector<TestCase> test_cases; |
| 228 | test_cases.push_back(TestCase("\xc2", false, "")); |
| 229 | test_cases.push_back(TestCase("\xb5", false, "\xc2\xb5")); |
| 230 | |
| 231 | RunTest(test_cases); |
| 232 | } |
| 233 | |
Sergey Ulanov | c7ddfb6c | 2022-12-13 05:04:02 | [diff] [blame] | 234 | TEST_F(ProcessOutputWatcherTest, DISABLED_SplitUTF8CharacterLength3) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 235 | std::vector<TestCase> test_cases; |
| 236 | test_cases.push_back(TestCase("test3\xe2\x82", false, "test3")); |
| 237 | test_cases.push_back(TestCase("\xac", false, "\xe2\x82\xac")); |
| 238 | |
| 239 | RunTest(test_cases); |
| 240 | } |
| 241 | |
Sergey Ulanov | c7ddfb6c | 2022-12-13 05:04:02 | [diff] [blame] | 242 | TEST_F(ProcessOutputWatcherTest, DISABLED_SplitSoleUTF8CharacterThreeWays) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 243 | std::vector<TestCase> test_cases; |
| 244 | test_cases.push_back(TestCase("\xe2", false, "")); |
| 245 | test_cases.push_back(TestCase("\x82", false, "")); |
| 246 | test_cases.push_back(TestCase("\xac", false, "\xe2\x82\xac")); |
| 247 | |
| 248 | RunTest(test_cases); |
| 249 | } |
| 250 | |
Yuzu Saijo | 5b44b5b | 2022-11-08 01:09:13 | [diff] [blame] | 251 | // TODO(crbug.com/1382252) Re-enable test |
| 252 | TEST_F(ProcessOutputWatcherTest, DISABLED_EndsWithThreeByteUTF8Character) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 253 | std::vector<TestCase> test_cases; |
| 254 | test_cases.push_back(TestCase("test\xe2\x82\xac", false, "test\xe2\x82\xac")); |
| 255 | |
| 256 | RunTest(test_cases); |
| 257 | } |
| 258 | |
Sergey Ulanov | c7ddfb6c | 2022-12-13 05:04:02 | [diff] [blame] | 259 | TEST_F(ProcessOutputWatcherTest, DISABLED_SoleThreeByteUTF8Character) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 260 | std::vector<TestCase> test_cases; |
| 261 | test_cases.push_back(TestCase("\xe2\x82\xac", false, "\xe2\x82\xac")); |
| 262 | |
| 263 | RunTest(test_cases); |
| 264 | } |
| 265 | |
Sergey Ulanov | c7ddfb6c | 2022-12-13 05:04:02 | [diff] [blame] | 266 | TEST_F(ProcessOutputWatcherTest, DISABLED_HasThreeByteUTF8Character) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 267 | std::vector<TestCase> test_cases; |
| 268 | test_cases.push_back( |
| 269 | TestCase("test\xe2\x82\xac_", false, "test\xe2\x82\xac_")); |
| 270 | |
| 271 | RunTest(test_cases); |
| 272 | } |
| 273 | |
Alison Gale | b08fa1c2 | 2022-12-02 21:59:02 | [diff] [blame] | 274 | // TODO(crbug.com/1395483) Re-enable test |
| 275 | TEST_F(ProcessOutputWatcherTest, DISABLED_MultiByteUTF8CharNullTerminated) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 276 | std::vector<TestCase> test_cases; |
| 277 | test_cases.push_back(TestCase("test\xe2\x82\xac", true, "test\xe2\x82\xac")); |
| 278 | |
| 279 | RunTest(test_cases); |
| 280 | } |
| 281 | |
Sergey Ulanov | c7ddfb6c | 2022-12-13 05:04:02 | [diff] [blame] | 282 | TEST_F(ProcessOutputWatcherTest, DISABLED_MultipleMultiByteUTF8Characters) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 283 | std::vector<TestCase> test_cases; |
| 284 | test_cases.push_back( |
| 285 | TestCase("test\xe2\x82\xac\xc2", false, "test\xe2\x82\xac")); |
| 286 | test_cases.push_back(TestCase("\xb5", false, "\xc2\xb5")); |
| 287 | |
| 288 | RunTest(test_cases); |
| 289 | } |
| 290 | |
Sergey Ulanov | c7ddfb6c | 2022-12-13 05:04:02 | [diff] [blame] | 291 | TEST_F(ProcessOutputWatcherTest, DISABLED_ContainsInvalidUTF8) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 292 | std::vector<TestCase> test_cases; |
| 293 | test_cases.push_back(TestCase("\xc2_", false, "\xc2_")); |
| 294 | |
| 295 | RunTest(test_cases); |
| 296 | } |
| 297 | |
Keishi Hattori | 1c8b2f51 | 2022-12-09 02:50:05 | [diff] [blame] | 298 | // TODO(crbug.com/1399698): Re-enable this test |
| 299 | TEST_F(ProcessOutputWatcherTest, DISABLED_InvalidUTF8SeriesOfTrailingBytes) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 300 | std::vector<TestCase> test_cases; |
| 301 | test_cases.push_back(TestCase("\x82\x82\x82", false, "\x82\x82\x82")); |
| 302 | test_cases.push_back(TestCase("\x82\x82\x82", false, "\x82\x82\x82")); |
| 303 | |
| 304 | RunTest(test_cases); |
| 305 | } |
| 306 | |
Alison Gale | b08fa1c2 | 2022-12-02 21:59:02 | [diff] [blame] | 307 | // TODO(crbug.com/1395483) Re-enable test |
| 308 | TEST_F(ProcessOutputWatcherTest, DISABLED_EndsWithInvalidUTF8) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 309 | std::vector<TestCase> test_cases; |
| 310 | test_cases.push_back(TestCase("\xff", false, "\xff")); |
| 311 | |
| 312 | RunTest(test_cases); |
| 313 | } |
| 314 | |
Fergus Dall | 794ffeb | 2021-02-11 07:17:29 | [diff] [blame] | 315 | // TODO(crbug.com/1177137) Re-enable test |
| 316 | TEST_F(ProcessOutputWatcherTest, DISABLED_FourByteUTF8) { |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 317 | std::vector<TestCase> test_cases; |
| 318 | test_cases.push_back(TestCase("\xf0\xa4\xad", false, "")); |
| 319 | test_cases.push_back(TestCase("\xa2", false, "\xf0\xa4\xad\xa2")); |
| 320 | |
| 321 | RunTest(test_cases); |
thestig | b44bd35 | 2014-09-10 01:47:06 | [diff] [blame] | 322 | } |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 323 | |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 324 | // Verifies that sending '\0' generates PROCESS_OUTPUT_TYPE_OUT event and does |
| 325 | // not terminate output watcher. |
Alison Gale | b08fa1c2 | 2022-12-02 21:59:02 | [diff] [blame] | 326 | // TODO(crbug.com/1395483) Re-enable test |
| 327 | TEST_F(ProcessOutputWatcherTest, DISABLED_SendNull) { |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 328 | std::vector<TestCase> test_cases; |
tbarzic@chromium.org | 65bbd9d2 | 2014-05-15 20:34:37 | [diff] [blame] | 329 | // This will send '\0' to output watcher. |
tbarzic@chromium.org | 250f7f89 | 2012-04-11 02:46:43 | [diff] [blame] | 330 | test_cases.push_back(TestCase("", true)); |
| 331 | // Let's verify that next input also gets detected (i.e. output watcher does |
| 332 | // not exit after seeing '\0' from previous test case). |
| 333 | test_cases.push_back(TestCase("a", true)); |
| 334 | |
| 335 | RunTest(test_cases); |
thestig | b44bd35 | 2014-09-10 01:47:06 | [diff] [blame] | 336 | } |
phajdan.jr@chromium.org | 3a01162b | 2013-03-12 20:22:48 | [diff] [blame] | 337 | |
| 338 | } // namespace chromeos |