1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/browser/web_contents/web_contents_impl.h"
#include "content/common/features.h"
#include "content/public/test/accessibility_notification_waiter.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/content_browser_test.h"
#include "content/public/test/content_browser_test_utils.h"
#include "content/public/test/scoped_accessibility_mode_override.h"
#include "content/shell/browser/shell.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/accessibility/platform/browser_accessibility.h"
#include "ui/accessibility/platform/browser_accessibility_manager.h"
namespace content {
class AccessibilityFullscreenBrowserTest : public ContentBrowserTest {
public:
AccessibilityFullscreenBrowserTest() = default;
~AccessibilityFullscreenBrowserTest() override = default;
protected:
ui::BrowserAccessibility* FindButton(ui::BrowserAccessibility* node) {
if (node->GetRole() == ax::mojom::Role::kButton) {
return node;
}
for (unsigned i = 0; i < node->PlatformChildCount(); i++) {
if (ui::BrowserAccessibility* button =
FindButton(node->PlatformGetChild(i))) {
return button;
}
}
return nullptr;
}
int CountLinks(ui::BrowserAccessibility* node) {
if (node->GetRole() == ax::mojom::Role::kLink) {
return 1;
}
int links_in_children = 0;
for (unsigned i = 0; i < node->PlatformChildCount(); i++) {
links_in_children += CountLinks(node->PlatformGetChild(i));
}
return links_in_children;
}
};
namespace {
// FakeFullscreenDelegate simply stores the latest requested mod and reports it
// back, which is all that is required for the renderer to enter fullscreen.
class FakeFullscreenDelegate : public WebContentsDelegate {
public:
FakeFullscreenDelegate() = default;
FakeFullscreenDelegate(const FakeFullscreenDelegate&) = delete;
FakeFullscreenDelegate& operator=(const FakeFullscreenDelegate&) = delete;
~FakeFullscreenDelegate() override = default;
void EnterFullscreenModeForTab(
RenderFrameHost*,
const blink::mojom::FullscreenOptions&) override {
is_fullscreen_ = true;
}
void ExitFullscreenModeForTab(WebContents*) override {
is_fullscreen_ = false;
}
bool IsFullscreenForTabOrPending(const WebContents*) override {
return is_fullscreen_;
}
private:
bool is_fullscreen_ = false;
};
} // namespace
IN_PROC_BROWSER_TEST_F(AccessibilityFullscreenBrowserTest,
IgnoreElementsOutsideFullscreenElement) {
ASSERT_TRUE(embedded_test_server()->Start());
FakeFullscreenDelegate delegate;
shell()->web_contents()->SetDelegate(&delegate);
AccessibilityNotificationWaiter waiter(shell()->web_contents(),
ax::mojom::Event::kLoadComplete);
ScopedAccessibilityModeOverride complete_mode(ui::kAXModeComplete);
GURL url(
embedded_test_server()->GetURL("/accessibility/fullscreen/links.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
ASSERT_TRUE(waiter.WaitForNotification());
WebContentsImpl* web_contents =
static_cast<WebContentsImpl*>(shell()->web_contents());
ui::BrowserAccessibilityManager* manager =
web_contents->GetRootBrowserAccessibilityManager();
// Initially there are 3 links in the accessibility tree.
EXPECT_EQ(3, CountLinks(manager->GetBrowserAccessibilityRoot()));
// Enter fullscreen by finding the button and performing the default action,
// which is to click it.
ui::BrowserAccessibility* button =
FindButton(manager->GetBrowserAccessibilityRoot());
ASSERT_NE(nullptr, button);
manager->DoDefaultAction(*button);
// Upon entering fullscreen, the page will change the button text to "Done".
WaitForAccessibilityTreeToContainNodeWithName(web_contents, "Done");
// Now, the two links outside of the fullscreen element are gone.
EXPECT_EQ(1, CountLinks(manager->GetBrowserAccessibilityRoot()));
}
// Fails flakily on all platforms: crbug.com/825735
IN_PROC_BROWSER_TEST_F(AccessibilityFullscreenBrowserTest,
DISABLED_InsideIFrame) {
ASSERT_TRUE(embedded_test_server()->Start());
FakeFullscreenDelegate delegate;
shell()->web_contents()->SetDelegate(&delegate);
AccessibilityNotificationWaiter waiter(shell()->web_contents(),
ax::mojom::Event::kLoadComplete);
ScopedAccessibilityModeOverride complete_mode(ui::kAXModeComplete);
GURL url(
embedded_test_server()->GetURL("/accessibility/fullscreen/iframe.html"));
EXPECT_TRUE(NavigateToURL(shell(), url));
ASSERT_TRUE(waiter.WaitForNotification());
WebContentsImpl* web_contents =
static_cast<WebContentsImpl*>(shell()->web_contents());
ui::BrowserAccessibilityManager* manager =
web_contents->GetRootBrowserAccessibilityManager();
// Initially there's just one link, in the top frame.
EXPECT_EQ(1, CountLinks(manager->GetBrowserAccessibilityRoot()));
// Enter fullscreen by finding the button and performing the default action,
// which is to click it.
ui::BrowserAccessibility* button =
FindButton(manager->GetBrowserAccessibilityRoot());
ASSERT_NE(nullptr, button);
manager->DoDefaultAction(*button);
// After entering fullscreen, the page will add an iframe with a link inside
// in the inert part of the page, then exit fullscreen and change the button
// text to "Done". Then the link inside the iframe should also be exposed.
WaitForAccessibilityTreeToContainNodeWithName(web_contents, "Done");
EXPECT_EQ(2, CountLinks(manager->GetBrowserAccessibilityRoot()));
}
} // namespace content
|