Merge lp:~stolowski/unity-scopes-shell/session-id into lp:unity-scopes-shell
- session-id
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Pete Woods |
Approved revision: | 139 |
Merged at revision: | 139 |
Proposed branch: | lp:~stolowski/unity-scopes-shell/session-id |
Merge into: | lp:unity-scopes-shell |
Prerequisite: | lp:~stolowski/unity-scopes-shell/expandable-widget |
Diff against target: |
422 lines (+223/-4) 9 files modified
src/Unity/previewstack.cpp (+6/-1) src/Unity/previewstack.h (+3/-1) src/Unity/scope.cpp (+30/-1) src/Unity/scope.h (+6/-0) src/Unity/utils.cpp (+10/-0) src/Unity/utils.h (+2/-0) tests/data/mock-scope/mock-scope.cpp (+4/-1) tests/previewtest.cpp (+1/-0) tests/resultstest.cpp (+161/-0) |
To merge this branch: | bzr merge lp:~stolowski/unity-scopes-shell/session-id |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Marcus Tomlinson (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Needs Fixing | |
Review via email:
|
Commit message
Generate session_id (uuid) and pass it with search and preview request via SearchMetadata / ActionMetadata hints.
Description of the change
Generate session_id (uuid) and pass it with search and preview request via SearchMetadata / ActionMetadata hints. This requires https:/
The session id is re-created whenever a new search query is entered; appending or removing characters from existing search query keeps current session id.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
- 136. By Paweł Stołowski
-
Maintain and pass query_id.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:136
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Marcus Tomlinson (marcustomlinson) wrote : | # |
99 + // don't regenerate it if currenty query appends to previous query or removes
currenty -> currently
100 + // caharcters from previous query.
caharcters -> characters
101 + if (m_session_
102 + m_searchQuery.
103 + !(m_searchQuery
104 + search_
this is quite hard to read, and I think its wrong. Rather do something like this:
bool search_empty = m_searchQuery.
bool updates_previous = m_searchQuery.
if((m_session_
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Marcus Tomlinson (marcustomlinson) wrote : | # |
Also could we add a simple test for this?
- 137. By Paweł Stołowski
-
Refactored the conditional for re-creating session_id to be more readable.
- 138. By Paweł Stołowski
-
Added tests for session id in search metadata.
- 139. By Paweł Stołowski
-
Added test for passing session id with preview request.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Paweł Stołowski (stolowski) wrote : | # |
> 99 + // don't regenerate it if currenty query appends to previous
> query or removes
>
> currenty -> currently
>
> 100 + // caharcters from previous query.
>
> caharcters -> characters
>
> 101 + if (m_session_
> 102 + m_searchQuery.
> 103 + !(m_searchQuery
> 104 + search_
>
> this is quite hard to read, and I think its wrong. Rather do something like
> this:
>
> bool search_empty = m_searchQuery.
>
> bool updates_previous = m_searchQuery.
> search_
>
> if((m_session_
I think the logic in this conditional was correct though I agree it wasn't readable. The catch in it is that the startsWith check can only be made with non-empty strings (otherwise it yields true in cases where it shouldn't); I've refactored it a bit with helper variables.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Paweł Stołowski (stolowski) wrote : | # |
> Also could we add a simple test for this?
Added.
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:139
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Marcus Tomlinson (marcustomlinson) wrote : | # |
Looks good, thanks!
Preview Diff
1 | === modified file 'src/Unity/previewstack.cpp' | |||
2 | --- src/Unity/previewstack.cpp 2014-07-18 17:10:39 +0000 | |||
3 | +++ src/Unity/previewstack.cpp 2014-09-04 09:34:32 +0000 | |||
4 | @@ -31,6 +31,7 @@ | |||
5 | 31 | #include <QJsonDocument> | 31 | #include <QJsonDocument> |
6 | 32 | #include <QJsonObject> | 32 | #include <QJsonObject> |
7 | 33 | #include <QJsonValue> | 33 | #include <QJsonValue> |
8 | 34 | #include <QUuid> | ||
9 | 34 | 35 | ||
10 | 35 | #include <unity/scopes/ActionMetadata.h> | 36 | #include <unity/scopes/ActionMetadata.h> |
11 | 36 | #include <unity/scopes/Scope.h> | 37 | #include <unity/scopes/Scope.h> |
12 | @@ -76,9 +77,10 @@ | |||
13 | 76 | return false; | 77 | return false; |
14 | 77 | } | 78 | } |
15 | 78 | 79 | ||
17 | 79 | void PreviewStack::setAssociatedScope(scopes_ng::Scope* scope) | 80 | void PreviewStack::setAssociatedScope(scopes_ng::Scope* scope, QUuid const& session_id) |
18 | 80 | { | 81 | { |
19 | 81 | m_associatedScope = scope; | 82 | m_associatedScope = scope; |
20 | 83 | m_session_id = session_id; | ||
21 | 82 | } | 84 | } |
22 | 83 | 85 | ||
23 | 84 | void PreviewStack::loadForResult(scopes::Result::SPtr const& result) | 86 | void PreviewStack::loadForResult(scopes::Result::SPtr const& result) |
24 | @@ -119,6 +121,9 @@ | |||
25 | 119 | if (!extra_data.is_null()) { | 121 | if (!extra_data.is_null()) { |
26 | 120 | metadata.set_scope_data(extra_data); | 122 | metadata.set_scope_data(extra_data); |
27 | 121 | } | 123 | } |
28 | 124 | if (!m_session_id.isNull()) { | ||
29 | 125 | metadata["session-id"] = uuidToString(m_session_id).toStdString(); | ||
30 | 126 | } | ||
31 | 122 | 127 | ||
32 | 123 | std::shared_ptr<PreviewDataReceiver> listener(new PreviewDataReceiver(m_activePreview)); | 128 | std::shared_ptr<PreviewDataReceiver> listener(new PreviewDataReceiver(m_activePreview)); |
33 | 124 | std::weak_ptr<ScopeDataReceiverBase> wl(listener); | 129 | std::weak_ptr<ScopeDataReceiverBase> wl(listener); |
34 | 125 | 130 | ||
35 | === modified file 'src/Unity/previewstack.h' | |||
36 | --- src/Unity/previewstack.h 2014-05-19 09:58:14 +0000 | |||
37 | +++ src/Unity/previewstack.h 2014-09-04 09:34:32 +0000 | |||
38 | @@ -28,6 +28,7 @@ | |||
39 | 28 | #include <QSharedPointer> | 28 | #include <QSharedPointer> |
40 | 29 | #include <QMultiMap> | 29 | #include <QMultiMap> |
41 | 30 | #include <QPointer> | 30 | #include <QPointer> |
42 | 31 | #include <QUuid> | ||
43 | 31 | 32 | ||
44 | 32 | #include <unity/scopes/PreviewWidget.h> | 33 | #include <unity/scopes/PreviewWidget.h> |
45 | 33 | #include <unity/scopes/Result.h> | 34 | #include <unity/scopes/Result.h> |
46 | @@ -59,7 +60,7 @@ | |||
47 | 59 | 60 | ||
48 | 60 | void setWidgetColumnCount(int columnCount) override; | 61 | void setWidgetColumnCount(int columnCount) override; |
49 | 61 | int widgetColumnCount() const override; | 62 | int widgetColumnCount() const override; |
51 | 62 | void setAssociatedScope(scopes_ng::Scope*); | 63 | void setAssociatedScope(scopes_ng::Scope*, QUuid const&); |
52 | 63 | 64 | ||
53 | 64 | private Q_SLOTS: | 65 | private Q_SLOTS: |
54 | 65 | void widgetTriggered(QString const&, QString const&, QVariantMap const&); | 66 | void widgetTriggered(QString const&, QString const&, QVariantMap const&); |
55 | @@ -79,6 +80,7 @@ | |||
56 | 79 | std::shared_ptr<ScopeDataReceiverBase> m_lastActivation; | 80 | std::shared_ptr<ScopeDataReceiverBase> m_lastActivation; |
57 | 80 | 81 | ||
58 | 81 | unity::scopes::Result::SPtr m_previewedResult; | 82 | unity::scopes::Result::SPtr m_previewedResult; |
59 | 83 | QUuid m_session_id; | ||
60 | 82 | }; | 84 | }; |
61 | 83 | 85 | ||
62 | 84 | } // namespace scopes_ng | 86 | } // namespace scopes_ng |
63 | 85 | 87 | ||
64 | === modified file 'src/Unity/scope.cpp' | |||
65 | --- src/Unity/scope.cpp 2014-08-25 15:35:21 +0000 | |||
66 | +++ src/Unity/scope.cpp 2014-09-04 09:34:32 +0000 | |||
67 | @@ -54,6 +54,7 @@ | |||
68 | 54 | #include <unity/scopes/PreviewWidget.h> | 54 | #include <unity/scopes/PreviewWidget.h> |
69 | 55 | #include <unity/scopes/SearchMetadata.h> | 55 | #include <unity/scopes/SearchMetadata.h> |
70 | 56 | #include <unity/scopes/ActionMetadata.h> | 56 | #include <unity/scopes/ActionMetadata.h> |
71 | 57 | #include <unity/scopes/Variant.h> | ||
72 | 57 | 58 | ||
73 | 58 | namespace scopes_ng | 59 | namespace scopes_ng |
74 | 59 | { | 60 | { |
75 | @@ -67,6 +68,7 @@ | |||
76 | 67 | const int RESULTS_TTL_LARGE = 3600000; // 1 hour | 68 | const int RESULTS_TTL_LARGE = 3600000; // 1 hour |
77 | 68 | 69 | ||
78 | 69 | Scope::Scope(QObject *parent) : unity::shell::scopes::ScopeInterface(parent) | 70 | Scope::Scope(QObject *parent) : unity::shell::scopes::ScopeInterface(parent) |
79 | 71 | , m_query_id(0) | ||
80 | 70 | , m_formFactor("phone") | 72 | , m_formFactor("phone") |
81 | 71 | , m_isActive(false) | 73 | , m_isActive(false) |
82 | 72 | , m_searchInProgress(false) | 74 | , m_searchInProgress(false) |
83 | @@ -625,6 +627,10 @@ | |||
84 | 625 | 627 | ||
85 | 626 | if (m_proxy) { | 628 | if (m_proxy) { |
86 | 627 | scopes::SearchMetadata meta(QLocale::system().name().toStdString(), m_formFactor.toStdString()); | 629 | scopes::SearchMetadata meta(QLocale::system().name().toStdString(), m_formFactor.toStdString()); |
87 | 630 | if (!m_session_id.isNull()) { | ||
88 | 631 | meta["session-id"] = uuidToString(m_session_id).toStdString(); | ||
89 | 632 | } | ||
90 | 633 | meta["query-id"] = unity::scopes::Variant(m_query_id); | ||
91 | 628 | if (m_settings) { | 634 | if (m_settings) { |
92 | 629 | QVariant remoteSearch(m_settings->get("remote-content-search")); | 635 | QVariant remoteSearch(m_settings->get("remote-content-search")); |
93 | 630 | if (remoteSearch.toString() == QString("none")) { | 636 | if (remoteSearch.toString() == QString("none")) { |
94 | @@ -940,6 +946,21 @@ | |||
95 | 940 | */ | 946 | */ |
96 | 941 | 947 | ||
97 | 942 | if (m_searchQuery.isNull() || search_query != m_searchQuery) { | 948 | if (m_searchQuery.isNull() || search_query != m_searchQuery) { |
98 | 949 | // regenerate session id uuid if previous or current search string is empty or | ||
99 | 950 | // if current and previous query have no common prefix; | ||
100 | 951 | // don't regenerate it if current query appends to previous query or removes | ||
101 | 952 | // characters from previous query. | ||
102 | 953 | bool search_empty = m_searchQuery.isEmpty() || search_query.isEmpty(); | ||
103 | 954 | |||
104 | 955 | // only check for common prefix if search is not empty | ||
105 | 956 | bool common_prefix = (!search_empty) && (m_searchQuery.startsWith(search_query) || search_query.startsWith(m_searchQuery)); | ||
106 | 957 | |||
107 | 958 | if (m_session_id.isNull() || search_empty || !common_prefix) { | ||
108 | 959 | m_session_id = QUuid::createUuid(); | ||
109 | 960 | m_query_id = 0; | ||
110 | 961 | } else { | ||
111 | 962 | ++m_query_id; | ||
112 | 963 | } | ||
113 | 943 | m_searchQuery = search_query; | 964 | m_searchQuery = search_query; |
114 | 944 | 965 | ||
115 | 945 | // atm only empty query can have a filter state | 966 | // atm only empty query can have a filter state |
116 | @@ -1049,7 +1070,7 @@ | |||
117 | 1049 | } | 1070 | } |
118 | 1050 | 1071 | ||
119 | 1051 | PreviewStack* stack = new PreviewStack(nullptr); | 1072 | PreviewStack* stack = new PreviewStack(nullptr); |
121 | 1052 | stack->setAssociatedScope(this); | 1073 | stack->setAssociatedScope(this, m_session_id); |
122 | 1053 | stack->loadForResult(result); | 1074 | stack->loadForResult(result); |
123 | 1054 | return stack; | 1075 | return stack; |
124 | 1055 | } | 1076 | } |
125 | @@ -1084,6 +1105,14 @@ | |||
126 | 1084 | return m_resultsDirty; | 1105 | return m_resultsDirty; |
127 | 1085 | } | 1106 | } |
128 | 1086 | 1107 | ||
129 | 1108 | QString Scope::sessionId() const { | ||
130 | 1109 | return uuidToString(m_session_id); | ||
131 | 1110 | } | ||
132 | 1111 | |||
133 | 1112 | int Scope::queryId() const { | ||
134 | 1113 | return m_query_id; | ||
135 | 1114 | } | ||
136 | 1115 | |||
137 | 1087 | void Scope::activateUri(QString const& uri) | 1116 | void Scope::activateUri(QString const& uri) |
138 | 1088 | { | 1117 | { |
139 | 1089 | /* | 1118 | /* |
140 | 1090 | 1119 | ||
141 | === modified file 'src/Unity/scope.h' | |||
142 | --- src/Unity/scope.h 2014-08-25 15:35:21 +0000 | |||
143 | +++ src/Unity/scope.h 2014-09-04 09:34:32 +0000 | |||
144 | @@ -31,6 +31,7 @@ | |||
145 | 31 | #include <QMultiMap> | 31 | #include <QMultiMap> |
146 | 32 | #include <QSet> | 32 | #include <QSet> |
147 | 33 | #include <QGSettings> | 33 | #include <QGSettings> |
148 | 34 | #include <QUuid> | ||
149 | 34 | 35 | ||
150 | 35 | // scopes | 36 | // scopes |
151 | 36 | #include <unity/scopes/ActivationResponse.h> | 37 | #include <unity/scopes/ActivationResponse.h> |
152 | @@ -159,6 +160,9 @@ | |||
153 | 159 | bool resultsDirty() const; | 160 | bool resultsDirty() const; |
154 | 160 | virtual unity::scopes::ScopeProxy proxy_for_result(unity::scopes::Result::SPtr const& result) const; | 161 | virtual unity::scopes::ScopeProxy proxy_for_result(unity::scopes::Result::SPtr const& result) const; |
155 | 161 | 162 | ||
156 | 163 | QString sessionId() const; | ||
157 | 164 | int queryId() const; | ||
158 | 165 | |||
159 | 162 | public Q_SLOTS: | 166 | public Q_SLOTS: |
160 | 163 | void invalidateResults(); | 167 | void invalidateResults(); |
161 | 164 | 168 | ||
162 | @@ -198,6 +202,8 @@ | |||
163 | 198 | static unity::scopes::Department::SCPtr findDepartmentById(unity::scopes::Department::SCPtr const& root, std::string const& id); | 202 | static unity::scopes::Department::SCPtr findDepartmentById(unity::scopes::Department::SCPtr const& root, std::string const& id); |
164 | 199 | static unity::scopes::Department::SCPtr findUpdateNode(DepartmentNode* node, unity::scopes::Department::SCPtr const& scopeNode); | 203 | static unity::scopes::Department::SCPtr findUpdateNode(DepartmentNode* node, unity::scopes::Department::SCPtr const& scopeNode); |
165 | 200 | 204 | ||
166 | 205 | QUuid m_session_id; | ||
167 | 206 | int m_query_id; | ||
168 | 201 | QString m_searchQuery; | 207 | QString m_searchQuery; |
169 | 202 | QString m_noResultsHint; | 208 | QString m_noResultsHint; |
170 | 203 | QString m_formFactor; | 209 | QString m_formFactor; |
171 | 204 | 210 | ||
172 | === modified file 'src/Unity/utils.cpp' | |||
173 | --- src/Unity/utils.cpp 2014-03-25 16:34:26 +0000 | |||
174 | +++ src/Unity/utils.cpp 2014-09-04 09:34:32 +0000 | |||
175 | @@ -123,4 +123,14 @@ | |||
176 | 123 | } | 123 | } |
177 | 124 | } | 124 | } |
178 | 125 | 125 | ||
179 | 126 | Q_DECL_EXPORT QString uuidToString(QUuid const& uuid) | ||
180 | 127 | { | ||
181 | 128 | // workaround: use mid to get rid of curly braces; see https://bugreports.qt-project.org/browse/QTBUG-885 | ||
182 | 129 | auto const uuid_str = uuid.toString(); | ||
183 | 130 | if (uuid_str.startsWith("{")) { | ||
184 | 131 | return uuid_str.mid(1, 36); | ||
185 | 132 | } | ||
186 | 133 | return uuid_str; | ||
187 | 134 | } | ||
188 | 135 | |||
189 | 126 | } // namespace scopes_ng | 136 | } // namespace scopes_ng |
190 | 127 | 137 | ||
191 | === modified file 'src/Unity/utils.h' | |||
192 | --- src/Unity/utils.h 2014-03-25 16:34:26 +0000 | |||
193 | +++ src/Unity/utils.h 2014-09-04 09:34:32 +0000 | |||
194 | @@ -22,6 +22,7 @@ | |||
195 | 22 | 22 | ||
196 | 23 | // Qt | 23 | // Qt |
197 | 24 | #include <QVariant> | 24 | #include <QVariant> |
198 | 25 | #include <QUuid> | ||
199 | 25 | 26 | ||
200 | 26 | #include <unity/scopes/Variant.h> | 27 | #include <unity/scopes/Variant.h> |
201 | 27 | 28 | ||
202 | @@ -31,6 +32,7 @@ | |||
203 | 31 | Q_DECL_EXPORT QVariant scopeVariantToQVariant(unity::scopes::Variant const& variant); | 32 | Q_DECL_EXPORT QVariant scopeVariantToQVariant(unity::scopes::Variant const& variant); |
204 | 32 | Q_DECL_EXPORT unity::scopes::Variant qVariantToScopeVariant(QVariant const& variant); | 33 | Q_DECL_EXPORT unity::scopes::Variant qVariantToScopeVariant(QVariant const& variant); |
205 | 33 | Q_DECL_EXPORT QVariant backgroundUriToVariant(QString const& uri); | 34 | Q_DECL_EXPORT QVariant backgroundUriToVariant(QString const& uri); |
206 | 35 | Q_DECL_EXPORT QString uuidToString(QUuid const& uuid); | ||
207 | 34 | 36 | ||
208 | 35 | } // namespace scopes_ng | 37 | } // namespace scopes_ng |
209 | 36 | 38 | ||
210 | 37 | 39 | ||
211 | === modified file 'tests/data/mock-scope/mock-scope.cpp' | |||
212 | --- tests/data/mock-scope/mock-scope.cpp 2014-09-04 09:34:32 +0000 | |||
213 | +++ tests/data/mock-scope/mock-scope.cpp 2014-09-04 09:34:32 +0000 | |||
214 | @@ -233,6 +233,8 @@ | |||
215 | 233 | res.set_title("result for: \"" + query_ + "\""); | 233 | res.set_title("result for: \"" + query_ + "\""); |
216 | 234 | res.set_art("art"); | 234 | res.set_art("art"); |
217 | 235 | res.set_dnd_uri("test:dnd_uri"); | 235 | res.set_dnd_uri("test:dnd_uri"); |
218 | 236 | res["session-id"] = search_metadata()["session-id"].get_string(); | ||
219 | 237 | res["query-id"] = Variant(search_metadata()["query-id"].get_int()); | ||
220 | 236 | res.set_intercept_activation(); | 238 | res.set_intercept_activation(); |
221 | 237 | reply->push(res); | 239 | reply->push(res); |
222 | 238 | } | 240 | } |
223 | @@ -326,13 +328,14 @@ | |||
224 | 326 | } | 328 | } |
225 | 327 | 329 | ||
226 | 328 | PreviewWidgetList widgets; | 330 | PreviewWidgetList widgets; |
228 | 329 | PreviewWidget w1(R"({"id": "hdr", "type": "header", "components": {"title": "title", "subtitle": "uri", "attribute-1": "extra-data"}})"); | 331 | PreviewWidget w1(R"({"id": "hdr", "type": "header", "components": {"title": "title", "subtitle": "uri", "attribute-1": "extra-data", "session-id": "session-id-val"}})"); |
229 | 330 | PreviewWidget w2(R"({"id": "img", "type": "image", "components": {"source": "art"}, "zoomable": false})"); | 332 | PreviewWidget w2(R"({"id": "img", "type": "image", "components": {"source": "art"}, "zoomable": false})"); |
230 | 331 | widgets.push_back(w1); | 333 | widgets.push_back(w1); |
231 | 332 | widgets.push_back(w2); | 334 | widgets.push_back(w2); |
232 | 333 | reply->push(widgets); | 335 | reply->push(widgets); |
233 | 334 | 336 | ||
234 | 335 | reply->push("extra-data", Variant("foo")); | 337 | reply->push("extra-data", Variant("foo")); |
235 | 338 | reply->push("session-id-val", Variant(action_metadata()["session-id"])); | ||
236 | 336 | } | 339 | } |
237 | 337 | 340 | ||
238 | 338 | private: | 341 | private: |
239 | 339 | 342 | ||
240 | === modified file 'tests/previewtest.cpp' | |||
241 | --- tests/previewtest.cpp 2014-09-04 09:34:32 +0000 | |||
242 | +++ tests/previewtest.cpp 2014-09-04 09:34:32 +0000 | |||
243 | @@ -115,6 +115,7 @@ | |||
244 | 115 | QCOMPARE(props[QString("title")].toString(), QString::fromStdString(result->title())); | 115 | QCOMPARE(props[QString("title")].toString(), QString::fromStdString(result->title())); |
245 | 116 | QCOMPARE(props[QString("subtitle")].toString(), QString::fromStdString(result->uri())); | 116 | QCOMPARE(props[QString("subtitle")].toString(), QString::fromStdString(result->uri())); |
246 | 117 | QCOMPARE(props[QString("attribute-1")].toString(), QString("foo")); | 117 | QCOMPARE(props[QString("attribute-1")].toString(), QString("foo")); |
247 | 118 | QCOMPARE(props[QString("session-id")].toString(), m_scope->sessionId()); | ||
248 | 118 | 119 | ||
249 | 119 | idx = preview_widgets->index(1); | 120 | idx = preview_widgets->index(1); |
250 | 120 | QCOMPARE(preview_widgets->data(idx, PreviewWidgetModel::RoleWidgetId).toString(), QString("img")); | 121 | QCOMPARE(preview_widgets->data(idx, PreviewWidgetModel::RoleWidgetId).toString(), QString("img")); |
251 | 121 | 122 | ||
252 | === modified file 'tests/resultstest.cpp' | |||
253 | --- tests/resultstest.cpp 2014-08-26 13:47:35 +0000 | |||
254 | +++ tests/resultstest.cpp 2014-09-04 09:34:32 +0000 | |||
255 | @@ -260,6 +260,167 @@ | |||
256 | 260 | QCOMPARE(results->data(idx, ResultsModel::Roles::RoleCategoryId), categories->data(categories->index(0), Categories::Roles::RoleCategoryId)); | 260 | QCOMPARE(results->data(idx, ResultsModel::Roles::RoleCategoryId), categories->data(categories->index(0), Categories::Roles::RoleCategoryId)); |
257 | 261 | } | 261 | } |
258 | 262 | 262 | ||
259 | 263 | void testSessionId() | ||
260 | 264 | { | ||
261 | 265 | std::string lastSessionId; | ||
262 | 266 | |||
263 | 267 | performSearch(m_scope, QString("")); | ||
264 | 268 | |||
265 | 269 | QVERIFY(!m_scope->sessionId().isEmpty()); | ||
266 | 270 | QCOMPARE(m_scope->queryId(), 0); | ||
267 | 271 | |||
268 | 272 | { | ||
269 | 273 | auto categories = m_scope->categories(); | ||
270 | 274 | QVERIFY(categories->rowCount() > 0); | ||
271 | 275 | QVariant results_var = categories->data(categories->index(0), Categories::Roles::RoleResults); | ||
272 | 276 | auto results = results_var.value<ResultsModel*>(); | ||
273 | 277 | QVERIFY(results->rowCount() > 0); | ||
274 | 278 | |||
275 | 279 | auto idx = results->index(0); | ||
276 | 280 | auto result = results->data(idx, ResultsModel::Roles::RoleResult).value<std::shared_ptr<unity::scopes::Result>>(); | ||
277 | 281 | |||
278 | 282 | auto sessionId = (*result)["session-id"].get_string(); | ||
279 | 283 | auto queryId = (*result)["query-id"].get_int(); | ||
280 | 284 | |||
281 | 285 | // mock scope should send session-id and query-id it received back via custom result's values | ||
282 | 286 | QCOMPARE(sessionId, m_scope->sessionId().toStdString()); | ||
283 | 287 | QCOMPARE(queryId, m_scope->queryId()); | ||
284 | 288 | QCOMPARE(queryId, 0); | ||
285 | 289 | |||
286 | 290 | lastSessionId = sessionId; | ||
287 | 291 | } | ||
288 | 292 | |||
289 | 293 | // new search | ||
290 | 294 | performSearch(m_scope, QString("m")); | ||
291 | 295 | { | ||
292 | 296 | auto categories = m_scope->categories(); | ||
293 | 297 | QVERIFY(categories->rowCount() > 0); | ||
294 | 298 | QVariant results_var = categories->data(categories->index(0), Categories::Roles::RoleResults); | ||
295 | 299 | auto results = results_var.value<ResultsModel*>(); | ||
296 | 300 | QVERIFY(results->rowCount() > 0); | ||
297 | 301 | |||
298 | 302 | auto idx = results->index(0); | ||
299 | 303 | auto result = results->data(idx, ResultsModel::Roles::RoleResult).value<std::shared_ptr<unity::scopes::Result>>(); | ||
300 | 304 | |||
301 | 305 | auto sessionId = (*result)["session-id"].get_string(); | ||
302 | 306 | auto queryId = (*result)["query-id"].get_int(); | ||
303 | 307 | |||
304 | 308 | // mock scope should send session-id and query-id it received back via custom result's values | ||
305 | 309 | QCOMPARE(sessionId, m_scope->sessionId().toStdString()); | ||
306 | 310 | QCOMPARE(queryId, m_scope->queryId()); | ||
307 | 311 | QCOMPARE(queryId, 0); | ||
308 | 312 | |||
309 | 313 | // new session id | ||
310 | 314 | QVERIFY(sessionId != lastSessionId); | ||
311 | 315 | |||
312 | 316 | lastSessionId = sessionId; | ||
313 | 317 | } | ||
314 | 318 | |||
315 | 319 | // appends to previous search | ||
316 | 320 | performSearch(m_scope, QString("met")); | ||
317 | 321 | { | ||
318 | 322 | auto categories = m_scope->categories(); | ||
319 | 323 | QVERIFY(categories->rowCount() > 0); | ||
320 | 324 | QVariant results_var = categories->data(categories->index(0), Categories::Roles::RoleResults); | ||
321 | 325 | auto results = results_var.value<ResultsModel*>(); | ||
322 | 326 | QVERIFY(results->rowCount() > 0); | ||
323 | 327 | |||
324 | 328 | auto idx = results->index(0); | ||
325 | 329 | auto result = results->data(idx, ResultsModel::Roles::RoleResult).value<std::shared_ptr<unity::scopes::Result>>(); | ||
326 | 330 | |||
327 | 331 | auto sessionId = (*result)["session-id"].get_string(); | ||
328 | 332 | auto queryId = (*result)["query-id"].get_int(); | ||
329 | 333 | |||
330 | 334 | // mock scope should send session-id and query-id it received back via custom result's values | ||
331 | 335 | QCOMPARE(sessionId, m_scope->sessionId().toStdString()); | ||
332 | 336 | QCOMPARE(queryId, m_scope->queryId()); | ||
333 | 337 | QCOMPARE(queryId, 1); | ||
334 | 338 | |||
335 | 339 | // session id unchanged | ||
336 | 340 | QVERIFY(sessionId == lastSessionId); | ||
337 | 341 | |||
338 | 342 | lastSessionId = sessionId; | ||
339 | 343 | } | ||
340 | 344 | |||
341 | 345 | // removes characters from previous search | ||
342 | 346 | performSearch(m_scope, QString("me")); | ||
343 | 347 | { | ||
344 | 348 | auto categories = m_scope->categories(); | ||
345 | 349 | QVERIFY(categories->rowCount() > 0); | ||
346 | 350 | QVariant results_var = categories->data(categories->index(0), Categories::Roles::RoleResults); | ||
347 | 351 | auto results = results_var.value<ResultsModel*>(); | ||
348 | 352 | QVERIFY(results->rowCount() > 0); | ||
349 | 353 | |||
350 | 354 | auto idx = results->index(0); | ||
351 | 355 | auto result = results->data(idx, ResultsModel::Roles::RoleResult).value<std::shared_ptr<unity::scopes::Result>>(); | ||
352 | 356 | |||
353 | 357 | auto sessionId = (*result)["session-id"].get_string(); | ||
354 | 358 | auto queryId = (*result)["query-id"].get_int(); | ||
355 | 359 | |||
356 | 360 | // mock scope should send session-id and query-id it received back via custom result's values | ||
357 | 361 | QCOMPARE(sessionId, m_scope->sessionId().toStdString()); | ||
358 | 362 | QCOMPARE(queryId, m_scope->queryId()); | ||
359 | 363 | QCOMPARE(queryId, 2); | ||
360 | 364 | |||
361 | 365 | // session id unchanged | ||
362 | 366 | QVERIFY(sessionId == lastSessionId); | ||
363 | 367 | |||
364 | 368 | lastSessionId = sessionId; | ||
365 | 369 | } | ||
366 | 370 | |||
367 | 371 | // new non-empty search again | ||
368 | 372 | performSearch(m_scope, QString("iron")); | ||
369 | 373 | { | ||
370 | 374 | auto categories = m_scope->categories(); | ||
371 | 375 | QVERIFY(categories->rowCount() > 0); | ||
372 | 376 | QVariant results_var = categories->data(categories->index(0), Categories::Roles::RoleResults); | ||
373 | 377 | auto results = results_var.value<ResultsModel*>(); | ||
374 | 378 | QVERIFY(results->rowCount() > 0); | ||
375 | 379 | |||
376 | 380 | auto idx = results->index(0); | ||
377 | 381 | auto result = results->data(idx, ResultsModel::Roles::RoleResult).value<std::shared_ptr<unity::scopes::Result>>(); | ||
378 | 382 | |||
379 | 383 | auto sessionId = (*result)["session-id"].get_string(); | ||
380 | 384 | auto queryId = (*result)["query-id"].get_int(); | ||
381 | 385 | |||
382 | 386 | // mock scope should send session-id and query-id it received back via custom result's values | ||
383 | 387 | QCOMPARE(sessionId, m_scope->sessionId().toStdString()); | ||
384 | 388 | QCOMPARE(queryId, m_scope->queryId()); | ||
385 | 389 | QCOMPARE(queryId, 0); | ||
386 | 390 | |||
387 | 391 | // new session id | ||
388 | 392 | QVERIFY(sessionId != lastSessionId); | ||
389 | 393 | |||
390 | 394 | lastSessionId = sessionId; | ||
391 | 395 | } | ||
392 | 396 | |||
393 | 397 | // new empty search again | ||
394 | 398 | performSearch(m_scope, QString("")); | ||
395 | 399 | { | ||
396 | 400 | auto categories = m_scope->categories(); | ||
397 | 401 | QVERIFY(categories->rowCount() > 0); | ||
398 | 402 | QVariant results_var = categories->data(categories->index(0), Categories::Roles::RoleResults); | ||
399 | 403 | auto results = results_var.value<ResultsModel*>(); | ||
400 | 404 | QVERIFY(results->rowCount() > 0); | ||
401 | 405 | |||
402 | 406 | auto idx = results->index(0); | ||
403 | 407 | auto result = results->data(idx, ResultsModel::Roles::RoleResult).value<std::shared_ptr<unity::scopes::Result>>(); | ||
404 | 408 | |||
405 | 409 | auto sessionId = (*result)["session-id"].get_string(); | ||
406 | 410 | auto queryId = (*result)["query-id"].get_int(); | ||
407 | 411 | |||
408 | 412 | // mock scope should send session-id and query-id it received back via custom result's values | ||
409 | 413 | QCOMPARE(sessionId, m_scope->sessionId().toStdString()); | ||
410 | 414 | QCOMPARE(queryId, m_scope->queryId()); | ||
411 | 415 | QCOMPARE(queryId, 0); | ||
412 | 416 | |||
413 | 417 | // new session id | ||
414 | 418 | QVERIFY(sessionId != lastSessionId); | ||
415 | 419 | |||
416 | 420 | lastSessionId = sessionId; | ||
417 | 421 | } | ||
418 | 422 | } | ||
419 | 423 | |||
420 | 263 | void testResultMetadata() | 424 | void testResultMetadata() |
421 | 264 | { | 425 | { |
422 | 265 | performSearch(m_scope, QString("metadata")); | 426 | performSearch(m_scope, QString("metadata")); |
FAILED: Continuous integration, rev:135 jenkins. qa.ubuntu. com/job/ unity-scopes- shell-ci/ 213/ jenkins. qa.ubuntu. com/job/ unity-scopes- shell-utopic- amd64-ci/ 110/console jenkins. qa.ubuntu. com/job/ unity-scopes- shell-utopic- armhf-ci/ 110/console jenkins. qa.ubuntu. com/job/ unity-scopes- shell-utopic- i386-ci/ 110/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- scopes- shell-ci/ 213/rebuild
http://