Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(102)

Side by Side Diff: components/exo/shell_surface_unittest.cc

Issue 2640123004: Initial support for native accessibility in ARC (Closed)
Patch Set: m Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ash/common/accessibility_delegate.h" 5 #include "ash/common/accessibility_delegate.h"
6 #include "ash/common/wm/window_state.h" 6 #include "ash/common/wm/window_state.h"
7 #include "ash/common/wm/wm_event.h" 7 #include "ash/common/wm/wm_event.h"
8 #include "ash/common/wm_shell.h" 8 #include "ash/common/wm_shell.h"
9 #include "ash/common/wm_window.h" 9 #include "ash/common/wm_window.h"
10 #include "ash/public/cpp/shell_window_ids.h" 10 #include "ash/public/cpp/shell_window_ids.h"
11 #include "ash/wm/window_state_aura.h" 11 #include "ash/wm/window_state_aura.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "components/exo/ax_tree_source_surface.h"
14 #include "components/exo/buffer.h" 15 #include "components/exo/buffer.h"
15 #include "components/exo/display.h" 16 #include "components/exo/display.h"
16 #include "components/exo/shell_surface.h" 17 #include "components/exo/shell_surface.h"
17 #include "components/exo/sub_surface.h" 18 #include "components/exo/sub_surface.h"
18 #include "components/exo/surface.h" 19 #include "components/exo/surface.h"
19 #include "components/exo/test/exo_test_base.h" 20 #include "components/exo/test/exo_test_base.h"
20 #include "components/exo/test/exo_test_helper.h" 21 #include "components/exo/test/exo_test_helper.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 #include "ui/aura/client/aura_constants.h" 23 #include "ui/aura/client/aura_constants.h"
23 #include "ui/aura/window.h" 24 #include "ui/aura/window.h"
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 ash::WmShell::Get()->accessibility_delegate()->ToggleSpokenFeedback( 823 ash::WmShell::Get()->accessibility_delegate()->ToggleSpokenFeedback(
823 ash::A11Y_NOTIFICATION_NONE); 824 ash::A11Y_NOTIFICATION_NONE);
824 shell_surface.OnAccessibilityModeChanged(); 825 shell_surface.OnAccessibilityModeChanged();
825 shell_surface2.OnAccessibilityModeChanged(); 826 shell_surface2.OnAccessibilityModeChanged();
826 827
827 EXPECT_TRUE(shell_surface.shadow_underlay()->IsVisible()); 828 EXPECT_TRUE(shell_surface.shadow_underlay()->IsVisible());
828 EXPECT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds()); 829 EXPECT_EQ(shadow_bounds, shell_surface.shadow_underlay()->bounds());
829 EXPECT_EQ(shadow_bounds, shell_surface2.shadow_underlay()->bounds()); 830 EXPECT_EQ(shadow_bounds, shell_surface2.shadow_underlay()->bounds());
830 } 831 }
831 832
833 class FakeAXTreeSource : public AXTreeSourceSurface {
834 public:
835 bool GetTreeData(ui::AXTreeData* data) const override {
836 // In a real implementation, the embedder would point to this tree with a
837 // child tree id.
838 return false;
839 }
840
841 ui::AXNode* GetRoot() const override { return nullptr; }
842
843 ui::AXNode* GetFromId(int32_t id) const override { return nullptr; }
844
845 int32_t GetId(ui::AXNode* node) const override { return 1; }
846
847 void GetChildren(ui::AXNode* node,
848 std::vector<ui::AXNode*>* out_children) const override {}
849
850 ui::AXNode* GetParent(ui::AXNode* node) const override { return nullptr; }
851
852 bool IsValid(ui::AXNode* node) const override { return false; }
853
854 bool IsEqual(ui::AXNode* node1, ui::AXNode* node2) const override {
855 return false;
856 }
857
858 ui::AXNode* GetNull() const override { return nullptr; }
859
860 void SerializeNode(ui::AXNode* node,
861 ui::AXNodeData* out_data) const override {}
862
863 protected:
864 void Reset() override {
865 // Reset indicates we should initialize or reinitialize tree data
866 // e.g. when new observers are added.
867 // For testing, fire an event.
868 NotifyAccessibilityEvent(2U, ui::AX_EVENT_FOCUS);
869 }
870 };
871
872 class FakeAXTreeSourceObserver : public AXTreeSourceSurface::Observer {
873 public:
874 void OnAccessibilityEvent(uint32_t node_id, ui::AXEvent event) override {
875 // A real implementation might send this event to an extension.
876 events.push_back(std::pair<uint32_t, ui::AXEvent>(node_id, event));
877 }
878
879 std::vector<std::pair<uint32_t, ui::AXEvent>> events;
880 };
881
882 TEST_F(ShellSurfaceTest, AccessibilityNodeData) {
883 gfx::Size buffer_size(256, 256);
884 Buffer buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size));
885 Surface surface;
886 ShellSurface shell_surface(&surface, nullptr, gfx::Rect(640, 480), true,
887 false, ash::kShellWindowId_DefaultContainer);
888
889 surface.Attach(&buffer);
890
891 FakeAXTreeSource tree_source;
892 FakeAXTreeSourceObserver tree_source_observer;
893
894 // An embedder might get here by tracking focused windows.
895 surface.set_ax_tree_source(&tree_source);
896
897 // At this point, the tree source is empty. Once an embedder sees a shell
898 // surface window, the embedder can observe the tree source at which point the
899 // source tree will fetch data and fire any initial events. The test simulates
900 // the steps expected.
901 tree_source.AddObserver(&tree_source_observer);
902
903 ASSERT_EQ(1U, tree_source_observer.events.size());
904 ASSERT_EQ(2U, tree_source_observer.events.front().first);
905 ASSERT_EQ(ui::AX_EVENT_FOCUS, tree_source_observer.events.front().second);
906 }
907
832 } // namespace 908 } // namespace
833 } // namespace exo 909 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698