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