| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" | 5 #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" |
| 6 | 6 |
| 7 #include "ash/magnifier/magnification_controller.h" | 7 #include "ash/magnifier/magnification_controller.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 namespace { | 35 namespace { |
| 36 | 36 |
| 37 const char kTestUserName[] = "owner@invalid.domain"; | 37 const char kTestUserName[] = "owner@invalid.domain"; |
| 38 | 38 |
| 39 const int kTestAutoclickDelayMs = 2000; | 39 const int kTestAutoclickDelayMs = 2000; |
| 40 | 40 |
| 41 // Test user name for locally managed user. The domain part must be matched | 41 // Test user name for locally managed user. The domain part must be matched |
| 42 // with UserManager::kLocallyManagedUserDomain. | 42 // with UserManager::kLocallyManagedUserDomain. |
| 43 const char kTestLocallyManagedUserName[] = "test@locally-managed.localhost"; | 43 const char kTestLocallyManagedUserName[] = "test@locally-managed.localhost"; |
| 44 | 44 |
| 45 class MockAccessibilityObserver : public content::NotificationObserver { | 45 class MockAccessibilityObserver { |
| 46 public: | 46 public: |
| 47 MockAccessibilityObserver() : observed_(false), | 47 MockAccessibilityObserver() : observed_(false), |
| 48 observed_enabled_(false), | 48 observed_enabled_(false), |
| 49 observed_type_(-1) { | 49 observed_type_(-1) |
| 50 registrar_.Add( | 50 { |
| 51 this, | 51 AccessibilityManager* accessibility_manager = AccessibilityManager::Get(); |
| 52 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK, | 52 CHECK(accessibility_manager); |
| 53 content::NotificationService::AllSources()); | 53 accessibility_subscription_ = accessibility_manager->RegisterCallback( |
| 54 registrar_.Add( | 54 base::Bind(&MockAccessibilityObserver::OnAccessibilityStatusChanged, |
| 55 this, | 55 base::Unretained(this))); |
| 56 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE, | |
| 57 content::NotificationService::AllSources()); | |
| 58 registrar_.Add( | |
| 59 this, | |
| 60 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD, | |
| 61 content::NotificationService::AllSources()); | |
| 62 } | 56 } |
| 57 |
| 63 virtual ~MockAccessibilityObserver() {} | 58 virtual ~MockAccessibilityObserver() {} |
| 64 | 59 |
| 65 bool observed() const { return observed_; } | 60 bool observed() const { return observed_; } |
| 66 bool observed_enabled() const { return observed_enabled_; } | 61 bool observed_enabled() const { return observed_enabled_; } |
| 67 int observed_type() const { return observed_type_; } | 62 int observed_type() const { return observed_type_; } |
| 68 | 63 |
| 69 void reset() { observed_ = false; } | 64 void reset() { observed_ = false; } |
| 70 | 65 |
| 71 private: | 66 private: |
| 72 // content::NotificationObserver implimentation: | 67 void OnAccessibilityStatusChanged( |
| 73 virtual void Observe(int type, | 68 const AccessibilityStatusEventDetails& details) { |
| 74 const content::NotificationSource& source, | 69 if (details.notification_type != ACCESSIBILITY_TOGGLE_SCREEN_MAGNIFIER) { |
| 75 const content::NotificationDetails& details) OVERRIDE { | 70 observed_type_ = details.notification_type; |
| 76 AccessibilityStatusEventDetails* accessibility_status = | 71 observed_enabled_ = details.enabled; |
| 77 content::Details<AccessibilityStatusEventDetails>( | 72 observed_ = true; |
| 78 details).ptr(); | |
| 79 ASSERT_FALSE(observed_); | |
| 80 | |
| 81 switch (type) { | |
| 82 case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK: | |
| 83 observed_ = true; | |
| 84 observed_enabled_ = accessibility_status->enabled; | |
| 85 observed_type_ = type; | |
| 86 break; | |
| 87 case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE: | |
| 88 observed_ = true; | |
| 89 observed_enabled_ = accessibility_status->enabled; | |
| 90 observed_type_ = type; | |
| 91 break; | |
| 92 case chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD: | |
| 93 observed_ = true; | |
| 94 observed_enabled_ = accessibility_status->enabled; | |
| 95 observed_type_ = type; | |
| 96 break; | |
| 97 } | 73 } |
| 98 } | 74 } |
| 99 | 75 |
| 100 bool observed_; | 76 bool observed_; |
| 101 bool observed_enabled_; | 77 bool observed_enabled_; |
| 102 int observed_type_; | 78 int observed_type_; |
| 103 | 79 |
| 104 content::NotificationRegistrar registrar_; | 80 scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_; |
| 105 | 81 |
| 106 DISALLOW_COPY_AND_ASSIGN(MockAccessibilityObserver); | 82 DISALLOW_COPY_AND_ASSIGN(MockAccessibilityObserver); |
| 107 }; | 83 }; |
| 108 | 84 |
| 109 class MockBrailleController : public StubBrailleController { | 85 class MockBrailleController : public StubBrailleController { |
| 110 public: | 86 public: |
| 111 | 87 |
| 112 MockBrailleController() : available_(false), observer_(NULL) {} | 88 MockBrailleController() : available_(false), observer_(NULL) {} |
| 113 | 89 |
| 114 virtual scoped_ptr<DisplayState> GetDisplayState() OVERRIDE { | 90 virtual scoped_ptr<DisplayState> GetDisplayState() OVERRIDE { |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); | 440 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); |
| 465 UserManager::Get()->SessionStarted(); | 441 UserManager::Get()->SessionStarted(); |
| 466 | 442 |
| 467 EXPECT_FALSE(observer.observed()); | 443 EXPECT_FALSE(observer.observed()); |
| 468 observer.reset(); | 444 observer.reset(); |
| 469 | 445 |
| 470 SetSpokenFeedbackEnabled(true); | 446 SetSpokenFeedbackEnabled(true); |
| 471 EXPECT_TRUE(observer.observed()); | 447 EXPECT_TRUE(observer.observed()); |
| 472 EXPECT_TRUE(observer.observed_enabled()); | 448 EXPECT_TRUE(observer.observed_enabled()); |
| 473 EXPECT_EQ(observer.observed_type(), | 449 EXPECT_EQ(observer.observed_type(), |
| 474 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | 450 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 475 EXPECT_TRUE(IsSpokenFeedbackEnabled()); | 451 EXPECT_TRUE(IsSpokenFeedbackEnabled()); |
| 476 | 452 |
| 477 observer.reset(); | 453 observer.reset(); |
| 478 SetSpokenFeedbackEnabled(false); | 454 SetSpokenFeedbackEnabled(false); |
| 479 EXPECT_TRUE(observer.observed()); | 455 EXPECT_TRUE(observer.observed()); |
| 480 EXPECT_FALSE(observer.observed_enabled()); | 456 EXPECT_FALSE(observer.observed_enabled()); |
| 481 EXPECT_EQ(observer.observed_type(), | 457 EXPECT_EQ(observer.observed_type(), |
| 482 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | 458 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 483 EXPECT_FALSE(IsSpokenFeedbackEnabled()); | 459 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 484 | 460 |
| 485 observer.reset(); | 461 observer.reset(); |
| 486 SetHighContrastEnabled(true); | 462 SetHighContrastEnabled(true); |
| 487 EXPECT_TRUE(observer.observed()); | 463 EXPECT_TRUE(observer.observed()); |
| 488 EXPECT_TRUE(observer.observed_enabled()); | 464 EXPECT_TRUE(observer.observed_enabled()); |
| 489 EXPECT_EQ(observer.observed_type(), | 465 EXPECT_EQ(observer.observed_type(), |
| 490 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | 466 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 491 EXPECT_TRUE(IsHighContrastEnabled()); | 467 EXPECT_TRUE(IsHighContrastEnabled()); |
| 492 | 468 |
| 493 observer.reset(); | 469 observer.reset(); |
| 494 SetHighContrastEnabled(false); | 470 SetHighContrastEnabled(false); |
| 495 EXPECT_TRUE(observer.observed()); | 471 EXPECT_TRUE(observer.observed()); |
| 496 EXPECT_FALSE(observer.observed_enabled()); | 472 EXPECT_FALSE(observer.observed_enabled()); |
| 497 EXPECT_EQ(observer.observed_type(), | 473 EXPECT_EQ(observer.observed_type(), |
| 498 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | 474 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 499 EXPECT_FALSE(IsHighContrastEnabled()); | 475 EXPECT_FALSE(IsHighContrastEnabled()); |
| 500 | 476 |
| 501 observer.reset(); | 477 observer.reset(); |
| 502 SetVirtualKeyboardEnabled(true); | 478 SetVirtualKeyboardEnabled(true); |
| 503 EXPECT_TRUE(observer.observed()); | 479 EXPECT_TRUE(observer.observed()); |
| 504 EXPECT_TRUE(observer.observed_enabled()); | 480 EXPECT_TRUE(observer.observed_enabled()); |
| 505 EXPECT_EQ(observer.observed_type(), | 481 EXPECT_EQ(observer.observed_type(), |
| 506 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); | 482 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); |
| 507 EXPECT_TRUE(IsVirtualKeyboardEnabled()); | 483 EXPECT_TRUE(IsVirtualKeyboardEnabled()); |
| 508 | 484 |
| 509 observer.reset(); | 485 observer.reset(); |
| 510 SetVirtualKeyboardEnabled(false); | 486 SetVirtualKeyboardEnabled(false); |
| 511 EXPECT_TRUE(observer.observed()); | 487 EXPECT_TRUE(observer.observed()); |
| 512 EXPECT_FALSE(observer.observed_enabled()); | 488 EXPECT_FALSE(observer.observed_enabled()); |
| 513 EXPECT_EQ(observer.observed_type(), | 489 EXPECT_EQ(observer.observed_type(), |
| 514 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); | 490 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); |
| 515 EXPECT_FALSE(IsVirtualKeyboardEnabled()); | 491 EXPECT_FALSE(IsVirtualKeyboardEnabled()); |
| 516 } | 492 } |
| 517 | 493 |
| 518 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, | 494 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, |
| 519 ChangingTypePrefInvokesNotification) { | 495 ChangingTypePrefInvokesNotification) { |
| 520 MockAccessibilityObserver observer; | 496 MockAccessibilityObserver observer; |
| 521 | 497 |
| 522 // Logs in. | 498 // Logs in. |
| 523 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); | 499 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); |
| 524 UserManager::Get()->SessionStarted(); | 500 UserManager::Get()->SessionStarted(); |
| 525 | 501 |
| 526 EXPECT_FALSE(observer.observed()); | 502 EXPECT_FALSE(observer.observed()); |
| 527 observer.reset(); | 503 observer.reset(); |
| 528 | 504 |
| 529 SetSpokenFeedbackEnabledPref(true); | 505 SetSpokenFeedbackEnabledPref(true); |
| 530 EXPECT_TRUE(observer.observed()); | 506 EXPECT_TRUE(observer.observed()); |
| 531 EXPECT_TRUE(observer.observed_enabled()); | 507 EXPECT_TRUE(observer.observed_enabled()); |
| 532 EXPECT_EQ(observer.observed_type(), | 508 EXPECT_EQ(observer.observed_type(), |
| 533 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | 509 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 534 EXPECT_TRUE(IsSpokenFeedbackEnabled()); | 510 EXPECT_TRUE(IsSpokenFeedbackEnabled()); |
| 535 | 511 |
| 536 observer.reset(); | 512 observer.reset(); |
| 537 SetSpokenFeedbackEnabledPref(false); | 513 SetSpokenFeedbackEnabledPref(false); |
| 538 EXPECT_TRUE(observer.observed()); | 514 EXPECT_TRUE(observer.observed()); |
| 539 EXPECT_FALSE(observer.observed_enabled()); | 515 EXPECT_FALSE(observer.observed_enabled()); |
| 540 EXPECT_EQ(observer.observed_type(), | 516 EXPECT_EQ(observer.observed_type(), |
| 541 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | 517 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 542 EXPECT_FALSE(IsSpokenFeedbackEnabled()); | 518 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 543 | 519 |
| 544 observer.reset(); | 520 observer.reset(); |
| 545 SetHighContrastEnabledPref(true); | 521 SetHighContrastEnabledPref(true); |
| 546 EXPECT_TRUE(observer.observed()); | 522 EXPECT_TRUE(observer.observed()); |
| 547 EXPECT_TRUE(observer.observed_enabled()); | 523 EXPECT_TRUE(observer.observed_enabled()); |
| 548 EXPECT_EQ(observer.observed_type(), | 524 EXPECT_EQ(observer.observed_type(), |
| 549 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | 525 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 550 EXPECT_TRUE(IsHighContrastEnabled()); | 526 EXPECT_TRUE(IsHighContrastEnabled()); |
| 551 | 527 |
| 552 observer.reset(); | 528 observer.reset(); |
| 553 SetHighContrastEnabledPref(false); | 529 SetHighContrastEnabledPref(false); |
| 554 EXPECT_TRUE(observer.observed()); | 530 EXPECT_TRUE(observer.observed()); |
| 555 EXPECT_FALSE(observer.observed_enabled()); | 531 EXPECT_FALSE(observer.observed_enabled()); |
| 556 EXPECT_EQ(observer.observed_type(), | 532 EXPECT_EQ(observer.observed_type(), |
| 557 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | 533 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 558 EXPECT_FALSE(IsHighContrastEnabled()); | 534 EXPECT_FALSE(IsHighContrastEnabled()); |
| 559 | 535 |
| 560 observer.reset(); | 536 observer.reset(); |
| 561 SetVirtualKeyboardEnabledPref(true); | 537 SetVirtualKeyboardEnabledPref(true); |
| 562 EXPECT_TRUE(observer.observed()); | 538 EXPECT_TRUE(observer.observed()); |
| 563 EXPECT_TRUE(observer.observed_enabled()); | 539 EXPECT_TRUE(observer.observed_enabled()); |
| 564 EXPECT_EQ(observer.observed_type(), | 540 EXPECT_EQ(observer.observed_type(), |
| 565 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); | 541 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); |
| 566 EXPECT_TRUE(IsVirtualKeyboardEnabled()); | 542 EXPECT_TRUE(IsVirtualKeyboardEnabled()); |
| 567 | 543 |
| 568 observer.reset(); | 544 observer.reset(); |
| 569 SetVirtualKeyboardEnabledPref(false); | 545 SetVirtualKeyboardEnabledPref(false); |
| 570 EXPECT_TRUE(observer.observed()); | 546 EXPECT_TRUE(observer.observed()); |
| 571 EXPECT_FALSE(observer.observed_enabled()); | 547 EXPECT_FALSE(observer.observed_enabled()); |
| 572 EXPECT_EQ(observer.observed_type(), | 548 EXPECT_EQ(observer.observed_type(), |
| 573 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); | 549 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); |
| 574 EXPECT_FALSE(IsVirtualKeyboardEnabled()); | 550 EXPECT_FALSE(IsVirtualKeyboardEnabled()); |
| 575 } | 551 } |
| 576 | 552 |
| 577 class AccessibilityManagerUserTypeTest | 553 class AccessibilityManagerUserTypeTest |
| 578 : public AccessibilityManagerTest, | 554 : public AccessibilityManagerTest, |
| 579 public ::testing::WithParamInterface<const char*> { | 555 public ::testing::WithParamInterface<const char*> { |
| 580 protected: | 556 protected: |
| 581 AccessibilityManagerUserTypeTest() {} | 557 AccessibilityManagerUserTypeTest() {} |
| 582 virtual ~AccessibilityManagerUserTypeTest() {} | 558 virtual ~AccessibilityManagerUserTypeTest() {} |
| 583 | 559 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 EXPECT_FALSE(ShouldShowAccessibilityMenu()); | 653 EXPECT_FALSE(ShouldShowAccessibilityMenu()); |
| 678 | 654 |
| 679 // Check on-screen keyboard. | 655 // Check on-screen keyboard. |
| 680 SetVirtualKeyboardEnabled(true); | 656 SetVirtualKeyboardEnabled(true); |
| 681 EXPECT_TRUE(ShouldShowAccessibilityMenu()); | 657 EXPECT_TRUE(ShouldShowAccessibilityMenu()); |
| 682 SetVirtualKeyboardEnabled(false); | 658 SetVirtualKeyboardEnabled(false); |
| 683 EXPECT_FALSE(ShouldShowAccessibilityMenu()); | 659 EXPECT_FALSE(ShouldShowAccessibilityMenu()); |
| 684 } | 660 } |
| 685 | 661 |
| 686 } // namespace chromeos | 662 } // namespace chromeos |
| OLD | NEW |