Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1085)

Unified Diff: tests/compiler/dart2js_native/native_novel_html_test.dart

Issue 11553015: Add a fall-back for novel HTML Elements (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/compiler/dart2js_native/native_novel_html_test.dart
diff --git a/tests/compiler/dart2js_native/native_novel_html_test.dart b/tests/compiler/dart2js_native/native_novel_html_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..17de787bf0fec78eb64b10e4eea358dcf51f3757
--- /dev/null
+++ b/tests/compiler/dart2js_native/native_novel_html_test.dart
@@ -0,0 +1,55 @@
+// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
ngeoffray 2012/12/12 08:14:10 2011 is so almost 2 years ago :-)
+// 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.
+
+// Test to see if novel HTML tags are interpreted as HTMLElement.
+
+class Element native "*HTMLElement" {
+ String foo(int x) => '[${bar(x+1)}]';
+ String bar(int x) native;
+}
+
+makeE() native;
+makeF() native;
+
+void setup() native """
+// A novel HTML element.
+function HTMLGoofyElement(){}
+HTMLGoofyElement.prototype.bar = function(a){return 'Goofy.foo(' + a + ')';}
+makeE = function(){return new HTMLGoofyElement};
+
+// A non-HTML element with a misleading name.
+function HTMLFakeyElement(){}
+HTMLFakeyElement.prototype.bar = function(a){return 'Fakey.foo(' + a + ')';}
+makeF = function(){return new HTMLFakeyElement};
+
+// Make the HTMLGoofyElement look like a real host object.
+var theRealObjectToString = Object.prototype.toString;
+Object.prototype.toString = function() {
+ if (this instanceof HTMLGoofyElement) return '[object HTMLGoofyElement]';
+ return theRealObjectToString.call(this);
+}
+""";
+
+
+main() {
+ setup();
+
+ print(123);
kasperl 2012/12/12 06:43:50 Is this needed?
+ var e = makeE();
+ Expect.equals('[Goofy.foo(11)]', e.foo(10));
+
+ var f = makeF();
+ expectNoSuchMethod(() => f.foo(20), 'f.foo(20) should fail');
+}
+
+expectNoSuchMethod(action, note) {
kasperl 2012/12/12 06:43:50 Can you use Expect.throws?
+ bool caught = false;
+ try {
+ action();
+ } catch (ex) {
+ caught = true;
+ Expect.isTrue(ex is NoSuchMethodError, note);
+ }
+ Expect.isTrue(caught, note);
+}

Powered by Google App Engine
This is Rietveld 408576698