aboutsummaryrefslogtreecommitdiff
path: root/spec/BrowserWindowSpec.cpp
blob: 636b5c2b1bb31f7f048997d7d15f3bf113f50733 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <QWebEngineNewWindowRequest>
#include <QWebEngineProfile>
#include <qwebengineprofile.h>
#include <vector>

#include "Configuration.hpp"
#include "LuaRuntime.hpp"
#include "testUtils.h"
#include "widgets/Decorations.hpp"
#include "widgets/WebView.hpp"
#include "widgets/WebViewStack.hpp"

// NOLINTBEGIN
class BrowserWindowSpec : public QObject {
  Q_OBJECT

  // class FakeNewWindowRequest : public QWebEngineNewWindowRequest {
  // public:
  //   FakeNewWindowRequest(DestinationType t, const QRect &r, const QUrl &u, bool b)
  //       : QWebEngineNewWindowRequest(t, r, u, b, nullptr) {}
  // };

  QWebEngineProfile *profile() { return new QWebEngineProfile(); }

private slots:
  void beforeTestCase() { LuaRuntime::instance().start_event_loop(); }
  void cleanupTestCase() { LuaRuntime::instance().stop_event_loop(); }

  void test_initial_state() {
    describe("constructor");

    context("when initialized with some urls");
    it("opens those urls in stack") {
      Configuration configuration;
      QStringList urls{"https://example1.com", "https://example2.com"};

      BrowserWindow browser_window(configuration, profile(), urls);

      auto *webview_stack = browser_window.findChild<WebViewStack *>();
      QCOMPARE(webview_stack->count(), 2);
      std::vector<QUrl> expected_urls{QUrl("https://example1.com"), QUrl("https://example2.com")};
      QCOMPARE(webview_stack->urls(), expected_urls);
    }

    context("when initialized with no urls");
    it("opens configured new_view_url in stack") {
      Configuration configuration;

      BrowserWindow browser_window(configuration, profile());

      auto *webview_stack = browser_window.findChild<WebViewStack *>();
      QCOMPARE(webview_stack->count(), 1);
      QCOMPARE(webview_stack->urls(), {QUrl(configuration.new_view_url())});
    }
  }

  // void test_window_title_update() {
  //   context("when title is updated");
  //   it("opens configured new_view_url in stack") {
  //     Configuration configuration;
  //     BrowserWindow browser_window(configuration, profile(),
  //                                  {"https://one.com", "https://two.com"});
  //     auto *webview_stack = browser_window.findChild<WebViewStack *>();
  //     QSignalSpy current_webview_title_changed(webview_stack,
  //                                              &WebViewStack::current_webview_title_changed);
  //
  //     emit webview_stack->current_webview_title_changed(0);
  //     QVERIFY(current_webview_title_changed.wait(100));
  //
  //     qDebug() << browser_window.windowTitle();
  //     // QCOMPARE(webview_stack->count(), 1);
  //     // QCOMPARE(webview_stack->urls(), {QUrl(configuration.new_view_url())});
  //   }
  // }
};

QTEST_REGISTER(BrowserWindowSpec)
#include "BrowserWindowSpec.moc"
// NOLINTEND