New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
amp-sticky-ad: Force background-color alpha to be 1 #5819
Changes from all commits
43bd0cf
7d1073f
caabd2a
3cf0c96
07261fe
638a859
e3dd99d
fe85454
8b8aab5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
*/ | ||
|
||
import {createIframePromise} from '../../../../testing/iframe'; | ||
import {toggleExperiment} from '../../../../src/experiments'; | ||
import * as sinon from 'sinon'; | ||
import '../amp-sticky-ad'; | ||
import '../../../amp-ad/0.1/amp-ad'; | ||
|
@@ -30,10 +31,13 @@ describe('amp-sticky-ad', () => { | |
sandbox.restore(); | ||
}); | ||
|
||
function getAmpStickyAd() { | ||
function getAmpStickyAd(opt_attributes) { | ||
return createIframePromise().then(iframe => { | ||
const ampStickyAd = iframe.doc.createElement('amp-sticky-ad'); | ||
ampStickyAd.setAttribute('layout', 'nodisplay'); | ||
for (const attr in opt_attributes) { | ||
ampStickyAd.setAttribute(attr, opt_attributes[attr]); | ||
} | ||
const ampAd = iframe.doc.createElement('amp-ad'); | ||
ampAd.setAttribute('width', '300'); | ||
ampAd.setAttribute('height', '50'); | ||
|
@@ -377,4 +381,61 @@ describe('amp-sticky-ad', () => { | |
.to.be.true; | ||
}); | ||
}); | ||
|
||
it('should not allow container to be set transparent', () => { | ||
toggleExperiment(window, 'amp-sticky-ad-better-ux', true); | ||
return getAmpStickyAd({ | ||
'style': 'background-color: rgba(55, 55, 55, 0.55) !important', | ||
}).then(obj => { | ||
console.log(obj.ampStickyAd); | ||
const stickyAdElement = obj.ampStickyAd; | ||
const impl = stickyAdElement.implementation_; | ||
impl.vsync_.mutate = function(callback) { | ||
callback(); | ||
}; | ||
impl.scheduleLayoutForAd_(); | ||
impl.ad_.dispatchEvent(new Event('amp:built')); | ||
impl.ad_.dispatchEvent(new Event('amp:load:end')); | ||
expect(window.getComputedStyle(stickyAdElement) | ||
.getPropertyValue('background-color')).to.equal('rgb(55, 55, 55)'); | ||
}); | ||
}); | ||
|
||
it('should not allow container to be set semitransparent in rgba', () => { | ||
toggleExperiment(window, 'amp-sticky-ad-better-ux', true); | ||
return getAmpStickyAd({ | ||
'style': 'background-color: rgba(55, 55, 55, 0.55) !important', | ||
}).then(obj => { | ||
console.log(obj.ampStickyAd); | ||
const stickyAdElement = obj.ampStickyAd; | ||
const impl = stickyAdElement.implementation_; | ||
impl.vsync_.mutate = function(callback) { | ||
callback(); | ||
}; | ||
impl.scheduleLayoutForAd_(); | ||
impl.ad_.dispatchEvent(new Event('amp:built')); | ||
impl.ad_.dispatchEvent(new Event('amp:load:end')); | ||
expect(window.getComputedStyle(stickyAdElement) | ||
.getPropertyValue('background-color')).to.equal('rgb(55, 55, 55)'); | ||
}); | ||
}); | ||
|
||
it('should not allow container to be set to transparent', () => { | ||
toggleExperiment(window, 'amp-sticky-ad-better-ux', true); | ||
return getAmpStickyAd({ | ||
'style': 'background-color: transparent !important', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new test |
||
}).then(obj => { | ||
console.log(obj.ampStickyAd); | ||
const stickyAdElement = obj.ampStickyAd; | ||
const impl = stickyAdElement.implementation_; | ||
impl.vsync_.mutate = function(callback) { | ||
callback(); | ||
}; | ||
impl.scheduleLayoutForAd_(); | ||
impl.ad_.dispatchEvent(new Event('amp:built')); | ||
impl.ad_.dispatchEvent(new Event('amp:load:end')); | ||
expect(window.getComputedStyle(stickyAdElement) | ||
.getPropertyValue('background-color')).to.equal('rgb(0, 0, 0)'); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
* limitations under the License. | ||
*/ | ||
|
||
|
||
// Note: loaded by 3p system. Cannot rely on babel polyfills. | ||
|
||
/** @type {Object<string, string>} */ | ||
|
@@ -196,3 +195,15 @@ export function translate(x, opt_y) { | |
export function scale(value) { | ||
return `scale(${value})`; | ||
} | ||
|
||
/** | ||
* Remove alpha value from a rgba color value. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rephrase the comment |
||
* Return the new color property with alpha equals if has the alpha value. | ||
* Caller needs to make sure the input color value is a valid rgba/rgb value | ||
* @param {string} rgbaColor | ||
* @return {string} | ||
*/ | ||
export function removeAlphaFromColor(rgbaColor) { | ||
return rgbaColor.replace( | ||
/\(([^,]+),([^,]+),([^,)]+),[^)]+\)/g, '($1,$2,$3, 1)'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,15 @@ describe('Style', () => { | |
expect(st.camelCaseToTitleCase(str)).to.equal('TheQuickBrownFox'); | ||
}); | ||
|
||
it('removeAlphaFromColor', () => { | ||
expect(st.removeAlphaFromColor('rgba(1, 1, 1, 0)')).to.equal( | ||
'rgba(1, 1, 1, 1)'); | ||
expect(st.removeAlphaFromColor('rgb(1, 1, 1)')).to.equal( | ||
'rgb(1, 1, 1)'); | ||
expect(st.removeAlphaFromColor('rgba(0, 0, 0,-0.5)')).to.equal( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
'rgba(0, 0, 0, 1)'); | ||
}); | ||
|
||
describe('getVendorJsPropertyName', () => { | ||
|
||
it('no prefix', () => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add the
background-image: none
here as well