~abreu-alexandre/oxide/add-ua-to-downloadrequested

« back to all changes in this revision

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

Expose user agent as part of downloadRequest

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
  property var latestCookies
15
15
  property string latestMimeType: ""
16
16
  property string latestReferrer: ""
 
17
  property string latestUserAgent: ""
 
18
 
 
19
  context.userAgentOverrideDelegate: WebContextDelegateWorker {
 
20
    source: Qt.resolvedUrl("tst_WebView_downloadRequested.js");
 
21
  }
17
22
 
18
23
  onDownloadRequested: {
19
24
    latestDownloadUrl = request.url;
21
26
    latestMimeType = request.mimeType;
22
27
    latestSuggestedFilename = request.suggestedFilename;
23
28
    latestReferrer = request.referrer;
 
29
    latestUserAgent = request.userAgent;
 
30
  }
 
31
 
 
32
  function cleanLatestData() {
 
33
    latestDownloadUrl = "";
 
34
    latestCookies = "";
 
35
    latestMimeType = "";
 
36
    latestSuggestedFilename = "";
 
37
    latestReferrer = "";
 
38
    latestUserAgent = "";
24
39
  }
25
40
 
26
41
  SignalSpy {
35
50
 
36
51
    function init() {
37
52
      spy.clear();
 
53
      cleanLatestData();
38
54
    }
39
55
 
40
56
    function test_WebView_downloadRequestWithContentDisposition() {
48
64
      compare(webView.latestSuggestedFilename, "001.html")
49
65
    }
50
66
 
 
67
    function test_WebView_downloadRequestWithContentDispositionWithUserAgentOverride() {
 
68
      webView.url = "http://testsuite/tst_WebView_downloadRequested.py?override"
 
69
      verify(webView.waitForLoadStopped(),
 
70
             "Timed out waiting for a successful load");
 
71
 
 
72
      compare(spy.count, 1)
 
73
      compare(webView.latestMimeType, "text/html")
 
74
      compare(webView.latestCookies, "foo=bar, bar=bazz")
 
75
      compare(webView.latestSuggestedFilename, "001.html")
 
76
      compare(webView.latestUserAgent, "Override download user agent string");
 
77
    }
 
78
 
 
79
    function test_WebView_downloadAnchorRequest() {
 
80
      webView.url = "http://testsuite/tst_WebView_downloadRequestedAnchor.html"
 
81
      verify(webView.waitForLoadSucceeded(),
 
82
             "Timed out waiting for a successful load");
 
83
 
 
84
      var r = webView.getTestApi().getBoundingClientRectForSelector("#content");
 
85
      mouseClick(webView, r.x + r.width / 2, r.y + r.height / 2, Qt.LeftButton);
 
86
      spy.wait();
 
87
 
 
88
      compare(spy.count, 1)
 
89
      compare(webView.latestSuggestedFilename, "MyDownload")
 
90
    }
 
91
 
51
92
    function test_WebView_downloadRequestUnhandledMimeType() {
52
93
      webView.url = "http://testsuite/tst_WebView_downloadRequestedUnhandledMimeType.py"
53
94
      verify(webView.waitForLoadStopped(),