OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <set> | |
6 #include <string> | |
7 #include <vector> | |
8 | |
9 #include "base/strings/string16.h" | |
10 #include "base/strings/string_util.h" | |
11 #include "base/strings/utf_string_conversions.h" | |
12 #include "content/browser/accessibility/accessibility_event_recorder.h" | |
13 #include "content/browser/accessibility/accessibility_tree_formatter.h" | |
14 #include "content/browser/accessibility/browser_accessibility.h" | |
15 #include "content/browser/accessibility/browser_accessibility_manager.h" | |
16 #include "content/browser/accessibility/dump_accessibility_browsertest_base.h" | |
17 #include "content/browser/web_contents/web_contents_impl.h" | |
18 #include "content/shell/browser/shell.h" | |
19 #include "content/test/accessibility_browser_test_utils.h" | |
20 | |
21 namespace content { | |
22 | |
23 typedef AccessibilityTreeFormatter::Filter Filter; | |
24 | |
25 // | |
David Tseng
2014/12/16 16:53:05
?
dmazzoni
2014/12/16 23:26:32
Done.
| |
26 class DumpAccessibilityEventsTest : public DumpAccessibilityTestBase { | |
27 public: | |
28 void AddDefaultFilters(std::vector<Filter>* filters) override { | |
29 } | |
30 | |
31 std::vector<std::string> Dump() override; | |
32 | |
33 void AdditionalErrorLogging() override; | |
David Tseng
2014/12/16 16:53:05
nit: document these
dmazzoni
2014/12/16 23:26:32
These are overrides; see the base class.
| |
34 | |
35 private: | |
36 base::string16 initial_tree_; | |
37 base::string16 final_tree_; | |
38 }; | |
39 | |
40 std::vector<std::string> DumpAccessibilityEventsTest::Dump() { | |
41 WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( | |
42 shell()->web_contents()); | |
43 scoped_ptr<AccessibilityEventRecorder> event_recorder( | |
44 AccessibilityEventRecorder::Create( | |
45 web_contents->GetRootBrowserAccessibilityManager())); | |
46 | |
47 initial_tree_ = DumpUnfilteredAccessibilityTreeAsString(); | |
48 | |
49 scoped_ptr<AccessibilityNotificationWaiter> waiter; | |
50 waiter.reset(new AccessibilityNotificationWaiter( | |
51 shell(), AccessibilityModeComplete, ui::AX_EVENT_NONE)); | |
52 | |
53 // Execute the "go" command in the script. | |
54 web_contents->GetMainFrame()->ExecuteJavaScript( | |
55 base::ASCIIToUTF16("go()")); | |
56 | |
57 // Wait for at least one accessibility event. | |
58 waiter->WaitForNotification(); | |
59 | |
60 // Now wait for a hover. | |
61 waiter.reset(new AccessibilityNotificationWaiter( | |
62 shell(), AccessibilityModeComplete, ui::AX_EVENT_HOVER)); | |
63 BrowserAccessibilityManager* manager = | |
64 web_contents->GetRootBrowserAccessibilityManager(); | |
65 manager->delegate()->AccessibilityHitTest(gfx::Point(0, 0)); | |
66 waiter->WaitForNotification(); | |
67 | |
68 final_tree_ = DumpUnfilteredAccessibilityTreeAsString(); | |
69 | |
70 std::vector<std::string> event_logs = event_recorder->GetEventLogs(); | |
71 std::vector<std::string> result; | |
72 for (size_t i = 0; i < event_logs.size(); ++i) { | |
73 if (AccessibilityTreeFormatter::MatchesFilters( | |
74 filters_, base::UTF8ToUTF16(event_logs[i]), true)) { | |
75 result.push_back(event_logs[i]); | |
76 } | |
77 } | |
78 return result; | |
79 } | |
80 | |
81 void DumpAccessibilityEventsTest::AdditionalErrorLogging() { | |
82 printf("\n"); | |
83 printf("Initial accessibility tree (after load complete):\n"); | |
84 printf("%s\n", base::UTF16ToUTF8(initial_tree_).c_str()); | |
85 printf("\n"); | |
86 printf("Final accessibility tree after events fired:\n"); | |
87 printf("%s\n", base::UTF16ToUTF8(final_tree_).c_str()); | |
88 printf("\n"); | |
89 } | |
90 | |
91 IN_PROC_BROWSER_TEST_F(DumpAccessibilityEventsTest, | |
92 AccessibilityEventsCheckedStateChanged) { | |
93 RunTest(FILE_PATH_LITERAL("events-checked-state-changed.html")); | |
94 } | |
95 | |
96 IN_PROC_BROWSER_TEST_F(DumpAccessibilityEventsTest, | |
97 AccessibilityEventsInputTypeTextValueChanged) { | |
98 RunTest(FILE_PATH_LITERAL("events-input-type-text-value-changed.html")); | |
99 } | |
100 | |
101 } // namespace content | |
OLD | NEW |