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

Extra polish for showing history on back/forward long press #2733

Merged
merged 2 commits into from
Jul 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

## About tests

Tests use the [mocha test frameowrk](https://mochajs.org/).
Tests use the [mocha test framework](https://mochajs.org/).

Most tests use [webdriver.io](http://webdriver.io/) to bring up the browser and run through the tests.
Most tests use [webdriver.io](http://webdriver.io/) framework (via [Spectron](https://github.com/electron/spectron) to bring up the browser and run through the tests.

Tests are located in the top level `test` directory and their filenames have a suffix of `Test.js`.

Expand Down
42 changes: 29 additions & 13 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,28 +786,44 @@ class Frame extends ImmutableComponent {
this.webview.goBack()
}

getHistory () {
getHistoryEntry (sites, webContent, index) {
const url = webContent.getURLAtIndex(index)
const title = webContent.getTitleAtIndex(index)

let entry = {
index: index,
url: url,
display: title || url,
icon: null
}

if (url.startsWith('chrome-extension://')) {
// TODO: return brave lion (or better: get icon from extension if possible as data URI)
} else {
if (sites) {
const site = sites.find(function (element) { return element.get('location') === url })
if (site) { entry.icon = site.get('favicon') }
}

if (!entry.icon) { entry.icon = UrlUtil.getDefaultFaviconUrl(url) }
}

return entry
}

getHistory (appState) {
const webContent = this.webview.getWebContents()
const currentIndex = webContent.getCurrentEntryIndex()
const historyCount = webContent.getEntryCount()
const sites = appState ? appState.get('sites') : null

let history = {
count: historyCount,
currentIndex: currentIndex,
currentIndex: webContent.getCurrentEntryIndex(),
entries: []
}

for (let index = 0; index < historyCount; index++) {
const url = webContent.getURLAtIndex(index)
const title = webContent.getTitleAtIndex(index)

history.entries.push({
index: index,
url: url,
title: title,
display: title || url,
icon: UrlUtil.getDefaultFaviconUrl(url)
})
history.entries.push(this.getHistoryEntry(sites, webContent, index))
}

return history
Expand Down
4 changes: 2 additions & 2 deletions js/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,15 @@ class Main extends ImmutableComponent {
}

onBackLongPress (rect) {
contextMenus.onBackButtonHistoryMenu(this.activeFrame, this.activeFrame.getHistory(), rect)
contextMenus.onBackButtonHistoryMenu(this.activeFrame, this.activeFrame.getHistory(this.props.appState), rect)
}

onForward () {
this.activeFrame.goForward()
}

onForwardLongPress (rect) {
contextMenus.onForwardButtonHistoryMenu(this.activeFrame, this.activeFrame.getHistory(), rect)
contextMenus.onForwardButtonHistoryMenu(this.activeFrame, this.activeFrame.getHistory(this.props.appState), rect)
}

onBraveMenu () {
Expand Down
27 changes: 23 additions & 4 deletions js/contextMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const textUtils = require('./lib/text')
const {isIntermediateAboutPage, isUrl} = require('./lib/appUrlUtil')
const {getBase64FromImageUrl} = require('./lib/imageUtil')
const urlParse = require('url').parse
const eventUtil = require('./lib/eventUtil')

const isDarwin = process.platform === 'darwin'

Expand Down Expand Up @@ -1066,11 +1067,20 @@ function onBackButtonHistoryMenu (activeFrame, history, rect) {

if (activeFrame && history) {
for (let index = (history.currentIndex - 1); index > -1; index--) {
const url = history.entries[index].url

menuTemplate.push({
label: history.entries[index].display,
icon: history.entries[index].icon,
click: (item, focusedWindow) => {
activeFrame.goToIndex(index)
click: (e, focusedWindow) => {
if (eventUtil.isForSecondaryAction(e)) {
windowActions.newFrame({
location: url,
partitionNumber: activeFrame.props.frame.get('partitionNumber')
}, !!e.shiftKey)
} else {
activeFrame.goToIndex(index)
}
}
})
}
Expand All @@ -1088,11 +1098,20 @@ function onForwardButtonHistoryMenu (activeFrame, history, rect) {

if (activeFrame && history) {
for (let index = (history.currentIndex + 1); index < history.entries.length; index++) {
const url = history.entries[index].url

menuTemplate.push({
label: history.entries[index].display,
icon: history.entries[index].icon,
click: (item, focusedWindow) => {
activeFrame.goToIndex(index)
click: (e, focusedWindow) => {
if (eventUtil.isForSecondaryAction(e)) {
windowActions.newFrame({
location: url,
partitionNumber: activeFrame.props.frame.get('partitionNumber')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for catching partition number too 👍

}, !!e.shiftKey)
} else {
activeFrame.goToIndex(index)
}
}
})
}
Expand Down
1 change: 0 additions & 1 deletion test/lib/brave.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ require('babel-polyfill')
var Application = require('spectron').Application
var chai = require('chai')
require('./coMocha')
require('jsdom-global')()

const path = require('path')
const fs = require('fs')
Expand Down
1 change: 1 addition & 0 deletions test/unit/braveUnit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('jsdom-global')()
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* global describe, it */
const CryptoUtil = require('../../js/lib/cryptoUtil')
const CryptoUtil = require('../../../js/lib/cryptoUtil')
const assert = require('assert')

require('../braveUnit')

describe('crypto util test', function () {
it('gets random bytes', function () {
assert.equal(CryptoUtil.getRandomBytes(256).length, 256)
Expand Down
5 changes: 3 additions & 2 deletions test/lib/urlutilTest.js → test/unit/lib/urlutilTest.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* global describe, it */

const UrlUtil = require('../../js/lib/urlutil')
const UrlUtil = require('../../../js/lib/urlutil')
const assert = require('assert')

require('../braveUnit')

describe('urlutil', function () {
describe('getScheme', function () {
it('null for empty', function * () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* global describe, before, it */
const frameStateUtil = require('../../js/state/frameStateUtil')
/* global describe, before, it, beforeEach */
const frameStateUtil = require('../../../js/state/frameStateUtil')
const Immutable = require('immutable')
const assert = require('assert')

/*global beforeEach */
require('../braveUnit')

const defaultWindowStore = Immutable.fromJS({
activeFrameKey: null,
Expand Down
3 changes: 2 additions & 1 deletion tools/lib/ignoredPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ module.exports = [
'flow-bin',
'mkdirp',
'babel$',
'babel-(?!polyfill|regenerator-runtime)'
'babel-(?!polyfill|regenerator-runtime)',
'jsdom-global'
]