diff options
Diffstat (limited to 'chromium/chrome/browser/resources/chromeos/login/screen_context_test.html')
-rw-r--r-- | chromium/chrome/browser/resources/chromeos/login/screen_context_test.html | 207 |
1 files changed, 0 insertions, 207 deletions
diff --git a/chromium/chrome/browser/resources/chromeos/login/screen_context_test.html b/chromium/chrome/browser/resources/chromeos/login/screen_context_test.html deleted file mode 100644 index bc77e4bb158..00000000000 --- a/chromium/chrome/browser/resources/chromeos/login/screen_context_test.html +++ /dev/null @@ -1,207 +0,0 @@ -<!doctype html> -<title></title> -<script src="https://cdn.rawgit.com/google/closure-library/master/closure/goog/base.js"></script> -<script src="../../../../../ui/webui/resources/js/cr.js"></script> -<script src="screen_context.js"></script> -<script> - -goog.require('goog.testing.jsunit'); - -</script> -<body> -<script> - -function callSuccessful(f) { - try { - f(); - } catch (e) { - return false; - } - return true; -} - -function checkThrows(f) { - assertFalse(callSuccessful(f)); -} - -function checkNotThrows(f) { - assertTrue(callSuccessful(f)); -} - -function testSimple() { - var context = new login.ScreenContext; - assertFalse(context.hasChanges()); - - assertFalse(context.hasKey('key0')); - - var rv = context.set('key0', true); - assertTrue(rv); - assertTrue(context.hasKey('key0')); - assertTrue(context.get('key0')); - assertTrue(context.get('key0', false)); - assertTrue(context.hasChanges()); - - rv = context.set('key0', true); - assertFalse(rv); - - rv = context.set('key0', false); - assertTrue(rv); - assertTrue(context.hasKey('key0')); - assertFalse(context.get('key0')); - assertFalse(context.get('key0', true)); - assertTrue(context.hasChanges()); - - assertFalse(context.hasKey('key1')); - - assertEquals(1, context.get('key1', 1)); - rv = context.set('key1', 2); - assertTrue(rv); - assertTrue(context.hasKey('key1')); - assertEquals(2, context.get('key1')); - assertEquals(2, context.get('key1', 1)); -} - -function testChanges() { - var context = new login.ScreenContext; - assertFalse(context.hasChanges()); - - var rv = context.set('key0', 2); - assertTrue(rv); - assertEquals(2, context.get('key0')); - assertTrue(context.hasChanges()); - - var changes = context.getChangesAndReset(); - assertFalse(context.hasChanges()); - - assertEquals(1, Object.keys(changes).length); - - assertEquals(2, changes['key0']); - - rv = context.set('key0', 3); - assertTrue(rv); - assertEquals(3, context.get('key0', 3)); - assertTrue(context.hasChanges()); - - rv = context.set('key0', 2); - assertTrue(rv); - assertTrue(context.hasChanges()); -} - -function testComplexChanges() { - var context = new login.ScreenContext; - assertFalse(context.hasChanges()); - - context.set('key0', 'value0'); - context.set('key1', true); - context.set('key2', 3.14159); - assertTrue(context.hasChanges()); - - // Get all changes and verify them. - var changes = context.getChangesAndReset(); - assertFalse(context.hasChanges()); - assertEquals(3, Object.keys(changes).length); - - assertEquals('value0', changes['key0']); - assertEquals(true, changes['key1']); - assertEquals(3.14159, changes['key2']); - - context.set('key0', 'value1'); - assertTrue(context.hasChanges()); - - context.set('key0', 'value0'); - assertTrue(context.hasChanges()); - - changes = context.getChangesAndReset(); - assertFalse(context.hasChanges()); - assertEquals(1, Object.keys(changes).length); - assertEquals('value0', changes['key0']); -} - -function testApplyChanges() { - var context = new login.ScreenContext; - assertFalse(context.hasChanges()); - - var changes = { - key0: 'value0', - key1: 1, - key2: true - }; - - var keys = context.applyChanges(changes); - - assertEquals(3, keys.length); - keys.sort(); - assertEquals('key0', keys[0]); - assertEquals('key1', keys[1]); - assertEquals('key2', keys[2]); - - assertFalse(context.hasChanges()); - assertEquals('value0', context.get('key0')); - assertEquals(1, context.get('key1')); - assertTrue(context.get('key2')); -} - -function testErrorHandling() { - function createContext() { - return new login.ScreenContext; - } - - /* Invalid keys. */ - checkThrows(function() { - createContext().set(true, 10); - }); - checkThrows(function() { - createContext().set(new Object, 10); - }); - checkThrows(function() { - createContext().set(10, 10); - }); - checkNotThrows(function() { - createContext().set('key0', 10); - }); - checkThrows(function() { - var c = createContext(); - c.set('10', 10); - c.get(10); - }); - checkNotThrows(function() { - var c = createContext(); - c.set('10', 10); - c.get('10'); - }); - checkThrows(function() { - createContext().hasKey(20); - }); - - /* Missing key. */ - checkThrows(function() { - createContext().get('key'); - }); - checkNotThrows(function() { - createContext().get('key', 10); - }); - - /* Invalid values. */ - checkThrows(function() { - createContext().set('key0', new Object()); - }); - checkThrows(function() { - createContext().set('key0', new Boolean(true)); - }); - - /* Applying diff to context with changes. */ - checkThrows(function() { - var c = createContext(); - c.set('key', 'value'); - c.applyChanges({'key1': 'value1'}); - }); - checkNotThrows(function() { - var c = createContext(); - c.set('key', 'value'); - c.getChangesAndReset(); - c.applyChanges({'key1': 'value1'}); - }); -} - -</script> -</body> |