1 // Copyright 2014 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 * TestFixture for Invalidations WebUI testing.
7 * @extends {testing.Test}
10 function InvalidationsWebUITest() {}
12 InvalidationsWebUITest.prototype = {
13 __proto__: testing.Test.prototype,
16 * Browse to the Invalidations page.
18 browsePreload: 'chrome://invalidations',
19 runAccessibilityChecks: false,
20 accessibilityIssuesAreErrors: false
23 // Test that registering an invalidations appears properly on the textarea.
24 TEST_F('InvalidationsWebUITest', 'testRegisteringNewInvalidation', function() {
25 var invalidationsLog = $('invalidations-log');
27 isUnknownVersion: 'true',
28 objectId: {name: 'EXTENSIONS', source: 1004}
30 invalidationsLog.value = '';
31 chrome.invalidations.logInvalidations(invalidation);
33 invalidationsLog.value.indexOf(
34 'Received Invalidation with type ' +
35 '"EXTENSIONS" version "Unknown" with payload "undefined"') != -1;
36 expectTrue(isContained, 'Actual log is:' + invalidationsLog.value);
40 // Test that changing the Invalidations Service state appears both in the
41 // span and in the textarea.
42 TEST_F('InvalidationsWebUITest', 'testChangingInvalidationsState', function() {
43 var invalidationsState = $('invalidations-state');
44 var invalidationsLog = $('invalidations-log');
45 var newState = 'INVALIDATIONS_ENABLED';
46 var newNewState = 'TRANSIENT_INVALIDATION_ERROR';
48 chrome.invalidations.updateInvalidatorState(newState);
49 var isContainedState = invalidationsState.textContent.indexOf(
50 'INVALIDATIONS_ENABLED') != -1;
51 expectTrue(isContainedState, 'could not change the invalidations text');
53 invalidationsLog.value = '';
54 chrome.invalidations.updateInvalidatorState(newNewState);
55 var isContainedState2 = invalidationsState.textContent.indexOf(
56 'TRANSIENT_INVALIDATION_ERROR') != -1;
57 expectTrue(isContainedState2, 'could not change the invalidations text');
59 invalidationsLog.value.indexOf(
60 'Invalidations service state changed to ' +
61 '"TRANSIENT_INVALIDATION_ERROR"') != -1;
62 expectTrue(isContainedLog, 'Actual log is:' + invalidationsLog.value);
65 // Test that objects ids appear on the table.
66 TEST_F('InvalidationsWebUITest', 'testRegisteringNewIds', function() {
68 { name: 'EXTENSIONS', source: 1004, totalCount: 0},
69 { name: 'FAVICON_IMAGE', source: 1004, totalCount: 0}
71 var pattern1 = ['Fake', '1004', 'EXTENSIONS', '0', '0', '', '', ''];
72 var pattern2 = ['Fake', '1004', 'FAVICON_IMAGE', '0', '0', '', '', ''];
73 // Register two objects ID with 'Fake' registrar
74 chrome.invalidations.updateIds('Fake', newDataType);
75 // Disable the Extensions ObjectId by only sending FAVICON_IMAGE
76 newDataType = [{name: 'FAVICON_IMAGE', source: 1004}];
77 chrome.invalidations.updateIds('Fake', newDataType);
79 // Test that the two patterns are contained in the table.
80 var oidTable = $('objectsid-table-container');
81 var foundPattern1 = false;
82 var foundPattern2 = false;
83 for (var row = 0; row < oidTable.rows.length; row++) {
84 var pattern1Test = true;
85 var pattern2Test = true;
86 for (var cell = 0; cell < oidTable.rows[row].cells.length; cell++) {
87 pattern1Test = pattern1Test
88 && (pattern1[cell] == oidTable.rows[row].cells[cell].textContent);
89 pattern2Test = pattern2Test
90 && (pattern2[cell] == oidTable.rows[row].cells[cell].textContent);
93 expectEquals('greyed', oidTable.rows[row].className);
95 expectEquals('content', oidTable.rows[row].className);
97 foundPattern1 = foundPattern1 || pattern1Test;
98 foundPattern2 = foundPattern2 || pattern2Test;
100 expectTrue(foundPattern1, 'The entries were not ordererd');
102 expectTrue(foundPattern1 && foundPattern2, "couldn't find both objects ids");
105 // Test that registering new handlers appear on the website.
106 TEST_F('InvalidationsWebUITest', 'testUpdatingRegisteredHandlers', function() {
107 function text() { return $('registered-handlers').textContent; }
108 chrome.invalidations.updateHandlers(['FakeApi', 'FakeClient']);
109 expectNotEquals(text().indexOf('FakeApi'), -1);
110 expectNotEquals(text().indexOf('FakeClient'), -1);
112 chrome.invalidations.updateHandlers(['FakeClient']);
113 expectEquals(text().indexOf('FakeApi'), -1);
114 expectNotEquals(text().indexOf('FakeClient'), -1);
117 // Test that an object showing internal state is correctly displayed.
118 TEST_F('InvalidationsWebUITest', 'testUpdatingInternalDisplay', function() {
119 var newDetailedStatus = {MessagesSent: 1};
120 chrome.invalidations.updateDetailedStatus(newDetailedStatus);
121 expectEquals( $('internal-display').value, '{\n \"MessagesSent\": 1\n}');