imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 5 | #include "content/browser/presentation/presentation_service_impl.h" |
| 6 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | #include <stdint.h> |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 9 | |
mfoltz | 0dc2a6b | 2017-03-07 18:24:19 | [diff] [blame] | 10 | #include <iterator> |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 11 | #include <memory> |
kmarshall | f5367c64 | 2015-08-20 19:23:13 | [diff] [blame] | 12 | #include <string> |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 13 | #include <utility> |
kmarshall | f5367c64 | 2015-08-20 19:23:13 | [diff] [blame] | 14 | #include <vector> |
| 15 | |
Sebastien Marchand | f8cbfab | 2019-01-25 16:02:30 | [diff] [blame] | 16 | #include "base/bind.h" |
danakj | db9ae794 | 2020-11-11 16:01:35 | [diff] [blame] | 17 | #include "base/callback_helpers.h" |
Mario Sanchez Prada | 2311a9e | 2019-08-26 14:29:49 | [diff] [blame] | 18 | #include "base/macros.h" |
Mario Sanchez Prada | 2ae29e5a | 2019-08-26 14:42:23 | [diff] [blame] | 19 | #include "base/optional.h" |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 20 | #include "base/run_loop.h" |
Lei Zhang | e02299a | 2021-04-26 23:12:24 | [diff] [blame] | 21 | #include "base/strings/stringprintf.h" |
Rakina Zata Amni | c7bc826 | 2019-12-09 05:21:22 | [diff] [blame] | 22 | #include "content/browser/presentation/presentation_test_utils.h" |
Derek Cheng | 1071a23 | 2017-07-25 22:23:56 | [diff] [blame] | 23 | #include "content/public/browser/presentation_request.h" |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 24 | #include "content/public/browser/presentation_service_delegate.h" |
Camille Lamy | fa5767c | 2019-01-07 14:53:59 | [diff] [blame] | 25 | #include "content/public/test/mock_navigation_handle.h" |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 26 | #include "content/test/test_render_frame_host.h" |
| 27 | #include "content/test/test_render_view_host.h" |
| 28 | #include "content/test/test_web_contents.h" |
Mario Sanchez Prada | 2311a9e | 2019-08-26 14:29:49 | [diff] [blame] | 29 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
| 30 | #include "mojo/public/cpp/bindings/pending_remote.h" |
| 31 | #include "mojo/public/cpp/bindings/receiver.h" |
| 32 | #include "mojo/public/cpp/bindings/remote.h" |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 33 | #include "testing/gmock/include/gmock/gmock.h" |
| 34 | |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 35 | namespace content { |
| 36 | |
imcheng | 2ed5f820 | 2015-04-24 19:41:17 | [diff] [blame] | 37 | namespace { |
| 38 | |
mfoltz | fcad5262 | 2016-09-03 03:08:33 | [diff] [blame] | 39 | const char kPresentationId[] = "presentationId"; |
| 40 | const char kPresentationUrl1[] = "http://foo.com/index.html"; |
| 41 | const char kPresentationUrl2[] = "http://example.com/index.html"; |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 42 | const char kPresentationUrl3[] = "http://example.net/index.html"; |
haibinlu | 4ba4019 | 2015-06-23 21:43:09 | [diff] [blame] | 43 | |
imcheng | 2ed5f820 | 2015-04-24 19:41:17 | [diff] [blame] | 44 | } // namespace |
| 45 | |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 46 | class PresentationServiceImplTest : public RenderViewHostImplTestHarness { |
| 47 | public: |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 48 | PresentationServiceImplTest() |
| 49 | : presentation_url1_(GURL(kPresentationUrl1)), |
| 50 | presentation_url2_(GURL(kPresentationUrl2)), |
| 51 | presentation_url3_(GURL(kPresentationUrl3)) {} |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 52 | |
| 53 | void SetUp() override { |
| 54 | RenderViewHostImplTestHarness::SetUp(); |
Avi Drissman | 650a39d1 | 2020-07-14 17:18:29 | [diff] [blame] | 55 | // This needed to keep the WebContentsObserverConsistencyChecker checks |
| 56 | // happy for when AppendChild is called. |
jam | 5fdbb58 | 2017-02-06 22:09:59 | [diff] [blame] | 57 | NavigateAndCommit(GURL("about:blank")); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 58 | |
imcheng | 2ed5f820 | 2015-04-24 19:41:17 | [diff] [blame] | 59 | EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1); |
imcheng | ad59d85 | 2016-04-21 20:05:06 | [diff] [blame] | 60 | TestRenderFrameHost* render_frame_host = contents()->GetMainFrame(); |
| 61 | render_frame_host->InitializeRenderFrameIfNeeded(); |
imcheng | 16819b9 | 2015-04-03 08:52:45 | [diff] [blame] | 62 | service_impl_.reset(new PresentationServiceImpl( |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 63 | render_frame_host, contents(), &mock_delegate_, nullptr)); |
imcheng | 9ce5394b | 2015-05-12 19:27:01 | [diff] [blame] | 64 | |
Mario Sanchez Prada | 2ae29e5a | 2019-08-26 14:42:23 | [diff] [blame] | 65 | mojo::PendingRemote<PresentationController> presentation_controller_remote; |
| 66 | controller_receiver_.emplace( |
| 67 | &mock_controller_, |
| 68 | presentation_controller_remote.InitWithNewPipeAndPassReceiver()); |
| 69 | service_impl_->SetController(std::move(presentation_controller_remote)); |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 70 | |
| 71 | presentation_urls_.push_back(presentation_url1_); |
| 72 | presentation_urls_.push_back(presentation_url2_); |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 73 | |
| 74 | expect_presentation_success_cb_ = |
| 75 | base::BindOnce(&PresentationServiceImplTest::ExpectPresentationSuccess, |
| 76 | base::Unretained(this)); |
| 77 | expect_presentation_error_cb_ = |
| 78 | base::BindOnce(&PresentationServiceImplTest::ExpectPresentationError, |
| 79 | base::Unretained(this)); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | void TearDown() override { |
imcheng | 16819b9 | 2015-04-03 08:52:45 | [diff] [blame] | 83 | if (service_impl_.get()) { |
Derek Cheng | 4de47c5 | 2017-10-10 01:05:54 | [diff] [blame] | 84 | ExpectDelegateReset(); |
imcheng | 2ed5f820 | 2015-04-24 19:41:17 | [diff] [blame] | 85 | EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); |
imcheng | 16819b9 | 2015-04-03 08:52:45 | [diff] [blame] | 86 | service_impl_.reset(); |
| 87 | } |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 88 | RenderViewHostImplTestHarness::TearDown(); |
| 89 | } |
| 90 | |
jam | 5fdbb58 | 2017-02-06 22:09:59 | [diff] [blame] | 91 | void Navigate(bool main_frame) { |
mfoltz | 0dc2a6b | 2017-03-07 18:24:19 | [diff] [blame] | 92 | RenderFrameHost* rfh = main_rfh(); |
| 93 | RenderFrameHostTester* rfh_tester = RenderFrameHostTester::For(rfh); |
jam | 5fdbb58 | 2017-02-06 22:09:59 | [diff] [blame] | 94 | if (!main_frame) |
| 95 | rfh = rfh_tester->AppendChild("subframe"); |
Camille Lamy | fa5767c | 2019-01-07 14:53:59 | [diff] [blame] | 96 | MockNavigationHandle handle(GURL(), rfh); |
| 97 | handle.set_has_committed(true); |
| 98 | service_impl_->DidFinishNavigation(&handle); |
jam | 5fdbb58 | 2017-02-06 22:09:59 | [diff] [blame] | 99 | } |
| 100 | |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 101 | void ListenForScreenAvailabilityAndWait(const GURL& url, |
tapted | 8f125bdd | 2016-08-01 04:51:09 | [diff] [blame] | 102 | bool delegate_success) { |
mlamouri | 0c8ce52 | 2015-10-02 21:47:38 | [diff] [blame] | 103 | EXPECT_CALL(mock_delegate_, AddScreenAvailabilityListener()) |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 104 | .WillOnce(Return(delegate_success)); |
| 105 | service_impl_->ListenForScreenAvailability(url); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 106 | |
| 107 | EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
| 108 | } |
| 109 | |
Anton Vayvod | e3c3986 | 2017-06-20 20:53:32 | [diff] [blame] | 110 | void SimulateScreenAvailabilityChangeAndWait( |
| 111 | const GURL& url, |
| 112 | ScreenAvailability availability) { |
mfoltz | 3f30502f | 2015-08-11 16:13:38 | [diff] [blame] | 113 | auto listener_it = service_impl_->screen_availability_listeners_.find(url); |
| 114 | ASSERT_TRUE(listener_it->second); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 115 | |
Derek Cheng | f8ffbec5 | 2017-12-06 19:43:04 | [diff] [blame] | 116 | EXPECT_CALL(mock_controller_, |
| 117 | OnScreenAvailabilityUpdated(url, availability)); |
Anton Vayvod | e3c3986 | 2017-06-20 20:53:32 | [diff] [blame] | 118 | listener_it->second->OnScreenAvailabilityChanged(availability); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 119 | base::RunLoop().RunUntilIdle(); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 120 | } |
| 121 | |
Derek Cheng | 4de47c5 | 2017-10-10 01:05:54 | [diff] [blame] | 122 | void ExpectDelegateReset() { |
imcheng | 2ed5f820 | 2015-04-24 19:41:17 | [diff] [blame] | 123 | EXPECT_CALL(mock_delegate_, Reset(_, _)).Times(1); |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void ExpectCleanState() { |
mfoltz | fcad5262 | 2016-09-03 03:08:33 | [diff] [blame] | 127 | EXPECT_TRUE(service_impl_->default_presentation_urls_.empty()); |
mfoltz | 3f30502f | 2015-08-11 16:13:38 | [diff] [blame] | 128 | EXPECT_EQ( |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 129 | service_impl_->screen_availability_listeners_.find(presentation_url1_), |
mfoltz | 3f30502f | 2015-08-11 16:13:38 | [diff] [blame] | 130 | service_impl_->screen_availability_listeners_.end()); |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 131 | } |
| 132 | |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 133 | void ExpectPresentationSuccess(PresentationConnectionResultPtr result, |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 134 | PresentationErrorPtr error) { |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 135 | EXPECT_TRUE(result); |
| 136 | EXPECT_FALSE(error); |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 137 | presentation_cb_was_run_ = true; |
| 138 | } |
| 139 | |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 140 | void ExpectPresentationError(PresentationConnectionResultPtr result, |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 141 | PresentationErrorPtr error) { |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 142 | EXPECT_FALSE(result); |
| 143 | EXPECT_TRUE(error); |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 144 | presentation_cb_was_run_ = true; |
| 145 | } |
| 146 | |
| 147 | void ExpectPresentationCallbackWasRun() const { |
| 148 | EXPECT_TRUE(presentation_cb_was_run_) |
| 149 | << "ExpectPresentationSuccess or ExpectPresentationError was called"; |
| 150 | } |
| 151 | |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 152 | MockPresentationServiceDelegate mock_delegate_; |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 153 | MockReceiverPresentationServiceDelegate mock_receiver_delegate_; |
imcheng | 9ce5394b | 2015-05-12 19:27:01 | [diff] [blame] | 154 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 155 | std::unique_ptr<PresentationServiceImpl> service_impl_; |
imcheng | 9ce5394b | 2015-05-12 19:27:01 | [diff] [blame] | 156 | |
Derek Cheng | f8ffbec5 | 2017-12-06 19:43:04 | [diff] [blame] | 157 | MockPresentationController mock_controller_; |
Mario Sanchez Prada | 2ae29e5a | 2019-08-26 14:42:23 | [diff] [blame] | 158 | base::Optional<mojo::Receiver<PresentationController>> controller_receiver_; |
imcheng | 9ce5394b | 2015-05-12 19:27:01 | [diff] [blame] | 159 | |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 160 | GURL presentation_url1_; |
| 161 | GURL presentation_url2_; |
| 162 | GURL presentation_url3_; |
| 163 | std::vector<GURL> presentation_urls_; |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 164 | |
| 165 | NewPresentationCallback expect_presentation_success_cb_; |
| 166 | NewPresentationCallback expect_presentation_error_cb_; |
| 167 | bool presentation_cb_was_run_ = false; |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 168 | }; |
| 169 | |
avayvod | 9b5dbea4 | 2015-03-25 18:52:38 | [diff] [blame] | 170 | TEST_F(PresentationServiceImplTest, ListenForScreenAvailability) { |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 171 | ListenForScreenAvailabilityAndWait(presentation_url1_, true); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 172 | |
Anton Vayvod | e3c3986 | 2017-06-20 20:53:32 | [diff] [blame] | 173 | SimulateScreenAvailabilityChangeAndWait(presentation_url1_, |
| 174 | ScreenAvailability::AVAILABLE); |
| 175 | SimulateScreenAvailabilityChangeAndWait(presentation_url1_, |
| 176 | ScreenAvailability::UNAVAILABLE); |
| 177 | SimulateScreenAvailabilityChangeAndWait(presentation_url1_, |
| 178 | ScreenAvailability::AVAILABLE); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 179 | } |
| 180 | |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 181 | TEST_F(PresentationServiceImplTest, ScreenAvailabilityNotSupported) { |
| 182 | mock_delegate_.set_screen_availability_listening_supported(false); |
Derek Cheng | f8ffbec5 | 2017-12-06 19:43:04 | [diff] [blame] | 183 | EXPECT_CALL(mock_controller_, |
Anton Vayvod | ddd1c408d | 2017-06-20 20:54:59 | [diff] [blame] | 184 | OnScreenAvailabilityUpdated(presentation_url1_, |
| 185 | ScreenAvailability::DISABLED)); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 186 | ListenForScreenAvailabilityAndWait(presentation_url1_, false); |
| 187 | base::RunLoop().RunUntilIdle(); |
| 188 | } |
| 189 | |
Derek Cheng | 4de47c5 | 2017-10-10 01:05:54 | [diff] [blame] | 190 | TEST_F(PresentationServiceImplTest, OnDelegateDestroyed) { |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 191 | ListenForScreenAvailabilityAndWait(presentation_url1_, true); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 192 | |
Derek Cheng | 4de47c5 | 2017-10-10 01:05:54 | [diff] [blame] | 193 | service_impl_->OnDelegateDestroyed(); |
| 194 | |
| 195 | // TearDown() expects |mock_delegate_| to have been notified when |
| 196 | // |service_impl_| is destroyed; this does not apply here since the delegate |
| 197 | // is destroyed first. |
| 198 | service_impl_.reset(); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | TEST_F(PresentationServiceImplTest, DidNavigateThisFrame) { |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 202 | ListenForScreenAvailabilityAndWait(presentation_url1_, true); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 203 | |
Derek Cheng | 4de47c5 | 2017-10-10 01:05:54 | [diff] [blame] | 204 | ExpectDelegateReset(); |
jam | 5fdbb58 | 2017-02-06 22:09:59 | [diff] [blame] | 205 | Navigate(true); |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 206 | ExpectCleanState(); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 207 | } |
| 208 | |
imcheng | 9ce5394b | 2015-05-12 19:27:01 | [diff] [blame] | 209 | TEST_F(PresentationServiceImplTest, DidNavigateOtherFrame) { |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 210 | ListenForScreenAvailabilityAndWait(presentation_url1_, true); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 211 | |
jam | 5fdbb58 | 2017-02-06 22:09:59 | [diff] [blame] | 212 | Navigate(false); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 213 | |
| 214 | // Availability is reported and callback is invoked since it was not |
| 215 | // removed. |
Anton Vayvod | e3c3986 | 2017-06-20 20:53:32 | [diff] [blame] | 216 | SimulateScreenAvailabilityChangeAndWait(presentation_url1_, |
| 217 | ScreenAvailability::AVAILABLE); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 218 | } |
| 219 | |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 220 | TEST_F(PresentationServiceImplTest, DelegateFails) { |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 221 | ListenForScreenAvailabilityAndWait(presentation_url1_, false); |
mfoltz | 3f30502f | 2015-08-11 16:13:38 | [diff] [blame] | 222 | ASSERT_EQ( |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 223 | service_impl_->screen_availability_listeners_.end(), |
| 224 | service_impl_->screen_availability_listeners_.find(presentation_url1_)); |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 225 | } |
| 226 | |
mfoltz | fcad5262 | 2016-09-03 03:08:33 | [diff] [blame] | 227 | TEST_F(PresentationServiceImplTest, SetDefaultPresentationUrls) { |
Derek Cheng | 1071a23 | 2017-07-25 22:23:56 | [diff] [blame] | 228 | EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls( |
| 229 | PresentationUrlsAre(presentation_urls_), _)) |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 230 | .Times(1); |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 231 | |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 232 | service_impl_->SetDefaultPresentationUrls(presentation_urls_); |
mfoltz | fcad5262 | 2016-09-03 03:08:33 | [diff] [blame] | 233 | |
| 234 | // Sets different DPUs. |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 235 | std::vector<GURL> more_urls = presentation_urls_; |
| 236 | more_urls.push_back(presentation_url3_); |
mfoltz | fcad5262 | 2016-09-03 03:08:33 | [diff] [blame] | 237 | |
mfoltz | 11fc4df8 | 2017-03-20 23:49:18 | [diff] [blame] | 238 | PresentationConnectionCallback callback; |
Derek Cheng | 1071a23 | 2017-07-25 22:23:56 | [diff] [blame] | 239 | EXPECT_CALL(mock_delegate_, |
| 240 | SetDefaultPresentationUrls(PresentationUrlsAre(more_urls), _)) |
| 241 | .WillOnce(SaveArgByMove<1>(&callback)); |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 242 | service_impl_->SetDefaultPresentationUrls(more_urls); |
imcheng | fa43aae0 | 2015-11-11 17:28:44 | [diff] [blame] | 243 | |
mfoltz | 11fc4df8 | 2017-03-20 23:49:18 | [diff] [blame] | 244 | PresentationInfo presentation_info(presentation_url2_, kPresentationId); |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 245 | |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 246 | EXPECT_CALL(mock_controller_, OnDefaultPresentationStarted(_)) |
| 247 | .WillOnce([&presentation_info](PresentationConnectionResultPtr result) { |
| 248 | EXPECT_THAT(*result->presentation_info, InfoEquals(presentation_info)); |
| 249 | }); |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 250 | EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)); |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 251 | |
Mario Sanchez Prada | 23a91b2 | 2019-08-26 14:45:33 | [diff] [blame] | 252 | mojo::PendingRemote<PresentationConnection> presentation_connection_remote; |
Mario Sanchez Prada | 2311a9e | 2019-08-26 14:29:49 | [diff] [blame] | 253 | mojo::Remote<PresentationConnection> controller_remote; |
Mario Sanchez Prada | 23a91b2 | 2019-08-26 14:45:33 | [diff] [blame] | 254 | ignore_result( |
| 255 | presentation_connection_remote.InitWithNewPipeAndPassReceiver()); |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 256 | std::move(callback).Run(PresentationConnectionResult::New( |
| 257 | blink::mojom::PresentationInfo::New(presentation_url2_, kPresentationId), |
Mario Sanchez Prada | 23a91b2 | 2019-08-26 14:45:33 | [diff] [blame] | 258 | std::move(presentation_connection_remote), |
Mario Sanchez Prada | 2311a9e | 2019-08-26 14:29:49 | [diff] [blame] | 259 | controller_remote.BindNewPipeAndPassReceiver())); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 260 | base::RunLoop().RunUntilIdle(); |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 261 | } |
| 262 | |
imcheng | 22578da | 2017-07-11 23:09:11 | [diff] [blame] | 263 | TEST_F(PresentationServiceImplTest, |
| 264 | SetDefaultPresentationUrlsNoopsOnNonMainFrame) { |
| 265 | RenderFrameHost* rfh = main_rfh(); |
| 266 | RenderFrameHostTester* rfh_tester = RenderFrameHostTester::For(rfh); |
| 267 | rfh = rfh_tester->AppendChild("subframe"); |
| 268 | |
| 269 | EXPECT_CALL(mock_delegate_, RemoveObserver(_, _)).Times(1); |
| 270 | EXPECT_CALL(mock_delegate_, AddObserver(_, _, _)).Times(1); |
| 271 | service_impl_.reset( |
| 272 | new PresentationServiceImpl(rfh, contents(), &mock_delegate_, nullptr)); |
| 273 | |
Derek Cheng | 1071a23 | 2017-07-25 22:23:56 | [diff] [blame] | 274 | EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _)).Times(0); |
imcheng | 22578da | 2017-07-11 23:09:11 | [diff] [blame] | 275 | service_impl_->SetDefaultPresentationUrls(presentation_urls_); |
| 276 | } |
| 277 | |
zhaobin | 42407c7 | 2017-02-07 02:04:16 | [diff] [blame] | 278 | TEST_F(PresentationServiceImplTest, ListenForConnectionStateChange) { |
mfoltz | 11fc4df8 | 2017-03-20 23:49:18 | [diff] [blame] | 279 | PresentationInfo connection(presentation_url1_, kPresentationId); |
mfoltz | 0dc2a6b | 2017-03-07 18:24:19 | [diff] [blame] | 280 | PresentationConnectionStateChangedCallback state_changed_cb; |
Derek Cheng | f8ffbec5 | 2017-12-06 19:43:04 | [diff] [blame] | 281 | // Trigger state change. It should be propagated back up to |
| 282 | // |mock_controller_|. |
mfoltz | 11fc4df8 | 2017-03-20 23:49:18 | [diff] [blame] | 283 | PresentationInfo presentation_connection(presentation_url1_, kPresentationId); |
zhaobin | badd595 | 2016-11-09 18:25:50 | [diff] [blame] | 284 | |
| 285 | EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 286 | .WillOnce(SaveArg<3>(&state_changed_cb)); |
imcheng | 1ebdd16 | 2017-01-26 22:01:52 | [diff] [blame] | 287 | service_impl_->ListenForConnectionStateChange(connection); |
zhaobin | badd595 | 2016-11-09 18:25:50 | [diff] [blame] | 288 | |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 289 | EXPECT_CALL(mock_controller_, OnConnectionStateChanged( |
| 290 | InfoPtrEquals(presentation_connection), |
mark a. foltz | e8ad320 | 2018-04-23 22:50:23 | [diff] [blame] | 291 | PresentationConnectionState::TERMINATED)); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 292 | state_changed_cb.Run(PresentationConnectionStateChangeInfo( |
mark a. foltz | e8ad320 | 2018-04-23 22:50:23 | [diff] [blame] | 293 | PresentationConnectionState::TERMINATED)); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 294 | base::RunLoop().RunUntilIdle(); |
imcheng | ed10e96 | 2016-02-23 06:34:44 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | TEST_F(PresentationServiceImplTest, ListenForConnectionClose) { |
mfoltz | 11fc4df8 | 2017-03-20 23:49:18 | [diff] [blame] | 298 | PresentationInfo connection(presentation_url1_, kPresentationId); |
mfoltz | 0dc2a6b | 2017-03-07 18:24:19 | [diff] [blame] | 299 | PresentationConnectionStateChangedCallback state_changed_cb; |
imcheng | ed10e96 | 2016-02-23 06:34:44 | [diff] [blame] | 300 | EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 301 | .WillOnce(SaveArg<3>(&state_changed_cb)); |
imcheng | 1ebdd16 | 2017-01-26 22:01:52 | [diff] [blame] | 302 | service_impl_->ListenForConnectionStateChange(connection); |
imcheng | ed10e96 | 2016-02-23 06:34:44 | [diff] [blame] | 303 | |
| 304 | // Trigger connection close. It should be propagated back up to |
Derek Cheng | f8ffbec5 | 2017-12-06 19:43:04 | [diff] [blame] | 305 | // |mock_controller_|. |
mfoltz | 11fc4df8 | 2017-03-20 23:49:18 | [diff] [blame] | 306 | PresentationInfo presentation_connection(presentation_url1_, kPresentationId); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 307 | PresentationConnectionStateChangeInfo closed_info( |
mark a. foltz | e8ad320 | 2018-04-23 22:50:23 | [diff] [blame] | 308 | PresentationConnectionState::CLOSED); |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 309 | closed_info.close_reason = PresentationConnectionCloseReason::WENT_AWAY; |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 310 | closed_info.message = "Foo"; |
imcheng | ed10e96 | 2016-02-23 06:34:44 | [diff] [blame] | 311 | |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 312 | EXPECT_CALL( |
| 313 | mock_controller_, |
| 314 | OnConnectionClosed(InfoPtrEquals(presentation_connection), |
| 315 | PresentationConnectionCloseReason::WENT_AWAY, "Foo")); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 316 | state_changed_cb.Run(closed_info); |
| 317 | base::RunLoop().RunUntilIdle(); |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 318 | } |
| 319 | |
mfoltz | fcad5262 | 2016-09-03 03:08:33 | [diff] [blame] | 320 | TEST_F(PresentationServiceImplTest, SetSameDefaultPresentationUrls) { |
Derek Cheng | 1071a23 | 2017-07-25 22:23:56 | [diff] [blame] | 321 | EXPECT_CALL(mock_delegate_, SetDefaultPresentationUrls(_, _)).Times(1); |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 322 | service_impl_->SetDefaultPresentationUrls(presentation_urls_); |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 323 | EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
mfoltz | fcad5262 | 2016-09-03 03:08:33 | [diff] [blame] | 324 | |
| 325 | // Same URLs as before; no-ops. |
mfoltz | 7a2c823b | 2016-10-08 01:35:24 | [diff] [blame] | 326 | service_impl_->SetDefaultPresentationUrls(presentation_urls_); |
mfoltz | fcad5262 | 2016-09-03 03:08:33 | [diff] [blame] | 327 | EXPECT_TRUE(Mock::VerifyAndClearExpectations(&mock_delegate_)); |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 328 | } |
| 329 | |
mfoltz | 11fc4df8 | 2017-03-20 23:49:18 | [diff] [blame] | 330 | TEST_F(PresentationServiceImplTest, StartPresentationSuccess) { |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 331 | PresentationConnectionCallback saved_success_cb; |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 332 | EXPECT_CALL(mock_delegate_, StartPresentation(_, _, _)) |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 333 | .WillOnce([&saved_success_cb](const auto& request, auto success_cb, |
| 334 | auto error_cb) { |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 335 | saved_success_cb = std::move(success_cb); |
| 336 | }); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 337 | service_impl_->StartPresentation(presentation_urls_, |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 338 | std::move(expect_presentation_success_cb_)); |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 339 | EXPECT_FALSE(saved_success_cb.is_null()); |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 340 | EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 341 | .Times(1); |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 342 | std::move(saved_success_cb) |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 343 | .Run(PresentationConnectionResult::New( |
| 344 | blink::mojom::PresentationInfo::New(presentation_url1_, |
| 345 | kPresentationId), |
Mario Sanchez Prada | 2311a9e | 2019-08-26 14:29:49 | [diff] [blame] | 346 | mojo::NullRemote(), mojo::NullReceiver())); |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 347 | ExpectPresentationCallbackWasRun(); |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 348 | } |
| 349 | |
mfoltz | 11fc4df8 | 2017-03-20 23:49:18 | [diff] [blame] | 350 | TEST_F(PresentationServiceImplTest, StartPresentationError) { |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 351 | base::OnceCallback<void(const PresentationError&)> saved_error_cb; |
| 352 | EXPECT_CALL(mock_delegate_, StartPresentation(_, _, _)) |
| 353 | .WillOnce([&](const auto& request, auto success_cb, auto error_cb) { |
| 354 | saved_error_cb = std::move(error_cb); |
| 355 | }); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 356 | service_impl_->StartPresentation(presentation_urls_, |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 357 | std::move(expect_presentation_error_cb_)); |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 358 | EXPECT_FALSE(saved_error_cb.is_null()); |
| 359 | std::move(saved_error_cb) |
| 360 | .Run(PresentationError(PresentationErrorType::UNKNOWN, "Error message")); |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 361 | ExpectPresentationCallbackWasRun(); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | TEST_F(PresentationServiceImplTest, StartPresentationInProgress) { |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 365 | EXPECT_CALL(mock_delegate_, StartPresentation(_, _, _)).Times(1); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 366 | // Uninvoked callbacks must outlive |service_impl_| since they get invoked |
| 367 | // at |service_impl_|'s destruction. |
Peter Kasting | 341e1fb | 2018-02-24 00:03:01 | [diff] [blame] | 368 | service_impl_->StartPresentation(presentation_urls_, base::DoNothing()); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 369 | |
| 370 | // This request should fail immediately, since there is already a |
| 371 | // StartPresentation in progress. |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 372 | service_impl_->StartPresentation(presentation_urls_, |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 373 | std::move(expect_presentation_error_cb_)); |
| 374 | ExpectPresentationCallbackWasRun(); |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 375 | } |
| 376 | |
mfoltz | 11fc4df8 | 2017-03-20 23:49:18 | [diff] [blame] | 377 | TEST_F(PresentationServiceImplTest, ReconnectPresentationSuccess) { |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 378 | PresentationConnectionCallback saved_success_cb; |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 379 | EXPECT_CALL(mock_delegate_, ReconnectPresentation(_, kPresentationId, _, _)) |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 380 | .WillOnce([&saved_success_cb](const auto& request, const auto& id, |
| 381 | auto success_cb, auto error_cb) { |
| 382 | saved_success_cb = std::move(success_cb); |
| 383 | }); |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 384 | service_impl_->ReconnectPresentation( |
| 385 | presentation_urls_, kPresentationId, |
| 386 | std::move(expect_presentation_success_cb_)); |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 387 | EXPECT_FALSE(saved_success_cb.is_null()); |
imcheng | f3e5a01 | 2015-11-20 04:08:37 | [diff] [blame] | 388 | EXPECT_CALL(mock_delegate_, ListenForConnectionStateChange(_, _, _, _)) |
| 389 | .Times(1); |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 390 | std::move(saved_success_cb) |
btolsch | 8ca10fb2 | 2018-08-29 01:35:09 | [diff] [blame] | 391 | .Run(PresentationConnectionResult::New( |
| 392 | blink::mojom::PresentationInfo::New(presentation_url1_, |
| 393 | kPresentationId), |
Mario Sanchez Prada | 2311a9e | 2019-08-26 14:29:49 | [diff] [blame] | 394 | mojo::NullRemote(), mojo::NullReceiver())); |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 395 | ExpectPresentationCallbackWasRun(); |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 396 | } |
| 397 | |
mfoltz | 11fc4df8 | 2017-03-20 23:49:18 | [diff] [blame] | 398 | TEST_F(PresentationServiceImplTest, ReconnectPresentationError) { |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 399 | base::OnceCallback<void(const PresentationError&)> saved_error_cb; |
| 400 | EXPECT_CALL(mock_delegate_, ReconnectPresentation(_, kPresentationId, _, _)) |
| 401 | .WillOnce([&](const auto& request, const std::string& id, auto success_cb, |
| 402 | auto error_cb) { saved_error_cb = std::move(error_cb); }); |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 403 | service_impl_->ReconnectPresentation( |
| 404 | presentation_urls_, kPresentationId, |
| 405 | std::move(expect_presentation_error_cb_)); |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 406 | EXPECT_FALSE(saved_error_cb.is_null()); |
| 407 | std::move(saved_error_cb) |
| 408 | .Run(PresentationError(PresentationErrorType::UNKNOWN, "Error message")); |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 409 | ExpectPresentationCallbackWasRun(); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | TEST_F(PresentationServiceImplTest, MaxPendingReconnectPresentationRequests) { |
| 413 | const char* presentation_url = "http://fooUrl%d"; |
| 414 | const char* presentation_id = "presentationId%d"; |
| 415 | int num_requests = PresentationServiceImpl::kMaxQueuedRequests; |
| 416 | int i = 0; |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 417 | EXPECT_CALL(mock_delegate_, ReconnectPresentation(_, _, _, _)) |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 418 | .Times(num_requests); |
| 419 | for (; i < num_requests; ++i) { |
| 420 | std::vector<GURL> urls = {GURL(base::StringPrintf(presentation_url, i))}; |
| 421 | // Uninvoked callbacks must outlive |service_impl_| since they get invoked |
| 422 | // at |service_impl_|'s destruction. |
Peter Kasting | 341e1fb | 2018-02-24 00:03:01 | [diff] [blame] | 423 | service_impl_->ReconnectPresentation( |
| 424 | urls, base::StringPrintf(presentation_id, i), base::DoNothing()); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | std::vector<GURL> urls = {GURL(base::StringPrintf(presentation_url, i))}; |
| 428 | // Exceeded maximum queue size, should invoke mojo callback with error. |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 429 | service_impl_->ReconnectPresentation( |
mark a. foltz | d9d2a451 | 2018-04-16 20:42:45 | [diff] [blame] | 430 | urls, base::StringPrintf(presentation_id, i), |
| 431 | std::move(expect_presentation_error_cb_)); |
| 432 | ExpectPresentationCallbackWasRun(); |
imcheng | 271b9ef | 2015-03-18 19:43:19 | [diff] [blame] | 433 | } |
| 434 | |
mfoltz | d0c3de1 | 2015-12-12 04:43:08 | [diff] [blame] | 435 | TEST_F(PresentationServiceImplTest, CloseConnection) { |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 436 | EXPECT_CALL(mock_delegate_, CloseConnection(_, _, Eq(kPresentationId))); |
| 437 | service_impl_->CloseConnection(presentation_url1_, kPresentationId); |
haibinlu | 4ba4019 | 2015-06-23 21:43:09 | [diff] [blame] | 438 | } |
| 439 | |
mfoltz | d0c3de1 | 2015-12-12 04:43:08 | [diff] [blame] | 440 | TEST_F(PresentationServiceImplTest, Terminate) { |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 441 | EXPECT_CALL(mock_delegate_, Terminate(_, _, Eq(kPresentationId))); |
| 442 | service_impl_->Terminate(presentation_url1_, kPresentationId); |
mlamouri | c65a70d7 | 2015-11-27 16:28:59 | [diff] [blame] | 443 | } |
| 444 | |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 445 | TEST_F(PresentationServiceImplTest, ReceiverPresentationServiceDelegate) { |
zhaobin | dca98f63 | 2017-06-29 18:42:28 | [diff] [blame] | 446 | EXPECT_CALL(mock_receiver_delegate_, AddObserver(_, _, _)).Times(1); |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 447 | |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 448 | PresentationServiceImpl service_impl(main_rfh(), contents(), nullptr, |
zhaobin | dca98f63 | 2017-06-29 18:42:28 | [diff] [blame] | 449 | &mock_receiver_delegate_); |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 450 | |
| 451 | ReceiverConnectionAvailableCallback callback; |
zhaobin | dca98f63 | 2017-06-29 18:42:28 | [diff] [blame] | 452 | EXPECT_CALL(mock_receiver_delegate_, |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 453 | RegisterReceiverConnectionAvailableCallback(_)) |
| 454 | .WillOnce(SaveArg<0>(&callback)); |
| 455 | |
Derek Cheng | 4de47c5 | 2017-10-10 01:05:54 | [diff] [blame] | 456 | MockPresentationReceiver mock_receiver; |
Mario Sanchez Prada | 23a91b2 | 2019-08-26 14:45:33 | [diff] [blame] | 457 | mojo::Receiver<blink::mojom::PresentationReceiver> |
| 458 | presentation_receiver_receiver(&mock_receiver); |
| 459 | service_impl.SetReceiver( |
| 460 | presentation_receiver_receiver.BindNewPipeAndPassRemote()); |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 461 | EXPECT_FALSE(callback.is_null()); |
| 462 | |
mark a. foltz | e2084383c | 2018-05-11 19:21:50 | [diff] [blame] | 463 | PresentationInfo expected(presentation_url1_, kPresentationId); |
zhaobin | f3704f8 | 2017-01-12 07:19:36 | [diff] [blame] | 464 | |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 465 | // Client gets notified of receiver connections. |
Mario Sanchez Prada | 2311a9e | 2019-08-26 14:29:49 | [diff] [blame] | 466 | mojo::PendingRemote<PresentationConnection> controller_connection; |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 467 | MockPresentationConnection mock_presentation_connection; |
Mario Sanchez Prada | 2311a9e | 2019-08-26 14:29:49 | [diff] [blame] | 468 | mojo::Receiver<PresentationConnection> connection_binding( |
| 469 | &mock_presentation_connection, |
| 470 | controller_connection.InitWithNewPipeAndPassReceiver()); |
| 471 | mojo::Remote<PresentationConnection> receiver_connection; |
Derek Cheng | 4de47c5 | 2017-10-10 01:05:54 | [diff] [blame] | 472 | |
| 473 | EXPECT_CALL(mock_receiver, |
mark a. foltz | 756d07e | 2018-07-20 20:59:18 | [diff] [blame] | 474 | OnReceiverConnectionAvailable(InfoPtrEquals(expected), _, _)) |
Derek Cheng | 4de47c5 | 2017-10-10 01:05:54 | [diff] [blame] | 475 | .Times(1); |
mark a. foltz | e2084383c | 2018-05-11 19:21:50 | [diff] [blame] | 476 | callback.Run(PresentationInfo::New(expected), |
| 477 | std::move(controller_connection), |
Mario Sanchez Prada | 2311a9e | 2019-08-26 14:29:49 | [diff] [blame] | 478 | receiver_connection.BindNewPipeAndPassReceiver()); |
imcheng | fafb67d0 | 2017-06-15 17:30:14 | [diff] [blame] | 479 | base::RunLoop().RunUntilIdle(); |
| 480 | |
zhaobin | dca98f63 | 2017-06-29 18:42:28 | [diff] [blame] | 481 | EXPECT_CALL(mock_receiver_delegate_, RemoveObserver(_, _)).Times(1); |
| 482 | } |
| 483 | |
| 484 | TEST_F(PresentationServiceImplTest, ReceiverDelegateOnSubFrame) { |
| 485 | EXPECT_CALL(mock_receiver_delegate_, AddObserver(_, _, _)).Times(1); |
| 486 | |
| 487 | PresentationServiceImpl service_impl(main_rfh(), contents(), nullptr, |
| 488 | &mock_receiver_delegate_); |
| 489 | service_impl.is_main_frame_ = false; |
| 490 | |
| 491 | ReceiverConnectionAvailableCallback callback; |
| 492 | EXPECT_CALL(mock_receiver_delegate_, |
| 493 | RegisterReceiverConnectionAvailableCallback(_)) |
| 494 | .Times(0); |
| 495 | |
Mario Sanchez Prada | 2ae29e5a | 2019-08-26 14:42:23 | [diff] [blame] | 496 | mojo::PendingRemote<PresentationController> presentation_controller_remote; |
| 497 | controller_receiver_.emplace( |
| 498 | &mock_controller_, |
| 499 | presentation_controller_remote.InitWithNewPipeAndPassReceiver()); |
zhaobin | dca98f63 | 2017-06-29 18:42:28 | [diff] [blame] | 500 | service_impl.controller_delegate_ = nullptr; |
Mario Sanchez Prada | 2ae29e5a | 2019-08-26 14:42:23 | [diff] [blame] | 501 | service_impl.SetController(std::move(presentation_controller_remote)); |
zhaobin | dca98f63 | 2017-06-29 18:42:28 | [diff] [blame] | 502 | |
| 503 | EXPECT_CALL(mock_receiver_delegate_, Reset(_, _)).Times(0); |
| 504 | service_impl.Reset(); |
| 505 | |
| 506 | EXPECT_CALL(mock_receiver_delegate_, RemoveObserver(_, _)).Times(1); |
mlamouri | 0c8ce52 | 2015-10-02 21:47:38 | [diff] [blame] | 507 | } |
| 508 | |
imcheng | 9f515d0 | 2015-02-10 20:09:24 | [diff] [blame] | 509 | } // namespace content |