This repository has been archived by the owner on Dec 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 972
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #3121 Auditors: @bsclifton
- Loading branch information
Showing
14 changed files
with
194 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* This SourceCode Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
'use strict' | ||
|
||
const appConstants = require('../../../js/constants/appConstants') | ||
const {makeImmutable} = require('../../common/state/immutableUtil') | ||
const {emailActiveTab} = require('../share') | ||
|
||
const shareReducer = (state, action) => { | ||
action = makeImmutable(action) | ||
switch (action.get('actionType')) { | ||
case appConstants.APP_EMAIL_ACTIVE_TAB_REQUESTED: | ||
state = emailActiveTab(state, action.get('windowId')) | ||
break | ||
} | ||
return state | ||
} | ||
|
||
module.exports = shareReducer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
const tabState = require('../common/state/tabState') | ||
const {shell} = require('electron') | ||
|
||
const emailActiveTab = (state, windowId) => { | ||
const tabValue = tabState.getActiveTabValue(state, windowId) | ||
shell.openExternal( | ||
`mailto:?subject=${encodeURIComponent(tabValue.get('title') || '')}&body=${encodeURIComponent(tabValue.get('url'))}` | ||
) | ||
return state | ||
} | ||
|
||
module.exports = { | ||
emailActiveTab | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* global describe, it, before, after */ | ||
const mockery = require('mockery') | ||
const sinon = require('sinon') | ||
const Immutable = require('immutable') | ||
const assert = require('assert') | ||
const fakeElectron = require('../../../lib/fakeElectron') | ||
|
||
const appConstants = require('../../../../../js/constants/appConstants') | ||
require('../../../braveUnit') | ||
|
||
describe('shareReducer', function () { | ||
let shareReducer | ||
before(function () { | ||
mockery.enable({ | ||
warnOnReplace: false, | ||
warnOnUnregistered: false, | ||
useCleanCache: true | ||
}) | ||
mockery.registerMock('electron', fakeElectron) | ||
this.shareStub = { | ||
emailActiveTab: sinon.stub() | ||
} | ||
mockery.registerMock('../share', this.shareStub) | ||
shareReducer = require('../../../../../app/browser/reducers/shareReducer') | ||
}) | ||
|
||
after(function () { | ||
mockery.disable() | ||
}) | ||
|
||
describe('APP_EMAIL_ACTIVE_TAB_REQUESTED', function () { | ||
before(function () { | ||
this.state = Immutable.Map() | ||
this.windowId = 2 | ||
this.newState = shareReducer(this.state, {actionType: appConstants.APP_EMAIL_ACTIVE_TAB_REQUESTED, windowId: this.windowId}) | ||
}) | ||
it('calls emailActiveTab once with the correct args', function () { | ||
const callCount = this.shareStub.emailActiveTab.withArgs(this.state, this.windowId).callCount | ||
assert.equal(callCount, 1) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* global describe, it, before, after, afterEach */ | ||
const mockery = require('mockery') | ||
const sinon = require('sinon') | ||
const Immutable = require('immutable') | ||
const assert = require('assert') | ||
const fakeElectron = require('../../lib/fakeElectron') | ||
|
||
require('../../braveUnit') | ||
|
||
describe('share API', function () { | ||
let share | ||
before(function () { | ||
mockery.enable({ | ||
warnOnReplace: false, | ||
warnOnUnregistered: false, | ||
useCleanCache: true | ||
}) | ||
mockery.registerMock('electron', fakeElectron) | ||
share = require('../../../../app/browser/share') | ||
}) | ||
|
||
after(function () { | ||
mockery.disable() | ||
}) | ||
|
||
describe('emailActiveTab', function () { | ||
before(function () { | ||
this.state = Immutable.fromJS({ | ||
tabs: [{ | ||
windowId: 2, | ||
tabId: 2, | ||
url: 'https://www.brave.com/2', | ||
title: 'title 2', | ||
active: true | ||
}, { | ||
windowId: 3, | ||
tabId: 3, | ||
url: 'https://www.brave.com/3', | ||
title: 'title 3' | ||
}, { | ||
windowId: 5, | ||
tabId: 5, | ||
url: 'https://www.brave.com/5', | ||
title: 'title 5', | ||
active: true | ||
}] | ||
}) | ||
this.windowId = 2 | ||
this.openExternalSpy = sinon.spy(fakeElectron.shell, 'openExternal') | ||
}) | ||
afterEach(function () { | ||
this.openExternalSpy.reset() | ||
}) | ||
it('calls openExternal with the correct args', function () { | ||
share.emailActiveTab(this.state, 2) | ||
const expectedUrl = 'mailto:?subject=title%202&body=https%3A%2F%2Fwww.brave.com%2F2' | ||
const callCount = this.openExternalSpy.withArgs(expectedUrl).callCount | ||
assert.equal(callCount, 1) | ||
}) | ||
it('takes active tab windowId into consideration', function () { | ||
share.emailActiveTab(this.state, 5) | ||
const expectedUrl = 'mailto:?subject=title%205&body=https%3A%2F%2Fwww.brave.com%2F5' | ||
const callCount = this.openExternalSpy.withArgs(expectedUrl).callCount | ||
assert.equal(callCount, 1) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters