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

Side by Side Diff: remoting/webapp/base/js/host_options_unittest.js

Issue 1366093003: Improve HostOptions unit tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Improve unit tests. Created 5 years, 2 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 optionsNew = new remoting.HostOptions('host-id');
Jamie 2015/09/26 00:40:41 Loading into the same object as we saved would tri
kelvinp 2015/09/28 18:36:40 Nit: optionsLoaded may be a more descriptive name.
Jamie 2015/09/28 21:33:48 Done.
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 optionsNew.load();
71 }).then(function() { 72 }).then(function() {
72 assert.deepEqual(optionsCopy, base.deepCopy(options)); 73 assert.deepEqual(optionsCopy, base.deepCopy(optionsNew));
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');
Jamie 2015/09/26 00:40:41 This test wasn't really testing anything previousl
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 optionsNew = new remoting.HostOptions('host-id');
115 options['undefined-option'] = 42;
116 var optionsCopy = base.deepCopy(options);
117
118 return options.save().then(function() {
119 return optionsNew.load();
120 }).then(function() {
121 assert.deepEqual(optionsCopy, base.deepCopy(optionsNew));
kelvinp 2015/09/28 18:36:40 Nit: maybe good to assert options['undefined-optio
Jamie 2015/09/28 21:33:48 Done.
122 });
123 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698