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

Side by Side Diff: client/tests/client/html/LocalStorageTest.dart

Issue 10191033: test renaming overhaul: step 4 client tests (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « client/tests/client/html/EventTest.dart ('k') | client/tests/client/html/MeasurementTest.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 #library('LocalStorageTest');
6 #import('../../../../lib/unittest/unittest.dart');
7 #import('../../../../lib/unittest/html_config.dart');
8 #import('dart:html');
9
10 main() {
11 useHtmlConfiguration();
12
13 void testWithLocalStorage(String name, fn()) {
14 test(name, () {
15 window.localStorage['key1'] = 'val1';
16 window.localStorage['key2'] = 'val2';
17 window.localStorage['key3'] = 'val3';
18
19 try {
20 fn();
21 } finally {
22 window.localStorage.clear();
23 }
24 });
25 }
26
27 testWithLocalStorage('containsValue', () {
28 Expect.isFalse(window.localStorage.containsValue('does not exist'));
29 Expect.isFalse(window.localStorage.containsValue('key1'));
30 Expect.isTrue(window.localStorage.containsValue('val1'));
31 Expect.isTrue(window.localStorage.containsValue('val3'));
32 });
33
34 testWithLocalStorage('containsKey', () {
35 Expect.isFalse(window.localStorage.containsKey('does not exist'));
36 Expect.isFalse(window.localStorage.containsKey('val1'));
37 Expect.isTrue(window.localStorage.containsKey('key1'));
38 Expect.isTrue(window.localStorage.containsKey('key3'));
39 });
40
41 testWithLocalStorage('[]', () {
42 Expect.isNull(window.localStorage['does not exist']);
43 Expect.equals('val1', window.localStorage['key1']);
44 Expect.equals('val3', window.localStorage['key3']);
45 });
46
47 testWithLocalStorage('[]=', () {
48 Expect.isNull(window.localStorage['key4']);
49 window.localStorage['key4'] = 'val4';
50 Expect.equals('val4', window.localStorage['key4']);
51
52 Expect.equals('val3', window.localStorage['key3']);
53 window.localStorage['key3'] = 'val3-new';
54 Expect.equals('val3-new', window.localStorage['key3']);
55 });
56
57 testWithLocalStorage('putIfAbsent', () {
58 Expect.isNull(window.localStorage['key4']);
59 Expect.equals('val4',
60 window.localStorage.putIfAbsent('key4', () => 'val4'));
61 Expect.equals('val4', window.localStorage['key4']);
62
63 Expect.equals('val3', window.localStorage['key3']);
64 Expect.equals('val3', window.localStorage.putIfAbsent(
65 'key3', () => Expect.fail('should not be called')));
66 Expect.equals('val3', window.localStorage['key3']);
67 });
68
69 testWithLocalStorage('remove', () {
70 Expect.isNull(window.localStorage.remove('does not exist'));
71 Expect.equals('val3', window.localStorage.remove('key3'));
72 Expect.mapEquals({'key1': 'val1', 'key2': 'val2'}, window.localStorage);
73 });
74
75 testWithLocalStorage('clear', () {
76 window.localStorage.clear();
77 Expect.mapEquals({}, window.localStorage);
78 });
79
80 testWithLocalStorage('forEach', () {
81 Map<String, String> results = {};
82 window.localStorage.forEach((k, v) {
83 results[k] = v;
84 });
85 Expect.mapEquals({'key1': 'val1', 'key2': 'val2', 'key3': 'val3'},
86 results);
87 });
88
89 testWithLocalStorage('getKeys', () {
90 Expect.setEquals(['key1', 'key2', 'key3'], window.localStorage.getKeys());
91 });
92
93 testWithLocalStorage('getVals', () {
94 Expect.setEquals(['val1', 'val2', 'val3'],
95 window.localStorage.getValues());
96 });
97
98 testWithLocalStorage('length', () {
99 Expect.equals(3, window.localStorage.length);
100 window.localStorage.clear();
101 Expect.equals(0, window.localStorage.length);
102 });
103
104 testWithLocalStorage('isEmpty', () {
105 Expect.isFalse(window.localStorage.isEmpty());
106 window.localStorage.clear();
107 Expect.isTrue(window.localStorage.isEmpty());
108 });
109 }
OLDNEW
« no previous file with comments | « client/tests/client/html/EventTest.dart ('k') | client/tests/client/html/MeasurementTest.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698