summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/webui/about_invalidations_browsertest.js
blob: cb4c36f40c3c89a50b531a0e9f374627635899d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * TestFixture for Invalidations WebUI testing.
 * @extends {testing.Test}
 * @constructor
 */
function InvalidationsWebUITest() {}

InvalidationsWebUITest.prototype = {
  __proto__: testing.Test.prototype,

  /**
   * Browse to the Invalidations page.
   */
  browsePreload: 'chrome://invalidations',
  runAccessibilityChecks: false,
  accessibilityIssuesAreErrors: false
};

// Test that registering an invalidations appears properly on the textarea.
TEST_F('InvalidationsWebUITest', 'testRegisteringNewInvalidation', function() {
  var invalidationsLog = $('invalidations-log');
  var invalidation = [{
    isUnknownVersion: 'true',
    objectId: {name: 'EXTENSIONS', source: 1004}
  }];
  invalidationsLog.value = '';
  chrome.invalidations.logInvalidations(invalidation);
  var isContained =
    invalidationsLog.value.indexOf(
      'Received Invalidation with type ' +
      '"EXTENSIONS" version "Unknown" with payload "undefined"') != -1;
  expectTrue(isContained, 'Actual log is:' + invalidationsLog.value);

});

// Test that changing the Invalidations Service state appears both in the
// span and in the textarea.
TEST_F('InvalidationsWebUITest', 'testChangingInvalidationsState', function() {
  var invalidationsState = $('invalidations-state');
  var invalidationsLog = $('invalidations-log');
  var newState = 'INVALIDATIONS_ENABLED';
  var newNewState = 'TRANSIENT_INVALIDATION_ERROR';

  chrome.invalidations.updateInvalidatorState(newState);
  var isContainedState = invalidationsState.textContent.indexOf(
      'INVALIDATIONS_ENABLED') != -1;
  expectTrue(isContainedState, 'could not change the invalidations text');

  invalidationsLog.value = '';
  chrome.invalidations.updateInvalidatorState(newNewState);
  var isContainedState2 = invalidationsState.textContent.indexOf(
      'TRANSIENT_INVALIDATION_ERROR') != -1;
  expectTrue(isContainedState2, 'could not change the invalidations text');
  var isContainedLog =
    invalidationsLog.value.indexOf(
      'Invalidations service state changed to ' +
      '"TRANSIENT_INVALIDATION_ERROR"') != -1;
  expectTrue(isContainedLog, 'Actual log is:' + invalidationsLog.value);
});

// Test that objects ids appear on the table.
TEST_F('InvalidationsWebUITest', 'testRegisteringNewIds', function() {
  var newDataType = [
    { name: 'EXTENSIONS', source: 1004, totalCount: 0},
    { name: 'FAVICON_IMAGE', source: 1004, totalCount: 0}
  ];
  var pattern1 = ['Fake', '1004', 'EXTENSIONS', '0', '0', '', '', ''];
  var pattern2 = ['Fake', '1004', 'FAVICON_IMAGE', '0', '0', '', '', ''];
  // Register two objects ID with 'Fake' registrar
  chrome.invalidations.updateIds('Fake', newDataType);
  // Disable the Extensions ObjectId by only sending FAVICON_IMAGE
  newDataType = [{name: 'FAVICON_IMAGE', source: 1004}];
  chrome.invalidations.updateIds('Fake', newDataType);

  // Test that the two patterns are contained in the table.
  var oidTable = $('objectsid-table-container');
  var foundPattern1 = false;
  var foundPattern2 = false;
  for (var row = 0; row < oidTable.rows.length; row++) {
    var pattern1Test = true;
    var pattern2Test = true;
    for (var cell = 0; cell < oidTable.rows[row].cells.length; cell++) {
      pattern1Test = pattern1Test
          && (pattern1[cell] == oidTable.rows[row].cells[cell].textContent);
      pattern2Test = pattern2Test
          && (pattern2[cell] == oidTable.rows[row].cells[cell].textContent);
    }
    if (pattern1Test)
      expectEquals('greyed', oidTable.rows[row].className);
    if (pattern2Test)
      expectEquals('content', oidTable.rows[row].className);

    foundPattern1 = foundPattern1 || pattern1Test;
    foundPattern2 = foundPattern2 || pattern2Test;
    if (foundPattern2)
      expectTrue(foundPattern1, 'The entries were not ordererd');
  }
  expectTrue(foundPattern1 && foundPattern2, "couldn't find both objects ids");
});

// Test that registering new handlers appear on the website.
TEST_F('InvalidationsWebUITest', 'testUpdatingRegisteredHandlers', function() {
  function text() { return $('registered-handlers').textContent; }
  chrome.invalidations.updateHandlers(['FakeApi', 'FakeClient']);
  expectNotEquals(text().indexOf('FakeApi'), -1);
  expectNotEquals(text().indexOf('FakeClient'), -1);

  chrome.invalidations.updateHandlers(['FakeClient']);
  expectEquals(text().indexOf('FakeApi'), -1);
  expectNotEquals(text().indexOf('FakeClient'), -1);
});

// Test that an object showing internal state is correctly displayed.
TEST_F('InvalidationsWebUITest', 'testUpdatingInternalDisplay', function() {
  var newDetailedStatus = {MessagesSent: 1};
  chrome.invalidations.updateDetailedStatus(newDetailedStatus);
  expectEquals( $('internal-display').value, '{\n  \"MessagesSent\": 1\n}');
});