Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/media/router/mojo/media_router_mojo_test.h

Issue 1826403002: [Media Router] Moves mojo-specific code into mojo/ folder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_TEST_HELPER_H_ 5 #ifndef CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_
6 #define CHROME_BROWSER_MEDIA_ROUTER_TEST_HELPER_H_ 6 #define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10 7
11 #include <string> 8 #include <string>
12 #include <vector>
13 9
14 #include "base/macros.h" 10 #include "base/macros.h"
15 #include "chrome/browser/media/router/issues_observer.h" 11 #include "base/memory/ref_counted.h"
16 #include "chrome/browser/media/router/media_router.mojom.h" 12 #include "base/message_loop/message_loop.h"
17 #include "chrome/browser/media/router/media_router_mojo_impl.h" 13 #include "chrome/browser/media/router/mock_media_router.h"
18 #include "chrome/browser/media/router/media_routes_observer.h" 14 #include "chrome/browser/media/router/mojo/media_router.mojom.h"
19 #include "chrome/browser/media/router/media_sinks_observer.h" 15 #include "chrome/browser/media/router/mojo/media_router_mojo_impl.h"
16 #include "chrome/browser/media/router/test_helper.h"
17 #include "chrome/test/base/testing_profile.h"
20 #include "extensions/browser/event_page_tracker.h" 18 #include "extensions/browser/event_page_tracker.h"
19 #include "extensions/common/extension.h"
20 #include "mojo/public/cpp/bindings/binding.h"
21 #include "testing/gmock/include/gmock/gmock.h" 21 #include "testing/gmock/include/gmock/gmock.h"
22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 namespace media_router { 24 namespace media_router {
24 25
25 // Matcher for objects that uses Equals() member function for equality check. 26 class MediaRouterMojoImpl;
26 MATCHER_P(Equals, other, "") { 27 class MessagePump;
27 return arg.Equals(other);
28 }
29
30 // Matcher for a sequence of objects that uses Equals() member function for
31 // equality check.
32 MATCHER_P(SequenceEquals, other, "") {
33 if (arg.size() != other.size()) {
34 return false;
35 }
36 for (size_t i = 0; i < arg.size(); ++i) {
37 if (!arg[i].Equals(other[i])) {
38 return false;
39 }
40 }
41 return true;
42 }
43
44 // Matcher for checking all fields in Issue objects except the ID.
45 MATCHER_P(EqualsIssue, other, "") {
46 if (arg.title() != other.title())
47 return false;
48
49 if (arg.message() != other.message())
50 return false;
51
52 if (!arg.default_action().Equals(other.default_action()))
53 return false;
54
55 if (arg.secondary_actions().size() != other.secondary_actions().size())
56 return false;
57
58 for (size_t i = 0; i < arg.secondary_actions().size(); ++i) {
59 if (!arg.secondary_actions()[i].Equals(other.secondary_actions()[i]))
60 return false;
61 }
62
63 if (arg.route_id() != other.route_id())
64 return false;
65
66 if (arg.severity() != other.severity())
67 return false;
68
69 if (arg.is_blocking() != other.is_blocking())
70 return false;
71
72 if (arg.help_url() != other.help_url())
73 return false;
74
75 return true;
76 }
77
78 MATCHER_P(IssueTitleEquals, title, "") {
79 return arg.title() == title;
80 }
81
82 MATCHER_P(StateChageInfoEquals, other, "") {
83 return arg.state == other.state && arg.close_reason == other.close_reason &&
84 arg.message == other.message;
85 }
86
87 class MockIssuesObserver : public IssuesObserver {
88 public:
89 explicit MockIssuesObserver(MediaRouter* router);
90 ~MockIssuesObserver() override;
91
92 MOCK_METHOD1(OnIssueUpdated, void(const Issue* issue));
93 };
94 28
95 class MockMediaRouteProvider : public interfaces::MediaRouteProvider { 29 class MockMediaRouteProvider : public interfaces::MediaRouteProvider {
96 public: 30 public:
97 MockMediaRouteProvider(); 31 MockMediaRouteProvider();
98 ~MockMediaRouteProvider() override; 32 ~MockMediaRouteProvider() override;
99 33
100 MOCK_METHOD8(CreateRoute, 34 MOCK_METHOD8(CreateRoute,
101 void(const mojo::String& source_urn, 35 void(const mojo::String& source_urn,
102 const mojo::String& sink_id, 36 const mojo::String& sink_id,
103 const mojo::String& presentation_id, 37 const mojo::String& presentation_id,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 void(const mojo::String& route_id)); 82 void(const mojo::String& route_id));
149 MOCK_METHOD1(OnPresentationSessionDetached, 83 MOCK_METHOD1(OnPresentationSessionDetached,
150 void(const mojo::String& route_id)); 84 void(const mojo::String& route_id));
151 MOCK_METHOD1(StartObservingMediaRoutes, void(const mojo::String& source)); 85 MOCK_METHOD1(StartObservingMediaRoutes, void(const mojo::String& source));
152 MOCK_METHOD1(StopObservingMediaRoutes, void(const mojo::String& source)); 86 MOCK_METHOD1(StopObservingMediaRoutes, void(const mojo::String& source));
153 87
154 private: 88 private:
155 DISALLOW_COPY_AND_ASSIGN(MockMediaRouteProvider); 89 DISALLOW_COPY_AND_ASSIGN(MockMediaRouteProvider);
156 }; 90 };
157 91
158 class MockMediaSinksObserver : public MediaSinksObserver {
159 public:
160 MockMediaSinksObserver(MediaRouter* router,
161 const MediaSource& source,
162 const GURL& origin);
163 ~MockMediaSinksObserver() override;
164
165 MOCK_METHOD1(OnSinksReceived, void(const std::vector<MediaSink>& sinks));
166 };
167
168 class MockMediaRoutesObserver : public MediaRoutesObserver {
169 public:
170 explicit MockMediaRoutesObserver(MediaRouter* router,
171 const MediaSource::Id source_id = std::string());
172 ~MockMediaRoutesObserver() override;
173
174 MOCK_METHOD2(OnRoutesUpdated, void(const std::vector<MediaRoute>& routes,
175 const std::vector<MediaRoute::Id>& joinable_route_ids));
176 };
177
178 class MockEventPageTracker : public extensions::EventPageTracker { 92 class MockEventPageTracker : public extensions::EventPageTracker {
179 public: 93 public:
180 MockEventPageTracker(); 94 MockEventPageTracker();
181 ~MockEventPageTracker(); 95 ~MockEventPageTracker();
182 96
183 MOCK_METHOD1(IsEventPageSuspended, bool(const std::string& extension_id)); 97 MOCK_METHOD1(IsEventPageSuspended, bool(const std::string& extension_id));
184 MOCK_METHOD2(WakeEventPage, 98 MOCK_METHOD2(WakeEventPage,
185 bool(const std::string& extension_id, 99 bool(const std::string& extension_id,
186 const base::Callback<void(bool)>& callback)); 100 const base::Callback<void(bool)>& callback));
187 }; 101 };
188 102
189 class MockPresentationConnectionStateChangedCallback { 103 // Tests the API call flow between the MediaRouterMojoImpl and the Media Router
104 // Mojo service in both directions.
105 class MediaRouterMojoTest : public ::testing::Test {
190 public: 106 public:
191 MockPresentationConnectionStateChangedCallback(); 107 MediaRouterMojoTest();
192 ~MockPresentationConnectionStateChangedCallback(); 108 ~MediaRouterMojoTest() override;
193 MOCK_METHOD1(Run, 109
194 void(const content::PresentationConnectionStateChangeInfo&)); 110 protected:
111 void SetUp() override;
112
113 void ProcessEventLoop();
114
115 void ConnectProviderManagerService();
116
117 const std::string& extension_id() const { return extension_->id(); }
118
119 MediaRouterMojoImpl* router() const { return mock_media_router_.get(); }
120
121 // Mock objects.
122 MockMediaRouteProvider mock_media_route_provider_;
123 testing::NiceMock<MockEventPageTracker> mock_event_page_tracker_;
124
125 // Mojo proxy object for |mock_media_router_|
126 media_router::interfaces::MediaRouterPtr media_router_proxy_;
127
128 private:
129 scoped_refptr<extensions::Extension> extension_;
130 scoped_ptr<MediaRouterMojoImpl> mock_media_router_;
131 scoped_ptr<mojo::Binding<interfaces::MediaRouteProvider>> binding_;
132 base::MessageLoop message_loop_;
133
134 DISALLOW_COPY_AND_ASSIGN(MediaRouterMojoTest);
195 }; 135 };
196 136
197 } // namespace media_router 137 } // namespace media_router
198 138
199 #endif // CHROME_BROWSER_MEDIA_ROUTER_TEST_HELPER_H_ 139 #endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_ROUTER_MOJO_TEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698