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

Unified Diff: client/tests/client/html/LocalStorageTests.dart

Issue 9956076: Make Storage implement Map. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Marked underlying Storage methods as private Created 8 years, 9 months 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
« no previous file with comments | « no previous file | lib/dom/scripts/systemhtml.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/tests/client/html/LocalStorageTests.dart
diff --git a/client/tests/client/html/LocalStorageTests.dart b/client/tests/client/html/LocalStorageTests.dart
index 0ef45ea88e05b7efcc72663bb2814551e68c8d44..7c072585f9cbea3df6525caa9bee0c5ec632a481 100644
--- a/client/tests/client/html/LocalStorageTests.dart
+++ b/client/tests/client/html/LocalStorageTests.dart
@@ -5,15 +5,101 @@
void testLocalStorage() {
forLayoutTests();
- test('GetItem', () {
- final value = window.localStorage.getItem('does not exist');
- Expect.isNull(value);
- });
- test('SetItem', () {
- final key = 'foo';
- final value = 'bar';
- window.localStorage.setItem(key, value);
- final stored = window.localStorage.getItem(key);
- Expect.equals(value, stored);
+
+ 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.isFalse(window.localStorage.containsValue('does not exist'));
+ Expect.isFalse(window.localStorage.containsValue('key1'));
+ Expect.isTrue(window.localStorage.containsValue('val1'));
+ Expect.isTrue(window.localStorage.containsValue('val3'));
+ });
+
+ testWithLocalStorage('containsKey', () {
+ Expect.isFalse(window.localStorage.containsKey('does not exist'));
+ Expect.isFalse(window.localStorage.containsKey('val1'));
+ Expect.isTrue(window.localStorage.containsKey('key1'));
+ Expect.isTrue(window.localStorage.containsKey('key3'));
+ });
+
+ testWithLocalStorage('[]', () {
+ Expect.isNull(window.localStorage['does not exist']);
+ Expect.equals('val1', window.localStorage['key1']);
+ Expect.equals('val3', window.localStorage['key3']);
+ });
+
+ testWithLocalStorage('[]=', () {
+ Expect.isNull(window.localStorage['key4']);
+ window.localStorage['key4'] = 'val4';
+ Expect.equals('val4', window.localStorage['key4']);
+
+ Expect.equals('val3', window.localStorage['key3']);
+ window.localStorage['key3'] = 'val3-new';
+ Expect.equals('val3-new', window.localStorage['key3']);
+ });
+
+ testWithLocalStorage('putIfAbsent', () {
+ Expect.isNull(window.localStorage['key4']);
+ Expect.equals('val4',
+ window.localStorage.putIfAbsent('key4', () => 'val4'));
+ Expect.equals('val4', window.localStorage['key4']);
+
+ Expect.equals('val3', window.localStorage['key3']);
+ Expect.equals('val3', window.localStorage.putIfAbsent(
+ 'key3', () => Expect.fail('should not be called')));
+ Expect.equals('val3', window.localStorage['key3']);
+ });
+
+ testWithLocalStorage('remove', () {
+ Expect.isNull(window.localStorage.remove('does not exist'));
+ Expect.equals('val3', window.localStorage.remove('key3'));
+ Expect.mapEquals({'key1': 'val1', 'key2': 'val2'}, window.localStorage);
+ });
+
+ testWithLocalStorage('clear', () {
+ window.localStorage.clear();
+ Expect.mapEquals({}, window.localStorage);
+ });
+
+ testWithLocalStorage('forEach', () {
+ Map<String, String> results = {};
+ window.localStorage.forEach((k, v) {
+ results[k] = v;
+ });
+ Expect.mapEquals({'key1': 'val1', 'key2': 'val2', 'key3': 'val3'},
+ results);
+ });
+
+ testWithLocalStorage('getKeys', () {
+ Expect.setEquals(['key1', 'key2', 'key3'], window.localStorage.getKeys());
+ });
+
+ testWithLocalStorage('getVals', () {
+ Expect.setEquals(['val1', 'val2', 'val3'],
+ window.localStorage.getValues());
+ });
+
+ testWithLocalStorage('length', () {
+ Expect.equals(3, window.localStorage.length);
+ window.localStorage.clear();
+ Expect.equals(0, window.localStorage.length);
+ });
+
+ testWithLocalStorage('isEmpty', () {
+ Expect.isFalse(window.localStorage.isEmpty());
+ window.localStorage.clear();
+ Expect.isTrue(window.localStorage.isEmpty());
});
}
« no previous file with comments | « no previous file | lib/dom/scripts/systemhtml.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698