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
3 // found in the LICENSE file.
6 * Test fixture for sync internals WebUI testing.
8 * @extends {testing.Test}
10 function SyncInternalsWebUITest() {}
12 SyncInternalsWebUITest.prototype = {
13 __proto__: testing.Test.prototype,
16 * Browse to the sync internals page.
19 browsePreload: 'chrome://sync-internals',
23 this.makeAndRegisterMockHandler([
29 * Checks aboutInfo's details section for the specified field.
30 * @param {boolean} isValid Whether the field is valid.
31 * @param {string} key The name of the key to search for in details.
32 * @param {string} value The expected value if |key| is found.
33 * @return {boolean} whether the field was found in the details.
36 hasInDetails: function(isValid, key, value) {
37 var details = chrome.sync.aboutInfo.details;
40 for (var i = 0; i < details.length; ++i) {
43 for (var j = 0; j < details[i].data.length; ++j) {
44 var obj = details[i].data[j];
45 if (obj.stat_name == key)
46 return obj.is_valid == isValid && obj.stat_value == value;
53 /** Constant hard-coded value to return from mock getAllNodes */
54 var HARD_CODED_ALL_NODES = [
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==",
63 "IS_UNAPPLIED_UPDATE": false,
65 "LOCAL_EXTERNAL_ID": "0",
67 "MTIME": "Wednesday, December 31, 1969 4:00:00 PM",
68 "NON_UNIQUE_NAME": "Typed URLs",
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",
78 "visit_transitions": [],
82 "SERVER_UNIQUE_POSITION": "INVALID[]",
83 "SERVER_VERSION": "1388699799780000",
86 "visit_transitions": [],
91 "TRANSACTION_VERSION": "1",
92 "UNIQUE_BOOKMARK_TAG": "",
93 "UNIQUE_CLIENT_TAG": "",
94 "UNIQUE_POSITION": "INVALID[]",
95 "UNIQUE_SERVER_TAG": "google_chrome_typed_urls",
97 "serverModelType": "Typed URLs"
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==",
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": {
126 "url": "http://chrome.com/",
127 "visit_transitions": [
135 "SERVER_UNIQUE_POSITION": "INVALID[]",
136 "SERVER_VERSION": "1372291923970334",
141 "url": "http://chrome.com/",
142 "visit_transitions": [
151 "TRANSACTION_VERSION": "1",
152 "UNIQUE_BOOKMARK_TAG": "",
153 "UNIQUE_CLIENT_TAG": "J28uWKpXPuQwR3SJKbuLqzYGOcM=",
154 "UNIQUE_POSITION": "INVALID[]",
155 "UNIQUE_SERVER_TAG": "",
157 "serverModelType": "Typed URLs"
161 TEST_F('SyncInternalsWebUITest', 'Uninitialized', function() {
162 assertNotEquals(null, chrome.sync.aboutInfo);
163 expectTrue(this.hasInDetails(true, 'Username', ''));
164 expectTrue(this.hasInDetails(false, 'Summary', 'Uninitialized'));
167 TEST_F('SyncInternalsWebUITest', 'SearchTabDoesntChangeOnItemSelect',
169 // Select the search tab.
170 $('sync-search-tab').selected = true;
171 expectTrue($('sync-search-tab').selected);
173 // Build the data model and attach to result list.
174 cr.ui.List.decorate($('sync-results-list'));
175 $('sync-results-list').dataModel = new cr.ui.ArrayDataModel([
178 toString: function() { return 'node 0'; },
182 toString: function() { return 'node 1'; },
186 // Select the first list item and verify the search tab remains selected.
187 $('sync-results-list').getListItemByIndex(0).selected = true;
188 expectTrue($('sync-search-tab').selected);
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);
197 // Hit the refresh button.
198 $('node-browser-refresh-button').click();
200 // Check that the refresh time was updated.
201 expectNotEquals($('node-browser-refresh-time').textContent, 'Never');
203 // Verify some hard-coded assumptions. These depend on the vaue of the
204 // hard-coded nodes, specified elsewhere in this file.
206 // Start with the tree itself.
207 var tree = $('sync-node-tree');
208 assertEquals(1, tree.items.length);
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);
216 // An actual sync node. The child of the type root.
217 var leaf = typeRoot.items[0];
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'));
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);
231 // Should start with non-refreshed node browser.
232 expectEquals($('node-browser-refresh-time').textContent, 'Never');
234 // Selecting the tab will refresh it.
235 $('sync-browser-tab').selected = true;
236 expectNotEquals($('node-browser-refresh-time').textContent, 'Never');
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');