Skip to content
Merged
Prev Previous commit
Next Next commit
clean up
  • Loading branch information
Cameron Neale
Cameron Neale committed Aug 3, 2026
commit e688072db8bc327e7ed34bc22096a7506cebc011
5 changes: 0 additions & 5 deletions build-system/server/server-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ app.use((req, res, next) => {
res.set({
'Content-Security-Policy': req.query['--CSP'],
});
} else {
res.set({
'Content-Security-Policy':
"frame-ancestors 'self' https://*.proxy.googlers.com http://localhost:* http://127.0.0.1:*;",
});
}
// Allow COOP overrides but default to same-origin-allow-popups
res.set({
Expand Down
25 changes: 0 additions & 25 deletions src/components/activities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,31 +224,6 @@ export class ActivityPorts {

constructor(private readonly deps_: Deps) {
this.activityPorts_ = new WebActivityPorts(deps_.win());

try {
const win = deps_.win();
if (win && win.document) {
const iframe = win.document.createElement('iframe');
const dummyPort = new WebActivityIframePort(iframe, 'about:blank', {});
const messengerProto = Object.getPrototypeOf(
(dummyPort as any).messenger_
);
if (messengerProto && !messengerProto.__patchedForSwg) {
messengerProto.__patchedForSwg = true;
messengerProto.getOptionalTarget_ = function (this: any) {
if (this.onCommand_) {
if (typeof this.targetOrCallback_ === 'function') {
return this.targetOrCallback_();
}
return this.targetOrCallback_;
}
return null;
};
}
}
} catch (e) {
// Ignore in non-browser testing environments
}
}

/**
Expand Down
54 changes: 54 additions & 0 deletions src/runtime/publisher-runtime-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,47 @@ describes.realWin('installPublisherRuntime', (env) => {
expect(button.querySelector('iframe')).to.not.be.null; // Iframe injected
});

it('should call updateStatus on injected buttons if currentStatus_ is already defined', async () => {
const updateStatusStub = sandbox.stub(
AddPreferredSourceButtonIframe.prototype,
'updateStatus'
);

api.addPreferredSource();
await new Promise((resolve) => setTimeout(resolve, 0));
await new Promise((resolve) => setTimeout(resolve, 0));

const button = win.document.createElement('div');
button.setAttribute('google-add-preferred-source-btn', '');
win.document.body.appendChild(button);

api.init({theme: 'dark'});
await new Promise((resolve) => setTimeout(resolve, 0));

expect(updateStatusStub).to.have.been.calledWith(
AddPreferredSourceStatus.ADD_PREFERRED_SOURCE_STATUS_SUCCESS
);
});

it('should trigger addPreferredSource when button iframe attach callback is invoked', async () => {
const button = win.document.createElement('div');
button.setAttribute('google-add-preferred-source-btn', '');
win.document.body.appendChild(button);

api.init({theme: 'dark'});
await new Promise((resolve) => setTimeout(resolve, 0));

expect(AddPreferredSourceButtonIframe.prototype.attach).to.have.been
.called;
const onResultCallback =
AddPreferredSourceButtonIframe.prototype.attach.getCall(0).args[0];

AddPreferredSourceFlow.prototype.start.resetHistory();
const res = await onResultCallback();
expect(AddPreferredSourceFlow.prototype.start).to.have.been.calledOnce;
expect(res).to.be.true;
});

it('should show toast when addPreferredSource is called', async () => {
api.addPreferredSource();

Expand All @@ -134,6 +175,19 @@ describes.realWin('installPublisherRuntime', (env) => {
expect(toastInstance.src_).to.include('confirmationType=3');
});

it('should include theme parameter in toast URL when theme option is set in init', async () => {
api.init({theme: 'dark'});
await new Promise((resolve) => setTimeout(resolve, 0));

api.addPreferredSource();

await new Promise((resolve) => setTimeout(resolve, 0));
await new Promise((resolve) => setTimeout(resolve, 0));
expect(toastOpenStub).to.have.been.calledOnce;
const toastInstance = toastOpenStub.getCall(0).thisValue;
expect(toastInstance.src_).to.include('theme=dark');
});

it('should ignore toast if addPreferredSource is cancelled or fails', async () => {
AddPreferredSourceFlow.prototype.start.restore(); // override the beforeEach stub
sandbox
Expand Down
44 changes: 44 additions & 0 deletions src/ui/add-preferred-source-button-iframe-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@

import {ActivityIframePort, ActivityPorts} from '../components/activities';
import {AddPreferredSourceButtonIframe} from './add-preferred-source-button-iframe';
import {
AddPreferredSourceStatus,
UpdateAddPreferredSourceButtonRequest,
} from '../proto/api_messages';

describes.realWin('AddPreferredSourceButtonIframe', (env) => {
let win;
Expand Down Expand Up @@ -117,4 +121,44 @@ describes.realWin('AddPreferredSourceButtonIframe', (env) => {

expect(resultCalled).to.be.false; // Exception handled gracefully in attach
});

describe('updateStatus', () => {
const statuses = [
AddPreferredSourceStatus.ADD_PREFERRED_SOURCE_STATUS_UNSPECIFIED,
AddPreferredSourceStatus.ADD_PREFERRED_SOURCE_STATUS_ALREADY_ADDED,
AddPreferredSourceStatus.ADD_PREFERRED_SOURCE_STATUS_INELIGIBLE,
AddPreferredSourceStatus.ADD_PREFERRED_SOURCE_STATUS_SUCCESS,
];

statuses.forEach((status) => {
it(`should send UpdateAddPreferredSourceButtonRequest for status ${status}`, async () => {
await iframeComponent.attach(() => {});
await iframeComponent.updateStatus(status);

expect(portStub.execute).to.have.been.calledOnce;
const msg = portStub.execute.getCall(0).args[0];
expect(msg).to.be.an.instanceOf(UpdateAddPreferredSourceButtonRequest);
expect(msg.getStatus()).to.equal(status);
});
});

it('should silently no-op when called before attach', async () => {
await iframeComponent.updateStatus(
AddPreferredSourceStatus.ADD_PREFERRED_SOURCE_STATUS_SUCCESS
);

expect(portStub.execute).to.not.have.been.called;
});

it('should catch and log errors if port.execute throws', async () => {
portStub.execute.throws(new Error('Port error'));
await iframeComponent.attach(() => {});

await iframeComponent.updateStatus(
AddPreferredSourceStatus.ADD_PREFERRED_SOURCE_STATUS_SUCCESS
);

expect(portStub.execute).to.have.been.calledOnce;
});
});
});
10 changes: 1 addition & 9 deletions test/e2e/commands/switchToFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@
*/

module.exports.command = function (iframeSrcString, iframeMsg, callback) {
if (!iframeSrcString) {
return this.frame(null, () => {
this.log('Switching to top-level frame');
callback && callback();
});
}
return this.element('css selector', `iframe${iframeSrcString}`, (frame) => {
if (frame.status == -1 || !frame.value) {
if (frame.status == -1) {
this.log(frame.error, true);
callback && callback();
return;
}
this.frame(frame.value, () => {
this.log(`Switching to ${iframeMsg}`);
Expand Down
15 changes: 5 additions & 10 deletions test/e2e/commands/switchToTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,10 @@
*/
module.exports.command = function (windowName) {
return this.windowHandles(function (result) {
const handles = Array.isArray(result)
? result
: (result && result.value) || [];
if (handles.length > 0) {
const newWindow = handles[handles.length - 1];
this.pause(1000)
.log(`Switching window to ${windowName}`)
.switchWindow(newWindow);
this.pause(2000);
}
const newWindow = result.value[result.value.length - 1];
this.pause(1000)
.log(`Switching window to ${windowName}`)
.switchWindow(newWindow);
this.pause(2000);
});
};
2 changes: 1 addition & 1 deletion test/e2e/pages/enterpriseNewsletter.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const {swgPageUrl} = require('../util');
*/
const commands = {
viewNewsletter: function () {
return this.pause(3000)
return this.pause(1000)
.log('Viewing newsletter')
.switchToFrame('[src*="about:blank"]', 'SwG outer iFrame')
.switchToFrame('[src*="newsletteriframe"]', 'SwG inner iFrame');
Expand Down
6 changes: 4 additions & 2 deletions test/e2e/pages/enterpriseSubscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const commands = {
.switchToFrame('[src*="subscriptionoffersiframe"]', 'SwG inner iFrame');
},
subscribe: function () {
return this.log('Clicking buy button').click('@buyButton');
return this.log('Clicking buy button')
.assert.textContains('@buyButton', 'Subscribe now')
.click('@buyButton');
},
};

Expand All @@ -43,7 +45,7 @@ module.exports = {
commands: [commands],
elements: {
buyButton: {
selector: '.PNojLb button, .qLPyoc, .skWZYc button, button',
selector: '.skWZYc button',
},
subscriptionHeader: {
selector: '.jNru1c',
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/tests/basicByoeNewsletter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ module.exports = {
.waitForElementPresent('@swgDialog', 'Found SwG dialog')
.waitForElementVisible('@swgDialog')
.pause(3000)
.assert.screenshotIdenticalToBaseline('html', 'basic-newsletter', {
threshold: 0.1,
})
.assert.screenshotIdenticalToBaseline('html', 'basic-newsletter')
.viewNewsletter()
.assert.textContains(
'@consentMessage',
Expand Down
4 changes: 1 addition & 3 deletions test/e2e/tests/basicNewsletter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ module.exports = {
.waitForElementPresent('@swgDialog', 'Found SwG dialog')
.waitForElementVisible('@swgDialog')
.pause(3000)
.assert.screenshotIdenticalToBaseline('html', 'basic-newsletter', {
threshold: 0.1,
})
.assert.screenshotIdenticalToBaseline('html', 'basic-newsletter')
.viewNewsletter()
.assert.textContains(
'@consentMessage',
Expand Down
Loading