Merge lp:~larryprice/libertine-scope/filter-state into lp:libertine-scope

Proposed by Larry Price
Status: Merged
Approved by: Christopher Townsend
Approved revision: 55
Merged at revision: 61
Proposed branch: lp:~larryprice/libertine-scope/filter-state
Merge into: lp:libertine-scope
Diff against target: 350 lines (+179/-43)
8 files modified
scope/apps/action.cpp (+26/-15)
scope/apps/action.h (+21/-15)
scope/apps/scope.cpp (+14/-1)
scope/apps/scope.h (+1/-0)
tests/CMakeLists.txt (+2/-0)
tests/mock_hidden_apps.h (+32/-0)
tests/test_action.cpp (+82/-0)
tests/test_query.cpp (+1/-12)
To merge this branch: bzr merge lp:~larryprice/libertine-scope/filter-state
Reviewer Review Type Date Requested Status
Christopher Townsend Approve
Libertine CI Bot continuous-integration Approve
Review via email: mp+301426@code.launchpad.net

Commit message

Showing/hiding applications should retain filter state.

Description of the change

Showing/hiding applications should retain filter state.

I added two items to the ctor of Action: filter_state gives the last known state of the scope filters and allows us to set the filters after a show/hide, and open_action is a lambda which tells Action what to do when "open" is called. Since we use url-dispatcher, this was the quickest way I came up with to mock this function call so I could set up some proper unit tests.

To post a comment you must log in.
Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:54
https://jenkins.canonical.com/libertine/job/lp-libertine-scope-ci/56/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/214
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=vivid+overlay,testname=default/174
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/174
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=yakkety,testname=default/174
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=vivid+overlay,testname=default/174
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/174
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=yakkety,testname=default/174
    None: https://jenkins.canonical.com/libertine/job/lp-generic-update-mp/163/console
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/217
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=vivid+overlay/202
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=xenial+overlay/202
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=yakkety/202
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/195
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/195/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/195
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/195/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/195
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/195/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/195
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/195/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/195
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/195/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/195
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/195/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-scope-ci/56/rebuild

review: Approve (continuous-integration)
55. By Larry Price

Merge

Revision history for this message
Libertine CI Bot (libertine-ci-bot) wrote :

PASSED: Continuous integration, rev:55
https://jenkins.canonical.com/libertine/job/lp-libertine-scope-ci/57/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/libertine/job/build/217
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=vivid+overlay,testname=default/177
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=xenial+overlay,testname=default/177
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=amd64,release=yakkety,testname=default/177
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=vivid+overlay,testname=default/177
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=xenial+overlay,testname=default/177
    SUCCESS: https://jenkins.canonical.com/libertine/job/test-0-autopkgtest/label=i386,release=yakkety,testname=default/177
    None: https://jenkins.canonical.com/libertine/job/lp-generic-update-mp/164/console
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-0-fetch/220
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=vivid+overlay/205
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=xenial+overlay/205
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-1-sourcepkg/release=yakkety/205
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/198
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=vivid+overlay/198/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/198
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=xenial+overlay/198/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/198
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=amd64,release=yakkety/198/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/198
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=vivid+overlay/198/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/198
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=xenial+overlay/198/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/198
        deb: https://jenkins.canonical.com/libertine/job/build-2-binpkg/arch=i386,release=yakkety/198/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/libertine/job/lp-libertine-scope-ci/57/rebuild

review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

