Fix and rename native_library_same_name_used_frog_test.

This test had two kinds of compile-time errors since Dart 2.0:
  * Invalid overrides. This was fixed by using the interface type in the `write`
  overrides.

  * Unsupported type lookups in the behavior string. Since 2.0 we limited the
  type lookup to search for names in dart:html and other native libraries and,
  for stest, only in the main library of the test. Moving the `JS` and the types
  used within it to the main library was necessary to circumvent the issue.

Change-Id: I1568cff19eb64fbbda1a0224c392d77f9e90f526
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175004
Reviewed-by: Stephen Adams <sra@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
Auto-Submit: Sigmund Cherem <sigmund@google.com>
diff --git a/tests/dart2js_2/native/native_library_same_name_used_frog_test.dart b/tests/dart2js/native/name_conflict_test.dart
similarity index 74%
copy from tests/dart2js_2/native/native_library_same_name_used_frog_test.dart
copy to tests/dart2js/native/name_conflict_test.dart
index 974bf07..555c78e 100644
--- a/tests/dart2js_2/native/native_library_same_name_used_frog_test.dart
+++ b/tests/dart2js/native/name_conflict_test.dart
@@ -2,14 +2,30 @@
 // 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.
 
-// @dart = 2.7
-
 // Test for correct hidden native class when abstract class has same name.
 
 library main;
 
+import 'dart:_js_helper';
+import 'dart:_foreign_helper' show JS;
+
 import 'native_testing.dart';
