Commit 1ba1a817 authored by Tibor Goldschwendt's avatar Tibor Goldschwendt Committed by Commit Bot

[webui][ntp] Prevent history entry when changing background image

The history entry appeared because we set the background image URL by
setting src of the background image iframe. This CL changes this to
contentWindow.location.replace, which does not add a history entry.

Fixed: 1114089
Change-Id: I2038de67b7fab71fc732152357a43c3fd885f7d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2347317
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Auto-Submit: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#797130}
parent 8d170b13
...@@ -112,7 +112,9 @@ export class BackgroundManager { ...@@ -112,7 +112,9 @@ export class BackgroundManager {
this.loadTimeResolver_.reject(); this.loadTimeResolver_.reject();
this.loadTimeResolver_ = null; this.loadTimeResolver_ = null;
} }
this.backgroundImage_.src = url.href; // We use |contentWindow.location.replace| because reloading the iframe by
// setting its |src| adds a history entry.
this.backgroundImage_.contentWindow.location.replace(url.href);
} }
/** /**
......
...@@ -35,6 +35,13 @@ suite('NewTabPageBackgroundManagerTest', () => { ...@@ -35,6 +35,13 @@ suite('NewTabPageBackgroundManagerTest', () => {
backgroundImage = document.createElement('div'); backgroundImage = document.createElement('div');
backgroundImage.id = 'backgroundImage'; backgroundImage.id = 'backgroundImage';
backgroundImage.contentWindow = {
location: {
replace: url => {
backgroundImage.url = url;
}
}
};
document.body.appendChild(backgroundImage); document.body.appendChild(backgroundImage);
backgroundManager = new BackgroundManager(); backgroundManager = new BackgroundManager();
...@@ -64,7 +71,7 @@ suite('NewTabPageBackgroundManagerTest', () => { ...@@ -64,7 +71,7 @@ suite('NewTabPageBackgroundManagerTest', () => {
backgroundManager.setBackgroundImage({url: {url: 'https://example.com'}}); backgroundManager.setBackgroundImage({url: {url: 'https://example.com'}});
// Assert. // Assert.
assertEquals(wrapImageUrl('https://example.com'), backgroundImage.src); assertEquals(wrapImageUrl('https://example.com'), backgroundImage.url);
}); });
test('setting custom style updates src', () => { test('setting custom style updates src', () => {
...@@ -86,7 +93,7 @@ suite('NewTabPageBackgroundManagerTest', () => { ...@@ -86,7 +93,7 @@ suite('NewTabPageBackgroundManagerTest', () => {
`url2x=${encodeURIComponent('https://example2x.com')}&` + `url2x=${encodeURIComponent('https://example2x.com')}&` +
'size=cover&repeatX=no-repeat&repeatY=repeat&positionX=left&' + 'size=cover&repeatX=no-repeat&repeatY=repeat&positionX=left&' +
'positionY=top'; 'positionY=top';
assertEquals(expected, backgroundImage.src); assertEquals(expected, backgroundImage.url);
}); });
test.skip('receiving load time resolves promise', async () => { test.skip('receiving load time resolves promise', async () => {
......
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