Initialize Tizen 2.3
[framework/web/webkit-efl.git] / LayoutTests / accessibility / loading-iframe-sends-notification.html
1 <html>
2 <head>
3 <link rel="stylesheet" href="../fast/js/resources/js-test-style.css">
4 <script src="../fast/js/resources/js-test-pre.js"></script>
5 </head>
6 <body>
7
8 <p>Before</p>
9
10 <iframe id="iframe" title="InnerFrame"></iframe>
11
12 <p>After</p>
13
14 <p>End of test</p>
15
16 <p id="description"></p>
17 <div id="console"></div>
18
19 <script>
20     description("This tests that when an iframe finishes loading, it sends a notification.");
21
22     if (window.testRunner)
23         testRunner.waitUntilDone();
24
25     window.jsTestIsAsync = true;
26
27     // Recursively search the entire accessibility tree starting at the given
28     // AccessibilityUIElement (inclusive) and return the element whose title
29     // contains the given string. This makes it possible to find a node even
30     // when there are platform differences in the tree, i.e. due to different
31     // nodes being ignored.
32     function findByAccessibleTitleSubstring(startElement, titleSubstring)
33     {
34         if (startElement.title.indexOf(titleSubstring) >= 0)
35             return startElement;
36
37         for (var i = 0; i < startElement.childrenCount; i++) {
38             var found = findByAccessibleTitleSubstring(startElement.childAtIndex(i), titleSubstring);
39             if (found)
40                 return found;
41         }
42
43         return null;
44     }
45
46     function runTest()
47     {
48         window.gotIframeNotification = false;
49
50         if (window.accessibilityController) {
51             window.root = accessibilityController.rootElement;
52
53             // Initially, the iframe should not be loaded, so we shouldn't be able to find this button.
54             shouldBeFalse("findByAccessibleTitleSubstring(root, 'InnerButton') != null");
55
56             window.accessibilityController.addNotificationListener(function (target, notification) {
57                 // Ignore this notification if it's not on the iframe.
58                 if (target.description.indexOf("InnerFrame") == -1)
59                     return;
60
61                 debug("Got notification on iframe.");
62                 gotIframeNotification = true;
63
64                 // Check that the button within the iframe is now reachable from the root.
65                 shouldBeTrue("findByAccessibleTitleSubstring(root, 'InnerButton') != null");
66             });
67         }
68
69         window.iframeElement = document.getElementById("iframe");
70         iframeElement.addEventListener("load", function() {
71             window.setTimeout(function() {
72                 shouldBeTrue("gotIframeNotification");
73                 if (window.accessibilityController)
74                     accessibilityController.removeNotificationListener();
75
76                 finishJSTest();
77             }, 10);
78         }, false);
79
80         // Load content into the iframe. This will trigger the event
81         // handler above, which will check that the accessibility tree
82         // was updated with new content.
83         window.iframeElement.src = "data:text/html,<body><button>InnerButton</button></body>";
84     }
85
86     window.addEventListener('load', function() {
87         setTimeout(runTest, 10);
88     }, false);
89
90 </script>
91
92 <script src="../fast/js/resources/js-test-post.js"></script>
93 </body>
94 </html>