| 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 <deque> | 9 #include <deque> |
| 10 | 10 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 // display size doubles and the controller gets notified of a brltty | 62 // display size doubles and the controller gets notified of a brltty |
| 63 // restart. | 63 // restart. |
| 64 bool reappear_on_disconnect; | 64 bool reappear_on_disconnect; |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 class MockBrlapiConnection : public BrlapiConnection { | 67 class MockBrlapiConnection : public BrlapiConnection { |
| 68 public: | 68 public: |
| 69 explicit MockBrlapiConnection(MockBrlapiConnectionData* data) | 69 explicit MockBrlapiConnection(MockBrlapiConnectionData* data) |
| 70 : data_(data) {} | 70 : data_(data) {} |
| 71 virtual ConnectResult Connect(const OnDataReadyCallback& on_data_ready) | 71 virtual ConnectResult Connect(const OnDataReadyCallback& on_data_ready) |
| 72 OVERRIDE { | 72 override { |
| 73 data_->connected = true; | 73 data_->connected = true; |
| 74 on_data_ready_ = on_data_ready; | 74 on_data_ready_ = on_data_ready; |
| 75 if (!data_->pending_keys.empty()) { | 75 if (!data_->pending_keys.empty()) { |
| 76 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 76 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 77 base::Bind(&MockBrlapiConnection::NotifyDataReady, | 77 base::Bind(&MockBrlapiConnection::NotifyDataReady, |
| 78 base::Unretained(this))); | 78 base::Unretained(this))); |
| 79 } | 79 } |
| 80 return CONNECT_SUCCESS; | 80 return CONNECT_SUCCESS; |
| 81 } | 81 } |
| 82 | 82 |
| 83 virtual void Disconnect() OVERRIDE { | 83 virtual void Disconnect() override { |
| 84 data_->connected = false; | 84 data_->connected = false; |
| 85 if (data_->reappear_on_disconnect) { | 85 if (data_->reappear_on_disconnect) { |
| 86 data_->display_size *= 2; | 86 data_->display_size *= 2; |
| 87 BrowserThread::PostTask( | 87 BrowserThread::PostTask( |
| 88 BrowserThread::IO, FROM_HERE, | 88 BrowserThread::IO, FROM_HERE, |
| 89 base::Bind(&BrailleControllerImpl::PokeSocketDirForTesting, | 89 base::Bind(&BrailleControllerImpl::PokeSocketDirForTesting, |
| 90 base::Unretained(BrailleControllerImpl::GetInstance()))); | 90 base::Unretained(BrailleControllerImpl::GetInstance()))); |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 | 93 |
| 94 virtual bool Connected() OVERRIDE { | 94 virtual bool Connected() override { |
| 95 return data_->connected; | 95 return data_->connected; |
| 96 } | 96 } |
| 97 | 97 |
| 98 virtual brlapi_error_t* BrlapiError() OVERRIDE { | 98 virtual brlapi_error_t* BrlapiError() override { |
| 99 return &data_->error; | 99 return &data_->error; |
| 100 } | 100 } |
| 101 | 101 |
| 102 virtual std::string BrlapiStrError() OVERRIDE { | 102 virtual std::string BrlapiStrError() override { |
| 103 return data_->error.brlerrno != BRLAPI_ERROR_SUCCESS ? "Error" : "Success"; | 103 return data_->error.brlerrno != BRLAPI_ERROR_SUCCESS ? "Error" : "Success"; |
| 104 } | 104 } |
| 105 | 105 |
| 106 virtual bool GetDisplaySize(size_t* size) OVERRIDE { | 106 virtual bool GetDisplaySize(size_t* size) override { |
| 107 *size = data_->display_size; | 107 *size = data_->display_size; |
| 108 return true; | 108 return true; |
| 109 } | 109 } |
| 110 | 110 |
| 111 virtual bool WriteDots(const unsigned char* cells) OVERRIDE { | 111 virtual bool WriteDots(const unsigned char* cells) override { |
| 112 std::string written(reinterpret_cast<const char*>(cells), | 112 std::string written(reinterpret_cast<const char*>(cells), |
| 113 data_->display_size); | 113 data_->display_size); |
| 114 data_->written_content.push_back(written); | 114 data_->written_content.push_back(written); |
| 115 return true; | 115 return true; |
| 116 } | 116 } |
| 117 | 117 |
| 118 virtual int ReadKey(brlapi_keyCode_t* key_code) OVERRIDE { | 118 virtual int ReadKey(brlapi_keyCode_t* key_code) override { |
| 119 if (!data_->pending_keys.empty()) { | 119 if (!data_->pending_keys.empty()) { |
| 120 brlapi_keyCode_t queued_key_code = data_->pending_keys.front(); | 120 brlapi_keyCode_t queued_key_code = data_->pending_keys.front(); |
| 121 data_->pending_keys.pop_front(); | 121 data_->pending_keys.pop_front(); |
| 122 if (queued_key_code == kErrorKeyCode) { | 122 if (queued_key_code == kErrorKeyCode) { |
| 123 data_->error.brlerrno = BRLAPI_ERROR_EOF; | 123 data_->error.brlerrno = BRLAPI_ERROR_EOF; |
| 124 return -1; // Signal error. | 124 return -1; // Signal error. |
| 125 } | 125 } |
| 126 *key_code = queued_key_code; | 126 *key_code = queued_key_code; |
| 127 return 1; | 127 return 1; |
| 128 } else { | 128 } else { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 140 base::Unretained(this))); | 140 base::Unretained(this))); |
| 141 } | 141 } |
| 142 } | 142 } |
| 143 | 143 |
| 144 MockBrlapiConnectionData* data_; | 144 MockBrlapiConnectionData* data_; |
| 145 OnDataReadyCallback on_data_ready_; | 145 OnDataReadyCallback on_data_ready_; |
| 146 }; | 146 }; |
| 147 | 147 |
| 148 class BrailleDisplayPrivateApiTest : public ExtensionApiTest { | 148 class BrailleDisplayPrivateApiTest : public ExtensionApiTest { |
| 149 public: | 149 public: |
| 150 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 150 virtual void SetUpInProcessBrowserTestFixture() override { |
| 151 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 151 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 152 connection_data_.connected = false; | 152 connection_data_.connected = false; |
| 153 connection_data_.display_size = 0; | 153 connection_data_.display_size = 0; |
| 154 connection_data_.error.brlerrno = BRLAPI_ERROR_SUCCESS; | 154 connection_data_.error.brlerrno = BRLAPI_ERROR_SUCCESS; |
| 155 connection_data_.reappear_on_disconnect = false; | 155 connection_data_.reappear_on_disconnect = false; |
| 156 BrailleControllerImpl::GetInstance()->SetCreateBrlapiConnectionForTesting( | 156 BrailleControllerImpl::GetInstance()->SetCreateBrlapiConnectionForTesting( |
| 157 base::Bind( | 157 base::Bind( |
| 158 &BrailleDisplayPrivateApiTest::CreateBrlapiConnection, | 158 &BrailleDisplayPrivateApiTest::CreateBrlapiConnection, |
| 159 base::Unretained(this))); | 159 base::Unretained(this))); |
| 160 DisableAccessibilityManagerBraille(); | 160 DisableAccessibilityManagerBraille(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, DisplayStateChanges) { | 261 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateApiTest, DisplayStateChanges) { |
| 262 connection_data_.display_size = 11; | 262 connection_data_.display_size = 11; |
| 263 connection_data_.pending_keys.push_back(kErrorKeyCode); | 263 connection_data_.pending_keys.push_back(kErrorKeyCode); |
| 264 connection_data_.reappear_on_disconnect = true; | 264 connection_data_.reappear_on_disconnect = true; |
| 265 ASSERT_TRUE(RunComponentExtensionTest( | 265 ASSERT_TRUE(RunComponentExtensionTest( |
| 266 "braille_display_private/display_state_changes")); | 266 "braille_display_private/display_state_changes")); |
| 267 } | 267 } |
| 268 | 268 |
| 269 class BrailleDisplayPrivateAPIUserTest : public BrailleDisplayPrivateApiTest { | 269 class BrailleDisplayPrivateAPIUserTest : public BrailleDisplayPrivateApiTest { |
| 270 public: | 270 public: |
| 271 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 271 virtual void SetUpCommandLine(CommandLine* command_line) override { |
| 272 command_line->AppendSwitch(chromeos::switches::kLoginManager); | 272 command_line->AppendSwitch(chromeos::switches::kLoginManager); |
| 273 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, | 273 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, |
| 274 TestingProfile::kTestUserProfileDir); | 274 TestingProfile::kTestUserProfileDir); |
| 275 } | 275 } |
| 276 | 276 |
| 277 class MockEventDelegate : public BrailleDisplayPrivateAPI::EventDelegate { | 277 class MockEventDelegate : public BrailleDisplayPrivateAPI::EventDelegate { |
| 278 public: | 278 public: |
| 279 MockEventDelegate() : event_count_(0) {} | 279 MockEventDelegate() : event_count_(0) {} |
| 280 | 280 |
| 281 int GetEventCount() { return event_count_; } | 281 int GetEventCount() { return event_count_; } |
| 282 | 282 |
| 283 virtual void BroadcastEvent(scoped_ptr<Event> event) OVERRIDE { | 283 virtual void BroadcastEvent(scoped_ptr<Event> event) override { |
| 284 ++event_count_; | 284 ++event_count_; |
| 285 } | 285 } |
| 286 virtual bool HasListener() OVERRIDE { return true; } | 286 virtual bool HasListener() override { return true; } |
| 287 | 287 |
| 288 private: | 288 private: |
| 289 int event_count_; | 289 int event_count_; |
| 290 }; | 290 }; |
| 291 | 291 |
| 292 MockEventDelegate* SetMockEventDelegate(BrailleDisplayPrivateAPI* api) { | 292 MockEventDelegate* SetMockEventDelegate(BrailleDisplayPrivateAPI* api) { |
| 293 MockEventDelegate* delegate = new MockEventDelegate(); | 293 MockEventDelegate* delegate = new MockEventDelegate(); |
| 294 api->SetEventDelegateForTest( | 294 api->SetEventDelegateForTest( |
| 295 scoped_ptr<BrailleDisplayPrivateAPI::EventDelegate>(delegate).Pass()); | 295 scoped_ptr<BrailleDisplayPrivateAPI::EventDelegate>(delegate).Pass()); |
| 296 return delegate; | 296 return delegate; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 311 ScreenLocker::Hide(); | 311 ScreenLocker::Hide(); |
| 312 content::WindowedNotificationObserver lock_state_observer( | 312 content::WindowedNotificationObserver lock_state_observer( |
| 313 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, | 313 chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED, |
| 314 content::NotificationService::AllSources()); | 314 content::NotificationService::AllSources()); |
| 315 if (tester->IsLocked()) | 315 if (tester->IsLocked()) |
| 316 lock_state_observer.Wait(); | 316 lock_state_observer.Wait(); |
| 317 ASSERT_FALSE(tester->IsLocked()); | 317 ASSERT_FALSE(tester->IsLocked()); |
| 318 } | 318 } |
| 319 | 319 |
| 320 protected: | 320 protected: |
| 321 virtual void DisableAccessibilityManagerBraille() OVERRIDE { | 321 virtual void DisableAccessibilityManagerBraille() override { |
| 322 // Let the accessibility manager behave as usual for these tests. | 322 // Let the accessibility manager behave as usual for these tests. |
| 323 } | 323 } |
| 324 }; | 324 }; |
| 325 | 325 |
| 326 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateAPIUserTest, | 326 IN_PROC_BROWSER_TEST_F(BrailleDisplayPrivateAPIUserTest, |
| 327 KeyEventOnLockScreen) { | 327 KeyEventOnLockScreen) { |
| 328 scoped_ptr<ScreenLockerTester> tester(ScreenLocker::GetTester()); | 328 scoped_ptr<ScreenLockerTester> tester(ScreenLocker::GetTester()); |
| 329 // Log in. | 329 // Log in. |
| 330 user_manager::UserManager::Get()->UserLoggedIn( | 330 user_manager::UserManager::Get()->UserLoggedIn( |
| 331 kTestUserName, kTestUserName, true); | 331 kTestUserName, kTestUserName, true); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 DismissLockScreen(tester.get()); | 364 DismissLockScreen(tester.get()); |
| 365 signin_api.OnBrailleKeyEvent(key_event); | 365 signin_api.OnBrailleKeyEvent(key_event); |
| 366 user_api.OnBrailleKeyEvent(key_event); | 366 user_api.OnBrailleKeyEvent(key_event); |
| 367 EXPECT_EQ(1, signin_delegate->GetEventCount()); | 367 EXPECT_EQ(1, signin_delegate->GetEventCount()); |
| 368 EXPECT_EQ(2, user_delegate->GetEventCount()); | 368 EXPECT_EQ(2, user_delegate->GetEventCount()); |
| 369 } | 369 } |
| 370 | 370 |
| 371 } // namespace braille_display_private | 371 } // namespace braille_display_private |
| 372 } // namespace api | 372 } // namespace api |
| 373 } // namespace extensions | 373 } // namespace extensions |
| OLD | NEW |