Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Commit

Permalink
Enable and fix unit tests (#498 squashed)
Browse files Browse the repository at this point in the history
  • Loading branch information
balcy authored Aug 5, 2021
1 parent f15b0dc commit eef6ff6
Show file tree
Hide file tree
Showing 44 changed files with 302 additions and 589 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ add_custom_target(uninstall

add_subdirectory(src)

#enable_testing()
#add_subdirectory(tests)
enable_testing()
add_subdirectory(tests)

# make non compiled files (QML, JS, images, etc.) visible in QtCreator
file(GLOB NON_COMPILED_ROOT *.png .bzrignore COPYING README snapcraft.yaml)
Expand Down
2 changes: 2 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ Build-Depends: apparmor:native,
qml-module-qt-labs-folderlistmodel,
qml-module-qt-labs-settings,
qml-module-qtquick2 (>= 5.4),
qml-module-qtquick-controls2,
qml-module-qtquick-layouts,
qml-module-qtsysteminfo,
qml-module-qttest,
qml-module-qtwebengine,
qt5-default,
qtbase5-dev (>= 5.4),
qtbase5-dev-tools,
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ override_dh_clean:

override_dh_auto_test:
mkdir -p $(BUILDHOME)
HOME=$(BUILDHOME) dh_auto_test -- ARGS+=-VV
HOME=$(BUILDHOME) dh_auto_test --no-parallel -- ARGS+=-VV
56 changes: 26 additions & 30 deletions src/app/ChromeController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ Item {
QtObject {
id: internal

readonly property int modeAuto: 0//Oxide.LocationBarController.ModeAuto
readonly property int modeShown: 2//Oxide.LocationBarController.ModeShown
readonly property int modeHidden: 3//Oxide.LocationBarController.ModeHidden
readonly property int modeAuto: 0
readonly property int modeShown: 1
readonly property int modeHidden: 2

function updateVisibility() {
if (!webview) {
if (!webview || !webview.locationBarController) {
return
}
return

webview.locationBarController.animated = false
if (forceHide) {
webview.locationBarController.mode = internal.modeHidden
} else if (forceShow) {
webview.locationBarController.mode = internal.modeShown
} else if (!webview.fullscreen) {
} else if (!webview.isFullScreen) {
webview.locationBarController.mode = defaultMode
if (webview.locationBarController.mode == internal.modeAuto) {
if (webview.locationBarController.mode === internal.modeAuto) {
webview.locationBarController.show(false)
}
}
Expand All @@ -60,38 +60,34 @@ Item {
Connections {
target: webview

onFullScreenRequested: {
if (!forceHide) {
if (forceShow) {
webview.locationBarController.mode = internal.modeShown
} else {
webview.locationBarController.mode = defaultMode
if (webview.locationBarController.mode == internal.modeAuto) {
webview.locationBarController.show(true)
}
}
}
}

onFullScreenCancelled: {
webview.locationBarController.mode = internal.modeHidden
onIsFullScreenChanged: {
if (webview.isFullScreen) {
webview.locationBarController.mode = internal.modeHidden
} else if (!forceHide) {
if (forceShow) {
webview.locationBarController.mode = internal.modeShown
} else {
webview.locationBarController.mode = defaultMode
if (webview.locationBarController.mode === internal.modeAuto) {
webview.locationBarController.show(true)
}
}
}
}

onLoadingChanged: {
// When loading, force ModeShown until the load is committed or stopped,
// to work around https://launchpad.net/bugs/1453908.
if (forceHide || forceShow) return
if (loadRequest.status == WebEngineLoadRequest.LoadStartedStatus) {
if (loadRequest.status === WebEngineLoadRequest.LoadStartedStatus) {
if (!webview.isFullScreen && (webview.locationBarController.mode === internal.modeAuto)) {
webview.locationBarController.show(true)
}
webview.locationBarController.mode = internal.modeShown
} else if ((loadRequest.status == WebEngineLoadRequest.LoadSucceededStatus) ||
(loadRequest.status == WebEngineLoadRequest.LoadFailedStatus)) {
} else if ((loadRequest.status === WebEngineLoadRequest.LoadSucceededStatus) ||
(loadRequest.status === WebEngineLoadRequest.LoadFailedStatus)) {
webview.locationBarController.mode = defaultMode
}

if (webview.loading && !webview.fullscreen && !forceHide && !forceShow &&
(webview.locationBarController.mode == internal.modeAuto)) {
webview.locationBarController.show(true)
}
}
}
}
24 changes: 19 additions & 5 deletions src/app/WebProcessMonitor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@ Item {

property var webview: null

readonly property bool killed: webview && false
//(webview.webProcessStatus == Oxide.WebView.WebProcessKilled)
readonly property bool crashed: webview && false
//(webview.webProcessStatus == Oxide.WebView.WebProcessCrashed)
readonly property bool killed: webview && internal.killed
readonly property bool crashed: webview && internal.crashed

// When the renderer process is killed (most likely by the system’s
// OOM killer), try to reload the page once, and if this results in
Expand All @@ -41,17 +39,31 @@ Item {
QtObject {
id: internal
property int killedRetries: 0
property bool killed
property bool crashed
}

Connections {
target: webview
onRenderProcessTerminated: {
if (terminationStatus == WebEngineView.KilledTerminationStatus) {
internal.killed = true;
if (internal.killedRetries == 0) {
// Do not attempt reloading right away, this would result in a crash
delayedReload.restart()
delayedReload.restart();
}
}
if (terminationStatus == WebEngineView.CrashedTerminationStatus) {
internal.crashed = true;
}
}

onLoadingChanged: {
if ((loadRequest.status == WebEngineLoadRequest.LoadSucceededStatus) ||
(loadRequest.status == WebEngineLoadRequest.LoadFailedStatus)) {
internal.killed = false;
internal.crashed = false;
}
}
}

Expand All @@ -73,6 +85,8 @@ Item {

onWebviewChanged: {
internal.killedRetries = 0
internal.killed = false
internal.crashed = false
delayedReload.stop()
monitorTimer.stop()
}
Expand Down
80 changes: 20 additions & 60 deletions src/app/downloads-model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,30 @@ void DownloadsModel::setComplete(const QString& downloadId, const bool complete)
if (entry.complete == complete) {
return;
}
QVector<int> updatedRoles;

entry.complete = complete;
Q_EMIT dataChanged(this->index(index, 0), this->index(index, 0), QVector<int>() << Complete);
updatedRoles.append(Complete);

// Override reported mimetype from server with detected mimetype from file once downloaded
if (complete && QFile::exists(entry.path))
{
QFileInfo fi(entry.path);
QMimeDatabase mimeDatabase;
QString mimetype = mimeDatabase.mimeTypeForFile(fi).name();
if (mimetype != entry.mimetype) {
entry.mimetype = mimetype;
updatedRoles.append(Mimetype);
}
}

Q_EMIT dataChanged(this->index(index, 0), this->index(index, 0), QVector<int>() << updatedRoles);
if (!entry.incognito) {
QSqlQuery query(m_database);
static QString updateStatement = QLatin1String("UPDATE downloads SET complete=? WHERE downloadId=?;");
static QString updateStatement = QLatin1String("UPDATE downloads SET complete=?, mimetype=? WHERE downloadId=?;");
query.prepare(updateStatement);
query.addBindValue(complete);
query.addBindValue(entry.complete);
query.addBindValue(entry.mimetype);
query.addBindValue(downloadId);
query.exec();
}
Expand Down Expand Up @@ -285,63 +302,6 @@ void DownloadsModel::setError(const QString& downloadId, const QString& error)
}
}

void DownloadsModel::moveToDownloads(const QString& downloadId, const QString& path)
{
int index = getIndexForDownloadId(downloadId);
if (index == -1) {
return;
}
QFile file(path);
if (file.exists()) {
QFileInfo fi(path);
DownloadEntry& entry = m_orderedEntries[index];
QVector<int> updatedRoles;

// Override reported mimetype from server with detected mimetype from file once downloaded
QMimeDatabase mimeDatabase;
QString mimetype = mimeDatabase.mimeTypeForFile(fi).name();
if (mimetype != entry.mimetype) {
entry.mimetype = mimetype;
updatedRoles.append(Mimetype);
}

// Move file to XDG Downloads folder
QDir dir(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation));
if (!dir.exists()) {
QDir::root().mkpath(dir.absolutePath());
}
QString baseName = fi.baseName();
QString suffix = fi.completeSuffix();
QString destination = dir.absoluteFilePath(QString("%1.%2").arg(baseName, suffix));
// Avoid filename collision by automatically inserting an incremented
// number into the filename if the original name already exists.
int append = 1;
while (QFile::exists(destination)) {
destination = dir.absoluteFilePath(QString("%1.%2.%3").arg(baseName, QString::number(append++), suffix));
}
if (file.rename(destination)) {
entry.path = destination;
updatedRoles.append(Path);
} else {
qWarning() << "Failed moving file from" << path << "to" << destination;
}

Q_EMIT dataChanged(this->index(index, 0), this->index(index, 0), updatedRoles);
if (!entry.incognito && !updatedRoles.isEmpty()) {
QSqlQuery query(m_database);
static QString updateStatement = QLatin1String("UPDATE downloads SET mimetype = ?, "
"path = ? WHERE downloadId = ?");
query.prepare(updateStatement);
query.addBindValue(mimetype);
query.addBindValue(destination);
query.addBindValue(downloadId);
query.exec();
}
} else {
qWarning() << "Download not found:" << path;
}
}

void DownloadsModel::insertNewEntryInDatabase(const DownloadEntry& entry)
{
QSqlQuery query(m_database);
Expand Down
1 change: 0 additions & 1 deletion src/app/downloads-model.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class DownloadsModel : public QAbstractListModel

Q_INVOKABLE bool contains(const QString& downloadId) const;
Q_INVOKABLE void add(const QString& downloadId, const QUrl& url, const QString& path, const QString& mimetype, bool incognito);
Q_INVOKABLE void moveToDownloads(const QString& downloadId, const QString& path);
Q_INVOKABLE void setComplete(const QString& downloadId, const bool complete);
Q_INVOKABLE void setError(const QString& downloadId, const QString& error);
Q_INVOKABLE void deleteDownload(const QString& path);
Expand Down
18 changes: 8 additions & 10 deletions src/app/webbrowser/Browser.qml
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,19 @@ Common.BrowserView {
property Component windowFactory

function serializeTabState(tab) {
var state = {}
state.uniqueId = tab.uniqueId
state.url = tab.url.toString()
state.title = tab.title
state.icon = tab.icon.toString()
state.preview = Qt.resolvedUrl(PreviewManager.previewPathFromUrl(tab.url))
state.savedState = tab.webview ? tab.webview.currentState : tab.restoreState
return state
var state = {};
state.uniqueId = tab.uniqueId;
state.url = tab.url.toString();
state.title = tab.title;
state.icon = tab.icon.toString();
state.preview = Qt.resolvedUrl(PreviewManager.previewPathFromUrl(tab.url)).toString();
return state;
}

function restoreTabState(state) {
var properties = {'initialUrl': state.url, 'initialTitle': state.title,
'uniqueId': state.uniqueId, 'initialIcon': state.icon,
'preview': state.preview, 'restoreState': state.savedState}
// 'restoreType': Oxide.WebView.RestoreLastSessionExitedCleanly}
'preview': state.preview}
return createTab(properties)
}

Expand Down
12 changes: 2 additions & 10 deletions src/app/webbrowser/BrowserTab.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ FocusScope {
property url initialUrl
property string initialTitle
property url initialIcon
property string restoreState
property int restoreType
property var request
property Component webviewComponent
readonly property var webview: webviewContainer.webview
Expand All @@ -43,7 +41,7 @@ FocusScope {
property bool current: false
readonly property real lastCurrent: internal.lastCurrent
property bool incognito
readonly property bool empty: !url.toString() && !initialUrl.toString() && !restoreState && !request
readonly property bool empty: !url.toString() && !initialUrl.toString() && !request
property bool loadingPreview: false
readonly property size previewSize: webview ? Qt.size(webview.width*Screen.devicePixelRatio,
webview.height*Screen.devicePixelRatio) : Qt.size(0,0)
Expand Down Expand Up @@ -77,13 +75,7 @@ FocusScope {

function load() {
if (!webview && !internal.incubator) {
var properties = {'tab': tab, 'incognito': incognito}
if (restoreState) {
properties['restoreState'] = restoreState
properties['restoreType'] = restoreType
} else {
properties['url'] = initialUrl
}
var properties = {'tab': tab, 'incognito': incognito, 'url': initialUrl}
var incubator = webviewComponent.incubateObject(webviewContainer, properties)
if (incubator === null) {
console.warn("Webview incubator failed to initialize")
Expand Down
7 changes: 6 additions & 1 deletion src/app/webbrowser/HoveredUrlLabel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Item {
}
fontSize: "small"
elide: (root.state == "expanded") ? Text.ElideNone : Text.ElideRight
text: ""//(root.webview && root.webview.visible) ? root.webview.hoveredUrl : ""
text: ""
onTextChanged: {
if (text) {
if (root.state == "hidden") {
Expand All @@ -86,4 +86,9 @@ Item {
}
}
}

Connections {
target: root.webview
onLinkHovered: label.text = hoveredUrl.toString()
}
}
2 changes: 1 addition & 1 deletion src/app/webbrowser/PreviewManager.qml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Item {
}
function contains(url) {
for (var i = 0; i < topSites.count; i++) {
if (topSites.get(i).url === url) return true
if (topSites.get(i).url == url) return true
}
return false
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/webcontainer/WebApp.qml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ Common.BrowserView {
left: parent.left
right: parent.right
}
visible: state !== "hidden"
height: (state === "hidden") ? 0 : units.gu(6)
y: webapp.currentWebview ? containerWebView.currentWebview.locationBarController.offset : 0
availableHeight: containerWebView.height
Expand Down Expand Up @@ -491,7 +492,7 @@ Common.BrowserView {
if (webapp.currentWebview.isFullScreen) {
chromeLoader.item.state = "hidden";
} else {
chromeLoader.item.state === "shown";
chromeLoader.item.state = "shown";
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/autopilot/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ project(autopilot-tests)
execute_process(COMMAND python3 -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())"
OUTPUT_VARIABLE PYTHON_PACKAGE_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)

install(DIRECTORY webbrowser_app webapp_container
DESTINATION ${PYTHON_PACKAGE_DIR}
)
#install(DIRECTORY webbrowser_app webapp_container
# DESTINATION ${PYTHON_PACKAGE_DIR}
# )
Loading

0 comments on commit eef6ff6

Please sign in to comment.