- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / extensions / api_test / mutation_observers / background.js
1 // Copyright (c) 2012 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 window.addEventListener('DOMContentLoaded', function() {
6   var body = document.body;
7   var div = body.appendChild(document.createElement('div'));
8   var input1 = body.appendChild(document.createElement('input'));
9   var input2 = body.appendChild(document.createElement('input'));
10
11   input1.focus();
12   input1.addEventListener('blur', function() {
13     div.setAttribute('baz', 'bat');
14   });
15
16   var success = false;
17   var mutationsDelivered = false;
18
19   var observer = new MutationObserver(function() {
20     mutationsDelivered = true;
21     if (success)
22       chrome.test.succeed();
23   });
24   observer.observe(document, { subtree: true, attributes: true });
25
26   // The getAll callback should be counted as a V8RecursionScope and cause
27   // the delivery of MutationRecords to be delayed until it has exited.
28   chrome.windows.getAll(function() {
29     div.setAttribute('foo', 'bar');
30     input2.focus();
31     if (mutationsDelivered)
32       chrome.test.fail();
33     else
34       success = true;
35   });
36 });