Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / chrome / test / data / local_ntp_browsertest.js
bloba7b6640cd5818a77e862d4e0cb4bd7cdd00ceb7a
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.
6 /**
7 * @fileoverview Tests the local NTP.
8 */
11 /**
12 * Shortcut for document.getElementById.
13 * @param {string} id of the element.
14 * @return {HTMLElement} with the id.
16 function $(id) {
17 return document.getElementById(id);
21 /**
22 * Sets up for the next test case. Recreates the default local NTP DOM.
24 function setUp() {
25 document.body.innerHTML = '';
26 document.body.appendChild($('local-ntp-body').content.cloneNode(true));
30 /**
31 * Cleans up after test execution.
33 function tearDown() {
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.
41 function assert(condition, opt_message) {
42 if (!condition)
43 throw new Error(opt_message || 'Assertion failed');
46 /**
47 * Runs all tests.
48 * @return {boolean} True if all tests pass and false otherwise.
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;
64 return pass;
68 /**
69 * Tests that Google NTPs show a fakebox and logo.
71 function testShowsFakeboxAndLogoIfGoogle() {
72 var localNTP = LocalNTP();
73 configData.isGooglePage = true;
74 localNTP.init();
75 assert($('fakebox'));
76 assert($('logo'));
80 /**
81 * Tests that non-Google NTPs do not show a fakebox.
83 function testDoesNotShowFakeboxIfNotGoogle() {
84 var localNTP = LocalNTP();
85 configData.isGooglePage = false;
86 localNTP.init();
87 assert(!$('fakebox'));
88 assert(!$('logo'));
92 /**
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++;
104 var params = {};
105 var href = 'file:///some/local/file';
106 var title = 'Title';
107 var text = 'text';
108 var provider = 'foobar';
109 var link = createMostVisitedLink(params, href, title, text, provider);
111 link.click();
113 ntpHandle.navigateContentWindow = originalNavigateContentWindow;
114 assert(navigateContentWindowCalls > 0);