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

Commit

Permalink
WIP unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Apr 26, 2017
1 parent 4583fd6 commit dc3207d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
7 changes: 7 additions & 0 deletions app/renderer/lib/domUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports.createWebView = () => {
return document.createElement('webview')
}

module.exports.appendChild = (element, child) => {
element.appendChild(child)
}
22 changes: 12 additions & 10 deletions js/components/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const UrlUtil = require('../lib/urlutil')
const cx = require('../lib/classSet')
const urlParse = require('../../app/common/urlParse')
const contextMenus = require('../contextMenus')
const domUtil = require('../../app/renderer/lib/domUtil')
const {
aboutUrls,
isSourceMagnetUrl,
Expand Down Expand Up @@ -191,7 +192,7 @@ class Frame extends React.Component {
// Create the webview dynamically because React doesn't whitelist all
// of the attributes we need
if (this.shouldCreateWebview()) {
this.webview = document.createElement('webview')
this.webview = domUtil.createWebView()
this.webview.setAttribute('data-frame-key', this.props.frameKey)

this.addEventListeners()
Expand All @@ -210,7 +211,7 @@ class Frame extends React.Component {
this.webview.setAttribute('partition', frameStateUtil.getPartition(this.frame))
this.webview.setAttribute('src', newSrc)
}
this.webviewContainer.appendChild(this.webview)
domUtil.appendChild(this.webviewContainer, this.webview)
} else {
cb && cb(prevProps)
}
Expand Down Expand Up @@ -355,13 +356,13 @@ class Frame extends React.Component {
// This can happen for pages which don't load properly.
// Some examples are basic http auth and bookmarklets.
// In this case both the user display and the user think they're on this.props.location.
if (this.tab.get('url') !== this.props.location &&
if (this.props.tabUrl !== this.props.location &&
!this.isAboutPage() &&
!isTorrentViewerURL(this.props.location)) {
this.webview.loadURL(this.props.location)
} else if (this.isIntermediateAboutPage() &&
this.tab.get('url') !== this.props.location &&
this.tab.get('url') !== this.props.aboutDetailsUrl) {
this.props.tabUrl !== this.props.location &&
this.props.tabUrl !== this.props.aboutDetailsUrl) {
appActions.loadURLRequested(this.props.aboutDetailsUrl,
this.props.aboutDetailsFrameKey)
} else {
Expand All @@ -384,7 +385,7 @@ class Frame extends React.Component {
this.zoomReset()
break
case 'view-source':
const sourceLocation = UrlUtil.getViewSourceUrlFromUrl(this.tab.get('url'))
const sourceLocation = UrlUtil.getViewSourceUrlFromUrl(this.props.tabUrl)
if (sourceLocation !== null) {
appActions.createTabRequested({
url: sourceLocation,
Expand All @@ -398,8 +399,8 @@ class Frame extends React.Component {
break
case 'save':
const downloadLocation = getSetting(settings.PDFJS_ENABLED)
? UrlUtil.getLocationIfPDF(this.tab.get('url'))
: this.tab.get('url')
? UrlUtil.getLocationIfPDF(this.props.tabUrl)
: this.props.tabUrl
// TODO: Sometimes this tries to save in a non-existent directory
this.webview.downloadURL(downloadLocation, true)
break
Expand All @@ -410,7 +411,7 @@ class Frame extends React.Component {
windowActions.setFindbarShown(this.props.frameKey, true)
break
case 'fill-password':
let currentUrl = urlParse(this.tab.get('url'))
let currentUrl = urlParse(this.props.tabUrl)
if (currentUrl &&
[currentUrl.protocol, currentUrl.host].join('//') === this.props.shortcutDetailsOrigin) {
this.webview.send(messages.GOT_PASSWORD,
Expand Down Expand Up @@ -1032,7 +1033,8 @@ class Frame extends React.Component {
props.unloaded = frame.get('unloaded')
props.isWidevineEnabled = state.get('widevine') && state.getIn(['widevine', 'enabled'])
props.siteZoomLevel = frameSiteSettings && frameSiteSettings.get('zoomLevel')
props.allSiteSettings = allSiteSettings // TODO remove
props.allSiteSettings = allSiteSettings // TODO (nejc) can be improved even more
props.tabUrl = tab && tab.get('url')

return Object.assign({}, ownProps, props)
}
Expand Down
22 changes: 21 additions & 1 deletion test/unit/js/components/frameTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,26 @@ describe('Frame component unit tests', function () {
const fakeWindowActions = {
frameShortcutChanged: () => {},
setFindbarShown: () => {},
setActiveFrame: () => {}
setActiveFrame: () => {},
setLastZoomPercentage: () => {}
}

const domUtil = {
appendChild: () => {},
createWebView: () => {
return {
setAttribute: () => {},
addEventListener: () => {},
removeEventListener: () => {},
attachGuest: () => {},
zoomIn: () => {},
zoomOut: () => {},
zoomReset: () => {},
executeScriptInTab: () => {},
focus: () => {},
getZoomPercent: () => {}
}
}
}

before(function () {
Expand All @@ -64,6 +83,7 @@ describe('Frame component unit tests', function () {
mockery.registerMock('../../extensions/brave/img/caret_down_grey.svg', 'caret_down_grey.svg')
mockery.registerMock('electron', require('../../lib/fakeElectron'))
mockery.registerMock('../actions/windowActions', fakeWindowActions)
mockery.registerMock('../../app/renderer/lib/domUtil', domUtil)
// the version in frame.js
mockery.registerMock('../stores/appStoreRenderer', fakeAppStoreRenderer)
// the version in reduxComponent.js
Expand Down

0 comments on commit dc3207d

Please sign in to comment.