OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 'use strict'; | 5 'use strict'; |
6 | 6 |
7 QUnit.module('HostOptions', { | 7 QUnit.module('HostOptions', { |
8 beforeEach: function() { | 8 beforeEach: function() { |
9 sinon.stub(remoting, 'platformIsChromeOS'); | 9 sinon.stub(remoting, 'platformIsChromeOS'); |
10 }, | 10 }, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 var options = new remoting.HostOptions('host-id'); | 49 var options = new remoting.HostOptions('host-id'); |
50 return options.load().then( | 50 return options.load().then( |
51 function() { | 51 function() { |
52 assertDefaults(assert, options, true); | 52 assertDefaults(assert, options, true); |
53 }); | 53 }); |
54 }); | 54 }); |
55 | 55 |
56 QUnit.test('Saving and loading a host preserves the saved values', | 56 QUnit.test('Saving and loading a host preserves the saved values', |
57 function(assert) { | 57 function(assert) { |
58 var options = new remoting.HostOptions('host-id'); | 58 var options = new remoting.HostOptions('host-id'); |
| 59 var optionsLoaded = new remoting.HostOptions('host-id'); |
59 options.setShrinkToFit(false); | 60 options.setShrinkToFit(false); |
60 options.setResizeToClient(false); | 61 options.setResizeToClient(false); |
61 options.setDesktopScale(2); | 62 options.setDesktopScale(2); |
62 options.setRemapKeys({2: 1, 1: 2}); | 63 options.setRemapKeys({2: 1, 1: 2}); |
63 options.setPairingInfo({ | 64 options.setPairingInfo({ |
64 clientId: 'client-id', | 65 clientId: 'client-id', |
65 sharedSecret: 'shared-secret' | 66 sharedSecret: 'shared-secret' |
66 }); | 67 }); |
67 var optionsCopy = base.deepCopy(options); | 68 var optionsCopy = base.deepCopy(options); |
68 | 69 |
69 return options.save().then(function() { | 70 return options.save().then(function() { |
70 return options.load(); | 71 return optionsLoaded.load(); |
71 }).then(function() { | 72 }).then(function() { |
72 assert.deepEqual(optionsCopy, base.deepCopy(options)); | 73 assert.deepEqual(optionsCopy, base.deepCopy(optionsLoaded)); |
73 }); | 74 }); |
74 }); | 75 }); |
75 | 76 |
76 QUnit.test('Saving a host ignores unset values', | 77 QUnit.test('Saving a host ignores unset values', |
77 function(assert) { | 78 function(assert) { |
78 var options = new remoting.HostOptions('host-id'); | 79 var options = new remoting.HostOptions('host-id'); |
| 80 options.setShrinkToFit(false); |
79 var optionsCopy = base.deepCopy(options); | 81 var optionsCopy = base.deepCopy(options); |
| 82 var optionsEmpty = new remoting.HostOptions('host-id'); |
80 | 83 |
81 return options.save().then(function() { | 84 return optionsEmpty.save().then(function() { |
82 return options.load(); | 85 return options.load(); |
83 }).then(function() { | 86 }).then(function() { |
84 assert.deepEqual(optionsCopy, base.deepCopy(options)); | 87 assert.deepEqual(optionsCopy, base.deepCopy(options)); |
85 }); | 88 }); |
86 }); | 89 }); |
87 | 90 |
88 QUnit.test('Old-style (string-formatted) key remappings are parsed correctly', | 91 QUnit.test('Old-style (string-formatted) key remappings are parsed correctly', |
89 function(assert) { | 92 function(assert) { |
90 var options1 = new remoting.HostOptions('host-id'); | 93 var options1 = new remoting.HostOptions('host-id'); |
91 options1.setRemapKeys({2: 1, 1: 2}); | 94 options1.setRemapKeys({2: 1, 1: 2}); |
92 var savedHostOptions = { | 95 var savedHostOptions = { |
93 'host-id': { | 96 'host-id': { |
94 'remapKeys': '2>1,1>2' | 97 'remapKeys': '2>1,1>2' |
95 } | 98 } |
96 }; | 99 }; |
97 var savedAllOptions = { | 100 var savedAllOptions = { |
98 'remoting-host-options': JSON.stringify(savedHostOptions) | 101 'remoting-host-options': JSON.stringify(savedHostOptions) |
99 }; | 102 }; |
100 chrome.storage.local.set(savedAllOptions); // Mock storage is synchronous | 103 chrome.storage.local.set(savedAllOptions); // Mock storage is synchronous |
101 var options2 = new remoting.HostOptions('host-id'); | 104 var options2 = new remoting.HostOptions('host-id'); |
102 return options2.load().then( | 105 return options2.load().then( |
103 function() { | 106 function() { |
104 assert.deepEqual(options1, options2); | 107 assert.deepEqual(options1, options2); |
105 }); | 108 }); |
106 }); | 109 }); |
| 110 |
| 111 QUnit.test('New options are loaded and saved without updating the code', |
| 112 function(assert) { |
| 113 var options = new remoting.HostOptions('host-id'); |
| 114 var optionsLoaded = new remoting.HostOptions('host-id'); |
| 115 options['undefined-option'] = 42; |
| 116 |
| 117 return options.save().then(function() { |
| 118 return optionsLoaded.load(); |
| 119 }).then(function() { |
| 120 assert.equal(optionsLoaded['undefined-option'], 42); |
| 121 }); |
| 122 }); |
OLD | NEW |