Chromium Code Reviews| Index: pkg/polymer/test/visibility_test.dart |
| diff --git a/pkg/polymer/test/visibility_test.dart b/pkg/polymer/test/visibility_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7d16654e4130df80fa3bbfdee83e4f91b040f11c |
| --- /dev/null |
| +++ b/pkg/polymer/test/visibility_test.dart |
| @@ -0,0 +1,65 @@ |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +import 'dart:async'; |
| +import 'dart:html'; |
| +import 'dart:js'; |
| +import 'package:unittest/unittest.dart'; |
| +import 'package:unittest/html_config.dart'; |
| +import 'package:polymer/polymer.dart'; |
| + |
| +var done = new Completer(); |
| + |
| +class MyModel { |
| + String value; |
| + MyModel(this.value); |
| +} |
| + |
| +main() => initPolymer().run(() { |
| + useHtmlConfiguration(); |
| + |
| + setUp(() => Polymer.onReady); |
| + |
| + test('Polymer.import', () { |
| + AutoBindingElement t = querySelector('#myTemplate'); |
| + var myModel = new MyModel(''); |
| + t.model = myModel; |
| + t.on['template-bound'].listen((_) { |
| + // TODO(jakemac): Is this check necessary on the dart side? |
|
Siggi Cherem (dart-lang)
2014/11/25 17:53:41
nope, we can remove it :)
|
| + var hasObjectObserve = context['Observer']['hasObjectObserve']; |
| + if (hasObjectObserve != null && hasObjectObserve) { |
| + myModel.value = 'test skipped due to Object.observe'; |
| + done.complete(); |
| + } else { |
| + myModel.value = 'a'; |
| + var s = document.querySelector('span'); |
| + var a = document.querySelector('a'); |
| + document.on['visibilitychange'].listen((_) { |
|
Siggi Cherem (dart-lang)
2014/11/25 17:53:41
on['visibilitychange'] => onVisibilityChange
|
| + print('visiblity change!'); |
| + }); |
| + window.on['message'].listen((e) { |
|
Siggi Cherem (dart-lang)
2014/11/25 17:53:41
on['message'] => onMessage
|
| + if (e.data == 'popup-initialized') { |
| + print('got popup initialized'); |
| + myModel.value = 'b'; |
| + new Future.delayed(new Duration(milliseconds: 300), () { |
| + expect(document.hidden, true); |
| + expect(s.text, 'a', |
| + reason: 'change did not occur, and shouldn\'t'); |
| + print('send close'); |
| + e.source.postMessage('close', window.location.origin); |
| + }); |
| + } |
| + if (e.data == 'popup-closed') { |
| + new Future.delayed(new Duration(milliseconds: 300), () { |
|
Siggi Cherem (dart-lang)
2014/11/25 17:53:41
not sure why we need the 300ms here and above?
|
| + expect(s.text, 'b', reason: 'change did occur, and should'); |
| + done.complete(); |
| + }); |
| + } |
| + }); |
| + } |
| + }); |
| + return done; |
|
Siggi Cherem (dart-lang)
2014/11/25 17:53:41
return done.future;
|
| + }); |
| +}); |
| + |