Good, thanks

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'scope/apps/action.cpp'
--- scope/apps/action.cpp 2016-07-28 15:46:36 +0000
+++ scope/apps/action.cpp 2016-07-29 13:21:50 +0000
@@ -29,14 +29,30 @@
29namespace usc = unity::scopes;29namespace usc = unity::scopes;
3030
3131
32namespace
33{
34static usc::ActivationResponse
35sendToResults(usc::FilterState const& filter_state)
36{
37 usc::CannedQuery query(FULLY_QUALIFIED_APPS_SCOPE);
38 query.set_filter_state(filter_state);
39 return usc::ActivationResponse(query);
40}
41}
42
43
32Action::44Action::
33Action(usc::Result const& result,45Action(unity::scopes::Result const& result,
34 usc::ActionMetadata const& metadata,46 unity::scopes::ActionMetadata const& metadata,
35 std::string const& action_id, 47 std::string const& action_id,
36 std::shared_ptr<HiddenApps> hidden)48 Action::OpenUriAction open_action,
37 : usc::ActivationQueryBase(result, metadata),49 std::shared_ptr<HiddenApps> hidden,
38 action_id_(action_id),50 unity::scopes::FilterState const& filter_state)
39 hidden_(hidden)51 : usc::ActivationQueryBase(result, metadata)
52 , action_id_(action_id)
53 , open_action_(open_action)
54 , hidden_(hidden)
55 , filter_state_(filter_state)
40{56{
41}57}
4258
@@ -46,22 +62,17 @@
46{62{
47 if (action_id_ == "open")63 if (action_id_ == "open")
48 {64 {
49 url_dispatch_send(result().uri().c_str() , NULL, NULL);65 open_action_(result().uri());
50 return usc::ActivationResponse(usc::ActivationResponse::Status::NotHandled);
51 }66 }
52 else if (action_id_ == "hide")67 else if (action_id_ == "hide")
53 {68 {
54 hidden_->add(QString::fromStdString(result()["app_id"].get_string()));69 hidden_->add(QString::fromStdString(result()["app_id"].get_string()));
5570 return sendToResults(filter_state_);
56 usc::CannedQuery cq(FULLY_QUALIFIED_APPS_SCOPE);
57 return usc::ActivationResponse(cq);
58 }71 }
59 else if (action_id_ == "show")72 else if (action_id_ == "show")
60 {73 {
61 hidden_->remove(QString::fromStdString(result()["app_id"].get_string()));74 hidden_->remove(QString::fromStdString(result()["app_id"].get_string()));
6275 return sendToResults(filter_state_);
63 usc::CannedQuery cq(FULLY_QUALIFIED_APPS_SCOPE);
64 return usc::ActivationResponse(cq);
65 }76 }
66 return usc::ActivationResponse(usc::ActivationResponse::Status::NotHandled);77 return usc::ActivationResponse(usc::ActivationResponse::Status::NotHandled);
67}78}
6879
=== modified file 'scope/apps/action.h'
--- scope/apps/action.h 2016-07-12 18:26:07 +0000
+++ scope/apps/action.h 2016-07-29 13:21:50 +0000
@@ -15,31 +15,37 @@
15 * * Authored by:15 * * Authored by:
16 * Kyle Nitzsche <kyle.nitzsche@canonical.com>16 * Kyle Nitzsche <kyle.nitzsche@canonical.com>
17 */17 */
18
19#ifndef SCOPE_ACTION_H_18#ifndef SCOPE_ACTION_H_
20#define SCOPE_ACTION_H_19#define SCOPE_ACTION_H_
2120
22#include "scope/apps/scope.h"21
23#include <unity/scopes/ActionMetadata.h>22#include <unity/scopes/ActionMetadata.h>
24#include <unity/scopes/ActivationQueryBase.h>23#include <unity/scopes/ActivationQueryBase.h>
25#include <unity/scopes/ActivationResponse.h>24#include <unity/scopes/ActivationResponse.h>
26#include <unity/scopes/Result.h>25#include <unity/scopes/Result.h>
2726
27
28class HiddenApps;28class HiddenApps;
2929
30class Action : public unity::scopes::ActivationQueryBase {30class Action : public unity::scopes::ActivationQueryBase {
31 public:31public:
32 Action(unity::scopes::Result const& result,32 typedef std::function<void(std::string const&)> OpenUriAction;
33 unity::scopes::ActionMetadata const& metadata,33
34 std::string const& action_id, 34 explicit Action(unity::scopes::Result const& result,
35 std::shared_ptr<HiddenApps> hidden);35 unity::scopes::ActionMetadata const& metadata,
3636 std::string const& action_id,
37 virtual ~Action() = default;37 OpenUriAction open_action,
38 virtual unity::scopes::ActivationResponse activate() override;38 std::shared_ptr<HiddenApps> hidden,
3939 unity::scopes::FilterState const& filterState);
40 private:40
41 std::string action_id_;41 virtual ~Action() = default;
42 std::string cache_dir_;42 virtual unity::scopes::ActivationResponse activate() override;
43 std::shared_ptr<HiddenApps> hidden_;43
44private:
45 std::string action_id_;
46 std::string cache_dir_;
47 OpenUriAction open_action_;
48 std::shared_ptr<HiddenApps> hidden_;
49 unity::scopes::FilterState filter_state_;
44};50};
45#endif51#endif
4652
=== modified file 'scope/apps/scope.cpp'
--- scope/apps/scope.cpp 2016-07-28 15:47:35 +0000
+++ scope/apps/scope.cpp 2016-07-29 13:21:50 +0000
@@ -29,6 +29,16 @@
29namespace usc = unity::scopes;29namespace usc = unity::scopes;
3030
3131
32namespace
33{
34static void
35open_application(std::string const& app_uri)
36{
37 url_dispatch_send(app_uri.c_str(), NULL, NULL);
38}
39}
40
41
32Scope::42Scope::
33Scope(Libertine::Factory const& libertine_factory)43Scope(Libertine::Factory const& libertine_factory)
34: libertine_factory_(libertine_factory)44: libertine_factory_(libertine_factory)
@@ -56,6 +66,7 @@
56search(usc::CannedQuery const& query,66search(usc::CannedQuery const& query,
57 usc::SearchMetadata const& metadata)67 usc::SearchMetadata const& metadata)
58{68{
69 filter_state_ = query.filter_state();
59 return usc::SearchQueryBase::UPtr(new Query(query,70 return usc::SearchQueryBase::UPtr(new Query(query,
60 metadata,71 metadata,
61 libertine_factory_,72 libertine_factory_,
@@ -81,7 +92,9 @@
81 return usc::ActivationQueryBase::UPtr(new Action(result,92 return usc::ActivationQueryBase::UPtr(new Action(result,
82 metadata,93 metadata,
83 action_id,94 action_id,
84 std::make_shared<HiddenApps>(cache_directory())));95 open_application,
96 std::make_shared<HiddenApps>(cache_directory()),
97 filter_state_));
85}98}
8699
87100
88101
=== modified file 'scope/apps/scope.h'
--- scope/apps/scope.h 2016-07-12 18:26:07 +0000
+++ scope/apps/scope.h 2016-07-29 13:21:50 +0000
@@ -78,6 +78,7 @@
7878
79private:79private:
80 Libertine::Factory libertine_factory_;80 Libertine::Factory libertine_factory_;
81 unity::scopes::FilterState filter_state_;
81};82};
8283
83#endif // LIBERTINE_SCOPE_SCOPE_H_84#endif // LIBERTINE_SCOPE_SCOPE_H_
8485
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2016-07-12 18:26:07 +0000
+++ tests/CMakeLists.txt 2016-07-29 13:21:50 +0000
@@ -7,6 +7,7 @@
7 add_executable(${test_name}_exe7 add_executable(${test_name}_exe
8 fake_container.cpp8 fake_container.cpp
9 fake_libertine.cpp9 fake_libertine.cpp
10 mock_hidden_apps.h
10 ${test_name}.cpp11 ${test_name}.cpp
11 )12 )
1213
@@ -25,5 +26,6 @@
25create_test(test_query)26create_test(test_query)
26create_test(test_hidden_apps)27create_test(test_hidden_apps)
27create_test(test_blacklist)28create_test(test_blacklist)
29create_test(test_action)
2830
29file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})31file(COPY data DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
3032
=== added file 'tests/mock_hidden_apps.h'
--- tests/mock_hidden_apps.h 1970-01-01 00:00:00 +0000
+++ tests/mock_hidden_apps.h 2016-07-29 13:21:50 +0000
@@ -0,0 +1,32 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, version 3, as published by the
6 * Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include "scope/apps/hidden_apps.h"
17#include <gmock/gmock.h>
18
19
20class MockHiddenApps : public HiddenApps
21{
22public:
23 MockHiddenApps()
24 : HiddenApps("")
25 {
26 }
27
28 MOCK_CONST_METHOD1(app_is_hidden, bool(QString const&));
29 MOCK_CONST_METHOD0(empty, bool());
30 MOCK_METHOD1(remove, void(QString const&));
31 MOCK_METHOD1(add, void(QString const&));
32};
033
=== added file 'tests/test_action.cpp'
--- tests/test_action.cpp 1970-01-01 00:00:00 +0000
+++ tests/test_action.cpp 2016-07-29 13:21:50 +0000
@@ -0,0 +1,82 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, version 3, as published by the
6 * Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include "scope/apps/action.h"
17#include "tests/mock_hidden_apps.h"
18
19#include <unity/scopes/ActionMetadata.h>
20#include <unity/scopes/testing/Result.h>
21#include <gmock/gmock.h>
22
23
24namespace
25{
26TEST(ActionTest, OpenSendsDispatchURI)
27{
28 unity::scopes::testing::Result result;
29 result.set_uri("app://this/is/my/app");
30 unity::scopes::ActionMetadata metadata("en_US", "phone");
31 auto hidden = std::make_shared<testing::NiceMock<MockHiddenApps> >();
32 unity::scopes::FilterState filter_state;
33
34 std::string uri;
35
36 Action action(result, metadata, "open", [&](std::string const& app_uri) {
37 uri = app_uri;
38 }, hidden, filter_state);
39
40 auto response = action.activate();
41 EXPECT_EQ(unity::scopes::ActivationResponse::Status::NotHandled, response.status());
42 EXPECT_EQ(result.uri(), uri);
43}
44
45
46TEST(ActionTest, ShowRemovesAppFromHidden)
47{
48 unity::scopes::testing::Result result;
49 unity::scopes::ActionMetadata metadata("en_US", "phone");
50 unity::scopes::FilterState filter_state;
51 auto hidden = std::make_shared<testing::NiceMock<MockHiddenApps> >();
52
53 QString app_id = "something.desktop";
54 result["app_id"] = app_id.toStdString();
55 EXPECT_CALL(*hidden, remove(app_id));
56
57 Action action(result, metadata, "show", Action::OpenUriAction{}, hidden, filter_state);
58
59 auto response = action.activate();
60 EXPECT_EQ(filter_state.serialize(), response.query().filter_state().serialize());
61 EXPECT_EQ(unity::scopes::ActivationResponse::Status::PerformQuery, response.status());
62}
63
64
65TEST(ActionTest, HideAddsAppToHidden)
66{
67 unity::scopes::testing::Result result;
68 unity::scopes::ActionMetadata metadata("en_US", "phone");
69 unity::scopes::FilterState filter_state;
70 auto hidden = std::make_shared<testing::NiceMock<MockHiddenApps> >();
71
72 QString app_id = "something.desktop";
73 result["app_id"] = app_id.toStdString();
74 EXPECT_CALL(*hidden, add(app_id));
75
76 Action action(result, metadata, "hide", Action::OpenUriAction{}, hidden, filter_state);
77
78 auto response = action.activate();
79 EXPECT_EQ(filter_state.serialize(), response.query().filter_state().serialize());
80 EXPECT_EQ(unity::scopes::ActivationResponse::Status::PerformQuery, response.status());
81}
82}
083
=== modified file 'tests/test_query.cpp'
--- tests/test_query.cpp 2016-07-12 18:26:07 +0000
+++ tests/test_query.cpp 2016-07-29 13:21:50 +0000
@@ -17,6 +17,7 @@
17#include "scope/apps/query.h"17#include "scope/apps/query.h"
18#include "scope/apps/config.h"18#include "scope/apps/config.h"
19#include "tests/fake_libertine.h"19#include "tests/fake_libertine.h"
20#include "tests/mock_hidden_apps.h"
20#include <unity/scopes/SearchMetadata.h>21#include <unity/scopes/SearchMetadata.h>
21#include <unity/scopes/CannedQuery.h>22#include <unity/scopes/CannedQuery.h>
22#include <unity/scopes/SearchReplyProxyFwd.h>23#include <unity/scopes/SearchReplyProxyFwd.h>
@@ -67,18 +68,6 @@
67};68};
6869
6970
70class MockHiddenApps : public HiddenApps
71{
72public:
73 MockHiddenApps()
74 : HiddenApps("")
75 {
76 }
77
78 MOCK_CONST_METHOD1(app_is_hidden, bool(QString const&));
79 MOCK_CONST_METHOD0(empty, bool());
80};
81
82class MockBlacklist : public Blacklist71class MockBlacklist : public Blacklist
83{72{
84public:73public:

Subscribers

People subscribed via source and target branches