1 /* This file is part of the KDE project
2 Copyright (C) 2006 David Faure <faure@kde.org>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include <qtest_kde.h>
19 #include "konqviewmgrtest.h"
20 #include "../konqsettingsxt.h"
22 #include <qtestmouse.h>
24 #include <konqframe.h>
25 #include <konqmainwindow.h>
26 #include <konqviewmanager.h>
29 #include <konqframevisitor.h>
30 #include <kstandarddirs.h>
31 #include <kconfiggroup.h>
34 #include <khtml_part.h>
35 #include <khtmlview.h>
36 #include <dom/html_inline.h>
37 #include <dom/html_document.h>
39 QTEST_KDEMAIN_WITH_COMPONENTNAME( ViewMgrTest
, GUI
, "konqueror" )
42 // could be used to load dummy parts; or to check that the right parts are being loaded
43 // (and to detect the case where a part is loaded and then replacd with another one for no good reason)
44 class KonqTestFactory
: public KonqAbstractFactory
47 virtual KonqViewFactory
createView( const QString
&serviceType
,
48 const QString
&serviceName
= QString(),
49 KService::Ptr
*serviceImpl
= 0,
50 KService::List
*partServiceOffers
= 0,
51 KService::List
*appServiceOffers
= 0,
52 bool forceAutoEmbed
= false );
57 void ViewMgrTest::sendAllPendingResizeEvents( QWidget
* mainWindow
)
62 QList
<QWidget
*> allChildWidgets
= mainWindow
->findChildren
<QWidget
*>();
63 allChildWidgets
.prepend( mainWindow
);
64 foreach( QWidget
* w
, allChildWidgets
) {
65 if (w
->testAttribute(Qt::WA_PendingResizeEvent
)) {
66 //qDebug() << "Resizing" << w << " to " << w->size() << endl;
67 QResizeEvent
e(w
->size(), QSize());
68 QApplication::sendEvent(w
, &e
);
69 w
->setAttribute(Qt::WA_PendingResizeEvent
, false);
70 // hack: make QTabWidget think it's visible; no layout otherwise
71 w
->setAttribute(Qt::WA_WState_Visible
, true);
75 // Process LayoutRequest events, in particular
76 qApp
->sendPostedEvents();
77 //qDebug() << "Loop done, checking again";
79 if (!foundOne
) { // about to exit, reset visible flag, to avoid crashes in qt
80 foreach( QWidget
* w
, allChildWidgets
) {
81 w
->setAttribute(Qt::WA_WState_Visible
, false);
87 class DebugFrameVisitor
: public KonqFrameVisitor
90 DebugFrameVisitor() {}
91 QString
output() const { return m_output
; }
92 virtual bool visit(KonqFrame
*) { m_output
+= 'F'; return true; }
93 virtual bool visit(KonqFrameContainer
*) { m_output
+= "C("; return true; }
94 virtual bool visit(KonqFrameTabs
*) { m_output
+= "T["; return true; }
95 virtual bool visit(KonqMainWindow
*) { m_output
+= 'M'; return true; }
96 virtual bool endVisit(KonqFrameContainer
*) { m_output
+= ')'; return true; }
97 virtual bool endVisit(KonqFrameTabs
*) { m_output
+= ']'; return true; }
98 virtual bool endVisit(KonqMainWindow
*) { m_output
+= '.'; return true; }
100 static QString
inspect(KonqMainWindow
* mainWindow
) {
101 DebugFrameVisitor dfv
;
102 bool ok
= mainWindow
->accept( &dfv
);
104 return QString("ERROR: visitor returned false");
112 void ViewMgrTest::initTestCase()
114 QCOMPARE(KGlobal::mainComponent().componentName(), QString("konqueror"));
115 QCOMPARE(KonqSettings::mmbOpensTab(), true);
116 QCOMPARE(KonqSettings::popupsWithinTabs(), false);
119 void ViewMgrTest::testCreateFirstView()
121 KonqMainWindow mainWindow
;
122 KonqViewManager
* viewManager
= mainWindow
.viewManager();
123 KonqView
* view
= viewManager
->createFirstView( "KonqAboutPage", "konq_aboutpage" );
125 QVERIFY( viewManager
->tabContainer() );
127 // Use DebugFrameVisitor to find out the structure of the frame hierarchy
128 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[F].") ); // mainWindow, one tab, one frame
130 // Check widget parents: part's widget -> frame -> [tabwidget's stack] -> tabwidget -> mainWindow
131 QWidget
* partWidget
= view
->part()->widget();
132 QCOMPARE( partWidget
->window(), &mainWindow
);
133 QWidget
* frame
= view
->frame()->asQWidget();
134 QCOMPARE( partWidget
->parentWidget(), frame
);
135 QWidget
* tabWidget
= viewManager
->tabContainer()->asQWidget();
136 QCOMPARE( frame
->parentWidget()->parentWidget(), tabWidget
);
138 // Check frame geometry, to check that all layouts are there
139 // (the mainWindow is resized to 700x480 in its constructor)
140 // But pending resize events are only sent by show(), and we don't want to see
141 // widgets from unit tests.
142 // So we iterate over all widgets and ensure the pending resize events are sent.
143 sendAllPendingResizeEvents( &mainWindow
);
144 for ( QWidget
* w
= partWidget
; w
; w
= w
->parentWidget() )
145 qDebug() << w
<< w
->geometry();
146 //const QList<QToolBar*> toolbars = mainWindow.findChildren<QToolBar *>();
147 //foreach( QToolBar* toolbar, toolbars ) {
148 // if (!toolbar->isHidden())
149 // qDebug() << toolbar << toolbar->geometry();
151 QVERIFY( frame
->width() > 680 );
152 QVERIFY( frame
->height() > 240 ); // usually 325, but can be 256 with oxygen when three toolbars are shown
153 //qDebug() << "partWidget geom:" << partWidget->geometry();
154 QVERIFY( partWidget
->width() > 680 );
155 QVERIFY( partWidget
->height() > frame
->height() - 50 /*statusbar*/ );
156 //qDebug() << "tabWidget geom: " << tabWidget->geometry();
157 QVERIFY( tabWidget
->width() > 680 );
158 QVERIFY( tabWidget
->height() > frame
->height() );
161 void ViewMgrTest::testRemoveFirstView()
163 KonqMainWindow mainWindow
;
164 KonqViewManager
* viewManager
= mainWindow
.viewManager();
165 KonqView
* view
= viewManager
->createFirstView( "KonqAboutPage", "konq_aboutpage" );
166 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[F].") ); // mainWindow, tab widget, one frame
167 viewManager
->removeView( view
);
168 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[F].") ); // removing not allowed
169 // real test for removeView is part of testSplitView
172 void ViewMgrTest::testSplitView()
174 KonqMainWindow mainWindow
;
175 KonqViewManager
* viewManager
= mainWindow
.viewManager();
176 KonqView
* view
= viewManager
->createFirstView( "KonqAboutPage", "konq_aboutpage" );
178 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[F].") ); // mainWindow, tab widget, one frame
179 KonqView
* view2
= viewManager
->splitView( view
, Qt::Horizontal
);
181 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[C(FF)].") ); // mainWindow, tab widget, one splitter, two frames
183 // Check widget parents
184 //mainWindow.dumpObjectTree();
185 QWidget
* partWidget
= view
->part()->widget();
186 QCOMPARE( partWidget
->window(), &mainWindow
);
187 QWidget
* frame
= view
->frame()->asQWidget();
188 QCOMPARE( partWidget
->parentWidget(), frame
);
189 QVERIFY(!frame
->isHidden());
191 QWidget
* part2Widget
= view2
->part()->widget();
192 QCOMPARE( part2Widget
->window(), &mainWindow
);
193 QWidget
* frame2
= view2
->frame()->asQWidget();
194 QCOMPARE( part2Widget
->parentWidget(), frame2
);
195 QVERIFY(!frame2
->isHidden());
198 QVERIFY(view
->frame()->parentContainer()->frameType() == KonqFrameBase::Container
);
199 KonqFrameContainer
* container
= static_cast<KonqFrameContainer
*>(view
->frame()->parentContainer());
201 QCOMPARE(container
->count(), 2);
202 QCOMPARE(container
, view2
->frame()->parentContainer());
203 QCOMPARE(container
->firstChild(), view
->frame());
204 QCOMPARE(container
->secondChild(), view2
->frame());
205 QCOMPARE(container
->widget(0), view
->frame()->asQWidget());
206 QCOMPARE(container
->widget(1), view2
->frame()->asQWidget());
208 // Check frame geometries
209 sendAllPendingResizeEvents( &mainWindow
);
210 //for ( QWidget* w = partWidget; w; w = w->parentWidget() )
211 // qDebug() << w << w->geometry() << "visible:" << w->isVisible();
213 //qDebug() << "view geom:" << frame->geometry();
214 QVERIFY( frame
->width() > 300 && frame
->width() < 400 ); // horiz split, so half the mainWindow width
215 QVERIFY( frame
->height() > 240 ); // usually 325, but can be 256 with oxygen when three toolbars are shown
216 //qDebug() << "view2 geom:" << frame2->geometry();
217 QVERIFY( frame2
->width() > 300 && frame2
->width() < 400 ); // horiz split, so half the mainWindow width
218 QVERIFY( frame2
->height() > 240 ); // usually 325, but can be 256 with oxygen when three toolbars are shown
219 // Both frames should have the same size; well, if the width was odd then there can be an off-by-one...
220 QCOMPARE( frame
->height(), frame2
->height() );
221 QVERIFY( qAbs(frame
->width() - frame2
->width()) <= 1 ); // e.g. 173 and 172 are "close enough"
222 //qDebug() << "partWidget geom:" << partWidget->geometry();
223 QVERIFY( partWidget
->width() > 300 && partWidget
->width() < 400 ); // horiz split, so half the mainWindow width
224 QVERIFY( partWidget
->height() > 220 ); // frame minus statusbar height
225 QVERIFY( part2Widget
->width() > 300 && part2Widget
->width() < 400 ); // horiz split, so half the mainWindow width
226 QVERIFY( part2Widget
->height() > 220 );
228 //KonqFrameContainerBase* container = view->frame()->parentContainer();
229 //QVERIFY( container );
230 //qDebug() << "container geom: " << container->asQWidget()->geometry();
234 KonqView
* view3
= viewManager
->splitView( view
, Qt::Horizontal
);
236 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[C(C(FF)F)].") );
238 // Now test removing the first view
239 viewManager
->removeView( view
);
240 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[C(FF)].") ); // mainWindow, tab widget, one splitter, two frames
242 // Now test removing the last view
243 viewManager
->removeView( view3
);
244 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[F].") ); // mainWindow, tab widget, one frame
247 void ViewMgrTest::testSplitMainContainer()
249 KonqMainWindow mainWindow
;
250 KonqViewManager
* viewManager
= mainWindow
.viewManager();
251 KonqView
* view
= viewManager
->createFirstView( "KonqAboutPage", "konq_aboutpage" );
252 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[F].") ); // mainWindow, tab widget, one frame
253 KonqFrameContainerBase
* tabContainer
= view
->frame()->parentContainer();
254 KonqView
* view2
= viewManager
->splitMainContainer( view
, Qt::Horizontal
, "KonqAboutPage", "konq_aboutpage", true );
256 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MC(FT[F]).") ); // mainWindow, splitter, frame, tab widget, one frame
258 // Check widget parents
259 QWidget
* partWidget
= view
->part()->widget();
260 QCOMPARE( partWidget
->window(), &mainWindow
);
261 QWidget
* frame
= view
->frame()->asQWidget();
262 QCOMPARE( partWidget
->parentWidget(), frame
);
263 QVERIFY(!frame
->isHidden());
265 QWidget
* part2Widget
= view2
->part()->widget();
266 QCOMPARE( part2Widget
->window(), &mainWindow
);
267 QWidget
* frame2
= view2
->frame()->asQWidget();
268 QCOMPARE( part2Widget
->parentWidget(), frame2
);
269 QVERIFY(!frame2
->isHidden());
272 QVERIFY(view
->frame()->parentContainer()->frameType() == KonqFrameBase::Tabs
);
273 QVERIFY(view2
->frame()->parentContainer()->frameType() == KonqFrameBase::Container
);
274 KonqFrameContainer
* container
= static_cast<KonqFrameContainer
*>(view2
->frame()->parentContainer());
276 QCOMPARE(container
->count(), 2);
277 QCOMPARE(container
, view2
->frame()->parentContainer());
278 QCOMPARE(container
->firstChild(), view2
->frame());
279 QCOMPARE(container
->secondChild(), tabContainer
);
280 QCOMPARE(container
->widget(0), view2
->frame()->asQWidget());
281 QCOMPARE(container
->widget(1), tabContainer
->asQWidget());
283 // Now test removing the view we added last
284 viewManager
->removeView( view2
);
285 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[F].") ); // mainWindow, tab widget, one frame
288 static void openHtmlWithLink(KonqMainWindow
& mainWindow
)
290 // Much like KonqHtmlTest::loadSimpleHtml.
291 mainWindow
.openUrl(0, KUrl("data:text/html, <a href=\"data:text/html, Link target\">Click me</a>"), "text/html");
292 KonqView
* view
= mainWindow
.currentView();
294 QVERIFY(QTest::kWaitForSignal(view
, SIGNAL(viewCompleted(KonqView
*)), 20000));
295 QCOMPARE(view
->serviceType(), QString("text/html"));
298 void ViewMgrTest::testLinkedViews()
300 KonqMainWindow mainWindow
;
301 openHtmlWithLink(mainWindow
);
302 KonqView
* view
= mainWindow
.currentView();
304 qDebug() << "SPLITTING";
305 mainWindow
.slotSplitViewHorizontal();
306 KonqView
* view2
= mainWindow
.currentView();
308 QCOMPARE(view2
->serviceType(), QString("text/html"));
309 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[C(FF)].") ); // mainWindow, tab widget, one splitter, two frames
310 QVERIFY(QTest::kWaitForSignal(view2
, SIGNAL(viewCompleted(KonqView
*)), 20000));
311 KUrl origUrl
= view
->url();
312 QCOMPARE(view2
->url().url(), origUrl
.url());
313 view
->setLinkedView(true);
314 view2
->setLinkedView(true);
315 view
->setLockedLocation(true);
316 // "Click" on the link
317 qDebug() << "ACTIVATING LINK";
318 KHTMLPart
* part
= qobject_cast
<KHTMLPart
*>(view
->part());
319 DOM::HTMLAnchorElement anchor
= part
->htmlDocument().getElementsByTagName(DOM::DOMString("a")).item(0);
320 Q_ASSERT(!anchor
.isNull());
322 QKeyEvent
ev( QKeyEvent::KeyPress
, Qt::Key_Return
, 0, "\n" );
323 QApplication::sendEvent( part
->view(), &ev
);
324 qApp
->processEvents(); // openUrlRequestDelayed
325 // Check that the link opened in the 2nd view, not the first one
326 QCOMPARE(view
->url().url(), origUrl
.url());
327 QCOMPARE(view2
->url().url(), KUrl("data:text/html, Link target").url());
330 void ViewMgrTest::testPopupNewTab() // RMB, "Open in new tab"
332 KonqMainWindow mainWindow
;
333 openHtmlWithLink(mainWindow
);
334 KFileItem
item(KUrl("data:text/html, hello"), "text/html", S_IFREG
);
335 mainWindow
.prepareForPopupMenu(KFileItemList() << item
, KParts::OpenUrlArguments(), KParts::BrowserArguments());
336 QMetaObject::invokeMethod(&mainWindow
, "slotPopupNewTab");
338 QCOMPARE(DebugFrameVisitor::inspect(&mainWindow
), QString("MT[FF].")); // mainWindow, tab widget, two tabs
339 QCOMPARE(KMainWindow::memberList().count(), 1);
342 static void checkSecondWindowHasOneTab() // and delete it.
344 QCOMPARE(KMainWindow::memberList().count(), 2);
345 KonqMainWindow
* newWindow
= qobject_cast
<KonqMainWindow
*>(KMainWindow::memberList().last());
347 QCOMPARE(DebugFrameVisitor::inspect(newWindow
), QString("MT[F].")); // mainWindow, tab widget, one tab
351 void ViewMgrTest::testPopupNewWindow() // RMB, "Open new window"
353 KonqMainWindow mainWindow
;
354 openHtmlWithLink(mainWindow
);
355 KFileItem
item(KUrl("data:text/html, hello"), "text/html", S_IFREG
);
356 mainWindow
.prepareForPopupMenu(KFileItemList() << item
, KParts::OpenUrlArguments(), KParts::BrowserArguments());
357 QMetaObject::invokeMethod(&mainWindow
, "slotPopupNewWindow");
359 QCOMPARE(DebugFrameVisitor::inspect(&mainWindow
), QString("MT[F].")); // mainWindow, tab widget, one tab
360 QVERIFY(KMainWindow::memberList().last() != &mainWindow
);
361 checkSecondWindowHasOneTab();
364 void ViewMgrTest::testCtrlClickOnLink()
366 KonqMainWindow mainWindow
;
367 openHtmlWithLink(mainWindow
);
368 KonqView
* view
= mainWindow
.currentView();
369 KHTMLPart
* part
= qobject_cast
<KHTMLPart
*>(view
->part());
370 qDebug() << "CLICKING NOW";
371 QTest::mouseClick(part
->view()->widget(), Qt::LeftButton
, Qt::ControlModifier
, QPoint(10, 10));
373 // Expected behavior for Ctrl+click:
374 // new tab, if mmbOpensTab
375 // new window, if !mmbOpensTab
376 if (KonqSettings::mmbOpensTab()) {
377 QCOMPARE(DebugFrameVisitor::inspect(&mainWindow
), QString("MT[FF].")); // mainWindow, tab widget, two tabs
378 QCOMPARE(KMainWindow::memberList().count(), 1);
380 QCOMPARE(DebugFrameVisitor::inspect(&mainWindow
), QString("MT[F].")); // mainWindow, tab widget, one tab
381 checkSecondWindowHasOneTab();
385 void ViewMgrTest::sameTestsWithMmbOpenTabsFalse()
387 // Redo testPopupNewTab, testPopupNewWindow and testCtrlClickOnLink,
388 // but as if the user (e.g. Pino) had disabled the setting "Open links in new tabs".
389 KonqSettings::setMmbOpensTab(false);
391 testPopupNewWindow();
392 testCtrlClickOnLink();
393 KonqSettings::setMmbOpensTab(true);
396 static void openTabWithTitle(KonqMainWindow
& mainWindow
, const QString
& title
, KonqView
*& view
)
398 KonqViewManager
* viewManager
= mainWindow
.viewManager();
399 view
= viewManager
->addTab("text/html");
401 QVERIFY(view
->supportsMimeType("text/html"));
402 QVERIFY(!view
->supportsMimeType("text/plain"));
403 // correct since it's a subclass of text/html, khtml can display it
404 QVERIFY(view
->supportsMimeType("application/x-netscape-bookmarks"));
406 view
->openUrl(KUrl("data:text/html, <title>" + title
.toUtf8() + "</title>"), QString("http://loc.bar.url"));
407 QVERIFY(QTest::kWaitForSignal(view
, SIGNAL(viewCompleted(KonqView
*)), 10000));
408 QCOMPARE(view
->caption(), title
);
409 QCOMPARE(view
->locationBarURL(), QString("http://loc.bar.url"));
412 void ViewMgrTest::testAddTabs()
414 KonqMainWindow mainWindow
;
415 KonqViewManager
* viewManager
= mainWindow
.viewManager();
417 KonqView
* view
= viewManager
->createFirstView( "KonqAboutPage", "konq_aboutpage" );
420 // The testcase was "konqueror www.kde.org www.google.fr bugs.kde.org www.cuil.com www.davidfaure.fr"
421 titles
<< "K Desktop Environment - Be free"
423 << "KDE Bug Tracking System"
425 << "http://www.davidfaure.fr/";
426 view
->setCaption(titles
[0]);
428 KTabWidget
* tabWidget
= mainWindow
.findChild
<KTabWidget
*>();
430 KonqView
* viewTab2
, *viewTab3
, *viewTab4
, *viewTab5
;
431 openTabWithTitle(mainWindow
, titles
[1], viewTab2
);
432 openTabWithTitle(mainWindow
, titles
[2], viewTab3
);
433 openTabWithTitle(mainWindow
, titles
[3], viewTab4
);
434 openTabWithTitle(mainWindow
, titles
[4], viewTab5
);
435 for (int i
= 0; i
< titles
.count(); ++i
)
436 QCOMPARE(tabWidget
->tabText(i
), QString(titles
[i
]));
438 // Ensure tabwidget has a nice size
439 mainWindow
.resize(599, 699);
440 sendAllPendingResizeEvents( &mainWindow
);
442 // Remove active tab (#170470)
443 tabWidget
->setCurrentIndex(2);
444 KonqFrameBase
* frame
= dynamic_cast<KonqFrameBase
*>(viewManager
->tabContainer()->currentWidget());
446 viewManager
->removeTab(frame
);
447 QList
<int> expectedTitles
; expectedTitles
<< 0 << 1 << 3 << 4;
448 for (int i
= 0; i
< expectedTitles
.count(); ++i
)
449 QCOMPARE(tabWidget
->tabText(i
), titles
[expectedTitles
[i
]]);
450 for (int i
= 0; i
< expectedTitles
.count(); ++i
)
451 QCOMPARE(tabWidget
->QTabWidget::tabText(i
).left(10), titles
[expectedTitles
[i
]].left(10));
453 tabWidget
->removeTab(0);
454 expectedTitles
.removeAt(0);
455 for (int i
= 0; i
< expectedTitles
.count(); ++i
)
456 QCOMPARE(tabWidget
->tabText(i
), QString(titles
[expectedTitles
[i
]]));
459 void ViewMgrTest::testDuplicateTab()
461 KonqMainWindow mainWindow
;
462 KonqViewManager
* viewManager
= mainWindow
.viewManager();
463 KonqView
* view
= viewManager
->createFirstView( "KonqAboutPage", "konq_aboutpage" );
464 viewManager
->duplicateTab(view
->frame()); // should return a KonqFrameBase?
466 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[FF].") ); // mainWindow, tab widget, two tabs
467 // TODO check serviceType and serviceName of the new view
470 void ViewMgrTest::testDuplicateSplittedTab()
472 KonqMainWindow mainWindow
;
473 KonqViewManager
* viewManager
= mainWindow
.viewManager();
474 KonqView
* view
= viewManager
->createFirstView( "KonqAboutPage", "konq_aboutpage" );
475 KonqView
* view2
= viewManager
->splitView( view
, Qt::Vertical
);
477 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[C(FF)].") ); // mainWindow, tab widget, one splitter, two frames
479 KonqFrameContainer
* container
= static_cast<KonqFrameContainer
*>(view
->frame()->parentContainer());
480 QVERIFY( container
);
481 QVERIFY(container
->parentContainer()->frameType() == KonqFrameBase::Tabs
);
483 viewManager
->duplicateTab(container
); // TODO shouldn't it return a KonqFrameBase?
484 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[C(FF)C(FF)].") ); // mainWindow, tab widget, two tabs
486 viewManager
->removeTab(container
);
487 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[C(FF)].") ); // mainWindow, tab widget, one tab
490 // Like in http://bugs.kde.org/show_bug.cgi?id=153533,
491 // where the part deletes itself.
492 void ViewMgrTest::testDeletePartInTab()
494 KonqMainWindow mainWindow
;
495 KonqViewManager
* viewManager
= mainWindow
.viewManager();
496 KonqView
* view
= viewManager
->createFirstView( "KonqAboutPage", "konq_aboutpage" );
498 QPointer
<KonqView
> viewTab2
= viewManager
->addTab("text/html");
499 QVERIFY(!viewTab2
.isNull());
500 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[FF].") ); // mainWindow, tab widget, two tabs
502 delete viewTab2
->part();
503 QVERIFY(viewTab2
.isNull());
504 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[F].") ); // mainWindow, tab widget, one tab
507 static void loadFileManagementProfile(KonqMainWindow
& mainWindow
)
509 const QString profile
= KStandardDirs::locate("data", "konqueror/profiles/filemanagement");
510 QVERIFY(!profile
.isEmpty());
511 const QString path
= QDir::homePath();
512 mainWindow
.viewManager()->loadViewProfileFromFile(profile
, "filemanagement", KUrl(path
));
513 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MC(FT[F]).") ); // mainWindow, splitter, frame, tab widget, one frame
514 QCOMPARE(mainWindow
.locationBarURL(), path
);
515 QCOMPARE(mainWindow
.currentView()->locationBarURL(), path
);
518 void ViewMgrTest::testLoadProfile()
520 KonqMainWindow mainWindow
;
521 loadFileManagementProfile(mainWindow
);
523 sendAllPendingResizeEvents( &mainWindow
);
525 QVERIFY(mainWindow
.width() > 680);
526 // QCOMPARE(frameType,QByteArray("Container")) leads to unreadable output on a mismatch :)
527 QCOMPARE(mainWindow
.childFrame()->frameType(), KonqFrameBase::Container
);
528 KonqFrameContainer
* container
= static_cast<KonqFrameContainer
*>(mainWindow
.childFrame());
529 KonqFrameBase
* firstChild
= container
->firstChild();
530 QWidget
* sidebarFrame
= container
->widget(0);
531 QCOMPARE(firstChild
->asQWidget(), sidebarFrame
);
532 QCOMPARE(firstChild
->frameType(), KonqFrameBase::View
);
533 //QVERIFY(qobject_cast<KonqFrame*>(sidebarFrame));
534 KonqFrameBase
* secondChild
= container
->secondChild();
535 QCOMPARE(secondChild
->frameType(), KonqFrameBase::Tabs
);
536 QWidget
* tabFrame
= container
->widget(1);
537 QCOMPARE(secondChild
->asQWidget(), tabFrame
);
538 QCOMPARE(sidebarFrame
->sizePolicy().horizontalPolicy(), QSizePolicy::Preferred
);
539 QCOMPARE(sidebarFrame
->sizePolicy().horizontalStretch(), 0);
540 QCOMPARE(tabFrame
->sizePolicy().horizontalPolicy(), QSizePolicy::Expanding
);
541 QCOMPARE(tabFrame
->sizePolicy().horizontalStretch(), 0);
542 const QList
<int> sizes
= container
->sizes();
543 QCOMPARE(sizes
.count(), 2);
544 QVERIFY(sizes
[0] < sizes
[1]);
547 void ViewMgrTest::testDuplicateWindow()
549 KonqMainWindow mainWindow
;
550 mainWindow
.openUrl(0, KUrl("data:text/html, <p>Hello World</p>"), "text/html");
551 KonqViewManager
* viewManager
= mainWindow
.viewManager();
552 KonqView
* viewTab2
= viewManager
->addTab("text/html");
553 KonqView
* splitted
= viewManager
->splitView( viewTab2
, Qt::Horizontal
);
555 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[FC(FF)].") ); // mainWindow, tab widget, first tab = one frame, second tab = splitter with two frames
556 KonqMainWindow
* secondWindow
= viewManager
->duplicateWindow();
557 QCOMPARE( DebugFrameVisitor::inspect(secondWindow
), QString("MT[FC(FF)].") ); // mainWindow, tab widget, first tab = one frame, second tab = splitter with two frames
561 void ViewMgrTest::testCloseOtherTabs()
563 KonqMainWindow mainWindow
;
564 mainWindow
.openUrl(0, KUrl("data:text/html, <p>Hello World</p>"), "text/html");
565 KonqViewManager
* viewManager
= mainWindow
.viewManager();
566 viewManager
->addTab("text/html");
567 KonqView
* viewTab2
= viewManager
->addTab("text/html");
568 viewManager
->splitView( viewTab2
, Qt::Horizontal
);
569 viewManager
->addTab("text/html");
570 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[FFC(FF)F].") ); // mainWindow, tab widget, first tab = one frame, second tab = one frame, third tab = splitter with two frames, fourth tab = one frame
571 mainWindow
.setWorkingTab(viewTab2
->frame()); // This actually sets a frame which is not a tab, but KonqViewManager::removeOtherTabs should be able to deal with these cases
572 mainWindow
.slotRemoveOtherTabsPopupDelayed();
573 QCOMPARE( DebugFrameVisitor::inspect(&mainWindow
), QString("MT[C(FF)].") ); // mainWindow, tab widget, first tab = splitter with two frames
576 void ViewMgrTest::testDuplicateWindowWithSidebar()
578 KonqMainWindow mainWindow
;
579 loadFileManagementProfile(mainWindow
);
580 KonqViewManager
* viewManager
= mainWindow
.viewManager();
581 KonqMainWindow
* secondWindow
= viewManager
->duplicateWindow();
582 QCOMPARE( DebugFrameVisitor::inspect(secondWindow
), QString("MC(FT[F]).") ); // mainWindow, splitter, frame, tab widget, one frame
586 void ViewMgrTest::testBrowserArgumentsNewTab()
588 KonqMainWindow mainWindow
;
589 mainWindow
.openUrl(0, KUrl("data:text/html, <p>Hello World</p>"), "text/html");
590 KParts::OpenUrlArguments urlArgs
;
591 KParts::BrowserArguments browserArgs
;
592 browserArgs
.setNewTab(true);
593 KonqView
* view
= mainWindow
.currentView();
594 KParts::BrowserExtension
* ext
= view
->browserExtension();
596 emit ext
->openUrlRequest(KUrl("data:text/html, <p>Second tab test</p>"), urlArgs
, browserArgs
);
598 QCOMPARE(DebugFrameVisitor::inspect(&mainWindow
), QString("MT[FF].")); // mainWindow, tab widget, two tabs
599 QCOMPARE(view
->url(), KUrl("data:text/html, <p>Hello World</p>"));
601 // compare the url of the new view... how to?
602 // QCOMPARE(view->url(), KUrl("data:text/html, <p>Second tab test</p>"));
605 #include "konqviewmgrtest.moc"