OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 /** | 5 /** |
6 * Test fixture for sync internals WebUI testing. | 6 * Test fixture for sync internals WebUI testing. |
7 * @constructor | 7 * @constructor |
8 * @extends {testing.Test} | 8 * @extends {testing.Test} |
9 */ | 9 */ |
10 function SyncInternalsWebUITest() {} | 10 function SyncInternalsWebUITest() {} |
11 | 11 |
12 SyncInternalsWebUITest.prototype = { | 12 SyncInternalsWebUITest.prototype = { |
13 __proto__: testing.Test.prototype, | 13 __proto__: testing.Test.prototype, |
14 | 14 |
15 /** | 15 /** |
16 * Browse to the sync internals page. | 16 * Browse to the sync internals page. |
17 * @override | 17 * @override |
18 */ | 18 */ |
19 browsePreload: 'chrome://sync-internals', | 19 browsePreload: 'chrome://sync-internals', |
20 | 20 |
21 /** @override */ | 21 /** @override */ |
22 preLoad: function() { | 22 preLoad: function() { |
23 // TODO(zea): mock out the the sync info to fake an active syncer. | 23 this.makeAndRegisterMockHandler([ |
| 24 'getAllNodes', |
| 25 ]); |
24 }, | 26 }, |
25 | 27 |
26 /** | 28 /** |
27 * Checks aboutInfo's details section for the specified field. | 29 * Checks aboutInfo's details section for the specified field. |
28 * @param {boolean} isValid Whether the field is valid. | 30 * @param {boolean} isValid Whether the field is valid. |
29 * @param {string} key The name of the key to search for in details. | 31 * @param {string} key The name of the key to search for in details. |
30 * @param {string} value The expected value if |key| is found. | 32 * @param {string} value The expected value if |key| is found. |
31 * @return {boolean} whether the field was found in the details. | 33 * @return {boolean} whether the field was found in the details. |
32 * @protected | 34 * @protected |
33 */ | 35 */ |
34 hasInDetails: function(isValid, key, value) { | 36 hasInDetails: function(isValid, key, value) { |
35 var details = chrome.sync.aboutInfo.details; | 37 var details = chrome.sync.aboutInfo.details; |
36 if (!details) | 38 if (!details) |
37 return false; | 39 return false; |
38 for (var i = 0; i < details.length; ++i) { | 40 for (var i = 0; i < details.length; ++i) { |
39 if (!details[i].data) | 41 if (!details[i].data) |
40 continue; | 42 continue; |
41 for (var j = 0; j < details[i].data.length; ++j) { | 43 for (var j = 0; j < details[i].data.length; ++j) { |
42 var obj = details[i].data[j]; | 44 var obj = details[i].data[j]; |
43 if (obj.stat_name == key) | 45 if (obj.stat_name == key) |
44 return obj.is_valid == isValid && obj.stat_value == value; | 46 return obj.is_valid == isValid && obj.stat_value == value; |
45 } | 47 } |
46 } | 48 } |
47 return false; | 49 return false; |
48 } | 50 } |
49 }; | 51 }; |
50 | 52 |
| 53 /** Constant hard-coded value to return from mock getAllNodes */ |
| 54 var HARD_CODED_ALL_NODES = [ |
| 55 { |
| 56 "BASE_SERVER_SPECIFICS": {}, |
| 57 "BASE_VERSION": "1388699799780000", |
| 58 "CTIME": "Wednesday, December 31, 1969 4:00:00 PM", |
| 59 "ID": "sZ:ADqtAZw5kjSwSkukraMoMX6z0OlFXENzhA+1HZNcO6LbATQrkVenHJS5" + |
| 60 "AgICYfj8/6KcvwlCw3FIvcRFtOEP3zSP5YJ1VH53/Q==", |
| 61 "IS_DEL": false, |
| 62 "IS_DIR": true, |
| 63 "IS_UNAPPLIED_UPDATE": false, |
| 64 "IS_UNSYNCED": false, |
| 65 "LOCAL_EXTERNAL_ID": "0", |
| 66 "META_HANDLE": "376", |
| 67 "MTIME": "Wednesday, December 31, 1969 4:00:00 PM", |
| 68 "NON_UNIQUE_NAME": "Typed URLs", |
| 69 "PARENT_ID": "r", |
| 70 "SERVER_CTIME": "Wednesday, December 31, 1969 4:00:00 PM", |
| 71 "SERVER_IS_DEL": false, |
| 72 "SERVER_IS_DIR": true, |
| 73 "SERVER_MTIME": "Wednesday, December 31, 1969 4:00:00 PM", |
| 74 "SERVER_NON_UNIQUE_NAME": "Typed URLs", |
| 75 "SERVER_PARENT_ID": "r", |
| 76 "SERVER_SPECIFICS": { |
| 77 "typed_url": { |
| 78 "visit_transitions": [], |
| 79 "visits": [] |
| 80 } |
| 81 }, |
| 82 "SERVER_UNIQUE_POSITION": "INVALID[]", |
| 83 "SERVER_VERSION": "1388699799780000", |
| 84 "SPECIFICS": { |
| 85 "typed_url": { |
| 86 "visit_transitions": [], |
| 87 "visits": [] |
| 88 } |
| 89 }, |
| 90 "SYNCING": false, |
| 91 "TRANSACTION_VERSION": "1", |
| 92 "UNIQUE_BOOKMARK_TAG": "", |
| 93 "UNIQUE_CLIENT_TAG": "", |
| 94 "UNIQUE_POSITION": "INVALID[]", |
| 95 "UNIQUE_SERVER_TAG": "google_chrome_typed_urls", |
| 96 "isDirty": false, |
| 97 "serverModelType": "Typed URLs" |
| 98 }, |
| 99 { |
| 100 "BASE_SERVER_SPECIFICS": {}, |
| 101 "BASE_VERSION": "1372291923970334", |
| 102 "CTIME": "Wednesday, June 26, 2013 5:12:03 PM", |
| 103 "ID": "sZ:ADqtAZyz70DhOIusPT1v2XCd/8YT8Fy43WlqdRyH6UwoBAqMkX5Pnkl/sW9A" + |
| 104 "+AVrmzAPWFTrRBf0AWD57HyN4GcYXwSR9q4lYA==", |
| 105 "IS_DEL": false, |
| 106 "IS_DIR": false, |
| 107 "IS_UNAPPLIED_UPDATE": false, |
| 108 "IS_UNSYNCED": false, |
| 109 "LOCAL_EXTERNAL_ID": "0", |
| 110 "META_HANDLE": "3011", |
| 111 "MTIME": "Wednesday, June 26, 2013 5:12:03 PM", |
| 112 "NON_UNIQUE_NAME": "http://chrome.com/", |
| 113 "PARENT_ID": "sZ:ADqtAZw5kjSwSkukraMoMX6z0OlFXENzhA+1HZNcO6LbATQrkVen" + |
| 114 "HJS5AgICYfj8/6KcvwlCw3FIvcRFtOEP3zSP5YJ1VH53/Q==", |
| 115 "SERVER_CTIME": "Wednesday, June 26, 2013 5:12:03 PM", |
| 116 "SERVER_IS_DEL": false, |
| 117 "SERVER_IS_DIR": false, |
| 118 "SERVER_MTIME": "Wednesday, June 26, 2013 5:12:03 PM", |
| 119 "SERVER_NON_UNIQUE_NAME": "http://chrome.com/", |
| 120 "SERVER_PARENT_ID": "sZ:ADqtAZw5kjSwSkukraMoMX6z0OlFXENzhA+1HZNcO6LbAT" + |
| 121 "QrkVenHJS5AgICYfj8/6KcvwlCw3FIvcRFtOEP3zSP5YJ1VH53/Q==", |
| 122 "SERVER_SPECIFICS": { |
| 123 "typed_url": { |
| 124 "hidden": false, |
| 125 "title": "Chrome", |
| 126 "url": "http://chrome.com/", |
| 127 "visit_transitions": [ |
| 128 "268435457" |
| 129 ], |
| 130 "visits": [ |
| 131 "13016765523677321" |
| 132 ] |
| 133 } |
| 134 }, |
| 135 "SERVER_UNIQUE_POSITION": "INVALID[]", |
| 136 "SERVER_VERSION": "1372291923970334", |
| 137 "SPECIFICS": { |
| 138 "typed_url": { |
| 139 "hidden": false, |
| 140 "title": "Chrome", |
| 141 "url": "http://chrome.com/", |
| 142 "visit_transitions": [ |
| 143 "268435457" |
| 144 ], |
| 145 "visits": [ |
| 146 "13016765523677321" |
| 147 ] |
| 148 } |
| 149 }, |
| 150 "SYNCING": false, |
| 151 "TRANSACTION_VERSION": "1", |
| 152 "UNIQUE_BOOKMARK_TAG": "", |
| 153 "UNIQUE_CLIENT_TAG": "J28uWKpXPuQwR3SJKbuLqzYGOcM=", |
| 154 "UNIQUE_POSITION": "INVALID[]", |
| 155 "UNIQUE_SERVER_TAG": "", |
| 156 "isDirty": false, |
| 157 "serverModelType": "Typed URLs" |
| 158 } |
| 159 ]; |
| 160 |
51 TEST_F('SyncInternalsWebUITest', 'Uninitialized', function() { | 161 TEST_F('SyncInternalsWebUITest', 'Uninitialized', function() { |
52 assertNotEquals(null, chrome.sync.aboutInfo); | 162 assertNotEquals(null, chrome.sync.aboutInfo); |
53 expectTrue(this.hasInDetails(true, 'Username', '')); | 163 expectTrue(this.hasInDetails(true, 'Username', '')); |
54 expectTrue(this.hasInDetails(false, 'Summary', 'Uninitialized')); | 164 expectTrue(this.hasInDetails(false, 'Summary', 'Uninitialized')); |
55 }); | 165 }); |
56 | 166 |
57 TEST_F('SyncInternalsWebUITest', 'SearchTabDoesntChangeOnItemSelect', | 167 TEST_F('SyncInternalsWebUITest', 'SearchTabDoesntChangeOnItemSelect', |
58 function() { | 168 function() { |
59 // Select the search tab. | 169 // Select the search tab. |
60 $('sync-search-tab').selected = true; | 170 $('sync-search-tab').selected = true; |
61 expectTrue($('sync-search-tab').selected); | 171 expectTrue($('sync-search-tab').selected); |
62 | 172 |
63 // Build the data model and attach to result list. | 173 // Build the data model and attach to result list. |
64 cr.ui.List.decorate($('sync-results-list')); | 174 cr.ui.List.decorate($('sync-results-list')); |
65 $('sync-results-list').dataModel = new cr.ui.ArrayDataModel([ | 175 $('sync-results-list').dataModel = new cr.ui.ArrayDataModel([ |
66 { | 176 { |
67 value: 'value 0', | 177 value: 'value 0', |
68 toString: function() { return 'node 0'; }, | 178 toString: function() { return 'node 0'; }, |
69 }, | 179 }, |
70 { | 180 { |
71 value: 'value 1', | 181 value: 'value 1', |
72 toString: function() { return 'node 1'; }, | 182 toString: function() { return 'node 1'; }, |
73 } | 183 } |
74 ]); | 184 ]); |
75 | 185 |
76 // Select the first list item and verify the search tab remains selected. | 186 // Select the first list item and verify the search tab remains selected. |
77 $('sync-results-list').getListItemByIndex(0).selected = true; | 187 $('sync-results-list').getListItemByIndex(0).selected = true; |
78 expectTrue($('sync-search-tab').selected); | 188 expectTrue($('sync-search-tab').selected); |
79 }); | 189 }); |
| 190 |
| 191 TEST_F('SyncInternalsWebUITest', 'NodeBrowserTest', function() { |
| 192 this.mockHandler.expects(once()).getAllNodes([]).will( |
| 193 callFunction(function() { |
| 194 chrome.sync.getAllNodes.handleReply(HARD_CODED_ALL_NODES); |
| 195 })); |
| 196 |
| 197 // Hit the refresh button. |
| 198 $('node-browser-refresh-button').click(); |
| 199 |
| 200 // Check that the refresh time was updated. |
| 201 expectNotEquals($('node-browser-refresh-time').textContent, 'Never'); |
| 202 |
| 203 // Verify some hard-coded assumptions. These depend on the vaue of the |
| 204 // hard-coded nodes, specified elsewhere in this file. |
| 205 |
| 206 // Start with the tree itself. |
| 207 var tree = $('sync-node-tree'); |
| 208 assertEquals(1, tree.items.length); |
| 209 |
| 210 // Check the type root and expand it. |
| 211 var typeRoot = tree.items[0]; |
| 212 expectFalse(typeRoot.expanded); |
| 213 typeRoot.expanded = true; |
| 214 assertEquals(1, typeRoot.items.length); |
| 215 |
| 216 // An actual sync node. The child of the type root. |
| 217 var leaf = typeRoot.items[0]; |
| 218 |
| 219 // Verify that selecting it affects the details view. |
| 220 expectTrue($('node-details').hasAttribute('hidden')); |
| 221 leaf.selected = true; |
| 222 expectFalse($('node-details').hasAttribute('hidden')); |
| 223 }); |
| 224 |
| 225 TEST_F('SyncInternalsWebUITest', 'NodeBrowserRefreshOnTabSelect', function() { |
| 226 this.mockHandler.expects(once()).getAllNodes([]).will( |
| 227 callFunction(function() { |
| 228 chrome.sync.getAllNodes.handleReply(HARD_CODED_ALL_NODES); |
| 229 })); |
| 230 |
| 231 // Should start with non-refreshed node browser. |
| 232 expectEquals($('node-browser-refresh-time').textContent, 'Never'); |
| 233 |
| 234 // Selecting the tab will refresh it. |
| 235 $('sync-browser-tab').selected = true; |
| 236 expectNotEquals($('node-browser-refresh-time').textContent, 'Never'); |
| 237 |
| 238 // Re-selecting the tab shouldn't re-refresh. |
| 239 $('node-browser-refresh-time').textContent = 'TestCanary'; |
| 240 $('sync-browser-tab').selected = false; |
| 241 $('sync-browser-tab').selected = true; |
| 242 expectEquals($('node-browser-refresh-time').textContent, 'TestCanary'); |
| 243 }); |
OLD | NEW |