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

Side by Side Diff: content/browser/accessibility/snapshot_ax_tree_browsertest.cc

Issue 1051923003: Add a WebContentsImpl API to snapshot the accessibility tree. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Clean up callbacks before end of OnRenderProcessGone Created 5 years, 8 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
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "base/callback.h"
6 #include "content/browser/web_contents/web_contents_impl.h"
7 #include "content/public/test/content_browser_test.h"
8 #include "content/public/test/content_browser_test_utils.h"
9 #include "content/public/test/test_utils.h"
10 #include "content/shell/browser/shell.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/accessibility/ax_node.h"
13 #include "ui/accessibility/ax_tree.h"
14
15 namespace content {
16
17 namespace {
18
19 class AXTreeSnapshotWaiter {
20 public:
21 AXTreeSnapshotWaiter() : loop_runner_(new MessageLoopRunner()) {}
22
23 void Wait() {
24 loop_runner_->Run();
25 }
26
27 const ui::AXTreeUpdate& snapshot() const { return snapshot_; }
28
29 void ReceiveSnapshot(const ui::AXTreeUpdate& snapshot) {
30 snapshot_ = snapshot;
31 loop_runner_->Quit();
32 }
33
34 private:
35 ui::AXTreeUpdate snapshot_;
36 scoped_refptr<MessageLoopRunner> loop_runner_;
37
38 DISALLOW_COPY_AND_ASSIGN(AXTreeSnapshotWaiter);
39 };
40
41 } // namespace
42
43 class SnapshotAXTreeBrowserTest : public ContentBrowserTest {
44 public:
45 SnapshotAXTreeBrowserTest() {}
46 ~SnapshotAXTreeBrowserTest() override {}
47 };
48
49 IN_PROC_BROWSER_TEST_F(SnapshotAXTreeBrowserTest,
50 SnapshotAccessibilityTreeFromWebContents) {
51 GURL url("data:text/html,<button>Click</button>");
52 NavigateToURL(shell(), url);
53
54 WebContentsImpl* web_contents =
55 static_cast<WebContentsImpl*>(shell()->web_contents());
56
57 AXTreeSnapshotWaiter waiter;
58 web_contents->RequestAXTreeSnapshot(
59 base::Bind(&AXTreeSnapshotWaiter::ReceiveSnapshot,
60 base::Unretained(&waiter)));
61 waiter.Wait();
62
63 // Dump the whole tree if one of the assertions below fails
64 // to aid in debugging why it failed.
65 SCOPED_TRACE(waiter.snapshot().ToString());
66
67 ui::AXTree tree(waiter.snapshot());
68 ui::AXNode* root = tree.root();
69 ASSERT_NE(nullptr, root);
70 ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->data().role);
71 ui::AXNode* group = root->ChildAtIndex(0);
72 ASSERT_EQ(ui::AX_ROLE_GROUP, group->data().role);
73 ui::AXNode* button = group->ChildAtIndex(0);
74 ASSERT_EQ(ui::AX_ROLE_BUTTON, button->data().role);
75 }
76
77 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/frame_host/render_frame_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698