Chromium Code Reviews| Index: content/browser/accessibility/dump_accessibility_events_browsertest.cc |
| diff --git a/content/browser/accessibility/dump_accessibility_events_browsertest.cc b/content/browser/accessibility/dump_accessibility_events_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..28983c7742968a727b861694e31ab3cfbabe1926 |
| --- /dev/null |
| +++ b/content/browser/accessibility/dump_accessibility_events_browsertest.cc |
| @@ -0,0 +1,101 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include <set> |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/strings/string16.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "content/browser/accessibility/accessibility_event_recorder.h" |
| +#include "content/browser/accessibility/accessibility_tree_formatter.h" |
| +#include "content/browser/accessibility/browser_accessibility.h" |
| +#include "content/browser/accessibility/browser_accessibility_manager.h" |
| +#include "content/browser/accessibility/dump_accessibility_browsertest_base.h" |
| +#include "content/browser/web_contents/web_contents_impl.h" |
| +#include "content/shell/browser/shell.h" |
| +#include "content/test/accessibility_browser_test_utils.h" |
| + |
| +namespace content { |
| + |
| +typedef AccessibilityTreeFormatter::Filter Filter; |
| + |
| +// |
|
David Tseng
2014/12/16 16:53:05
?
dmazzoni
2014/12/16 23:26:32
Done.
|
| +class DumpAccessibilityEventsTest : public DumpAccessibilityTestBase { |
| + public: |
| + void AddDefaultFilters(std::vector<Filter>* filters) override { |
| + } |
| + |
| + std::vector<std::string> Dump() override; |
| + |
| + 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.
|
| + |
| + private: |
| + base::string16 initial_tree_; |
| + base::string16 final_tree_; |
| +}; |
| + |
| +std::vector<std::string> DumpAccessibilityEventsTest::Dump() { |
| + WebContentsImpl* web_contents = static_cast<WebContentsImpl*>( |
| + shell()->web_contents()); |
| + scoped_ptr<AccessibilityEventRecorder> event_recorder( |
| + AccessibilityEventRecorder::Create( |
| + web_contents->GetRootBrowserAccessibilityManager())); |
| + |
| + initial_tree_ = DumpUnfilteredAccessibilityTreeAsString(); |
| + |
| + scoped_ptr<AccessibilityNotificationWaiter> waiter; |
| + waiter.reset(new AccessibilityNotificationWaiter( |
| + shell(), AccessibilityModeComplete, ui::AX_EVENT_NONE)); |
| + |
| + // Execute the "go" command in the script. |
| + web_contents->GetMainFrame()->ExecuteJavaScript( |
| + base::ASCIIToUTF16("go()")); |
| + |
| + // Wait for at least one accessibility event. |
| + waiter->WaitForNotification(); |
| + |
| + // Now wait for a hover. |
| + waiter.reset(new AccessibilityNotificationWaiter( |
| + shell(), AccessibilityModeComplete, ui::AX_EVENT_HOVER)); |
| + BrowserAccessibilityManager* manager = |
| + web_contents->GetRootBrowserAccessibilityManager(); |
| + manager->delegate()->AccessibilityHitTest(gfx::Point(0, 0)); |
| + waiter->WaitForNotification(); |
| + |
| + final_tree_ = DumpUnfilteredAccessibilityTreeAsString(); |
| + |
| + std::vector<std::string> event_logs = event_recorder->GetEventLogs(); |
| + std::vector<std::string> result; |
| + for (size_t i = 0; i < event_logs.size(); ++i) { |
| + if (AccessibilityTreeFormatter::MatchesFilters( |
| + filters_, base::UTF8ToUTF16(event_logs[i]), true)) { |
| + result.push_back(event_logs[i]); |
| + } |
| + } |
| + return result; |
| +} |
| + |
| +void DumpAccessibilityEventsTest::AdditionalErrorLogging() { |
| + printf("\n"); |
| + printf("Initial accessibility tree (after load complete):\n"); |
| + printf("%s\n", base::UTF16ToUTF8(initial_tree_).c_str()); |
| + printf("\n"); |
| + printf("Final accessibility tree after events fired:\n"); |
| + printf("%s\n", base::UTF16ToUTF8(final_tree_).c_str()); |
| + printf("\n"); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(DumpAccessibilityEventsTest, |
| + AccessibilityEventsCheckedStateChanged) { |
| + RunTest(FILE_PATH_LITERAL("events-checked-state-changed.html")); |
| +} |
| + |
| +IN_PROC_BROWSER_TEST_F(DumpAccessibilityEventsTest, |
| + AccessibilityEventsInputTypeTextValueChanged) { |
| + RunTest(FILE_PATH_LITERAL("events-input-type-text-value-changed.html")); |
| +} |
| + |
| +} // namespace content |