~osomon/oxide/i18n

« back to all changes in this revision

Viewing changes to qt/tests/qmltests/api/tst_NewViewRequest.qml

  • Committer: Olivier Tilloy
  • Date: 2014-04-08 10:03:11 UTC
  • mfrom: (312.2.173 oxide)
  • Revision ID: olivier.tilloy@canonical.com-20140408100311-b3zb7q1jfrevbrf1
Merge the latest changes from trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import QtQuick 2.0
 
2
import QtTest 1.0
 
3
import com.canonical.Oxide 1.0
 
4
import com.canonical.Oxide.Testing 1.0
 
5
 
 
6
Column {
 
7
  id: column
 
8
  focus: true
 
9
 
 
10
  TestWebView {
 
11
    id: webView
 
12
    width: 200
 
13
    height: 200
 
14
 
 
15
    property rect lastRequestPosition: Qt.rect(0,0,0,0)
 
16
    property int lastRequestDisposition: NewViewRequest.DispositionCurrentTab
 
17
 
 
18
    onNewViewRequested: {
 
19
      lastRequestPosition = request.position;
 
20
      lastRequestDisposition = request.disposition;
 
21
    }
 
22
  }
 
23
 
 
24
  SignalSpy {
 
25
    id: spy
 
26
    target: webView
 
27
    signalName: "newViewRequested"
 
28
  }
 
29
 
 
30
  SignalSpy {
 
31
    id: navSpy
 
32
    target: webView
 
33
    signalName: "navigationRequested"
 
34
  }
 
35
 
 
36
  TestCase {
 
37
    id: test
 
38
    name: "NewViewRequest"
 
39
    when: windowShown
 
40
 
 
41
    function init() {
 
42
      webView.context.popupBlockerEnabled = true;
 
43
      spy.clear();
 
44
      navSpy.clear();
 
45
    }
 
46
 
 
47
    function test_NewViewRequest1_from_user_gesture_data() {
 
48
      return [
 
49
        { selector: "#button1", modifiers: Qt.NoModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "window-open" },
 
50
        { selector: "#button1", modifiers: Qt.ShiftModifier, disposition: NewViewRequest.DispositionNewWindow, style: "window-open" },
 
51
        { selector: "#button1", modifiers: Qt.ControlModifier, disposition: NewViewRequest.DispositionNewBackgroundTab, style: "window-open" },
 
52
        { selector: "#button1", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "window-open" },
 
53
        { selector: "#button2", modifiers: Qt.NoModifier, disposition: NewViewRequest.DispositionNewPopup, style: "window-open" },
 
54
        { selector: "#button2", modifiers: Qt.ShiftModifier, disposition: NewViewRequest.DispositionNewPopup, style: "window-open" },
 
55
        { selector: "#button2", modifiers: Qt.ControlModifier, disposition: NewViewRequest.DispositionNewBackgroundTab, style: "window-open" },
 
56
        { selector: "#button2", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "window-open" },
 
57
        { selector: "#link1", modifiers: Qt.NoModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "link-new-window" },
 
58
        { selector: "#link1", modifiers: Qt.ShiftModifier, disposition: NewViewRequest.DispositionNewWindow, style: "link-new-window" },
 
59
        { selector: "#link1", modifiers: Qt.ControlModifier, disposition: NewViewRequest.DispositionNewBackgroundTab, style: "link-new-window" },
 
60
        { selector: "#link1", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "link-new-window" },
 
61
        { selector: "#link2", modifiers: Qt.NoModifier, disposition: NewViewRequest.DispositionCurrentTab, style: "link" },
 
62
        { selector: "#link2", modifiers: Qt.ShiftModifier, disposition: NewViewRequest.DispositionNewWindow, style: "link" },
 
63
        { selector: "#link2", modifiers: Qt.ControlModifier, disposition: NewViewRequest.DispositionNewBackgroundTab, style: "link" },
 
64
        { selector: "#link2", modifiers: Qt.ShiftModifier | Qt.ControlModifier, disposition: NewViewRequest.DispositionNewForegroundTab, style: "link" }
 
65
      ];
 
66
    }
 
67
 
 
68
    function test_NewViewRequest1_from_user_gesture(data) {
 
69
      webView.url = "http://localhost:8080/tst_NewViewRequest.html";
 
70
      verify(webView.waitForLoadSucceeded(),
 
71
             "Timed out waiting for successful load");
 
72
 
 
73
      var r = webView.getTestApi().getBoundingClientRectForSelector(data.selector);
 
74
      mouseClick(webView, r.x + r.width / 2, r.y + r.height / 2, Qt.LeftButton, data.modifiers);
 
75
 
 
76
      if (data.disposition == NewViewRequest.DispositionCurrentTab) {
 
77
        verify(webView.waitForLoadSucceeded());
 
78
        compare(spy.count, 0);
 
79
      } else {
 
80
        spy.wait();
 
81
        compare(spy.count, 1);
 
82
 
 
83
        if (data.style != "link-new-window") {
 
84
          // XXX: This will fail if the request is outside of the screen's availableRect
 
85
          //  (including shell chrome). The figures are set to make this unlikely though
 
86
          if (data.style == "window-open") {
 
87
            compare(webView.lastRequestPosition.x, 100, "Unexpected position.x");
 
88
            compare(webView.lastRequestPosition.y, 100, "Unexpected position.y");
 
89
          }
 
90
          compare(webView.lastRequestPosition.width, data.style == "window-open" ? 200 : webView.width, "Unexpected position.width");
 
91
          compare(webView.lastRequestPosition.height, data.style == "window-open" ? 200 : webView.height, "Unexpected position.height");
 
92
        }
 
93
        compare(webView.lastRequestDisposition, data.disposition, "Unexpected disposition");
 
94
      }
 
95
 
 
96
      compare(navSpy.count, 1);
 
97
    }
 
98
 
 
99
    function test_NewViewRequest2_no_user_gesture_data() {
 
100
      return test_NewViewRequest1_from_user_gesture_data();
 
101
    }
 
102
 
 
103
    function test_NewViewRequest2_no_user_gesture(data) {
 
104
      webView.context.popupBlockerEnabled = false;
 
105
 
 
106
      if (data.style == "link") {
 
107
        return;
 
108
      }
 
109
 
 
110
      webView.url = "http://localhost:8080/tst_NewViewRequest.html";
 
111
      verify(webView.waitForLoadSucceeded(),
 
112
             "Timed out waiting for successful load");
 
113
 
 
114
      webView.getTestApi().evaluateCode(
 
115
"var e = document.createEvent(\"HTMLEvents\");
 
116
e.initEvent(\"click\", true, false);
 
117
document.querySelector(\"" + data.selector + "\").dispatchEvent(e);", true);
 
118
 
 
119
      spy.wait();
 
120
 
 
121
      compare(spy.count, 1);
 
122
      compare(navSpy.count, 1);
 
123
 
 
124
      if (data.style != "link-new-window") {
 
125
        // XXX: This will fail if the request is outside of the screen's availableRect
 
126
        //  (including shell chrome). The figures are set to make this unlikely though
 
127
        compare(webView.lastRequestPosition.x, 100, "Unexpected position.x");
 
128
        compare(webView.lastRequestPosition.y, 100, "Unexpected position.y");
 
129
        compare(webView.lastRequestPosition.width, 200, "Unexpected position.width");
 
130
        compare(webView.lastRequestPosition.height, 200, "Unexpected position.height");
 
131
      }
 
132
      compare(webView.lastRequestDisposition, NewViewRequest.DispositionNewPopup,
 
133
              "Unexpected disposition");
 
134
    }
 
135
  }
 
136
}