- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / local_ntp_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 /**
7  * @fileoverview Tests the local NTP.
8  */
9
10
11 /**
12  * Shortcut for document.getElementById.
13  * @param {string} id of the element.
14  * @return {HTMLElement} with the id.
15  */
16 function $(id) {
17   return document.getElementById(id);
18 }
19
20
21 /**
22  * Sets up for the next test case. Recreates the default local NTP DOM.
23  */
24 function setUp() {
25   document.body.innerHTML = '';
26   document.body.appendChild($('local-ntp-body').content.cloneNode(true));
27 }
28
29
30 /**
31  * Cleans up after test execution.
32  */
33 function tearDown() {
34 }
35
36 /**
37  * Aborts a test if a condition is not met.
38  * @param {boolean} condition The condition that must be true.
39  * @param {string=} opt_message A message to log if the condition is not met.
40  */
41 function assert(condition, opt_message) {
42   if (!condition)
43     throw new Error(opt_message || 'Assertion failed');
44 }
45
46 /**
47  * Runs all tests.
48  * @return {boolean} True if all tests pass and false otherwise.
49  */
50 function runTests() {
51   var pass = true;
52   for (var testName in window) {
53     if (/^test.+/.test(testName) && typeof window[testName] == 'function') {
54       try {
55         setUp();
56         window[testName].call(window);
57         tearDown();
58       } catch (err) {
59         window.console.log(testName + ' ' + err);
60         pass = false;
61       }
62     }
63   }
64   return pass;
65 }
66
67
68 /**
69  * Tests that Google NTPs show a fakebox and logo.
70  */
71 function testShowsFakeboxAndLogoIfGoogle() {
72   var localNTP = LocalNTP();
73   configData.isGooglePage = true;
74   localNTP.init();
75   assert($('fakebox'));
76   assert($('logo'));
77 }
78
79
80 /**
81  * Tests that non-Google NTPs do not show a fakebox.
82  */
83 function testDoesNotShowFakeboxIfNotGoogle() {
84   var localNTP = LocalNTP();
85   configData.isGooglePage = false;
86   localNTP.init();
87   assert(!$('fakebox'));
88   assert(!$('logo'));
89 }