Chromium Code Reviews

Unified Diff: test/codegen/lib/html/localstorage_test.dart

Issue 1930043002: Add all dart:html tests from the sdk to test/codegen. (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: ptal Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
« no previous file with comments | « test/codegen/lib/html/keyboard_event_test.dart ('k') | test/codegen/lib/html/location_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/codegen/lib/html/localstorage_test.dart
diff --git a/test/codegen/lib/html/localstorage_test.dart b/test/codegen/lib/html/localstorage_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3e92b10dc7e0ad6256c8455418b22ae6b8e20629
--- /dev/null
+++ b/test/codegen/lib/html/localstorage_test.dart
@@ -0,0 +1,108 @@
+// Copyright (c) 2012, 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.
+
+library LocalStorageTest;
+import 'package:unittest/unittest.dart';
+import 'package:unittest/html_config.dart';
+import 'dart:html';
+
+main() {
+ useHtmlConfiguration();
+
+ void testWithLocalStorage(String name, fn()) {
+ test(name, () {
+ window.localStorage['key1'] = 'val1';
+ window.localStorage['key2'] = 'val2';
+ window.localStorage['key3'] = 'val3';
+
+ try {
+ fn();
+ } finally {
+ window.localStorage.clear();
+ }
+ });
+ }
+
+ testWithLocalStorage('containsValue', () {
+ expect(window.localStorage.containsValue('does not exist'), isFalse);
+ expect(window.localStorage.containsValue('key1'), isFalse);
+ expect(window.localStorage.containsValue('val1'), isTrue);
+ expect(window.localStorage.containsValue('val3'), isTrue);
+ });
+
+ testWithLocalStorage('containsKey', () {
+ expect(window.localStorage.containsKey('does not exist'), isFalse);
+ expect(window.localStorage.containsKey('val1'), isFalse);
+ expect(window.localStorage.containsKey('key1'), isTrue);
+ expect(window.localStorage.containsKey('key3'), isTrue);
+ });
+
+ testWithLocalStorage('[]', () {
+ expect(window.localStorage['does not exist'], isNull);
+ expect(window.localStorage['key1'], 'val1');
+ expect(window.localStorage['key3'], 'val3');
+ });
+
+ testWithLocalStorage('[]=', () {
+ expect(window.localStorage['key4'], isNull);
+ window.localStorage['key4'] = 'val4';
+ expect(window.localStorage['key4'], 'val4');
+
+ expect(window.localStorage['key3'], 'val3');
+ window.localStorage['key3'] = 'val3-new';
+ expect(window.localStorage['key3'], 'val3-new');
+ });
+
+ testWithLocalStorage('putIfAbsent', () {
+ expect(window.localStorage['key4'], isNull);
+ expect(window.localStorage.putIfAbsent('key4', () => 'val4'), 'val4');
+ expect(window.localStorage['key4'], 'val4');
+
+ expect(window.localStorage['key3'], 'val3');
+ expect(window.localStorage.putIfAbsent('key3',
+ () => expect(false, isTrue, reason: 'should not be called')), 'val3');
+ expect(window.localStorage['key3'], 'val3');
+ });
+
+ testWithLocalStorage('remove', () {
+ expect(window.localStorage.remove('does not exist'), isNull);
+ expect(window.localStorage.remove('key3'), 'val3');
+ expect(window.localStorage, equals({'key1': 'val1', 'key2': 'val2'}));
+ });
+
+ testWithLocalStorage('clear', () {
+ window.localStorage.clear();
+ expect(window.localStorage, equals({}));
+ });
+
+ testWithLocalStorage('forEach', () {
+ Map<String, String> results = {};
+ window.localStorage.forEach((k, v) {
+ results[k] = v;
+ });
+ expect(results, equals({'key1': 'val1', 'key2': 'val2', 'key3': 'val3'}));
+ });
+
+ testWithLocalStorage('getKeys', () {
+ expect(window.localStorage.keys.toList(),
+ unorderedEquals(['key1', 'key2', 'key3']));
+ });
+
+ testWithLocalStorage('getVals', () {
+ expect(window.localStorage.values.toList(),
+ unorderedEquals(['val1', 'val2', 'val3']));
+ });
+
+ testWithLocalStorage('length', () {
+ expect(window.localStorage.length, 3);
+ window.localStorage.clear();
+ expect(window.localStorage.length, 0);
+ });
+
+ testWithLocalStorage('isEmpty', () {
+ expect(window.localStorage.isEmpty, isFalse);
+ window.localStorage.clear();
+ expect(window.localStorage.isEmpty, isTrue);
+ });
+}
« no previous file with comments | « test/codegen/lib/html/keyboard_event_test.dart ('k') | test/codegen/lib/html/location_test.dart » ('j') | no next file with comments »

Powered by Google App Engine