on xenial help sign in
Added test_tryOpenNullPreview qmltest
commit6472b0fe8114bc79320adc5291165b111ffe7064 authorMarcus Tomlinson <marcus.tomlinson@canonical.com> dateFri 12 Sep 2014, 13:01 (12 years ago) parent4b36f44
4 files changed+42−5
tests/mocks/Unity/fake_scope.cpp+12−4 tests/mocks/Unity/fake_scope.h+3−1 tests/mocks/Unity/fake_scopes.cpp+1 tests/qmltests/Dash/tst_GenericScopeView.qml+26
tests/mocks/Unity/fake_scope.cpp+12−4
@@ -28,7 +28,7 @@ Scope::Scope(Scopes* parent) : Scope(QString(), QString(), false, parent)
2828{
2929}
3030
31−Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* parent, int categories)
31+Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* parent, int categories, bool returnNullPreview)
3232 : unity::shell::scopes::ScopeInterface(parent)
3333 , m_id(id)
3434 , m_name(name)
@@ -41,6 +41,7 @@ Scope::Scope(QString const& id, QString const& name, bool favorite, Scopes* pare
4141 , m_categories(new Categories(categories, this))
4242 , m_openScope(nullptr)
4343 , m_settings(new SettingsModel(this))
44+ , m_returnNullPreview(returnNullPreview)
4445{
4546}
4647
@@ -175,9 +176,16 @@ PreviewStack* Scope::preview(QVariant const& result)
175176{
176177 Q_UNUSED(result);
177178
178− // This probably leaks, do we don't care
179− // it's a test after all
180− return new PreviewStack;
179+ if (m_returnNullPreview)
180+ {
181+ return nullptr;
182+ }
183+ else
184+ {
185+ // This probably leaks, do we don't care
186+ // it's a test after all
187+ return new PreviewStack;
188+ }
181189}
182190
183191void Scope::cancelActivation()
tests/mocks/Unity/fake_scope.h+3−1
@@ -32,7 +32,7 @@ class Scope : public unity::shell::scopes::ScopeInterface
3232
3333public:
3434 Scope(Scopes* parent = 0);
35− Scope(QString const& id, QString const& name, bool favorite, Scopes* parent = 0, int categories = 20);
35+ Scope(QString const& id, QString const& name, bool favorite, Scopes* parent = 0, int categories = 20, bool returnNullPreview = false);
3636
3737 /* getters */
3838 QString id() const override;
@@ -97,6 +97,8 @@ protected:
9797 unity::shell::scopes::CategoriesInterface* m_categories;
9898 unity::shell::scopes::ScopeInterface* m_openScope;
9999 unity::shell::scopes::SettingsModelInterface* m_settings;
100+
101+ bool m_returnNullPreview;
100102};
101103
102104#endif // FAKE_SCOPE_H
tests/mocks/Unity/fake_scopes.cpp+1
@@ -59,6 +59,7 @@ void Scopes::updateScopes()
5959 addScope(new Scope("MockScope7", "MS7", false, this));
6060 addScope(new Scope("MockScope8", "MS8", false, this));
6161 addScope(new Scope("MockScope9", "MS9", false, this));
62+ addScope(new Scope("NullPreviewScope", "NPS", true, this, 1, true));
6263 m_scopesOverview = new ScopesOverview(this);
6364
6465 if (!m_loaded) {
tests/qmltests/Dash/tst_GenericScopeView.qml+26
@@ -301,6 +301,32 @@ Item {
301301 closePreview();
302302 }
303303
304+ function test_tryOpenNullPreview() {
305+ var originalScopeId = genericScopeView.scope.id;
306+ genericScopeView.scope = scopes.getScope("NullPreviewScope");
307+
308+ tryCompareFunction(function() {
309+ var cardGrid = findChild(genericScopeView, 0);
310+ if (cardGrid != null) {
311+ var tile = findChild(cardGrid, 0);
312+ return tile != null;
313+ }
314+ return false;
315+ },
316+ true);
317+ var tile = findChild(findChild(genericScopeView, 0), 0);
318+
319+ tryCompare(testCase.subPageLoader, "open", false);
320+ tryCompare(testCase.subPageLoader, "visible", false);
321+
322+ mouseClick(tile, tile.width / 2, tile.height / 2);
323+
324+ tryCompare(testCase.subPageLoader, "open", false);
325+ tryCompare(testCase.subPageLoader, "visible", false);
326+
327+ genericScopeView.scope = scopes.getScope(originalScopeId)
328+ }
329+
304330 function test_showPreviewCarousel() {
305331 var category = scrollToCategory("dashCategory1");
306332