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 973
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7660913
commit b058a21
Showing
16 changed files
with
1,167 additions
and
634 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* global describe, it, before, after */ | ||
const mockery = require('mockery') | ||
const Immutable = require('immutable') | ||
// const assert = require('assert') | ||
const fakeElectron = require('../../../lib/fakeElectron') | ||
|
||
// const windowConstants = require('../../../../../js/constants/windowConstants') | ||
require('../../../braveUnit') | ||
|
||
describe('tabContentReducer', function () { | ||
let tabContentReducer | ||
before(function () { | ||
mockery.enable({ | ||
warnOnReplace: false, | ||
warnOnUnregistered: false, | ||
useCleanCache: true | ||
}) | ||
mockery.registerMock('electron', fakeElectron) | ||
tabContentReducer = require('../../../../../app/renderer/reducers/tabContentReducer') | ||
}) | ||
|
||
after(function () { | ||
mockery.disable() | ||
}) | ||
|
||
describe('WINDOW_SET_TAB_CONTENT_INTERSECTION_STATE', function () { | ||
before(function () { | ||
this.newState = tabContentReducer(Immutable.Map({}), { | ||
// actionType: windowConstants.WINDOW_SET_TAB_CONTENT_INTERSECTION_STATE | ||
}) | ||
}) | ||
it('Does not modify state', function () { | ||
// TODO | ||
// assert() | ||
}) | ||
}) | ||
}) |
153 changes: 153 additions & 0 deletions
153
test/unit/app/common/state/tabContentState/audioStateTest.js
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,153 @@ | ||
/* 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/. */ | ||
|
||
/* global describe, it, before, after */ | ||
|
||
const assert = require('assert') | ||
const Immutable = require('immutable') | ||
const mockery = require('mockery') | ||
const fakeElectron = require('../../../../lib/fakeElectron') | ||
const {intersection} = require('../../../../../../app/renderer/components/styles/global') | ||
|
||
const frameKey = 1 | ||
const index = 0 | ||
let defaultState = Immutable.fromJS({ | ||
activeFrameKey: frameKey, | ||
frames: [{ | ||
key: frameKey, | ||
tabId: 1, | ||
location: 'http://brave.com' | ||
}], | ||
tabs: [{ | ||
key: frameKey, | ||
index: index | ||
}], | ||
framesInternal: { | ||
index: { 1: 0 }, | ||
tabIndex: { 1: 0 } | ||
} | ||
}) | ||
|
||
describe('audioState unit tests', function () { | ||
let audioState | ||
|
||
before(function () { | ||
mockery.enable({ | ||
warnOnReplace: false, | ||
warnOnUnregistered: false, | ||
useCleanCache: true | ||
}) | ||
mockery.registerMock('electron', fakeElectron) | ||
audioState = require('../../../../../../app/common/state/tabContentState/audioState') | ||
}) | ||
|
||
after(function () { | ||
mockery.deregisterAll() | ||
mockery.disable() | ||
}) | ||
|
||
describe('canPlayAudio', function () { | ||
it('returns false if frame is null/undefined', function * () { | ||
assert.equal(audioState.canPlayAudio(), false) | ||
}) | ||
|
||
it('returns true if audioPlaybackActive is true', function * () { | ||
const state = defaultState.setIn(['frames', index, 'audioPlaybackActive'], true) | ||
const result = audioState.canPlayAudio(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('returns true if audioMuted is true', function * () { | ||
const state = defaultState.setIn(['frames', index, 'audioMuted'], true) | ||
const result = audioState.canPlayAudio(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('returns true if both provided', function * () { | ||
const state = defaultState | ||
.setIn(['frames', index, 'audioMuted'], true) | ||
.setIn(['frames', index, 'audioPlaybackActive'], true) | ||
const result = audioState.canPlayAudio(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
}) | ||
|
||
describe('isAudioMuted', function () { | ||
it('returns false if frame is null/undefined', function * () { | ||
assert.equal(audioState.isAudioMuted(), false) | ||
}) | ||
|
||
it('returns true if audioMuted is true', function * () { | ||
const state = defaultState.setIn(['frames', index, 'audioMuted'], true) | ||
const result = audioState.isAudioMuted(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('returns false if audioMuted is false', function * () { | ||
const state = defaultState.setIn(['frames', index, 'audioMuted'], false) | ||
const result = audioState.isAudioMuted(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
}) | ||
|
||
describe('showAudioIcon', function () { | ||
it('returns false if frame is null/undefined', function * () { | ||
assert.equal(audioState.showAudioIcon(), false) | ||
}) | ||
|
||
it('returns true if tab can play audio and tab is not intercected', function * () { | ||
const state = defaultState | ||
.setIn(['frames', index, 'audioPlaybackActive'], true) | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.noIntersection) | ||
const result = audioState.showAudioIcon(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('returns false if tab can play audio and tab is intercected', function * () { | ||
const state = defaultState | ||
.setIn(['frames', index, 'audioPlaybackActive'], true) | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.at35) | ||
const result = audioState.showAudioIcon(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
|
||
it('returns false if tab can not play audio and tab is not intercected', function * () { | ||
const state = defaultState | ||
.setIn(['frames', index, 'audioPlaybackActive'], false) | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.at35) | ||
const result = audioState.showAudioIcon(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
}) | ||
|
||
describe('showAudioTopBorder', function () { | ||
it('returns false if frame is null/undefined', function * () { | ||
assert.equal(audioState.showAudioTopBorder(), false) | ||
}) | ||
|
||
it('returns true if tab can play audio and tab is intercected', function * () { | ||
const state = defaultState | ||
.setIn(['frames', index, 'audioPlaybackActive'], true) | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.at35) | ||
const result = audioState.showAudioTopBorder(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('returns false if tab can play audio and tab is not intercected', function * () { | ||
const state = defaultState | ||
.setIn(['frames', index, 'audioPlaybackActive'], true) | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.noIntersection) | ||
const result = audioState.showAudioTopBorder(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
|
||
it('returns false if tab can not play audio and tab is intercected', function * () { | ||
const state = defaultState | ||
.setIn(['frames', index, 'audioPlaybackActive'], false) | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.noIntersection) | ||
const result = audioState.showAudioTopBorder(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
}) | ||
}) |
182 changes: 182 additions & 0 deletions
182
test/unit/app/common/state/tabContentState/faviconStateTest.js
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,182 @@ | ||
/* 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/. */ | ||
|
||
/* global describe, it, before, after */ | ||
|
||
const assert = require('assert') | ||
const Immutable = require('immutable') | ||
const mockery = require('mockery') | ||
const fakeElectron = require('../../../../lib/fakeElectron') | ||
const {intersection} = require('../../../../../../app/renderer/components/styles/global') | ||
|
||
const frameKey = 1 | ||
const index = 0 | ||
let defaultState = Immutable.fromJS({ | ||
activeFrameKey: frameKey, | ||
frames: [{ | ||
key: frameKey, | ||
tabId: 1, | ||
location: 'http://brave.com' | ||
}], | ||
tabs: [{ | ||
key: frameKey, | ||
index: index | ||
}], | ||
framesInternal: { | ||
index: { 1: 0 }, | ||
tabIndex: { 1: 0 } | ||
} | ||
}) | ||
|
||
describe('faviconState unit tests', function () { | ||
let faviconState | ||
|
||
before(function () { | ||
mockery.enable({ | ||
warnOnReplace: false, | ||
warnOnUnregistered: false, | ||
useCleanCache: true | ||
}) | ||
mockery.registerMock('electron', fakeElectron) | ||
faviconState = require('../../../../../../app/common/state/tabContentState/faviconState') | ||
}) | ||
|
||
after(function () { | ||
mockery.deregisterAll() | ||
mockery.disable() | ||
}) | ||
|
||
describe('showFavicon', function () { | ||
it('returns false if frame is null/undefined', function * () { | ||
assert.equal(faviconState.showFavicon(), false) | ||
}) | ||
|
||
it('returns true if tab is only 35% visible and is not active', function * () { | ||
const state = defaultState | ||
.set('activeFrameKey', 1337) | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.at35) | ||
const result = faviconState.showFavicon(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('returns true if tab is not intercected and is not about:newtab', function * () { | ||
const state = defaultState | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.noIntersection) | ||
const result = faviconState.showFavicon(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('returns false if tab is not intercected and is about:newtab', function * () { | ||
const state = defaultState | ||
.setIn(['frames', index, 'location'], 'about:newtab') | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.noIntersection) | ||
const result = faviconState.showFavicon(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
}) | ||
|
||
describe('getFavicon', function () { | ||
it('returns false if frame is null/undefined', function * () { | ||
assert.equal(faviconState.getFavicon(), false) | ||
}) | ||
|
||
it('returns false if loading icon is visible', function * () { | ||
const favicon = 'fred_water.png' | ||
const state = defaultState.mergeIn(['frames', index], { loading: true, icon: favicon }) | ||
const result = faviconState.getFavicon(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
|
||
it('returns the favicon if loading is not visible', function * () { | ||
const favicon = 'fred_water_rlz.png' | ||
const state = defaultState.mergeIn(['frames', index], { loading: false, icon: favicon }) | ||
const result = faviconState.getFavicon(state, frameKey) | ||
assert.equal(result, favicon) | ||
}) | ||
}) | ||
|
||
describe('showLoadingIcon', function () { | ||
it('returns false if frame is null/undefined', function * () { | ||
assert.equal(faviconState.showLoadingIcon(), false) | ||
}) | ||
|
||
it('returns false if source is about page', function * () { | ||
const state = defaultState | ||
.setIn(['frames', index, 'location'], 'about:blank') | ||
const result = faviconState.showLoadingIcon(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
|
||
it('returns true if source is not about page', function * () { | ||
const state = defaultState.setIn(['frames', index, 'loading'], true) | ||
const result = faviconState.showLoadingIcon(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('returns false if page is not loading', function * () { | ||
const state = defaultState.setIn(['frames', index, 'loading'], false) | ||
const result = faviconState.showLoadingIcon(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
|
||
it('returns false if loading is undefined', function * () { | ||
const state = defaultState.setIn(['frames', index, 'loading'], undefined) | ||
const result = faviconState.showLoadingIcon(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
|
||
it('returns true if page is loading', function * () { | ||
const state = defaultState.setIn(['frames', index, 'loading'], true) | ||
const result = faviconState.showLoadingIcon(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
}) | ||
|
||
describe('showIconWithLessMargin', function () { | ||
it('returns false if frame is null/undefined', function * () { | ||
assert.equal(faviconState.showIconWithLessMargin(), false) | ||
}) | ||
|
||
it('returns true if tab is intersected at 20% size', function * () { | ||
const state = defaultState | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.at20) | ||
const result = faviconState.showIconWithLessMargin(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('returns true if tab is intersected at smaller size', function * () { | ||
const state = defaultState | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.at15) | ||
const result = faviconState.showIconWithLessMargin(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('returns false if tab is intersected at a larger size', function * () { | ||
const state = defaultState | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.at35) | ||
const result = faviconState.showIconWithLessMargin(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
}) | ||
|
||
describe('showFaviconAtReducedSize', function () { | ||
it('returns false if frame is null/undefined', function * () { | ||
assert.equal(faviconState.showFaviconAtReducedSize(), false) | ||
}) | ||
|
||
it('returns true if tab is intersected at 15% size', function * () { | ||
const state = defaultState | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.at15) | ||
const result = faviconState.showFaviconAtReducedSize(state, frameKey) | ||
assert.equal(result, true) | ||
}) | ||
|
||
it('returns false if tab is intersected at larger size', function * () { | ||
const state = defaultState | ||
.setIn(['ui', 'tabs', 'intersectionRatio'], intersection.at20) | ||
const result = faviconState.showFaviconAtReducedSize(state, frameKey) | ||
assert.equal(result, false) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.