Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / sync_internals_browsertest.js
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.
4
5 /**
6  * Test fixture for sync internals WebUI testing.
7  * @constructor
8  * @extends {testing.Test}
9  */
10 function SyncInternalsWebUITest() {}
11
12 SyncInternalsWebUITest.prototype = {
13   __proto__: testing.Test.prototype,
14
15   /**
16    * Browse to the sync internals page.
17    * @override
18    */
19   browsePreload: 'chrome://sync-internals',
20
21   /** @override */
22   preLoad: function() {
23     this.makeAndRegisterMockHandler([
24         'getAllNodes',
25     ]);
26   },
27
28   /**
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.
34    * @protected
35    */
36   hasInDetails: function(isValid, key, value) {
37     var details = chrome.sync.aboutInfo.details;
38     if (!details)
39       return false;
40     for (var i = 0; i < details.length; ++i) {
41       if (!details[i].data)
42         continue;
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;
47       }
48     }
49     return false;
50   }
51 };
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
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'));
165 });
166
167 TEST_F('SyncInternalsWebUITest', 'SearchTabDoesntChangeOnItemSelect',
168        function() {
169   // Select the search tab.
170   $('sync-search-tab').selected = true;
171   expectTrue($('sync-search-tab').selected);
172
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([
176     {
177       value: 'value 0',
178       toString: function() { return 'node 0'; },
179     },
180     {
181       value: 'value 1',
182       toString: function() { return 'node 1'; },
183     }
184   ]);
185
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);
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 });