Commit b53e3fd1 authored by danhn@chromium.org's avatar danhn@chromium.org

Ported NTP4 UI tests to WebUI.


This CL moves UI tests from the patch off issue 9420040 to WebUI testing framework.


TEST=browser_tests --gtest_filter=NTP4*WebUITest*
     ui_tests --gtest_filter=NewTabUI*


Review URL: http://codereview.chromium.org/9625020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@126965 0039d316-1c4b-4281-b951-d872f2087c98
parent 7adee63b
...@@ -4,101 +4,30 @@ ...@@ -4,101 +4,30 @@
#include "chrome/test/ui/ui_test.h" #include "chrome/test/ui/ui_test.h"
#include "base/memory/ref_counted.h"
#include "base/test/test_timeouts.h" #include "base/test/test_timeouts.h"
#include "chrome/app/chrome_command_ids.h" #include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/prefs/pref_value_store.h"
#include "chrome/browser/signin/signin_manager.h"
#include "chrome/browser/ui/webui/ntp/new_tab_ui.h" #include "chrome/browser/ui/webui/ntp/new_tab_ui.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
#include "chrome/common/json_pref_store.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/test/automation/automation_proxy.h" #include "chrome/test/automation/automation_proxy.h"
#include "chrome/test/automation/browser_proxy.h" #include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h" #include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/window_proxy.h" #include "googleurl/src/gurl.h"
#include "chrome/test/base/testing_pref_service.h"
class NewTabUITest : public UITest { class NewTabUITest : public UITest {
public: public:
NewTabUITest() { NewTabUITest() {
dom_automation_enabled_ = true; dom_automation_enabled_ = true;
// Set home page to the empty string so that we can set the home page using
// preferences.
set_homepage("");
// Setup the DEFAULT_THEME profile (has fake history entries). // Setup the DEFAULT_THEME profile (has fake history entries).
set_template_user_data(UITest::ComputeTypicalUserDataSource( set_template_user_data(UITest::ComputeTypicalUserDataSource(
UITestBase::DEFAULT_THEME)); UITestBase::DEFAULT_THEME));
} }
}; };
#if defined(OS_WIN) // Bug 87200: Disable ChromeHangInNTP for Windows and ChromeOS
// Bug 87200: Disable NTPHasThumbnails for Windows #if defined(OS_WIN) || defined(OS_CHROMEOS)
#define MAYBE_NTPHasThumbnails DISABLED_NTPHasThumbnails
#elif defined(OS_LINUX)
// This test is flaky on Linux and CrOS: http://crbug/30367
#define MAYBE_NTPHasThumbnails DISABLED_NTPHasThumbnails
#elif defined(OS_MACOSX)
// Acting flaky on Mac: http://crbug.com/87200
#define MAYBE_NTPHasThumbnails DISABLED_NTPHasThumbnails
#else
#define MAYBE_NTPHasThumbnails NTPHasThumbnails
#endif
TEST_F(NewTabUITest, MAYBE_NTPHasThumbnails) {
// Switch to the "new tab" tab, which should be any new tab after the
// first (the first is about:blank).
scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
ASSERT_TRUE(window.get());
// Bring up a new tab page.
ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB));
scoped_refptr<TabProxy> tab = window->GetActiveTab();
ASSERT_TRUE(tab.get());
// TopSites should return at least 3 non-filler pages.
// 8 - 3 = max 5 filler pages.
ASSERT_TRUE(WaitUntilJavaScriptCondition(tab, L"",
L"window.domAutomationController.send("
L"document.getElementsByClassName('filler').length <= 5)",
TestTimeouts::action_max_timeout_ms()));
}
// Sometimes hangs: http://crbug.com/70157
TEST_F(NewTabUITest, DISABLED_NTPHasLoginName) {
scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
ASSERT_TRUE(window.get());
ASSERT_TRUE(window->SetStringPreference(prefs::kGoogleServicesUsername,
"user@gmail.com"));
// Bring up a new tab page.
ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB));
scoped_refptr<TabProxy> tab = window->GetActiveTab();
ASSERT_TRUE(tab.get());
std::wstring displayed_username;
// The login span should be eventually populated and have the
// correct value.
ASSERT_TRUE(WaitUntilJavaScriptCondition(tab, L"",
L"window.domAutomationController.send("
L"document.getElementById('login-username').innerText.length > 0)",
TestTimeouts::action_max_timeout_ms()));
ASSERT_TRUE(tab->ExecuteAndExtractString(
L"",
L"window.domAutomationController.send("
L"document.getElementById('login-username').innerText)",
&displayed_username));
EXPECT_EQ(L"user@gmail.com", displayed_username);
}
// Bug 87200: Disable ChromeHangInNTP for Windows
#if defined(OS_WIN)
#define MAYBE_ChromeHangInNTP DISABLED_ChromeHangInNTP
#elif defined(OS_CHROMEOS)
#define MAYBE_ChromeHangInNTP DISABLED_ChromeHangInNTP #define MAYBE_ChromeHangInNTP DISABLED_ChromeHangInNTP
#elif defined(OS_MACOSX) #elif defined(OS_MACOSX)
// Acting flaky on Mac: http://crbug.com/87200 // Acting flaky on Mac: http://crbug.com/87200
......
...@@ -2858,8 +2858,10 @@ ...@@ -2858,8 +2858,10 @@
'test/data/webui/net_internals/test_view.js', 'test/data/webui/net_internals/test_view.js',
'test/data/webui/net_internals/timeline_view.js', 'test/data/webui/net_internals/timeline_view.js',
'test/data/webui/ntp4.js', 'test/data/webui/ntp4.js',
'test/data/webui/print_preview.h', 'test/data/webui/ntp4_browsertest.cc',
'test/data/webui/ntp4_browsertest.h',
'test/data/webui/print_preview.cc', 'test/data/webui/print_preview.cc',
'test/data/webui/print_preview.h',
'test/data/webui/print_preview.js', 'test/data/webui/print_preview.js',
'test/gpu/gpu_feature_browsertest.cc', 'test/gpu/gpu_feature_browsertest.cc',
'test/ui/ppapi_uitest.cc', 'test/ui/ppapi_uitest.cc',
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
GEN('#include "chrome/test/data/webui/ntp4_browsertest.h"');
/** /**
* TestFixture for NTP4 WebUI testing. * TestFixture for NTP4 WebUI testing.
* @extends {testing.Test} * @extends {testing.Test}
...@@ -12,20 +14,83 @@ function NTP4WebUITest() {} ...@@ -12,20 +14,83 @@ function NTP4WebUITest() {}
NTP4WebUITest.prototype = { NTP4WebUITest.prototype = {
__proto__: testing.Test.prototype, __proto__: testing.Test.prototype,
/** /** @override */
* Browse to the newtab page & call preLoad().
*/
browsePreload: 'chrome://newtab', browsePreload: 'chrome://newtab',
}; };
// Test loading new tab page and selecting each card doesn't have console // Test loading new tab page and selecting each card doesn't have console
// errors. // errors.
TEST_F('NTP4WebUITest', 'TestBrowsePages', function() { TEST_F('NTP4WebUITest', 'TestBrowsePages', function() {
// This tests the ntp4 new tab page which is not used on touch builds. // This tests the ntp4 new tab page which is not used on touch builds.
var cardSlider = ntp.getCardSlider(); var cardSlider = ntp.getCardSlider();
assertNotEquals(null, cardSlider); assertNotEquals(null, cardSlider);
for (var i = 0; i < cardSlider.cardCount; ++i) { for (var i = 0; i < cardSlider.cardCount; i++) {
cardSlider.selectCard(i); cardSlider.selectCard(i);
expectEquals(i, cardSlider.currentCard); expectEquals(i, cardSlider.currentCard);
} }
}); });
TEST_F('NTP4WebUITest', 'NTPHasThumbnails', function() {
var mostVisited = document.querySelectorAll('.most-visited');
assertEquals(8, mostVisited.length, 'There should be 8 most visited tiles.');
var apps = document.querySelectorAll('.app');
if (window.templateData.showApps)
assertGE(apps.length, 1, 'There should be at least one app.');
else
assertEquals(0, apps.length, 'There should be no apps.');
});
TEST_F('NTP4WebUITest', 'NTPHasNavDots', function() {
var navDots = document.querySelectorAll('.dot');
if (window.templateData.showApps)
assertGE(navDots.length, 2, 'There should be at least two navdots.');
else
assertEquals(1, navDots.length, 'There should be exactly one navdot.');
});
TEST_F('NTP4WebUITest', 'NTPHasSelectedPageAndDot', function() {
var selectedDot = document.querySelectorAll('.dot.selected');
assertEquals(1, selectedDot.length,
'There should be exactly one selected dot.');
var selectedTilePage = document.querySelectorAll('.tile-page.selected-card');
assertEquals(1, selectedTilePage.length,
'There should be exactly one selected tile page.');
});
TEST_F('NTP4WebUITest', 'NTPHasNoLoginNameWhenSignedOut', function() {
var userName = document.querySelector('#login-status-header .profile-name');
assertEquals(null, userName, 'Login name shouldn\'t exist when signed out.');
});
/**
* Test fixture for NTP4 WebUI testing with login.
* @extends {NTP4WebUITest}
* @constructor
*/
function NTP4LoggedInWebUITest() {}
NTP4LoggedInWebUITest.prototype = {
__proto__: NTP4WebUITest.prototype,
/** @override */
typedefCppFixture: 'NTP4LoggedInWebUITest',
/** @override */
testGenPreamble: function() {
GEN(' SetLoginName("user@gmail.com");');
},
};
// The following test is irrelevant to Chrome on Chrome OS.
GEN('#if !defined(OS_CHROMEOS)');
TEST_F('NTP4LoggedInWebUITest', 'NTPHasLoginNameWhenSignedIn', function() {
var userName = document.querySelector('#login-status-header .profile-name');
assertNotEquals(userName, null, 'The logged-in user name can\'t be found.');
assertEquals('user@gmail.com', userName.textContent,
'The user name should be present on the new tab.');
});
GEN('#endif');
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/data/webui/ntp4_browsertest.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
NTP4LoggedInWebUITest::NTP4LoggedInWebUITest() {}
NTP4LoggedInWebUITest::~NTP4LoggedInWebUITest() {}
void NTP4LoggedInWebUITest::SetLoginName(const std::string& name) {
browser()->profile()->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
name);
}
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_TEST_DATA_WEBUI_NTP4_BROWSERTEST_H_
#define CHROME_TEST_DATA_WEBUI_NTP4_BROWSERTEST_H_
#pragma once
#include "chrome/browser/ui/webui/web_ui_browsertest.h"
class NTP4LoggedInWebUITest : public WebUIBrowserTest {
public:
NTP4LoggedInWebUITest();
virtual ~NTP4LoggedInWebUITest();
protected:
// Sets the user name in the profile as if the user had logged in.
void SetLoginName(const std::string& name);
private:
DISALLOW_COPY_AND_ASSIGN(NTP4LoggedInWebUITest);
};
#endif // CHROME_TEST_DATA_WEBUI_NTP4_BROWSERTEST_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment