| 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_(ACCESSIBILITY_NOTIFICATION_NONE) |
| 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 observed_type_ = details.notification_type; |
| 75 const content::NotificationDetails& details) OVERRIDE { | 70 observed_enabled_ = details.enabled; |
| 76 AccessibilityStatusEventDetails* accessibility_status = | 71 observed_ = true; |
| 77 content::Details<AccessibilityStatusEventDetails>( | |
| 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 } | |
| 98 } | 72 } |
| 99 | 73 |
| 100 bool observed_; | 74 bool observed_; |
| 101 bool observed_enabled_; | 75 bool observed_enabled_; |
| 102 int observed_type_; | 76 enum AccessibilityNotificationType observed_type_; |
| 103 | 77 |
| 104 content::NotificationRegistrar registrar_; | 78 scoped_ptr<AccessibilityStatusSubscription> accessibility_subscription_; |
| 105 | 79 |
| 106 DISALLOW_COPY_AND_ASSIGN(MockAccessibilityObserver); | 80 DISALLOW_COPY_AND_ASSIGN(MockAccessibilityObserver); |
| 107 }; | 81 }; |
| 108 | 82 |
| 109 class MockBrailleController : public StubBrailleController { | 83 class MockBrailleController : public StubBrailleController { |
| 110 public: | 84 public: |
| 111 | 85 |
| 112 MockBrailleController() : available_(false), observer_(NULL) {} | 86 MockBrailleController() : available_(false), observer_(NULL) {} |
| 113 | 87 |
| 114 virtual scoped_ptr<DisplayState> GetDisplayState() OVERRIDE { | 88 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); | 438 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); |
| 465 UserManager::Get()->SessionStarted(); | 439 UserManager::Get()->SessionStarted(); |
| 466 | 440 |
| 467 EXPECT_FALSE(observer.observed()); | 441 EXPECT_FALSE(observer.observed()); |
| 468 observer.reset(); | 442 observer.reset(); |
| 469 | 443 |
| 470 SetSpokenFeedbackEnabled(true); | 444 SetSpokenFeedbackEnabled(true); |
| 471 EXPECT_TRUE(observer.observed()); | 445 EXPECT_TRUE(observer.observed()); |
| 472 EXPECT_TRUE(observer.observed_enabled()); | 446 EXPECT_TRUE(observer.observed_enabled()); |
| 473 EXPECT_EQ(observer.observed_type(), | 447 EXPECT_EQ(observer.observed_type(), |
| 474 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | 448 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 475 EXPECT_TRUE(IsSpokenFeedbackEnabled()); | 449 EXPECT_TRUE(IsSpokenFeedbackEnabled()); |
| 476 | 450 |
| 477 observer.reset(); | 451 observer.reset(); |
| 478 SetSpokenFeedbackEnabled(false); | 452 SetSpokenFeedbackEnabled(false); |
| 479 EXPECT_TRUE(observer.observed()); | 453 EXPECT_TRUE(observer.observed()); |
| 480 EXPECT_FALSE(observer.observed_enabled()); | 454 EXPECT_FALSE(observer.observed_enabled()); |
| 481 EXPECT_EQ(observer.observed_type(), | 455 EXPECT_EQ(observer.observed_type(), |
| 482 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | 456 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 483 EXPECT_FALSE(IsSpokenFeedbackEnabled()); | 457 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 484 | 458 |
| 485 observer.reset(); | 459 observer.reset(); |
| 486 SetHighContrastEnabled(true); | 460 SetHighContrastEnabled(true); |
| 487 EXPECT_TRUE(observer.observed()); | 461 EXPECT_TRUE(observer.observed()); |
| 488 EXPECT_TRUE(observer.observed_enabled()); | 462 EXPECT_TRUE(observer.observed_enabled()); |
| 489 EXPECT_EQ(observer.observed_type(), | 463 EXPECT_EQ(observer.observed_type(), |
| 490 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | 464 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 491 EXPECT_TRUE(IsHighContrastEnabled()); | 465 EXPECT_TRUE(IsHighContrastEnabled()); |
| 492 | 466 |
| 493 observer.reset(); | 467 observer.reset(); |
| 494 SetHighContrastEnabled(false); | 468 SetHighContrastEnabled(false); |
| 495 EXPECT_TRUE(observer.observed()); | 469 EXPECT_TRUE(observer.observed()); |
| 496 EXPECT_FALSE(observer.observed_enabled()); | 470 EXPECT_FALSE(observer.observed_enabled()); |
| 497 EXPECT_EQ(observer.observed_type(), | 471 EXPECT_EQ(observer.observed_type(), |
| 498 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | 472 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 499 EXPECT_FALSE(IsHighContrastEnabled()); | 473 EXPECT_FALSE(IsHighContrastEnabled()); |
| 500 | 474 |
| 501 observer.reset(); | 475 observer.reset(); |
| 502 SetVirtualKeyboardEnabled(true); | 476 SetVirtualKeyboardEnabled(true); |
| 503 EXPECT_TRUE(observer.observed()); | 477 EXPECT_TRUE(observer.observed()); |
| 504 EXPECT_TRUE(observer.observed_enabled()); | 478 EXPECT_TRUE(observer.observed_enabled()); |
| 505 EXPECT_EQ(observer.observed_type(), | 479 EXPECT_EQ(observer.observed_type(), |
| 506 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); | 480 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); |
| 507 EXPECT_TRUE(IsVirtualKeyboardEnabled()); | 481 EXPECT_TRUE(IsVirtualKeyboardEnabled()); |
| 508 | 482 |
| 509 observer.reset(); | 483 observer.reset(); |
| 510 SetVirtualKeyboardEnabled(false); | 484 SetVirtualKeyboardEnabled(false); |
| 511 EXPECT_TRUE(observer.observed()); | 485 EXPECT_TRUE(observer.observed()); |
| 512 EXPECT_FALSE(observer.observed_enabled()); | 486 EXPECT_FALSE(observer.observed_enabled()); |
| 513 EXPECT_EQ(observer.observed_type(), | 487 EXPECT_EQ(observer.observed_type(), |
| 514 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); | 488 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); |
| 515 EXPECT_FALSE(IsVirtualKeyboardEnabled()); | 489 EXPECT_FALSE(IsVirtualKeyboardEnabled()); |
| 516 } | 490 } |
| 517 | 491 |
| 518 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, | 492 IN_PROC_BROWSER_TEST_F(AccessibilityManagerTest, |
| 519 ChangingTypePrefInvokesNotification) { | 493 ChangingTypePrefInvokesNotification) { |
| 520 MockAccessibilityObserver observer; | 494 MockAccessibilityObserver observer; |
| 521 | 495 |
| 522 // Logs in. | 496 // Logs in. |
| 523 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); | 497 UserManager::Get()->UserLoggedIn(kTestUserName, kTestUserName, true); |
| 524 UserManager::Get()->SessionStarted(); | 498 UserManager::Get()->SessionStarted(); |
| 525 | 499 |
| 526 EXPECT_FALSE(observer.observed()); | 500 EXPECT_FALSE(observer.observed()); |
| 527 observer.reset(); | 501 observer.reset(); |
| 528 | 502 |
| 529 SetSpokenFeedbackEnabledPref(true); | 503 SetSpokenFeedbackEnabledPref(true); |
| 530 EXPECT_TRUE(observer.observed()); | 504 EXPECT_TRUE(observer.observed()); |
| 531 EXPECT_TRUE(observer.observed_enabled()); | 505 EXPECT_TRUE(observer.observed_enabled()); |
| 532 EXPECT_EQ(observer.observed_type(), | 506 EXPECT_EQ(observer.observed_type(), |
| 533 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | 507 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 534 EXPECT_TRUE(IsSpokenFeedbackEnabled()); | 508 EXPECT_TRUE(IsSpokenFeedbackEnabled()); |
| 535 | 509 |
| 536 observer.reset(); | 510 observer.reset(); |
| 537 SetSpokenFeedbackEnabledPref(false); | 511 SetSpokenFeedbackEnabledPref(false); |
| 538 EXPECT_TRUE(observer.observed()); | 512 EXPECT_TRUE(observer.observed()); |
| 539 EXPECT_FALSE(observer.observed_enabled()); | 513 EXPECT_FALSE(observer.observed_enabled()); |
| 540 EXPECT_EQ(observer.observed_type(), | 514 EXPECT_EQ(observer.observed_type(), |
| 541 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); | 515 ACCESSIBILITY_TOGGLE_SPOKEN_FEEDBACK); |
| 542 EXPECT_FALSE(IsSpokenFeedbackEnabled()); | 516 EXPECT_FALSE(IsSpokenFeedbackEnabled()); |
| 543 | 517 |
| 544 observer.reset(); | 518 observer.reset(); |
| 545 SetHighContrastEnabledPref(true); | 519 SetHighContrastEnabledPref(true); |
| 546 EXPECT_TRUE(observer.observed()); | 520 EXPECT_TRUE(observer.observed()); |
| 547 EXPECT_TRUE(observer.observed_enabled()); | 521 EXPECT_TRUE(observer.observed_enabled()); |
| 548 EXPECT_EQ(observer.observed_type(), | 522 EXPECT_EQ(observer.observed_type(), |
| 549 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | 523 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 550 EXPECT_TRUE(IsHighContrastEnabled()); | 524 EXPECT_TRUE(IsHighContrastEnabled()); |
| 551 | 525 |
| 552 observer.reset(); | 526 observer.reset(); |
| 553 SetHighContrastEnabledPref(false); | 527 SetHighContrastEnabledPref(false); |
| 554 EXPECT_TRUE(observer.observed()); | 528 EXPECT_TRUE(observer.observed()); |
| 555 EXPECT_FALSE(observer.observed_enabled()); | 529 EXPECT_FALSE(observer.observed_enabled()); |
| 556 EXPECT_EQ(observer.observed_type(), | 530 EXPECT_EQ(observer.observed_type(), |
| 557 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); | 531 ACCESSIBILITY_TOGGLE_HIGH_CONTRAST_MODE); |
| 558 EXPECT_FALSE(IsHighContrastEnabled()); | 532 EXPECT_FALSE(IsHighContrastEnabled()); |
| 559 | 533 |
| 560 observer.reset(); | 534 observer.reset(); |
| 561 SetVirtualKeyboardEnabledPref(true); | 535 SetVirtualKeyboardEnabledPref(true); |
| 562 EXPECT_TRUE(observer.observed()); | 536 EXPECT_TRUE(observer.observed()); |
| 563 EXPECT_TRUE(observer.observed_enabled()); | 537 EXPECT_TRUE(observer.observed_enabled()); |
| 564 EXPECT_EQ(observer.observed_type(), | 538 EXPECT_EQ(observer.observed_type(), |
| 565 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); | 539 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); |
| 566 EXPECT_TRUE(IsVirtualKeyboardEnabled()); | 540 EXPECT_TRUE(IsVirtualKeyboardEnabled()); |
| 567 | 541 |
| 568 observer.reset(); | 542 observer.reset(); |
| 569 SetVirtualKeyboardEnabledPref(false); | 543 SetVirtualKeyboardEnabledPref(false); |
| 570 EXPECT_TRUE(observer.observed()); | 544 EXPECT_TRUE(observer.observed()); |
| 571 EXPECT_FALSE(observer.observed_enabled()); | 545 EXPECT_FALSE(observer.observed_enabled()); |
| 572 EXPECT_EQ(observer.observed_type(), | 546 EXPECT_EQ(observer.observed_type(), |
| 573 chrome::NOTIFICATION_CROS_ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); | 547 ACCESSIBILITY_TOGGLE_VIRTUAL_KEYBOARD); |
| 574 EXPECT_FALSE(IsVirtualKeyboardEnabled()); | 548 EXPECT_FALSE(IsVirtualKeyboardEnabled()); |
| 575 } | 549 } |
| 576 | 550 |
| 577 class AccessibilityManagerUserTypeTest | 551 class AccessibilityManagerUserTypeTest |
| 578 : public AccessibilityManagerTest, | 552 : public AccessibilityManagerTest, |
| 579 public ::testing::WithParamInterface<const char*> { | 553 public ::testing::WithParamInterface<const char*> { |
| 580 protected: | 554 protected: |
| 581 AccessibilityManagerUserTypeTest() {} | 555 AccessibilityManagerUserTypeTest() {} |
| 582 virtual ~AccessibilityManagerUserTypeTest() {} | 556 virtual ~AccessibilityManagerUserTypeTest() {} |
| 583 | 557 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 EXPECT_FALSE(ShouldShowAccessibilityMenu()); | 651 EXPECT_FALSE(ShouldShowAccessibilityMenu()); |
| 678 | 652 |
| 679 // Check on-screen keyboard. | 653 // Check on-screen keyboard. |
| 680 SetVirtualKeyboardEnabled(true); | 654 SetVirtualKeyboardEnabled(true); |
| 681 EXPECT_TRUE(ShouldShowAccessibilityMenu()); | 655 EXPECT_TRUE(ShouldShowAccessibilityMenu()); |
| 682 SetVirtualKeyboardEnabled(false); | 656 SetVirtualKeyboardEnabled(false); |
| 683 EXPECT_FALSE(ShouldShowAccessibilityMenu()); | 657 EXPECT_FALSE(ShouldShowAccessibilityMenu()); |
| 684 } | 658 } |
| 685 | 659 |
| 686 } // namespace chromeos | 660 } // namespace chromeos |
| OLD | NEW |