Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(346)

Unified Diff: chrome/test/data/local_ntp_browsertest.js

Issue 2691033004: [Local NTP] Add an integration test for the fakebox (Closed)
Patch Set: fix Mac Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/search/local_ntp_browsertest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/data/local_ntp_browsertest.js
diff --git a/chrome/test/data/local_ntp_browsertest.js b/chrome/test/data/local_ntp_browsertest.js
index 50028119b4a159aed3b89021929fb841fc3b129d..13bd93c5853527cb4c29136d4ab53d5ae1328e4c 100644
--- a/chrome/test/data/local_ntp_browsertest.js
+++ b/chrome/test/data/local_ntp_browsertest.js
@@ -22,15 +22,12 @@ function $(id) {
* Sets up for the next test case. Recreates the default local NTP DOM.
*/
function setUp() {
+ // First, clear up the DOM and state left over from any previous test case.
document.body.innerHTML = '';
- document.body.appendChild($('local-ntp-body').content.cloneNode(true));
-}
-
+ // The NTP stores some state such as fakebox focus in the body's classList.
+ document.body.classList = '';
-/**
- * Cleans up after test execution.
- */
-function tearDown() {
+ document.body.appendChild($('local-ntp-body').content.cloneNode(true));
}
/**
@@ -44,17 +41,17 @@ function assert(condition, opt_message) {
}
/**
- * Runs all tests.
+ * Runs all simple tests, i.e. those that don't require interaction from the
+ * native side.
* @return {boolean} True if all tests pass and false otherwise.
*/
-function runTests() {
+function runSimpleTests() {
var pass = true;
for (var testName in window) {
if (/^test.+/.test(testName) && typeof window[testName] == 'function') {
try {
setUp();
window[testName].call(window);
- tearDown();
} catch (err) {
window.console.log(testName + ' ' + err);
pass = false;
@@ -66,22 +63,36 @@ function runTests() {
/**
+ * 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.init();
+}
+
+
+/**
* Checks whether a given HTMLElement exists and is visible.
* @param {HTMLElement|undefined} elem An HTMLElement.
* @return {boolean} True if the element exists and is visible.
*/
function elementIsVisible(elem) {
- return elem && elem.offsetWidth > 0 && elem.offsetHeight > 0;
+ return elem && elem.offsetWidth > 0 && elem.offsetHeight > 0 &&
+ window.getComputedStyle(elem).visibility != 'hidden';
}
+// ******************************* SIMPLE TESTS *******************************
+// These are run by runSimpleTests above.
+
+
/**
* Tests that Google NTPs show a fakebox and logo.
*/
function testShowsFakeboxAndLogoIfGoogle() {
- var localNTP = LocalNTP();
- configData.isGooglePage = true;
- localNTP.init();
+ initLocalNTP(/*isGooglePage=*/true);
assert(elementIsVisible($('fakebox')));
assert(elementIsVisible($('logo')));
}
@@ -91,9 +102,43 @@ function testShowsFakeboxAndLogoIfGoogle() {
* Tests that non-Google NTPs do not show a fakebox.
*/
function testDoesNotShowFakeboxIfNotGoogle() {
- var localNTP = LocalNTP();
- configData.isGooglePage = false;
- localNTP.init();
+ initLocalNTP(/*isGooglePage=*/false);
assert(!elementIsVisible($('fakebox')));
assert(!elementIsVisible($('logo')));
}
+
+
+
+// ****************************** ADVANCED TESTS ******************************
+// Advanced tests are controlled from the native side. The helpers here are
+// called from native code to set up the page and to check results.
+
+function setupAdvancedTest() {
+ setUp();
+ initLocalNTP(/*isGooglePage=*/true);
+
+ assert(elementIsVisible($('fakebox')));
+
+ return true;
+}
+
+function getFakeboxPositionX() {
+ assert(elementIsVisible($('fakebox')));
+ var rect = $('fakebox').getBoundingClientRect();
+ return rect.left;
+}
+
+function getFakeboxPositionY() {
+ assert(elementIsVisible($('fakebox')));
+ var rect = $('fakebox').getBoundingClientRect();
+ return rect.top;
+}
+
+function fakeboxIsVisible() {
+ return elementIsVisible($('fakebox'));
+}
+
+function fakeboxIsFocused() {
+ return fakeboxIsVisible() &&
+ document.body.classList.contains('fakebox-focused');
+}
« no previous file with comments | « chrome/browser/ui/search/local_ntp_browsertest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698