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 975
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
Showing
21 changed files
with
1,080 additions
and
900 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
/* 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 locale = require('../../../js/l10n') | ||
const frameStateUtil = require('../../../js/state/frameStateUtil.js') | ||
|
||
module.exports.iconSize = 16 | ||
|
||
module.exports.getDisplayTitle = (state, frameKey) => { | ||
const frame = frameStateUtil.getFrameByKey(state, frameKey) | ||
|
||
if (!frame) { | ||
return '' | ||
} | ||
|
||
// For renderer initiated navigation, make sure we show Untitled | ||
// until we know what we're loading. We should probably do this for | ||
// all about: pages that we already know the title for so we don't have | ||
// to wait for the title to be parsed. | ||
if (frame.get('location') === 'about:blank') { | ||
return locale.translation('aboutBlankTitle') | ||
} else if (frame.get('location') === 'about:newtab') { | ||
return locale.translation('newTab') | ||
} | ||
|
||
// YouTube tries to change the title to add a play icon when | ||
// there is audio. Since we have our own audio indicator we get | ||
// rid of it. | ||
return (frame.get('title') || frame.get('location') || '').replace('▶ ', '') | ||
} |
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
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,95 @@ | ||
/* 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 frameKey = 1 | ||
const defaultWindowStore = Immutable.fromJS({ | ||
activeFrameKey: frameKey, | ||
frames: [{ | ||
key: frameKey, | ||
tabId: 1, | ||
location: 'http://brave.com' | ||
}], | ||
tabs: [{ | ||
key: frameKey | ||
}], | ||
framesInternal: { | ||
index: { | ||
1: 0 | ||
}, | ||
tabIndex: { | ||
1: 0 | ||
} | ||
} | ||
}) | ||
|
||
describe('tabContentUtil unit tests', function () { | ||
let tabContentUtil | ||
|
||
before(function () { | ||
mockery.enable({ | ||
warnOnReplace: false, | ||
warnOnUnregistered: false, | ||
useCleanCache: true | ||
}) | ||
mockery.registerMock('electron', fakeElectron) | ||
mockery.registerMock('../../../js/l10n', { | ||
translation: () => 'translated' | ||
}) | ||
tabContentUtil = require('../../../../../app/common/lib/tabContentUtil') | ||
}) | ||
|
||
after(function () { | ||
mockery.disable() | ||
}) | ||
|
||
it('should return empty string if frame is not found', function * () { | ||
const result = tabContentUtil.getDisplayTitle(defaultWindowStore, 0) | ||
assert.equal(result, '') | ||
}) | ||
|
||
it('should return translated title for about:blank', function * () { | ||
const windowStore = defaultWindowStore.mergeIn(['frames', 0], { | ||
location: 'about:blank' | ||
}) | ||
const result = tabContentUtil.getDisplayTitle(windowStore, frameKey) | ||
assert.equal(result, 'translated') | ||
}) | ||
|
||
it('should return translated title for about:newtab', function * () { | ||
const windowStore = defaultWindowStore.mergeIn(['frames', 0], { | ||
location: 'about:blank' | ||
}) | ||
const result = tabContentUtil.getDisplayTitle(windowStore, frameKey) | ||
assert.equal(result, 'translated') | ||
}) | ||
|
||
it('should return title', function * () { | ||
const title = 'Brave' | ||
const windowStore = defaultWindowStore.mergeIn(['frames', 0], { | ||
title: title | ||
}) | ||
const result = tabContentUtil.getDisplayTitle(windowStore, frameKey) | ||
assert.equal(result, title) | ||
}) | ||
|
||
it('should return location if title is not provided', function * () { | ||
const result = tabContentUtil.getDisplayTitle(defaultWindowStore, frameKey) | ||
assert.equal(result, defaultWindowStore.getIn(['frames', 0, 'location'])) | ||
}) | ||
|
||
it('should replace play indicator from the title (added by Youtube)', function * () { | ||
const windowStore = defaultWindowStore.mergeIn(['frames', 0], { | ||
title: '▶ Brave' | ||
}) | ||
const result = tabContentUtil.getDisplayTitle(windowStore, frameKey) | ||
assert.equal(result, 'Brave') | ||
}) | ||
}) |
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
Oops, something went wrong.