summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/local_ntp_browsertest.js
blob: 57f5b7ba72a18ae2bfdfd256f0f63378ecafad6d (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
// Copyright 2013 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.


/**
 * @fileoverview Tests the local NTP.
 */


/**
 * Shortcut for document.getElementById.
 * @param {string} id of the element.
 * @return {HTMLElement} with the id.
 */
function $(id) {
  return document.getElementById(id);
}


/**
 * Sets up for the next test case. Recreates the default local NTP DOM.
 */
function setUp() {
  document.body.innerHTML = '';
  document.body.appendChild($('local-ntp-body').content.cloneNode(true));
}


/**
 * Cleans up after test execution.
 */
function tearDown() {
}

/**
 * Aborts a test if a condition is not met.
 * @param {boolean} condition The condition that must be true.
 * @param {string=} opt_message A message to log if the condition is not met.
 */
function assert(condition, opt_message) {
  if (!condition)
    throw new Error(opt_message || 'Assertion failed');
}

/**
 * Runs all tests.
 * @return {boolean} True if all tests pass and false otherwise.
 */
function runTests() {
  var pass = true;
  for (var testName in window) {
    if (/^test.+/.test(testName) && typeof window[testName] == 'function') {
      try {
        setUp();
        window[testName].call(window);
        tearDown();
      } catch (err) {
        window.console.log(testName + ' ' + err);
        pass = false;
      }
    }
  }
  return pass;
}


/**
 * Tests that Google NTPs show a fakebox and logo.
 */
function testShowsFakeboxAndLogoIfGoogle() {
  var localNTP = LocalNTP();
  configData.isGooglePage = true;
  localNTP.init();
  assert($('fakebox'));
  assert($('logo'));
}


/**
 * Tests that non-Google NTPs do not show a fakebox.
 */
function testDoesNotShowFakeboxIfNotGoogle() {
  var localNTP = LocalNTP();
  configData.isGooglePage = false;
  localNTP.init();
  assert(!$('fakebox'));
  assert(!$('logo'));
}