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.
7 * @fileoverview Tests the local NTP.
12 * Shortcut for document.getElementById.
13 * @param {string} id of the element.
14 * @return {HTMLElement} with the id.
17 return document
.getElementById(id
);
22 * Sets up for the next test case. Recreates the default local NTP DOM.
25 document
.body
.innerHTML
= '';
26 document
.body
.appendChild($('local-ntp-body').content
.cloneNode(true));
31 * Cleans up after test execution.
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.
41 function assert(condition
, opt_message
) {
43 throw new Error(opt_message
|| 'Assertion failed');
48 * @return {boolean} True if all tests pass and false otherwise.
52 for (var testName
in window
) {
53 if (/^test.+/.test(testName
) && typeof window
[testName
] == 'function') {
56 window
[testName
].call(window
);
59 window
.console
.log(testName
+ ' ' + err
);
69 * Tests that Google NTPs show a fakebox and logo.
71 function testShowsFakeboxAndLogoIfGoogle() {
72 var localNTP
= LocalNTP();
73 configData
.isGooglePage
= true;
81 * Tests that non-Google NTPs do not show a fakebox.
83 function testDoesNotShowFakeboxIfNotGoogle() {
84 var localNTP
= LocalNTP();
85 configData
.isGooglePage
= false;
87 assert(!$('fakebox'));
93 * Tests that clicking on a Most Visited link calls navigateContentWindow.
95 function testMostVisitedLinkCallsNavigateContentWindow() {
96 var ntpHandle
= chrome
.embeddedSearch
.newTabPage
;
97 var originalNavigateContentWindow
= ntpHandle
.navigateContentWindow
;
99 var navigateContentWindowCalls
= 0;
100 ntpHandle
.navigateContentWindow = function() {
101 navigateContentWindowCalls
++;
105 var href
= 'file:///some/local/file';
108 var provider
= 'foobar';
109 var link
= createMostVisitedLink(params
, href
, title
, text
, provider
);
113 ntpHandle
.navigateContentWindow
= originalNavigateContentWindow
;
114 assert(navigateContentWindowCalls
> 0);