Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Commit

Permalink
Merge pull request #12487 from brave/issue-12482
Browse files Browse the repository at this point in the history
Adding site to temporary allow callback only when no notification interaction
  • Loading branch information
bsclifton authored Jan 3, 2018
2 parents 6f177ca + ea7fc32 commit 47fe275
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/browser/reducers/autoplayReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ const hideAutoplayMessageBox = (tabId) => {
if (notificationCallbacks[tabId]) {
ipcMain.removeListener(messages.NOTIFICATION_RESPONSE, notificationCallbacks[tabId])
delete notificationCallbacks[tabId]
temporaryAllowPlays[tabId] = origin
appActions.changeSiteSetting(origin, 'autoplay', true)
}
temporaryAllowPlays[tabId] = origin
appActions.changeSiteSetting(origin, 'autoplay', true)
}

const removeTemporaryAllowPlays = (tabId) => {
Expand Down
83 changes: 63 additions & 20 deletions test/unit/app/browser/reducers/autoplayReducerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,30 +302,71 @@ describe('autoplayReducer unit tests', function () {
})

describe('APP_MEDIA_STARTED_PLAYING', function () {
before(function () {
autoplayMedia = autoplayOption.ALWAYS_ASK
autoplayReducer(Immutable.fromJS({
siteSettings: {}
}), Immutable.fromJS({
actionType: appConstants.APP_AUTOPLAY_BLOCKED,
tabId: tabId
}))
autoplayReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_MEDIA_STARTED_PLAYING,
tabId: tabId
}))
})
describe('without NOTIFICATION_RESPONSE', function () {
before(function () {
autoplayMedia = autoplayOption.ALWAYS_ASK
autoplayReducer(Immutable.fromJS({
siteSettings: {}
}), Immutable.fromJS({
actionType: appConstants.APP_AUTOPLAY_BLOCKED,
tabId: tabId
}))
autoplayReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_MEDIA_STARTED_PLAYING,
tabId: tabId
}))
})

it('calls local.translation', function () {
assert(translationSpy.withArgs('allowAutoplay', {origin}).called)
})
it('calls local.translation', function () {
assert(translationSpy.withArgs('allowAutoplay', {origin}).called)
})

it('calls appActions.hideNotification', function () {
assert(hideNotificationSpy.withArgs(message).called)
it('calls appActions.hideNotification', function () {
assert(hideNotificationSpy.withArgs(message).called)
})

it('calls ipcMain.removeListener', function () {
assert(removeListenerSpy.called)
})

it('calls appActions.changeSiteSetting', function () {
assert(changeSiteSettingSpy.withArgs(origin, 'autoplay', true).called)
})
})

it('calls ipcMain.removeListener', function () {
assert(removeListenerSpy.called)
describe('with NOTIFICATION_RESPONSE', function () {
before(function () {
autoplayMedia = autoplayOption.ALWAYS_ASK
autoplayReducer(Immutable.fromJS({
siteSettings: {}
}), Immutable.fromJS({
actionType: appConstants.APP_AUTOPLAY_BLOCKED,
tabId: tabId
}))
fakeElectron.ipcMain.send(messages.NOTIFICATION_RESPONSE, {}, message, 0, true)
removeListenerSpy.reset()
changeSiteSettingSpy.reset()
autoplayReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_MEDIA_STARTED_PLAYING,
tabId: tabId
}))
})

it('calls local.translation', function () {
assert(translationSpy.withArgs('allowAutoplay', {origin}).called)
})

it('calls appActions.hideNotification', function () {
assert(hideNotificationSpy.withArgs(message).called)
})

it('no calls ipcMain.removeListener', function () {
assert(removeListenerSpy.notCalled)
})

it('no calls appActions.changeSiteSetting', function () {
assert(changeSiteSettingSpy.notCalled)
})
})
})

Expand All @@ -338,6 +379,7 @@ describe('autoplayReducer unit tests', function () {
actionType: appConstants.APP_AUTOPLAY_BLOCKED,
tabId: tabId
}))
fakeElectron.ipcMain.send(messages.NOTIFICATION_RESPONSE, {}, message, 0, false)
autoplayReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_TAB_CLOSED,
tabId: tabId
Expand Down Expand Up @@ -370,6 +412,7 @@ describe('autoplayReducer unit tests', function () {
actionType: appConstants.APP_AUTOPLAY_BLOCKED,
tabId: tabId
}))
fakeElectron.ipcMain.send(messages.NOTIFICATION_RESPONSE, {}, message, 0, false)
autoplayReducer(Immutable.Map(), Immutable.fromJS({
actionType: appConstants.APP_SHUTTING_DOWN
}))
Expand Down

0 comments on commit 47fe275

Please sign in to comment.