- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / test / data / webui / ntp4.js
1 // Copyright (c) 2012 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 GEN('#include "chrome/test/data/webui/ntp4_browsertest.h"');
6
7 /**
8  * TestFixture for NTP4 WebUI testing.
9  * @extends {testing.Test}
10  * @constructor
11  */
12 function NTP4WebUITest() {}
13
14 NTP4WebUITest.prototype = {
15   __proto__: testing.Test.prototype,
16
17   /** @override */
18   browsePreload: 'chrome://newtab',
19 };
20
21 // Test loading new tab page and selecting each card doesn't have console
22 // errors.
23 TEST_F('NTP4WebUITest', 'TestBrowsePages', function() {
24   // This tests the ntp4 new tab page which is not used on touch builds.
25   var cardSlider = ntp.getCardSlider();
26   assertNotEquals(null, cardSlider);
27   for (var i = 0; i < cardSlider.cardCount; i++) {
28     cardSlider.selectCard(i);
29     expectEquals(i, cardSlider.currentCard);
30   }
31 });
32
33 // http://crbug.com/118944
34 TEST_F('NTP4WebUITest', 'DISABLED_NTPHasThumbnails', function() {
35   var mostVisited = document.querySelectorAll('.most-visited');
36   assertEquals(8, mostVisited.length, 'There should be 8 most visited tiles.');
37
38   var apps = document.querySelectorAll('.app');
39   if (loadTimeData.getBoolean('showApps'))
40     assertGE(apps.length, 1, 'There should be at least one app.');
41   else
42     assertEquals(0, apps.length, 'There should be no apps.');
43 });
44
45 TEST_F('NTP4WebUITest', 'NTPHasNavDots', function() {
46   var navDots = document.querySelectorAll('.dot');
47   if (loadTimeData.getBoolean('showApps'))
48     assertGE(navDots.length, 2, 'There should be at least two navdots.');
49   else
50     assertEquals(1, navDots.length, 'There should be exactly one navdot.');
51 });
52
53 // http://crbug.com/118514
54 TEST_F('NTP4WebUITest', 'DISABLED_NTPHasSelectedPageAndDot', function() {
55   var selectedDot = document.querySelectorAll('.dot.selected');
56   assertEquals(1, selectedDot.length,
57                'There should be exactly one selected dot.');
58
59   var selectedTilePage = document.querySelectorAll('.tile-page.selected-card');
60   assertEquals(1, selectedTilePage.length,
61                'There should be exactly one selected tile page.');
62 });
63
64 TEST_F('NTP4WebUITest', 'NTPHasNoLoginNameWhenSignedOut', function() {
65   var userName = document.querySelector('#login-status-header .profile-name');
66   assertEquals(null, userName, 'Login name shouldn\'t exist when signed out.');
67 });
68
69 /**
70  * Test fixture for NTP4 WebUI testing with login.
71  * @extends {NTP4WebUITest}
72  * @constructor
73  */
74 function NTP4LoggedInWebUITest() {}
75
76 NTP4LoggedInWebUITest.prototype = {
77   __proto__: NTP4WebUITest.prototype,
78
79   /** @override */
80   typedefCppFixture: 'NTP4LoggedInWebUITest',
81
82   /** @override */
83   testGenPreamble: function() {
84     GEN('  SetLoginName("user@gmail.com");');
85   },
86 };
87
88 // The following test is irrelevant to Chrome on Chrome OS.
89 GEN('#if !defined(OS_CHROMEOS)');
90
91 TEST_F('NTP4LoggedInWebUITest', 'NTPHasLoginNameWhenSignedIn', function() {
92   var userName = document.querySelector('#login-status-header .profile-name');
93   assertNotEquals(userName, null, 'The logged-in user name can\'t be found.');
94   assertEquals('user@gmail.com', userName.textContent,
95                'The user name should be present on the new tab.');
96 });
97
98 GEN('#endif');