| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef USE_BRLAPI | 5 #ifndef USE_BRLAPI |
| 6 #error This test requires brlapi. | 6 #error This test requires brlapi. |
| 7 #endif | 7 #endif |
| 8 | 8 |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 | 10 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // Used to make ReadKeys return an error. | 47 // Used to make ReadKeys return an error. |
| 48 brlapi_keyCode_t kErrorKeyCode = BRLAPI_KEY_MAX; | 48 brlapi_keyCode_t kErrorKeyCode = BRLAPI_KEY_MAX; |
| 49 | 49 |
| 50 } // namespace | 50 } // namespace |
| 51 | 51 |
| 52 // Data maintained by the mock BrlapiConnection. This data lives throughout | 52 // Data maintained by the mock BrlapiConnection. This data lives throughout |
| 53 // a test, while the api implementation takes ownership of the connection | 53 // a test, while the api implementation takes ownership of the connection |
| 54 // itself. | 54 // itself. |
| 55 struct MockBrlapiConnectionData { | 55 struct MockBrlapiConnectionData { |
| 56 bool connected; | 56 bool connected; |
| 57 size_t display_size; | 57 size_t display_columns; |
| 58 size_t display_rows; |
| 58 brlapi_error_t error; | 59 brlapi_error_t error; |
| 59 std::vector<std::string> written_content; | 60 std::vector<std::string> written_content; |
| 60 // List of brlapi key codes. A negative number makes the connection mock | 61 // List of brlapi key codes. A negative number makes the connection mock |
| 61 // return an error from ReadKey. | 62 // return an error from ReadKey. |
| 62 std::deque<brlapi_keyCode_t> pending_keys; | 63 std::deque<brlapi_keyCode_t> pending_keys; |
| 63 // Causes a new display to appear to appear on disconnect, that is the | 64 // Causes a new display to appear to appear on disconnect, that is the |
| 64 // display size doubles and the controller gets notified of a brltty | 65 // display size doubles and the controller gets notified of a brltty |
| 65 // restart. | 66 // restart. |
| 66 bool reappear_on_disconnect; | 67 bool reappear_on_disconnect; |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 class MockBrlapiConnection : public BrlapiConnection { | 70 class MockBrlapiConnection : public BrlapiConnection { |
| 70 public: | 71 public: |
| 71 explicit MockBrlapiConnection(MockBrlapiConnectionData* data) | 72 explicit MockBrlapiConnection(MockBrlapiConnectionData* data) |
| 72 : data_(data) {} | 73 : data_(data) {} |
| 73 ConnectResult Connect(const OnDataReadyCallback& on_data_ready) override { | 74 ConnectResult Connect(const OnDataReadyCallback& on_data_ready) override { |
| 74 data_->connected = true; | 75 data_->connected = true; |
| 75 on_data_ready_ = on_data_ready; | 76 on_data_ready_ = on_data_ready; |
| 76 if (!data_->pending_keys.empty()) { | 77 if (!data_->pending_keys.empty()) { |
| 77 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 78 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 78 base::Bind(&MockBrlapiConnection::NotifyDataReady, | 79 base::Bind(&MockBrlapiConnection::NotifyDataReady, |
| 79 base::Unretained(this))); | 80 base::Unretained(this))); |
| 80 } | 81 } |
| 81 return CONNECT_SUCCESS; | 82 return CONNECT_SUCCESS; |
| 82 } | 83 } |
| 83 | 84 |
| 84 void Disconnect() override { | 85 void Disconnect() override { |
| 85 data_->connected = false; | 86 data_->connected = false; |
| 86 if (data_->reappear_on_disconnect) { | 87 if (data_->reappear_on_disconnect) { |
| 87 data_->display_size *= 2; | 88 data_->display_columns *= 2; |
| 88 BrowserThread::PostTask( | 89 BrowserThread::PostTask( |
| 89 BrowserThread::IO, FROM_HERE, | 90 BrowserThread::IO, FROM_HERE, |
| 90 base::Bind(&BrailleControllerImpl::PokeSocketDirForTesting, | 91 base::Bind(&BrailleControllerImpl::PokeSocketDirForTesting, |
| 91 base::Unretained(BrailleControllerImpl::GetInstance()))); | 92 base::Unretained(BrailleControllerImpl::GetInstance()))); |
| 92 } | 93 } |
| 93 } | 94 } |
| 94 | 95 |
| 95 bool Connected() override { return data_->connected; } | 96 bool Connected() override { return data_->connected; } |
| 96 | 97 |
| 97 brlapi_error_t* BrlapiError() override { return &data_->error; } | 98 brlapi_error_t* BrlapiError() override { return &data_->error; } |
| 98 | 99 |
| 99 std::string BrlapiStrError() override { | 100 std::string BrlapiStrError() override { |
| 100 return data_->error.brlerrno != BRLAPI_ERROR_SUCCESS ? "Error" : "Success"; | 101 return data_->error.brlerrno != BRLAPI_ERROR_SUCCESS ? "Error" : "Success"; |
| 101 } | 102 } |
| 102 | 103 |
| 103 bool GetDisplaySize(size_t* size) override { | 104 bool GetDisplaySize(unsigned int* columns, unsigned int* rows) override { |
| 104 *size = data_->display_size; | 105 *columns = data_->display_columns; |
| 106 *rows = data_->display_rows; |
| 105 return true; | 107 return true; |
| 106 } | 108 } |
| 107 | 109 |
| 108 bool WriteDots(const unsigned char* cells) override { | 110 bool WriteDots(const std::vector<unsigned char>& cells) override { |
| 109 std::string written(reinterpret_cast<const char*>(cells), | 111 std::string written( |
| 110 data_->display_size); | 112 cells.begin(), |
| 113 cells.begin() + data_->display_rows * data_->display_columns); |
| 111 data_->written_content.push_back(written); | 114 data_->written_content.push_back(written); |
| 112 return true; | 115 return true; |
| 113 } | 116 } |
| 114 | 117 |
| 115 int ReadKey(brlapi_keyCode_t* key_code) override { | 118 int ReadKey(brlapi_keyCode_t* key_code) override { |
| 116 if (!data_->pending_keys.empty()) { | 119 if (!data_->pending_keys.empty()) { |
| 117 brlapi_keyCode_t queued_key_code = data_->pending_keys.front(); | 120 brlapi_keyCode_t queued_key_code = data_->pending_keys.front(); |
| 118 data_->pending_keys.pop_front(); | 121 data_->pending_keys.pop_front(); |
| 119 if (queued_key_code == kErrorKeyCode) { | 122 if (queued_key_code == kErrorKeyCode) { |
| 120 data_->error.brlerrno = BRLAPI_ERROR_EOF; | 123 data_->error.brlerrno = BRLAPI_ERROR_EOF; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 140 | 143 |
| 141 MockBrlapiConnectionData* data_; | 144 MockBrlapiConnectionData* data_; |
| 142 OnDataReadyCallback on_data_ready_; | 145 OnDataReadyCallback on_data_ready_; |
| 143 }; | 146 }; |
| 144 | 147 |
| 145 class BrailleDisplayPrivateApiTest : public ExtensionApiTest { | 148 class BrailleDisplayPrivateApiTest : public ExtensionApiTest { |
| 146 public: | 149 public: |
| 147 void SetUpInProcessBrowserTestFixture() override { | 150 void SetUpInProcessBrowserTestFixture() override { |
| 148 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 151 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 149 connection_data_.connected = false; | 152 connection_data_.connected = false; |
| 150 connection_data_.display_size = 0; | 153 connection_data_.display_rows = 0; |
| 154 connection_data_.display_columns = 0; |
| 151 connection_data_.error.brlerrno = BRLAPI_ERROR_SUCCESS; | 155 connection_data_.error.brlerrno = BRLAPI_ERROR_SUCCESS; |
| 152 connection_data_.reappear_on_disconnect = false; | 156 connection_data_.reappear_on_disconnect = false; |
| 153 BrailleControllerImpl::GetInstance()->SetCreateBrlapiConnectionForTesting( | 157 BrailleControllerImpl::GetInstance()->SetCreateBrlapiConnectionForTesting( |
| 154 base::Bind( | 158 base::Bind( |
| 155 &BrailleDisplayPrivateApiTest::CreateBrlapiConnection, | 159 &BrailleDisplayPrivateApiTest::CreateBrlapiConnection, |
| 156 base::Unretained(this))); | 160 base::Unretained(this))); |
| 157 DisableAccessibilityManagerBraille(); | 161 DisableAccessibilityManagerBraille(); |
| 158 } | 162 } |
| 159 | 163 |
| 160 protected: | 164 protected: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 171 private: | 175 private: |
| 172 std::unique_ptr<BrlapiConnection> CreateBrlapiConnection() { | 176 std::unique_ptr<BrlapiConnection> CreateBrlapiConnection() { |
| 173 return std::unique_ptr<BrlapiConnection>( | 177 return std::unique_ptr<BrlapiConnection>( |
| 174 new MockBrlapiConnection(&connection_data_)); | 178 new MockBrlapiConnection(&connection_data_)); |
| 175 } | 179 } |
| 176 | 180 |
| 177 StubBrailleController stub_braille_controller_; | 181 StubBrailleController stub_braille_controller_; |
| 178 }; | 182 }; |
| 179 | 183 |
| 180 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, WriteDots) { | 184 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, WriteDots) { |
| 181 connection_data_.display_size = 11; | 185 connection_data_.display_columns = 11; |
| 186 connection_data_.display_rows = 1; |
| 182 ASSERT_TRUE(RunComponentExtensionTest("braille_display_private/write_dots")) | 187 ASSERT_TRUE(RunComponentExtensionTest("braille_display_private/write_dots")) |
| 183 << message_; | 188 << message_; |
| 184 ASSERT_EQ(3U, connection_data_.written_content.size()); | 189 ASSERT_EQ(3U, connection_data_.written_content.size()); |
| 185 const std::string expected_content(connection_data_.display_size, '\0'); | 190 const std::string expected_content( |
| 191 connection_data_.display_columns * connection_data_.display_rows, '\0'); |
| 186 for (size_t i = 0; i < connection_data_.written_content.size(); ++i) { | 192 for (size_t i = 0; i < connection_data_.written_content.size(); ++i) { |
| 187 ASSERT_EQ(std::string( | 193 ASSERT_EQ(std::string(connection_data_.display_columns * |
| 188 connection_data_.display_size, | 194 connection_data_.display_rows, |
| 189 static_cast<char>(i)), | 195 static_cast<char>(i)), |
| 190 connection_data_.written_content[i]) | 196 connection_data_.written_content[i]) |
| 191 << "String " << i << " doesn't match"; | 197 << "String " << i << " doesn't match"; |
| 192 } | 198 } |
| 193 } | 199 } |
| 194 | 200 |
| 195 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, KeyEvents) { | 201 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, KeyEvents) { |
| 196 connection_data_.display_size = 11; | 202 connection_data_.display_columns = 11; |
| 203 connection_data_.display_rows = 1; |
| 197 | 204 |
| 198 // Braille navigation commands. | 205 // Braille navigation commands. |
| 199 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | | 206 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | |
| 200 BRLAPI_KEY_CMD_LNUP); | 207 BRLAPI_KEY_CMD_LNUP); |
| 201 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | | 208 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | |
| 202 BRLAPI_KEY_CMD_LNDN); | 209 BRLAPI_KEY_CMD_LNDN); |
| 203 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | | 210 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | |
| 204 BRLAPI_KEY_CMD_FWINLT); | 211 BRLAPI_KEY_CMD_FWINLT); |
| 205 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | | 212 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | |
| 206 BRLAPI_KEY_CMD_FWINRT); | 213 BRLAPI_KEY_CMD_FWINRT); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // Braille dot keys, all combinations including space (0). | 256 // Braille dot keys, all combinations including space (0). |
| 250 for (int i = 0; i < 256; ++i) { | 257 for (int i = 0; i < 256; ++i) { |
| 251 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | | 258 connection_data_.pending_keys.push_back(BRLAPI_KEY_TYPE_CMD | |
| 252 BRLAPI_KEY_CMD_PASSDOTS | i); | 259 BRLAPI_KEY_CMD_PASSDOTS | i); |
| 253 } | 260 } |
| 254 | 261 |
| 255 ASSERT_TRUE(RunComponentExtensionTest("braille_display_private/key_events")); | 262 ASSERT_TRUE(RunComponentExtensionTest("braille_display_private/key_events")); |
| 256 } | 263 } |
| 257 | 264 |
| 258 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, DisplayStateChanges) { | 265 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, DisplayStateChanges) { |
| 259 connection_data_.display_size = 11; | 266 connection_data_.display_columns = 11; |
| 267 connection_data_.display_rows = 1; |
| 260 connection_data_.pending_keys.push_back(kErrorKeyCode); | 268 connection_data_.pending_keys.push_back(kErrorKeyCode); |
| 261 connection_data_.reappear_on_disconnect = true; | 269 connection_data_.reappear_on_disconnect = true; |
| 262 ASSERT_TRUE(RunComponentExtensionTest( | 270 ASSERT_TRUE(RunComponentExtensionTest( |
| 263 "braille_display_private/display_state_changes")); | 271 "braille_display_private/display_state_changes")); |
| 264 } | 272 } |
| 265 | 273 |
| 266 class BrailleDisplayPrivateAPIUserTest : public BrailleDisplayPrivateApiTest { | 274 class BrailleDisplayPrivateAPIUserTest : public BrailleDisplayPrivateApiTest { |
| 267 public: | 275 public: |
| 268 void SetUpCommandLine(base::CommandLine* command_line) override { | 276 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 269 command_line->AppendSwitch(chromeos::switches::kLoginManager); | 277 command_line->AppendSwitch(chromeos::switches::kLoginManager); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 DismissLockScreen(tester.get()); | 375 DismissLockScreen(tester.get()); |
| 368 signin_api.OnBrailleKeyEvent(key_event); | 376 signin_api.OnBrailleKeyEvent(key_event); |
| 369 user_api.OnBrailleKeyEvent(key_event); | 377 user_api.OnBrailleKeyEvent(key_event); |
| 370 EXPECT_EQ(1, signin_delegate->GetEventCount()); | 378 EXPECT_EQ(1, signin_delegate->GetEventCount()); |
| 371 EXPECT_EQ(2, user_delegate->GetEventCount()); | 379 EXPECT_EQ(2, user_delegate->GetEventCount()); |
| 372 } | 380 } |
| 373 | 381 |
| 374 } // namespace braille_display_private | 382 } // namespace braille_display_private |
| 375 } // namespace api | 383 } // namespace api |
| 376 } // namespace extensions | 384 } // namespace extensions |
| OLD | NEW |