summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonatan Pålsson <jonatan.palsson@pelagicore.com>2014-02-12 10:01:57 +0100
committerJonatan Pålsson <jonatan.palsson@pelagicore.com>2014-02-12 10:01:57 +0100
commit4152aaddcbf51aa391e25a6b5372c1202469063f (patch)
tree592841ac7af119c697518f62e451c593b2df5fd7
parent41c5d285ffd16d0efb1af8113a796b2d457fbff8 (diff)
downloadbrowser-poc-4152aaddcbf51aa391e25a6b5372c1202469063f.tar.gz
Added manual tests for CacheManager
-rw-r--r--browser/browser.cpp4
-rw-r--r--browser/browserview.cpp15
-rw-r--r--browser/browserview.h3
-rw-r--r--browser/cachemanager.cpp8
-rw-r--r--browser/cachemanager.h4
-rw-r--r--common/cachemanagerdbus.cpp31
-rw-r--r--common/cachemanagerdbus.h3
-rw-r--r--common/common.pri2
-rw-r--r--testapp/main.cpp2
-rw-r--r--testapp/qml/testapp/CacheManager.qml163
-rw-r--r--testapp/qml/testapp/main.qml14
-rw-r--r--testapp/testapp.pro13
12 files changed, 233 insertions, 29 deletions
diff --git a/browser/browser.cpp b/browser/browser.cpp
index 0bcbc00..5cf030b 100644
--- a/browser/browser.cpp
+++ b/browser/browser.cpp
@@ -33,9 +33,7 @@ conn::brw::ERROR_IDS browser::createPageWindow(int a_eDeviceId, const conn::brw:
Q_UNUSED(a_eDeviceId);
- BrowserView *bvi = new BrowserView();
- if (m_cacheManager)
- bvi->setCacheManager (m_cacheManager);
+ BrowserView *bvi = new BrowserView(m_cacheManager);
bvi->setGeometry(a_oGeometry.i32X, a_oGeometry.i32Y, a_oGeometry.i32Width,
a_oGeometry.i32Height);
diff --git a/browser/browserview.cpp b/browser/browserview.cpp
index ad44402..a063afb 100644
--- a/browser/browserview.cpp
+++ b/browser/browserview.cpp
@@ -20,10 +20,12 @@
#include <QWebSettings>
#include "browserview.h"
+#include "cachemanager.h"
#include "../common/browserdefs.h"
-BrowserView::BrowserView()
+BrowserView::BrowserView(cachemanager *cm)
{
+ m_cacheManager = cm;
if (!this->scene()) {
this->setScene(new QGraphicsScene());
}
@@ -31,6 +33,8 @@ BrowserView::BrowserView()
QWebSettings::setIconDatabasePath(".");
+ m_webview.page()->setNetworkAccessManager(cm->getNetworkAccessManager());
+
this->load("http://www.bmw.com");
this->installEventFilter(this);
@@ -266,12 +270,3 @@ void BrowserView::select() {
void BrowserView::activate() {
this->activateWindow();
}
-
-void BrowserView::setCacheManager(cachemanager *cm) {
- if (cm) {
- qDebug() << "Setting cacheManager" << cm;
- m_cacheManager = cm;
- m_webview.page()->setNetworkAccessManager(cm->getNetworkAccessManager());
- } else
- qDebug() << "Setting NULL networkManager!";
-}
diff --git a/browser/browserview.h b/browser/browserview.h
index 853c66f..3099c34 100644
--- a/browser/browserview.h
+++ b/browser/browserview.h
@@ -62,7 +62,7 @@ class BrowserView : public QGraphicsView
{
Q_OBJECT
public:
- BrowserView();
+ BrowserView(cachemanager *);
bool load(const QString &a_Url);
int getProgress() { return m_currentProgress; }
QString getUrl() { return m_webview.url().toString(); }
@@ -82,7 +82,6 @@ public:
QString getFaviconFilePath(QString url);
void activate();
void select();
- void setCacheManager (cachemanager *nm);
signals:
void pageLoadStarted();
diff --git a/browser/cachemanager.cpp b/browser/cachemanager.cpp
index dfe3dfa..7d18e34 100644
--- a/browser/cachemanager.cpp
+++ b/browser/cachemanager.cpp
@@ -26,7 +26,7 @@ cachemanager::cachemanager(QObject *parent) :
m_config = new BrowserConfig();
m_manager = new QNetworkAccessManager();
QNetworkDiskCache *cache = new QNetworkDiskCache();
- cache->setCacheDirectory ("cache");
+ cache->setCacheDirectory ("/tmp/browserpoc_cache");
if (cache)
m_manager->setCache(cache);
else
@@ -51,7 +51,8 @@ cachemanager::cachemanager(QObject *parent) :
}
}
-qlonglong cachemanager::getCacheSize(){
+qulonglong cachemanager::getCacheSize(){
+ qDebug() << "Getting cache size";
if (!m_manager->cache()) {
qDebug() << "Unable to retreive cache!";
return 0;
@@ -64,7 +65,7 @@ conn::brw::CACHE_POLICY cachemanager::getCachePolicy(){
return m_policy;
}
-qlonglong cachemanager::getMaximumCacheSize(){
+qulonglong cachemanager::getMaximumCacheSize(){
if (!m_manager->cache()) {
qDebug() << "Unable to retreive cache!";
return 0;
@@ -80,6 +81,7 @@ qlonglong cachemanager::getMaximumCacheSize(){
conn::brw::ERROR_IDS cachemanager::setCachePolicy(conn::brw::CACHE_POLICY pol)
{
+ qDebug() << "Setting cache policy:" << pol;
m_config->setValue(BrowserConfig::CONFIG_CACHEPOLICY, pol);
m_policy = pol;
return conn::brw::EID_NO_ERROR;
diff --git a/browser/cachemanager.h b/browser/cachemanager.h
index 4a821db..dba1f99 100644
--- a/browser/cachemanager.h
+++ b/browser/cachemanager.h
@@ -34,9 +34,9 @@ signals:
void cacheChanged();
public Q_SLOTS:
- qlonglong getCacheSize();
+ qulonglong getCacheSize();
conn::brw::CACHE_POLICY getCachePolicy();
- qlonglong getMaximumCacheSize();
+ qulonglong getMaximumCacheSize();
conn::brw::ERROR_IDS setCachePolicy(conn::brw::CACHE_POLICY);
conn::brw::ERROR_IDS clearCache();
diff --git a/common/cachemanagerdbus.cpp b/common/cachemanagerdbus.cpp
index 6431634..3fcc20d 100644
--- a/common/cachemanagerdbus.cpp
+++ b/common/cachemanagerdbus.cpp
@@ -51,8 +51,13 @@ void CacheManagerDbus::connectdbussession(QString id) {
qulonglong CacheManagerDbus::getCacheSize() {
qDebug() << __PRETTY_FUNCTION__;
+ qulonglong ret = 0;
+
+ if (!m_cachemanager){
+ qDebug() << "Manager not initialized, call connectdbussession first";
+ return ret;
+ }
- qulonglong ret;
QDBusReply<qulonglong> reply = m_cachemanager->getCacheSize();
if(reply.isValid()) {
@@ -68,7 +73,13 @@ qulonglong CacheManagerDbus::getCacheSize() {
conn::brw::CACHE_POLICY CacheManagerDbus::getCachePolicy() {
qDebug() << __PRETTY_FUNCTION__;
- conn::brw::CACHE_POLICY ret;
+ conn::brw::CACHE_POLICY ret = conn::brw::CP_ONLINE_CACHE;
+
+ if (!m_cachemanager){
+ qDebug() << "Manager not initialized, call connectdbussession first";
+ return ret;
+ }
+
QDBusReply<conn::brw::CACHE_POLICY> reply = m_cachemanager->getCachePolicy();
if(reply.isValid()) {
@@ -84,6 +95,10 @@ conn::brw::CACHE_POLICY CacheManagerDbus::getCachePolicy() {
void CacheManagerDbus::setCachePolicy(conn::brw::CACHE_POLICY policy) {
qDebug() << __PRETTY_FUNCTION__;
+ if (!m_cachemanager){
+ qDebug() << "Manager not initialized, call connectdbussession first";
+ }
+
QDBusReply<conn::brw::ERROR_IDS> reply = m_cachemanager->setCachePolicy(policy);
if(reply.isValid()) {
@@ -99,7 +114,13 @@ void CacheManagerDbus::setCachePolicy(conn::brw::CACHE_POLICY policy) {
qulonglong CacheManagerDbus::getMaximumCacheSize() {
qDebug() << __PRETTY_FUNCTION__;
- qlonglong ret;
+ qlonglong ret = 0;
+
+ if (!m_cachemanager){
+ qDebug() << "Manager not initialized, call connectdbussession first";
+ return ret;
+ }
+
QDBusReply<qulonglong> reply = m_cachemanager->getMaximumCacheSize();
if(reply.isValid()) {
@@ -117,6 +138,10 @@ void CacheManagerDbus::clearCache() {
QDBusReply<conn::brw::ERROR_IDS> reply = m_cachemanager->clearCache();
+ if (!m_cachemanager){
+ qDebug() << "Manager not initialized, call connectdbussession first";
+ }
+
if(reply.isValid()) {
conn::brw::ERROR_IDS ret;
ret = reply.value();
diff --git a/common/cachemanagerdbus.h b/common/cachemanagerdbus.h
index ff94f55..f9cf9fb 100644
--- a/common/cachemanagerdbus.h
+++ b/common/cachemanagerdbus.h
@@ -19,6 +19,7 @@
#include "icachemanager_interface.h"
#include "../common/bookmark.h"
+#include "browserdefs.h"
class CacheManagerDbus : public QObject
{
@@ -27,7 +28,7 @@ class CacheManagerDbus : public QObject
public:
explicit CacheManagerDbus(QObject *parent = 0);
- void connectdbussession(QString id);
+ Q_INVOKABLE void connectdbussession(QString id);
Q_INVOKABLE qulonglong getCacheSize();
Q_INVOKABLE conn::brw::CACHE_POLICY getCachePolicy();
Q_INVOKABLE void setCachePolicy(conn::brw::CACHE_POLICY);
diff --git a/common/common.pri b/common/common.pri
index 21019a8..256f32c 100644
--- a/common/common.pri
+++ b/common/common.pri
@@ -1,5 +1,5 @@
SOURCES += ../common/bookmark.cpp \
- ../common/browserdbus.cpp
+ ../common/browserdbus.cpp
HEADERS += ../common/bookmark.h \
../common/browserdefs.h \
diff --git a/testapp/main.cpp b/testapp/main.cpp
index 13a30c8..1149390 100644
--- a/testapp/main.cpp
+++ b/testapp/main.cpp
@@ -15,12 +15,14 @@
#include <QQuickWindow>
#include <QtQml>
#include "../common/browserdbus.h"
+#include "../common/cachemanagerdbus.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
qmlRegisterType<BrowserDbus>("browserdbusinterface",1,0,"BrowserInterface");
+ qmlRegisterType<CacheManagerDbus>("browserdbusinterface",1,0,"CacheManagerInterface");
qmlRegisterType<Bookmark>("browserdbusinterface",1,0,"Tmp");
QQmlApplicationEngine engine("qml/testapp/main.qml");
diff --git a/testapp/qml/testapp/CacheManager.qml b/testapp/qml/testapp/CacheManager.qml
new file mode 100644
index 0000000..be38609
--- /dev/null
+++ b/testapp/qml/testapp/CacheManager.qml
@@ -0,0 +1,163 @@
+import QtQuick 2.0
+import QtQuick.Controls 1.0
+
+Item {
+ id: root
+ anchors.fill: parent
+
+ GroupBox {
+ id: group_box2
+ y: 0
+ width: 9
+ title: "Fetch cache properties"
+ anchors.right: parent.right
+ anchors.rightMargin: 0
+ anchors.left: parent.left
+ anchors.leftMargin: 0
+
+ GroupBox { id: cacheSizeGroup;
+ width: -16
+ anchors.top: parent.top
+ anchors.topMargin: 0
+ anchors.right: parent.right
+ anchors.rightMargin: 0
+ anchors.left: parent.left
+ anchors.leftMargin: 0
+
+ Text {
+ id: textCacheSize
+ y: 0
+ text: qsTr("")
+ anchors.left: parent.left
+ anchors.leftMargin: 0
+ anchors.verticalCenter: cacheSizeButton.verticalCenter
+ font.pixelSize: 12
+ }
+
+ Button {
+ id: cacheSizeButton
+ x: 156
+ width: maxCacheSizeButton.width
+ text: "Get cache size"
+ anchors.right: parent.right
+ anchors.rightMargin: 0
+ anchors.top: parent.top
+ anchors.topMargin: 0
+ onClicked: textCacheSize.text = cachemanagerinterface.getCacheSize()
+ }
+
+ Button {
+ id: maxCacheSizeButton
+ x: -129
+ y: 47
+ width: 158
+ height: 31
+ text: "Get max cache size"
+ anchors.horizontalCenter: cacheSizeButton.horizontalCenter
+ anchors.topMargin: 10
+ anchors.top: cacheSizeButton.bottom
+ onClicked: textMaxCacheSize.text = cachemanagerinterface.getMaximumCacheSize()
+ }
+
+ Text {
+ id: textMaxCacheSize
+ y: 48
+ text: qsTr("")
+ anchors.left: parent.left
+ anchors.leftMargin: 0
+ anchors.verticalCenterOffset: 0
+ font.pixelSize: 12
+ anchors.verticalCenter: maxCacheSizeButton.verticalCenter
+ }
+
+ Button {
+ id: getCachePolicyButton
+ x: -422
+ width: maxCacheSizeButton.width
+ text: "Get cache policy"
+ anchors.top: maxCacheSizeButton.bottom
+ anchors.topMargin: 10
+ anchors.horizontalCenter: cacheSizeButton.horizontalCenter
+ onClicked:textCachePolicy.text = cachemanagerinterface.getCachePolicy();
+ }
+
+ Text {
+ id: textCachePolicy
+ y: 79
+ text: qsTr("")
+ anchors.left: parent.left
+ anchors.leftMargin: 0
+ anchors.verticalCenter: getCachePolicyButton.verticalCenter
+ font.pixelSize: 12
+}
+
+}
+ }
+
+ GroupBox {
+ id: group_box1
+ height: setCachePolicyGroup.height
+ anchors.top: group_box2.bottom
+ anchors.topMargin: 20
+ anchors.right: parent.right
+ anchors.rightMargin: 0
+ anchors.left: parent.left
+ anchors.leftMargin: 0
+ title: "Cache Settings"
+
+ GroupBox {
+ id: setCachePolicyGroup
+ x: 185
+ y: 0
+ width: onlineCachebutton.width*3
+ height: onlineCacheButton.height
+ title: ""
+ anchors.horizontalCenter: parent.horizontalCenter
+
+ Button {
+ id: onlineOnlyButton
+ x: 127
+ y: 6
+ width: onlineCacheButton.width
+ text: "CP_ONLINE_ONLY"
+ anchors.left: cacheOnlyButton.right
+ anchors.leftMargin: 0
+ anchors.verticalCenter: onlineCacheButton.verticalCenter
+ onClicked: cachemanagerinterface.setCachePolicy(2);
+ }
+
+ Button {
+ id: cacheOnlyButton
+ x: 42
+ y: 6
+ width: onlineCacheButton.width
+ text: "CP_CACHE_ONLY"
+ anchors.left: onlineCacheButton.right
+ anchors.leftMargin: 0
+ anchors.verticalCenter: onlineCacheButton.verticalCenter
+ onClicked: cachemanagerinterface.setCachePolicy(1);
+ }
+
+ Button {
+ id: onlineCacheButton
+ width: 170
+ height: 31
+ text: "CP_ONLINE_CACHE"
+ anchors.top: parent.top
+ anchors.topMargin: 0
+ anchors.left: parent.left
+ anchors.leftMargin: 0
+ onClicked: cachemanagerinterface.setCachePolicy(0);
+ }
+
+
+
+}
+}
+
+
+
+
+}
+
+
diff --git a/testapp/qml/testapp/main.qml b/testapp/qml/testapp/main.qml
index fe30f3e..9802b20 100644
--- a/testapp/qml/testapp/main.qml
+++ b/testapp/qml/testapp/main.qml
@@ -13,6 +13,10 @@ ApplicationWindow {
id: browserinterface
}
+ CacheManagerInterface {
+ id: cachemanagerinterface
+ }
+
Item {
id: header
width: parent.width
@@ -49,7 +53,8 @@ ApplicationWindow {
anchors.left: inputstring.right
anchors.leftMargin: 20
text: "Connect"
- onClicked: browserinterface.connectdbussession(inputstring.text)
+ onClicked: { browserinterface.connectdbussession(inputstring.text);
+ cachemanagerinterface.connectdbussession(inputstring.text);}
}
Component {
id: hallo
@@ -148,5 +153,12 @@ ApplicationWindow {
clip: true
BookmarkManager {}
}
+ Tab {
+ id: cachemanager
+ title: "ICacheManager"
+ anchors.fill: parent
+ clip: true
+ CacheManager {}
+ }
}
}
diff --git a/testapp/testapp.pro b/testapp/testapp.pro
index 4464fc4..42c13c5 100644
--- a/testapp/testapp.pro
+++ b/testapp/testapp.pro
@@ -8,6 +8,8 @@ QT += dbus qml quick
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+CONFIG += debug qt
+
TARGET = testapp
TEMPLATE = app
@@ -20,14 +22,19 @@ DBUS_INTERFACES += my_dbus_interfaces
include(../common/common.pri)
-SOURCES += main.cpp \
+SOURCES += main.cpp \
+ ../common/cachemanagerdbus.cpp \
+ ../common/icachemanager_interface.cpp
-HEADERS += \
+HEADERS += ../common/cachemanagerdbus.h \
+ ../common/browserdefs.h \
+ ../common/icachemanager_interface.h
OTHER_FILES += \
qml/testapp/main.qml \
qml/testapp/UserInput.qml \
qml/testapp/Browser.qml \
qml/testapp/BookmarkManager.qml \
- qml/testapp/WebPageWindow.qml
+ qml/testapp/WebPageWindow.qml \
+ qml/testapp/CacheManager.qml