-import 'native_library_same_name_used_lib1.dart';
+
+// 'I' is the name of an abstract class and the name of the native class.
+
+abstract class I {
+  I read();
+  write(I x);
+}
+
+// Native impl has same name as abstract class.
+@Native("I")
+class Impl implements I {
+  Impl read() native;
+  write(I x) native;
+}
+
+makeI() => JS('creates:Impl; returns:I;', 'makeI()');
 
 void setup() {
   JS('', r"""
@@ -27,13 +43,13 @@
 // A pure Dart implementation of I.
 
 class ProxyI implements I {
-  ProxyI b;
+  ProxyI? b;
   ProxyI read() {
-    return b;
+    return b!;
   }
 
-  write(ProxyI x) {
-    b = x;
+  write(I x) {
+    b = x as ProxyI;
   }
 }
 
diff --git a/tests/dart2js/native/native_library_same_name_used_frog_test.dart b/tests/dart2js/native/native_library_same_name_used_frog_test.dart
deleted file mode 100644
index 4909b7f..0000000
--- a/tests/dart2js/native/native_library_same_name_used_frog_test.dart
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright (c) 2011, 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.
-
-// Test for correct hidden native class when abstract class has same name.
-
-library main;
-
-import 'native_testing.dart';
-import 'native_library_same_name_used_lib1.dart';
-
-void setup() {
-  JS('', r"""
-(function(){
-  // This code is all inside 'setup' and so not accessible from the global
-  // scope.
-  function I(){}
-  I.prototype.read = function() { return this._x; };
-  I.prototype.write = function(x) { this._x = x; };
-  makeI = function(){return new I()};
-  self.nativeConstructor(I);
-})()""");
-}
-
-// A pure Dart implementation of I.
-
-class ProxyI implements I {
-  ProxyI b;
-  ProxyI read() {
-    return b;
-  }
-
-  write(ProxyI x) {
-    b = x;
-  }
-}
-
-main() {
-  nativeTesting();
-  setup();
-
-  var a1 = makeI();
-  var a2 = makeI();
-  var b1 = new ProxyI();
-  var b2 = new ProxyI();
-  var ob = new Object();
-
-  Expect.isFalse(ob is I, 'ob is I');
-  Expect.isFalse(ob is ProxyI, 'ob is ProxyI');
-
-  Expect.isTrue(b1 is I, 'b1 is I');
-  Expect.isTrue(b1 is ProxyI, 'b1 is ProxyI');
-
-  Expect.isTrue(a1 is I, 'a1 is I');
-  Expect.isFalse(a1 is ProxyI, 'a1 is ProxyI');
-
-  Expect.isTrue(confuse(a1) is I, 'a1 is I');
-  Expect.isFalse(confuse(a1) is ProxyI, 'a1 is ProxyI');
-}
diff --git a/tests/dart2js/native/native_library_same_name_used_lib1.dart b/tests/dart2js/native/native_library_same_name_used_lib1.dart
deleted file mode 100644
index 5046ff7..0000000
--- a/tests/dart2js/native/native_library_same_name_used_lib1.dart
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (c) 2011, 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.
-
-// 'I' is the name of an abstract class and the name of the native class.
-
-library native_library_same_name_used_lib1;
-
-import 'native_library_same_name_used_lib2.dart';
-import 'dart:_foreign_helper' show JS;
-
-abstract class I {
-  I read();
-  write(I x);
-}
-
-makeI() => JS('creates:Impl; returns:I;', 'makeI()');
diff --git a/tests/dart2js/native/native_library_same_name_used_lib2.dart b/tests/dart2js/native/native_library_same_name_used_lib2.dart
deleted file mode 100644
index feec6bb..0000000
--- a/tests/dart2js/native/native_library_same_name_used_lib2.dart
+++ /dev/null
@@ -1,17 +0,0 @@
-// Copyright (c) 2011, 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.
-
-// Native implementation.
-
-library lib2;
-
-import 'native_library_same_name_used_lib1.dart'; // To get abstract class I.
-import 'dart:_js_helper';
-
-// Native impl has same name as abstract class.
-@Native("I")
-class Impl implements I {
-  Impl read() native;
-  write(Impl x) native;
-}
diff --git a/tests/dart2js_2/native/native_library_same_name_used_frog_test.dart b/tests/dart2js_2/native/name_conflict_test.dart
similarity index 77%
rename from tests/dart2js_2/native/native_library_same_name_used_frog_test.dart
rename to tests/dart2js_2/native/name_conflict_test.dart
index 974bf07..d39bf3b 100644
--- a/tests/dart2js_2/native/native_library_same_name_used_frog_test.dart
+++ b/tests/dart2js_2/native/name_conflict_test.dart
@@ -8,8 +8,26 @@
 
 library main;
 
+import 'dart:_js_helper';
+import 'dart:_foreign_helper' show JS;
+
 import 'native_testing.dart';
-import 'native_library_same_name_used_lib1.dart';
+
+// 'I' is the name of an abstract class and the name of the native class.
+
+abstract class I {
+  I read();
+  write(I x);
+}
+
+// Native impl has same name as abstract class.
+@Native("I")
+class Impl implements I {
+  Impl read() native;
+  write(I x) native;
+}
+
+makeI() => JS('creates:Impl; returns:I;', 'makeI()');
 
 void setup() {
   JS('', r"""
@@ -32,7 +50,7 @@
     return b;
   }
 
-  write(ProxyI x) {
+  write(I x) {
     b = x;
   }
 }
diff --git a/tests/dart2js_2/native/native_library_same_name_used_lib1.dart b/tests/dart2js_2/native/native_library_same_name_used_lib1.dart
deleted file mode 100644
index 9e21adf..0000000
--- a/tests/dart2js_2/native/native_library_same_name_used_lib1.dart
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) 2011, 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.
-
-// @dart = 2.7
-
-// 'I' is the name of an abstract class and the name of the native class.
-
-library native_library_same_name_used_lib1;
-
-import 'native_library_same_name_used_lib2.dart';
-import 'dart:_foreign_helper' show JS;
-
-abstract class I {
-  I read();
-  write(I x);
-}
-
-makeI() => JS('creates:Impl; returns:I;', 'makeI()');
diff --git a/tests/dart2js_2/native/native_library_same_name_used_lib2.dart b/tests/dart2js_2/native/native_library_same_name_used_lib2.dart
deleted file mode 100644
index bec6852..0000000
--- a/tests/dart2js_2/native/native_library_same_name_used_lib2.dart
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright (c) 2011, 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.
-
-// @dart = 2.7
-
-// Native implementation.
-
-library lib2;
-
-import 'native_library_same_name_used_lib1.dart'; // To get abstract class I.
-import 'dart:_js_helper';
-
-// Native impl has same name as abstract class.
-@Native("I")
-class Impl implements I {
-  Impl read() native;
-  write(Impl x) native;
-}