summaryrefslogtreecommitdiffstats
path: root/third_party/WebKit/LayoutTests/accessibility/loading-iframe-sends-notification.html
blob: 2a3262bf6a0ea1b2cac3f29227693a5d40785aa7 (plain)
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
<html>
<head>
<script src="../resources/js-test.js"></script>
</head>
<body>

<p>Before</p>

<iframe id="iframe" title="InnerFrame"></iframe>

<p>After</p>

<p>End of test</p>

<p id="description"></p>
<div id="console"></div>

<script>
    description("This tests that when an iframe finishes loading, it sends a notification.");

    if (window.testRunner)
        testRunner.waitUntilDone();
    else
        debug("This test requires window.accessibilityController and must be run in content_shell with --run-layout-test.")

    window.jsTestIsAsync = true;

    function runTest()
    {
        if (window.accessibilityController) {
            // Initially, the iframe should not be loaded, so we shouldn't be able to find this button.
            shouldBeUndefined("accessibilityController.accessibleElementById('innerbutton')");

            window.accessibilityController.addNotificationListener(function (target, notification) {
                if (!target.parentElement() || !target.parentElement().parentElement())
                    return;

                // Ignore this notification if it's not within the subtree of the iframe.
                var frameTarget = target.parentElement().parentElement();
                if (frameTarget.name.indexOf("InnerFrame") == -1)
                    return;

                // Even still we'll get LayoutComplete notifications sooner than we want.
                if (!accessibilityController.accessibleElementById('innerbutton'))
                    return;

                // Check that the button within the iframe is now reachable from the root.
                shouldBeDefined("accessibilityController.accessibleElementById('innerbutton')");
                if (window.accessibilityController)
                    accessibilityController.removeNotificationListener();

                finishJSTest();
            });
        }

        // Load content into the iframe. This will trigger the event
        // handler above, which will check that the accessibility tree
        // was updated with new content.
        document.getElementById("iframe").src = "data:text/html,<body><button id='innerbutton'>InnerButton</button></body>";
    }
    window.addEventListener('load', runTest);
</script>

</body>
</html>