Commit 6724f2b6 authored by Tibor Goldschwendt's avatar Tibor Goldschwendt Committed by Commit Bot

[webui][ntp] Mock out doodle iframe in tests

NewTabPageLogoTest.All was disabled for flakiness. Likely, because we
embed iframes that do not finish or fail to load. However, it is not
material to the test whether the iframe loads. <ntp-untrusted-iframe>
provides capability to mock out loading. Therefore, make
<ntp-untrusted-iframe> usable for non-chrome-untrusted URL and use it
for the doodle iframe.

Fixed: 1097035
Change-Id: Ic1008278b957da2873f7e1b2ed56a0c90bbb5707
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2261716
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Auto-Submit: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarEsmael Elmoslimany <aee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#781711}
parent ec1cd75d
...@@ -17,6 +17,7 @@ js_type_check("closure_compile") { ...@@ -17,6 +17,7 @@ js_type_check("closure_compile") {
":doodle_share_dialog", ":doodle_share_dialog",
":fakebox", ":fakebox",
":grid", ":grid",
":iframe",
":logo", ":logo",
":realbox", ":realbox",
":realbox_button", ":realbox_button",
...@@ -24,7 +25,6 @@ js_type_check("closure_compile") { ...@@ -24,7 +25,6 @@ js_type_check("closure_compile") {
":realbox_icon", ":realbox_icon",
":realbox_match", ":realbox_match",
":theme_icon", ":theme_icon",
":untrusted_iframe",
":utils", ":utils",
":voice_search_overlay", ":voice_search_overlay",
] ]
...@@ -131,7 +131,7 @@ js_library("voice_search_overlay") { ...@@ -131,7 +131,7 @@ js_library("voice_search_overlay") {
js_library("utils") { js_library("utils") {
} }
js_library("untrusted_iframe") { js_library("iframe") {
deps = [ deps = [
"//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled", "//third_party/polymer/v3_0/components-chromium/polymer:polymer_bundled",
] ]
...@@ -229,7 +229,7 @@ html_to_js("web_components") { ...@@ -229,7 +229,7 @@ html_to_js("web_components") {
"realbox_match.js", "realbox_match.js",
"realbox.js", "realbox.js",
"theme_icon.js", "theme_icon.js",
"untrusted_iframe.js", "iframe.js",
"voice_search_overlay.js", "voice_search_overlay.js",
] ]
} }
......
...@@ -235,13 +235,11 @@ ...@@ -235,13 +235,11 @@
--ntp-theme-shortcut-background-color: --ntp-theme-shortcut-background-color:
[[rgbaOrInherit_(theme_.shortcutBackgroundColor)]]; [[rgbaOrInherit_(theme_.shortcutBackgroundColor)]];
--ntp-logo-color: [[rgbaOrInherit_(logoColor_)]];"> --ntp-logo-color: [[rgbaOrInherit_(logoColor_)]];">
<dom-if if="[[showIframedOneGoogleBar_]]"> <template is="dom-if" if="[[showIframedOneGoogleBar_]]">
<template> <ntp-iframe id="oneGoogleBar" src="[[oneGoogleBarIframePath_]]"
<ntp-untrusted-iframe id="oneGoogleBar" path="[[oneGoogleBarIframePath_]]" hidden$="[[!oneGoogleBarLoaded_]]">
hidden$="[[!oneGoogleBarLoaded_]]"> </ntp-iframe>
</ntp-untrusted-iframe> </template>
</template>
</dom-if>
<ntp-logo id="logo" doodle-allowed$="[[doodleAllowed_]]" <ntp-logo id="logo" doodle-allowed$="[[doodleAllowed_]]"
single-colored$="[[singleColoredLogo_]]" dark="[[theme_.isDark]]" single-colored$="[[singleColoredLogo_]]" dark="[[theme_.isDark]]"
background-color="[[backgroundColor_]]"> background-color="[[backgroundColor_]]">
...@@ -259,8 +257,9 @@ ...@@ -259,8 +257,9 @@
</ntp-most-visited> </ntp-most-visited>
<dom-if if="[[lazyRender_]]"> <dom-if if="[[lazyRender_]]">
<template> <template>
<ntp-untrusted-iframe id="promo" path="promo" hidden$="[[!promoLoaded_]]"> <ntp-iframe id="promo" hidden$="[[!promoLoaded_]]"
</ntp-untrusted-iframe> src="chrome-untrusted://new-tab-page/promo">
</ntp-iframe>
<a id="backgroundImageAttribution" <a id="backgroundImageAttribution"
href="[[backgroundImageAttributionUrl_]]" href="[[backgroundImageAttributionUrl_]]"
hidden="[[!backgroundImageAttribution1_]]"> hidden="[[!backgroundImageAttribution1_]]">
......
...@@ -6,7 +6,7 @@ import './strings.m.js'; ...@@ -6,7 +6,7 @@ import './strings.m.js';
import './most_visited.js'; import './most_visited.js';
import './customize_dialog.js'; import './customize_dialog.js';
import './voice_search_overlay.js'; import './voice_search_overlay.js';
import './untrusted_iframe.js'; import './iframe.js';
import './fakebox.js'; import './fakebox.js';
import './realbox.js'; import './realbox.js';
import './logo.js'; import './logo.js';
...@@ -64,7 +64,7 @@ class AppElement extends PolymerElement { ...@@ -64,7 +64,7 @@ class AppElement extends PolymerElement {
params.set( params.set(
'paramsencoded', 'paramsencoded',
btoa(window.location.search.replace(/^[?]/, '&'))); btoa(window.location.search.replace(/^[?]/, '&')));
return `one-google-bar?${params}`; return `chrome-untrusted://new-tab-page/one-google-bar?${params}`;
}, },
}, },
......
...@@ -59,11 +59,11 @@ export class BrowserProxy { ...@@ -59,11 +59,11 @@ export class BrowserProxy {
} }
/** /**
* @param {string} path * @param {string} src
* @return {string} * @return {string}
*/ */
createUntrustedIframeSrc(path) { createIframeSrc(src) {
return `chrome-untrusted://new-tab-page/${path}`; return src;
} }
/** /**
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
outline-width: 0; outline-width: 0;
} }
ntp-untrusted-iframe { ntp-iframe {
pointer-events: none; pointer-events: none;
} }
...@@ -196,9 +196,9 @@ ...@@ -196,9 +196,9 @@
<template> <template>
<div class="tile" tabindex="0" title="[[item.label]]" role="button" <div class="tile" tabindex="0" title="[[item.label]]" role="button"
on-click="onCollectionClick_"> on-click="onCollectionClick_">
<ntp-untrusted-iframe class="image" <ntp-iframe class="image"
path="background_image?[[item.previewImageUrl.url]]"> src="chrome-untrusted://new-tab-page/background_image?[[item.previewImageUrl.url]]">
</ntp-untrusted-iframe> </ntp-iframe>
<div class="label">[[item.label]]</div> <div class="label">[[item.label]]</div>
</div> </div>
</template> </template>
...@@ -212,9 +212,9 @@ ...@@ -212,9 +212,9 @@
[[getImageSelectedClass_(index, theme, backgroundSelection)]]" [[getImageSelectedClass_(index, theme, backgroundSelection)]]"
tabindex="0" title="[[item.attribution1]]" role="button" tabindex="0" title="[[item.attribution1]]" role="button"
on-click="onImageClick_"> on-click="onImageClick_">
<ntp-untrusted-iframe class="image" <ntp-iframe class="image"
path="background_image?[[item.previewImageUrl.url]]"> src="chrome-untrusted://new-tab-page/background_image?[[item.previewImageUrl.url]]">
</ntp-untrusted-iframe> </ntp-iframe>
<div class="selected-circle"></div> <div class="selected-circle"></div>
<div class="selected-check"></div> <div class="selected-check"></div>
</div> </div>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
import 'chrome://resources/cr_elements/hidden_style_css.m.js'; import 'chrome://resources/cr_elements/hidden_style_css.m.js';
import './grid.js'; import './grid.js';
import './mini_page.js'; import './mini_page.js';
import './untrusted_iframe.js'; import './iframe.js';
import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js'; import {loadTimeData} from 'chrome://resources/js/load_time_data.m.js';
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
......
...@@ -5,9 +5,14 @@ ...@@ -5,9 +5,14 @@
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import {BrowserProxy} from './browser_proxy.js'; import {BrowserProxy} from './browser_proxy.js';
class UntrustedIframeElement extends PolymerElement { /**
* @fileoverview Wrapper around <iframe> element that lets us mock out loading
* and postMessaging in tests.
*/
class IframeElement extends PolymerElement {
static get is() { static get is() {
return 'ntp-untrusted-iframe'; return 'ntp-iframe';
} }
static get template() { static get template() {
...@@ -17,7 +22,7 @@ class UntrustedIframeElement extends PolymerElement { ...@@ -17,7 +22,7 @@ class UntrustedIframeElement extends PolymerElement {
static get properties() { static get properties() {
return { return {
/** @type {string} */ /** @type {string} */
path: { src: {
reflectToAttribute: true, reflectToAttribute: true,
type: String, type: String,
}, },
...@@ -25,7 +30,7 @@ class UntrustedIframeElement extends PolymerElement { ...@@ -25,7 +30,7 @@ class UntrustedIframeElement extends PolymerElement {
/** @private */ /** @private */
src_: { src_: {
type: String, type: String,
computed: 'computeSrc_(path)', computed: 'computeSrc_(src)',
}, },
}; };
} }
...@@ -35,14 +40,17 @@ class UntrustedIframeElement extends PolymerElement { ...@@ -35,14 +40,17 @@ class UntrustedIframeElement extends PolymerElement {
* @param {*} message * @param {*} message
*/ */
postMessage(message) { postMessage(message) {
this.$.iframe.contentWindow.postMessage( BrowserProxy.getInstance().postMessage(
message, 'chrome-untrusted://new-tab-page'); this.$.iframe, message, new URL(this.src).origin);
} }
/** @private */ /**
* @return {string}
* @private
*/
computeSrc_() { computeSrc_() {
return BrowserProxy.getInstance().createUntrustedIframeSrc(this.path); return BrowserProxy.getInstance().createIframeSrc(this.src);
} }
} }
customElements.define(UntrustedIframeElement.is, UntrustedIframeElement); customElements.define(IframeElement.is, IframeElement);
...@@ -121,9 +121,9 @@ ...@@ -121,9 +121,9 @@
when starting the animation. --> when starting the animation. -->
<img id="image" src="[[imageUrl_]]" on-load="onImageLoad_"> <img id="image" src="[[imageUrl_]]" on-load="onImageLoad_">
</img> </img>
<ntp-untrusted-iframe id="animation" path="[[animationUrl_]]" <ntp-iframe id="animation" src="[[animationUrl_]]"
hidden="[[!showAnimation_]]"> hidden="[[!showAnimation_]]">
</ntp-untrusted-iframe> </ntp-iframe>
<cr-button id="shareButton" title="$i18n{shareDoodle}" <cr-button id="shareButton" title="$i18n{shareDoodle}"
on-click="onShareButtonClick_"> on-click="onShareButtonClick_">
<img id="shareButtonImage" <img id="shareButtonImage"
...@@ -133,7 +133,7 @@ ...@@ -133,7 +133,7 @@
</div> </div>
</div> </div>
<template is="dom-if" if="[[iframeUrl_]]" restamp> <template is="dom-if" if="[[iframeUrl_]]" restamp>
<iframe id="iframe" src="[[iframeUrl_]]"></iframe> <ntp-iframe id="iframe" src="[[iframeUrl_]]"></ntp-iframe>
</template> </template>
</div> </div>
</template> </template>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import 'chrome://resources/cr_elements/cr_button/cr_button.m.js'; import 'chrome://resources/cr_elements/cr_button/cr_button.m.js';
import 'chrome://resources/cr_elements/hidden_style_css.m.js'; import 'chrome://resources/cr_elements/hidden_style_css.m.js';
import './untrusted_iframe.js'; import './iframe.js';
import './doodle_share_dialog.js'; import './doodle_share_dialog.js';
import {assert} from 'chrome://resources/js/assert.m.js'; import {assert} from 'chrome://resources/js/assert.m.js';
...@@ -383,14 +383,7 @@ class LogoElement extends PolymerElement { ...@@ -383,14 +383,7 @@ class LogoElement extends PolymerElement {
this.dark === undefined || !iframe) { this.dark === undefined || !iframe) {
return; return;
} }
BrowserProxy.getInstance().postMessage( iframe.postMessage({cmd: 'changeMode', dark: this.dark});
iframe,
{
cmd: 'changeMode',
dark: this.dark,
},
new URL(iframe.src).origin,
);
} }
/** @private */ /** @private */
...@@ -412,7 +405,8 @@ class LogoElement extends PolymerElement { ...@@ -412,7 +405,8 @@ class LogoElement extends PolymerElement {
*/ */
computeAnimationUrl_() { computeAnimationUrl_() {
return this.imageDoodle_ && this.imageDoodle_.animationUrl ? return this.imageDoodle_ && this.imageDoodle_.animationUrl ?
`image?${this.imageDoodle_.animationUrl.url}` : `chrome-untrusted://new-tab-page/image?${
this.imageDoodle_.animationUrl.url}` :
''; '';
} }
......
...@@ -42,8 +42,8 @@ ...@@ -42,8 +42,8 @@
<include name="IDR_NEW_TAB_PAGE_GRID_JS" <include name="IDR_NEW_TAB_PAGE_GRID_JS"
file="${root_gen_dir}/chrome/browser/resources/new_tab_page/grid.js" file="${root_gen_dir}/chrome/browser/resources/new_tab_page/grid.js"
use_base_dir="false" type="BINDATA" compress="false" /> use_base_dir="false" type="BINDATA" compress="false" />
<include name="IDR_NEW_TAB_UNTRUSTED_IFRAME_JS" <include name="IDR_NEW_TAB_IFRAME_JS"
file="${root_gen_dir}/chrome/browser/resources/new_tab_page/untrusted_iframe.js" file="${root_gen_dir}/chrome/browser/resources/new_tab_page/iframe.js"
use_base_dir="false" type="BINDATA" compress="false" /> use_base_dir="false" type="BINDATA" compress="false" />
<include name="IDR_NEW_TAB_PAGE_MINI_PAGE_JS" <include name="IDR_NEW_TAB_PAGE_MINI_PAGE_JS"
file="${root_gen_dir}/chrome/browser/resources/new_tab_page/mini_page.js" file="${root_gen_dir}/chrome/browser/resources/new_tab_page/mini_page.js"
......
...@@ -56,8 +56,8 @@ suite('NewTabPageCustomizeBackgroundsTest', () => { ...@@ -56,8 +56,8 @@ suite('NewTabPageCustomizeBackgroundsTest', () => {
assertEquals(3, tiles.length); assertEquals(3, tiles.length);
assertEquals('col_0', tiles[2].getAttribute('title')); assertEquals('col_0', tiles[2].getAttribute('title'));
assertEquals( assertEquals(
'background_image?https://col_0.jpg', 'chrome-untrusted://new-tab-page/background_image?https://col_0.jpg',
tiles[2].querySelector('.image').path); tiles[2].querySelector('.image').src);
}); });
test('clicking collection selects collection', async function() { test('clicking collection selects collection', async function() {
...@@ -93,8 +93,8 @@ suite('NewTabPageCustomizeBackgroundsTest', () => { ...@@ -93,8 +93,8 @@ suite('NewTabPageCustomizeBackgroundsTest', () => {
// Arrange. // Arrange.
const image = { const image = {
attribution1: 'image_0', attribution1: 'image_0',
imageUrl: {url: 'https://example.com/image.png'}, imageUrl: {url: 'https://a.com/i.png'},
previewImageUrl: {url: 'https://example.com/image.png'}, previewImageUrl: {url: 'https://a.com/p.png'},
}; };
handler.setResultFor('getBackgroundImages', Promise.resolve({ handler.setResultFor('getBackgroundImages', Promise.resolve({
images: [image], images: [image],
...@@ -114,8 +114,8 @@ suite('NewTabPageCustomizeBackgroundsTest', () => { ...@@ -114,8 +114,8 @@ suite('NewTabPageCustomizeBackgroundsTest', () => {
customizeBackgrounds.shadowRoot.querySelectorAll('#images .tile'); customizeBackgrounds.shadowRoot.querySelectorAll('#images .tile');
assertEquals(tiles.length, 1); assertEquals(tiles.length, 1);
assertEquals( assertEquals(
tiles[0].querySelector('.image').path, tiles[0].querySelector('.image').src,
'background_image?https://example.com/image.png'); 'chrome-untrusted://new-tab-page/background_image?https://a.com/p.png');
}); });
test('Going back shows collections', async function() { test('Going back shows collections', async function() {
......
...@@ -245,7 +245,7 @@ function createSuite(themeModeDoodlesEnabled) { ...@@ -245,7 +245,7 @@ function createSuite(themeModeDoodlesEnabled) {
assertEquals(1, testProxy.getCallCount('postMessage')); assertEquals(1, testProxy.getCallCount('postMessage'));
const [iframe, {cmd, dark}, origin] = const [iframe, {cmd, dark}, origin] =
await testProxy.whenCalled('postMessage'); await testProxy.whenCalled('postMessage');
assertEquals($$(logo, '#iframe'), iframe); assertEquals($$($$(logo, '#iframe'), '#iframe'), iframe);
assertEquals('changeMode', cmd); assertEquals('changeMode', cmd);
assertEquals(false, dark); assertEquals(false, dark);
assertEquals('https://foo.com', origin); assertEquals('https://foo.com', origin);
...@@ -277,7 +277,7 @@ function createSuite(themeModeDoodlesEnabled) { ...@@ -277,7 +277,7 @@ function createSuite(themeModeDoodlesEnabled) {
assertEquals(1, testProxy.getCallCount('postMessage')); assertEquals(1, testProxy.getCallCount('postMessage'));
const [iframe, {cmd, dark}, origin] = const [iframe, {cmd, dark}, origin] =
await testProxy.whenCalled('postMessage'); await testProxy.whenCalled('postMessage');
assertEquals($$(logo, '#iframe'), iframe); assertEquals($$($$(logo, '#iframe'), '#iframe'), iframe);
assertEquals('changeMode', cmd); assertEquals('changeMode', cmd);
assertEquals(true, dark); assertEquals(true, dark);
assertEquals('https://foo.com', origin); assertEquals('https://foo.com', origin);
...@@ -464,7 +464,9 @@ function createSuite(themeModeDoodlesEnabled) { ...@@ -464,7 +464,9 @@ function createSuite(themeModeDoodlesEnabled) {
assertEquals(testProxy.getCallCount('open'), 0); assertEquals(testProxy.getCallCount('open'), 0);
assertNotStyle($$(logo, '#image'), 'display', 'none'); assertNotStyle($$(logo, '#image'), 'display', 'none');
assertNotStyle($$(logo, '#animation'), 'display', 'none'); assertNotStyle($$(logo, '#animation'), 'display', 'none');
assertEquals($$(logo, '#animation').path, 'image?https://foo.com'); assertEquals(
$$(logo, '#animation').src,
'chrome-untrusted://new-tab-page/image?https://foo.com');
assertDeepEquals( assertDeepEquals(
$$(logo, '#image').getBoundingClientRect(), $$(logo, '#image').getBoundingClientRect(),
$$(logo, '#animation').getBoundingClientRect()); $$(logo, '#animation').getBoundingClientRect());
......
...@@ -169,8 +169,7 @@ var NewTabPageLogoTest = class extends NewTabPageBrowserTest { ...@@ -169,8 +169,7 @@ var NewTabPageLogoTest = class extends NewTabPageBrowserTest {
} }
}; };
// Very flaky (crbug.com/1097035) TEST_F('NewTabPageLogoTest', 'All', function() {
TEST_F('NewTabPageLogoTest', 'DISABLED_All', function() {
mocha.run(); mocha.run();
}); });
......
...@@ -59,7 +59,7 @@ export function createTestProxy() { ...@@ -59,7 +59,7 @@ export function createTestProxy() {
testProxy.callbackRouter.$.bindNewPipeAndPassRemote(); testProxy.callbackRouter.$.bindNewPipeAndPassRemote();
testProxy.handler = testProxy.handler =
TestBrowserProxy.fromClass(newTabPage.mojom.PageHandlerRemote); TestBrowserProxy.fromClass(newTabPage.mojom.PageHandlerRemote);
testProxy.setResultFor('createUntrustedIframeSrc', ''); testProxy.setResultFor('createIframeSrc', '');
return testProxy; return testProxy;
} }
......
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