Commit aa4dc039 authored by Tibor Goldschwendt's avatar Tibor Goldschwendt Committed by Chromium LUCI CQ

[ntp] Add tests for ModuleDescriptor

Tests ModuleDescriptor.initialize, which is the only function of that
class with non-trivial logic. Adding tests is a precursor to making
changes to that class in subsequent CLs.

Change-Id: Ib023f014f21e547bcbf38776781a95b6d83b3e2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2623653
Auto-Submit: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#842396}
parent 5ca86f30
// Copyright 2021 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.
import {BrowserProxy, ModuleDescriptor} from 'chrome://new-tab-page/new_tab_page.js';
import {createTestProxy} from 'chrome://test/new_tab_page/test_support.js';
suite('NewTabPageModulesModuleDescriptorTest', () => {
/**
* @implements {BrowserProxy}
* @extends {TestBrowserProxy}
*/
let testProxy;
setup(() => {
PolymerTest.clearBody();
testProxy = createTestProxy();
BrowserProxy.instance_ = testProxy;
});
test('instantiate module with data', async () => {
// Arrange.
const element = document.createElement('div');
const moduleDescriptor =
new ModuleDescriptor('foo', 100, () => Promise.resolve(element));
testProxy.setResultFor('now', 123);
// Act.
await moduleDescriptor.initialize();
// Assert.
assertEquals(element, moduleDescriptor.element);
const [id, now] = await testProxy.handler.whenCalled('onModuleLoaded');
assertEquals(1, testProxy.handler.getCallCount('onModuleLoaded'));
assertEquals('foo', id);
assertEquals(123, now);
});
test('instantiate module without data', async () => {
// Arrange.
const moduleDescriptor =
new ModuleDescriptor('foo', 100, () => Promise.resolve(null));
// Act.
await moduleDescriptor.initialize();
// Assert.
assertEquals(null, moduleDescriptor.element);
assertEquals(0, testProxy.handler.getCallCount('onModuleLoaded'));
});
});
...@@ -195,6 +195,19 @@ TEST_F('NewTabPageImgTest', 'All', function() { ...@@ -195,6 +195,19 @@ TEST_F('NewTabPageImgTest', 'All', function() {
mocha.run(); mocha.run();
}); });
// eslint-disable-next-line no-var
var NewTabPageModulesModuleDescriptorTest =
class extends NewTabPageBrowserTest {
/** @override */
get browsePreload() {
return 'chrome://new-tab-page/test_loader.html?module=new_tab_page/modules/module_descriptor_test.js';
}
};
TEST_F('NewTabPageModulesModuleDescriptorTest', 'All', function() {
mocha.run();
});
// eslint-disable-next-line no-var // eslint-disable-next-line no-var
var NewTabPageModulesModuleRegistryTest = class extends NewTabPageBrowserTest { var NewTabPageModulesModuleRegistryTest = class extends NewTabPageBrowserTest {
/** @override */ /** @override */
......
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