Commit 26f40744 authored by Kyle Milka's avatar Kyle Milka Committed by Commit Bot

[NTP] Separate custom backgrounds JS tests from general tests

Split existing tests for custom backgrounds out from general
SimpleJavascriptTests. These tests were never being run anways,
as they didn't start with 'test'.

Update local_ntp_browsertest.html with changes from local_ntp.html.

Bug: 857256
Change-Id: I251abfdc8aec75d896118d4ce0b251831b2bff43
Reviewed-on: https://chromium-review.googlesource.com/1184143
Commit-Queue: Kyle Milka <kmilka@chromium.org>
Reviewed-by: default avatarKristi Park <kristipark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#585245}
parent e711fc3c
......@@ -49,7 +49,7 @@ class LocalNTPJavascriptTest : public LocalNTPJavascriptTestBase {
// This runs a bunch of pure JS-side tests, i.e. those that don't require any
// interaction from the native side.
IN_PROC_BROWSER_TEST_F(LocalNTPJavascriptTest, SimpleJavascriptTests) {
IN_PROC_BROWSER_TEST_F(LocalNTPJavascriptTest, LocalNTPTests) {
content::WebContents* active_tab = local_ntp_test_utils::OpenNewTab(
browser(), GURL(chrome::kChromeUINewTabURL));
ASSERT_TRUE(search::IsInstantNTP(active_tab));
......@@ -61,6 +61,20 @@ IN_PROC_BROWSER_TEST_F(LocalNTPJavascriptTest, SimpleJavascriptTests) {
EXPECT_TRUE(success);
}
// This runs a bunch of pure JS-side tests for custom backgrounds, i.e. those
// that don't require any interaction from the native side.
IN_PROC_BROWSER_TEST_F(LocalNTPJavascriptTest, CustomBackgroundsTests) {
content::WebContents* active_tab = local_ntp_test_utils::OpenNewTab(
browser(), GURL(chrome::kChromeUINewTabURL));
ASSERT_TRUE(search::IsInstantNTP(active_tab));
// Run the tests.
bool success = false;
ASSERT_TRUE(instant_test_utils::GetBoolFromJS(
active_tab, "!!runSimpleTests('customBackgrounds')", &success));
EXPECT_TRUE(success);
}
// A test class that sets up voice_browsertest.html as the NTP URL. It's
// mostly a copy of the real local_ntp.html, but it adds some testing JS.
class LocalNTPVoiceJavascriptTest : public LocalNTPJavascriptTestBase {
......
// Copyright 2018 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.
/**
* @fileoverview Tests local NTP custom backgrounds.
*/
/**
* Local NTP's object for test and setup functions.
*/
test.customBackgrounds = {};
/**
* Sets up the page for each individual test.
*/
test.customBackgrounds.setUp = function() {
setUpPage('local-ntp-template');
};
// ******************************* SIMPLE TESTS *******************************
// These are run by runSimpleTests above.
// Functions from test_utils.js are automatically imported.
/**
* Tests that the edit custom background button is visible if both
* the flag is enabled and no custom theme is being used.
*/
test.customBackgrounds.testShowEditCustomBackground = function() {
// Turn off voice search to avoid reinitializing the speech object
configData.isVoiceSearchEnabled = false;
configData.isCustomBackgroundsEnabled = true;
getThemeBackgroundInfo = () => {return {usingDefaultTheme: true};};
initLocalNTP(/*isGooglePage=*/true);
assertTrue(elementIsVisible($('edit-bg')));
}
/**
* Tests that the edit custom background button is not visible if
* the flag is disabled.
*/
test.customBackgrounds.testHideEditCustomBackgroundFlag = function() {
// Turn off voice search to avoid reinitializing the speech object
configData.isVoiceSearchEnabled = false;
configData.isCustomBackgroundsEnabled = false;
initLocalNTP(/*isGooglePage=*/true);
assertFalse(elementIsVisible($('edit-bg')));
}
/**
* Tests that the edit custom background button is not visible if
* a custom theme is being used.
*/
test.customBackgrounds.testHideEditCustomBackgroundTheme = function() {
// Turn off voice search to avoid reinitializing the speech object
configData.isVoiceSearchEnabled = false;
getThemeBackgroundInfo = () => {return {usingDefaultTheme: false};};
initLocalNTP(/*isGooglePage=*/true);
assertFalse(elementIsVisible($('edit-bg')));
}
......@@ -14,6 +14,7 @@
<script src="chrome-search://local-ntp/custom-backgrounds.js" charset="utf-8"></script>
<script src="test_utils.js" charset="utf-8"></script>
<script src="local_ntp_browsertest.js" charset="utf-8"></script>
<script src="custom_backgrounds_browsertest.js" charset="utf-8"></script>
<template id="local-ntp-template">
<div id="custom-bg"></div>
<div id="ntp-contents">
......@@ -92,7 +93,12 @@
<div class="bg-option-img"></div>
<div id="edit-bg-upload-image-text" class="bg-option-text"></div>
</div>
<div id="edit-bg-restore-default" class="bg-option" tabindex="0">
<div id="edit-bg-divider"></div>
<div id="custom-links-restore-default" class="bg-option bg-option-disabled" tabindex="0">
<div class="bg-option-img"></div>
<div id="custom-links-restore-default-text" class="bg-option-text"></div>
</div>
<div id="edit-bg-restore-default" class="bg-option bg-option-disabled" tabindex="0">
<div class="bg-option-img"></div>
<div id="edit-bg-restore-default-text" class="bg-option-text"></div>
</div>
......
......@@ -99,61 +99,6 @@ test.localNtp.testMDNotApplied = function() {
assertFalse(document.body.classList.contains('md'));
}
/**
* Tests that the edit custom background button is visible if both
* the flag is enabled and no custom theme is being used.
*/
test.localNtp.showEditCustomBackground = function() {
// Turn off voice search to avoid reinitializing the speech object
configData.isVoiceSearchEnabled = false;
configData.isCustomBackgroundsEnabled = true;
getThemeBackgroundInfo = () => {return {usingDefaultTheme: true};};
initLocalNTP(/*isGooglePage=*/true);
assertTrue(elementIsVisible($('edit-bg')));
}
/**
* Tests that the edit custom background button is not visible if
* the flag is disabled.
*/
test.localNtp.hideEditCustomBackgroundFlag = function() {
// Turn off voice search to avoid reinitializing the speech object
configData.isVoiceSearchEnabled = false;
configData.isCustomBackgroundsEnabled = false;
initLocalNTP(/*isGooglePage=*/true);
assertFalse(elementIsVisible($('edit-bg')));
}
/**
* Tests that the edit custom background button is not visible if
* a custom theme is being used.
*/
test.localNtp.hideEditCustomBackgroundTheme = function() {
// Turn off voice search to avoid reinitializing the speech object
configData.isVoiceSearchEnabled = false;
getThemeBackgroundInfo = () => {return {usingDefaultTheme: false};};
initLocalNTP(/*isGooglePage=*/true);
assertFalse(elementIsVisible($('edit-bg')));
}
// ***************************** HELPER FUNCTIONS *****************************
// Helper functions used in tests.
/**
* Creates and initializes a LocalNTP object.
* @param {boolean} isGooglePage Whether to make it a Google-branded NTP.
*/
function initLocalNTP(isGooglePage) {
configData.isGooglePage = isGooglePage;
var localNTP = LocalNTP();
localNTP.disableIframesForTesting();
localNTP.init();
}
// ****************************** ADVANCED TESTS ******************************
// Advanced tests are controlled from the native side. The helpers here are
......
......@@ -190,6 +190,18 @@ function elementIsVisible(elem) {
}
/**
* Creates and initializes a LocalNTP object.
* @param {boolean} isGooglePage Whether to make it a Google-branded NTP.
*/
function initLocalNTP(isGooglePage) {
configData.isGooglePage = isGooglePage;
var localNTP = LocalNTP();
localNTP.disableIframesForTesting();
localNTP.init();
}
// ***************************** HELPER CLASSES *****************************
// Helper classes used for mocking in tests.
......
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