~rpadovani/oxide/type-info

« back to all changes in this revision

Viewing changes to qt/tests/qmltests/TestWebView.qml

  • Committer: Riccardo Padovani
  • Date: 2015-10-19 07:56:29 UTC
  • mfrom: (1088.1.131 oxide)
  • Revision ID: riccardo@rpadovani.com-20151019075629-z0mlhwlb9xflkovw
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
import QtQuick 2.0
2
2
import QtTest 1.0
3
 
import com.canonical.Oxide 1.8
 
3
import com.canonical.Oxide 1.11
4
4
import com.canonical.Oxide.Testing 1.0 as Testing
5
5
import "TestUtils.js" as TestUtils
6
6
 
27
27
    qtest_expectedLoadsCommittedCount = 0;
28
28
  }
29
29
 
 
30
  property var qtest_testApiHosts: new Object()
 
31
 
30
32
  function getTestApi() {
31
 
    return new TestUtils.TestApiHost(this, rootFrame);
 
33
    if (!(rootFrame in qtest_testApiHosts)) {
 
34
      qtest_testApiHosts[rootFrame] = new TestUtils.TestApiHost(rootFrame);
 
35
    }
 
36
 
 
37
    return qtest_testApiHosts[rootFrame];
32
38
  }
33
39
 
34
40
  function getTestApiForFrame(frame) {
35
 
    return new TestUtils.TestApiHost(this, frame);
 
41
    if (!(frame in qtest_testApiHosts)) {
 
42
      qtest_testApiHosts[frame] = new TestUtils.TestApiHost(frame);
 
43
    }
 
44
 
 
45
    return qtest_testApiHosts[frame];
36
46
  }
37
47
 
38
48
  function waitForLoadStarted(timeout) {
39
49
    var expected = ++qtest_expectedLoadsStartedCount;
40
 
    return waitFor(
 
50
    return TestUtils.waitFor(
41
51
        function() { return expected == qtest_loadsStartedCount; },
42
52
        timeout);
43
53
  }
44
54
 
45
55
  function waitForLoadSucceeded(timeout) {
46
56
    var expected = ++qtest_expectedLoadsSucceededCount;
47
 
    return waitFor(
 
57
    return TestUtils.waitFor(
48
58
        function() { return expected == qtest_loadsSucceededCount; },
49
59
        timeout);
50
60
  }
51
61
 
52
62
  function waitForLoadStopped(timeout, gcDuringWait) {
53
63
    var expected = ++qtest_expectedLoadsStoppedCount;
54
 
    return waitFor(
 
64
    return TestUtils.waitFor(
55
65
        function() { return expected == qtest_loadsStoppedCount; },
56
66
        timeout, gcDuringWait);
57
67
  }
58
68
 
59
69
  function waitForLoadFailed(timeout) {
60
70
    var expected = ++qtest_expectedLoadsFailedCount;
61
 
    return waitFor(
 
71
    return TestUtils.waitFor(
62
72
        function() { return expected == qtest_loadsFailedCount; },
63
73
        timeout);
64
74
  }
65
75
 
66
76
  function waitForLoadCommitted(timeout) {
67
77
    var expected = ++qtest_expectedLoadsCommittedCount;
68
 
    return waitFor(
 
78
    return TestUtils.waitFor(
69
79
        function() { return expected == qtest_loadsCommittedCount; },
70
80
        timeout);
71
81
  }
72
82
 
73
 
  function waitFor(predicate, timeout, gcDuringWait) {
74
 
    timeout = timeout || 5000;
75
 
    var end = Date.now() + timeout;
76
 
    var i = Date.now();
77
 
    while (i < end && !predicate()) {
78
 
      qtest_testResult.wait(50);
79
 
      if (gcDuringWait) gc();
80
 
      i = Date.now();
81
 
    }
82
 
    return predicate();
83
 
  }
84
 
 
85
 
  function wait(timeout) {
86
 
    qtest_testResult.wait(timeout);
87
 
  }
88
 
 
89
83
  property int qtest_loadsStartedCount: 0
90
84
  property int qtest_loadsSucceededCount: 0
91
85
  property int qtest_loadsFailedCount: 0
101
95
  context: TestWebContext {}
102
96
 
103
97
  Connections {
 
98
    onFrameRemoved: {
 
99
      delete webView.qtest_testApiHosts[frame];
 
100
    }
 
101
 
104
102
    onLoadEvent: {
105
103
      if (event.type == LoadEvent.TypeStarted) {
106
104
        webView.qtest_loadsStartedCount++;
115
113
      }
116
114
    }
117
115
  }
118
 
 
119
 
  TestResult { id: qtest_testResult }
120
116
}