Chromium Code Reviews| Index: content/browser/accessibility/snapshot_ax_tree_browsertest.cc |
| diff --git a/content/browser/accessibility/snapshot_ax_tree_browsertest.cc b/content/browser/accessibility/snapshot_ax_tree_browsertest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6f849196d215d6c502df73c0f6a302f06563fe46 |
| --- /dev/null |
| +++ b/content/browser/accessibility/snapshot_ax_tree_browsertest.cc |
| @@ -0,0 +1,75 @@ |
| +// Copyright 2015 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 "base/callback.h" |
| +#include "content/browser/web_contents/web_contents_impl.h" |
| +#include "content/public/test/content_browser_test.h" |
| +#include "content/public/test/content_browser_test_utils.h" |
| +#include "content/public/test/test_utils.h" |
| +#include "content/shell/browser/shell.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/accessibility/ax_node.h" |
| +#include "ui/accessibility/ax_tree.h" |
| + |
| +namespace content { |
| + |
| +namespace { |
| + |
| +class AXTreeSnapshotWaiter { |
| + public: |
| + AXTreeSnapshotWaiter() : loop_runner_(new MessageLoopRunner()) {} |
| + |
| + void Wait() { |
| + loop_runner_->Run(); |
| + } |
| + |
| + const ui::AXTreeUpdate& snapshot() const { return snapshot_; } |
| + |
| + void ReceiveSnapshot(const ui::AXTreeUpdate& snapshot) { |
| + snapshot_ = snapshot; |
| + loop_runner_->Quit(); |
| + } |
| + |
| + private: |
| + ui::AXTreeUpdate snapshot_; |
| + scoped_refptr<MessageLoopRunner> loop_runner_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AXTreeSnapshotWaiter); |
| +}; |
| + |
| +} // namespace |
| + |
| +class SnapshotAXTreeBrowserTest : public ContentBrowserTest { |
| + public: |
| + SnapshotAXTreeBrowserTest() {} |
| + ~SnapshotAXTreeBrowserTest() override {} |
| +}; |
| + |
| +IN_PROC_BROWSER_TEST_F(SnapshotAXTreeBrowserTest, |
| + SnapshotAccessibilityTreeFromWebContents) { |
| + const char url_str[] = "data:text/html,<button>Click</button>"; |
|
Charlie Reis
2015/04/02 23:09:06
Just curious, why the char[]? I would normally ex
dmazzoni
2015/04/03 22:49:41
No preference - I forked this from another test wh
|
| + GURL url(url_str); |
| + NavigateToURL(shell(), url); |
| + |
| + WebContentsImpl* web_contents = |
| + static_cast<WebContentsImpl*>(shell()->web_contents()); |
| + |
| + AXTreeSnapshotWaiter waiter; |
| + web_contents->RequestAXTreeSnapshot( |
| + base::Bind(&AXTreeSnapshotWaiter::ReceiveSnapshot, |
| + base::Unretained(&waiter))); |
| + waiter.Wait(); |
| + |
| + LOG(INFO) << waiter.snapshot().ToString(); |
|
Charlie Reis
2015/04/02 23:09:06
LOG(INFO) isn't allowed in new code anymore, is it
dmazzoni
2015/04/03 22:49:41
It's banned for browser code, but I don't think it
Charlie Reis
2015/04/06 21:56:50
You can send it into a particular ASSERT_EQ statem
dmazzoni
2015/04/09 18:39:01
Great, idea, done.
|
| + |
| + ui::AXTree tree(waiter.snapshot()); |
| + ui::AXNode* root = tree.root(); |
| + ASSERT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->data().role); |
| + ui::AXNode* group = root->ChildAtIndex(0); |
| + ASSERT_EQ(ui::AX_ROLE_GROUP, group->data().role); |
| + ui::AXNode* button = group->ChildAtIndex(0); |
| + ASSERT_EQ(ui::AX_ROLE_BUTTON, button->data().role); |
| +} |
| + |
| +} // namespace content |