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

Side by Side Diff: third_party/WebKit/Source/modules/presentation/PresentationReceiverTest.cpp

Issue 2355723004: [Presentation API] 1-UA: send message between controller and receiver page (Closed)
Patch Set: Merge with changes in Issue 2343013002 Created 4 years, 2 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "modules/presentation/PresentationReceiver.h" 5 #include "modules/presentation/PresentationReceiver.h"
6 6
7 #include "bindings/core/v8/ScriptPromiseResolver.h" 7 #include "bindings/core/v8/ScriptPromiseResolver.h"
8 #include "bindings/core/v8/V8BindingForTesting.h" 8 #include "bindings/core/v8/V8BindingForTesting.h"
9 #include "core/frame/LocalFrame.h" 9 #include "core/frame/LocalFrame.h"
10 #include "core/testing/DummyPageHolder.h" 10 #include "core/testing/DummyPageHolder.h"
11 #include "modules/presentation/PresentationConnection.h"
11 #include "modules/presentation/PresentationConnectionList.h" 12 #include "modules/presentation/PresentationConnectionList.h"
12 #include "platform/testing/URLTestHelpers.h" 13 #include "platform/testing/URLTestHelpers.h"
13 #include "public/platform/modules/presentation/WebPresentationClient.h" 14 #include "public/platform/modules/presentation/WebPresentationClient.h"
14 #include "public/platform/modules/presentation/WebPresentationConnectionClient.h " 15 #include "public/platform/modules/presentation/WebPresentationConnectionClient.h "
15 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 #include <v8.h> 18 #include <v8.h>
18 19
19 namespace blink { 20 namespace blink {
20 21
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 class TestWebPresentationConnectionClient : public WebPresentationConnectionClie nt { 79 class TestWebPresentationConnectionClient : public WebPresentationConnectionClie nt {
79 public: 80 public:
80 WebString getId() override { return WebString::fromUTF8("id"); } 81 WebString getId() override { return WebString::fromUTF8("id"); }
81 WebURL getUrl() override { return URLTestHelpers::toKURL("http://www.example .com"); } 82 WebURL getUrl() override { return URLTestHelpers::toKURL("http://www.example .com"); }
82 }; 83 };
83 84
84 class PresentationReceiverTest : public ::testing::Test { 85 class PresentationReceiverTest : public ::testing::Test {
85 public: 86 public:
86 void addConnectionavailableEventListener( 87 void addConnectionavailableEventListener(
87 EventListener*, const PresentationReceiver*); 88 EventListener*, const PresentationReceiver*);
89 void addOnMessageEventListener(
90 EventListener*, const PresentationReceiver*);
88 void verifyConnectionListPropertyState( 91 void verifyConnectionListPropertyState(
89 ScriptPromisePropertyBase::State, const PresentationReceiver*); 92 ScriptPromisePropertyBase::State, const PresentationReceiver*);
90 void verifyConnectionListSize( 93 void verifyConnectionListSize(
91 size_t expectedSize, const PresentationReceiver*); 94 size_t expectedSize, const PresentationReceiver*);
92 }; 95 };
93 96
94 void PresentationReceiverTest::addConnectionavailableEventListener( 97 void PresentationReceiverTest::addConnectionavailableEventListener(
95 EventListener* eventHandler, 98 EventListener* eventHandler,
96 const PresentationReceiver* receiver) 99 const PresentationReceiver* receiver)
97 { 100 {
98 receiver->m_connectionList->addEventListener(EventTypeNames::connectionavail able, eventHandler); 101 receiver->m_connectionList->addEventListener(EventTypeNames::connectionavail able, eventHandler);
99 } 102 }
100 103
104 void PresentationReceiverTest::addOnMessageEventListener(
105 EventListener* eventHandler,
106 const PresentationReceiver* receiver)
107 {
108 for (auto const& connection : receiver->m_connectionList->m_connections)
109 connection->addEventListener(EventTypeNames::connect, eventHandler);
110 }
111
101 void PresentationReceiverTest::verifyConnectionListPropertyState( 112 void PresentationReceiverTest::verifyConnectionListPropertyState(
102 ScriptPromisePropertyBase::State expectedState, 113 ScriptPromisePropertyBase::State expectedState,
103 const PresentationReceiver* receiver) 114 const PresentationReceiver* receiver)
104 { 115 {
105 EXPECT_EQ(expectedState, receiver->m_connectionListProperty->getState()); 116 EXPECT_EQ(expectedState, receiver->m_connectionListProperty->getState());
106 } 117 }
107 118
108 void PresentationReceiverTest::verifyConnectionListSize( 119 void PresentationReceiverTest::verifyConnectionListSize(
109 size_t expectedSize, 120 size_t expectedSize,
110 const PresentationReceiver* receiver) 121 const PresentationReceiver* receiver)
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 204
194 TEST_F(PresentationReceiverTest, CreateReceiver) 205 TEST_F(PresentationReceiverTest, CreateReceiver)
195 { 206 {
196 MockWebPresentationClient client; 207 MockWebPresentationClient client;
197 EXPECT_CALL(client, setReceiver(testing::_)); 208 EXPECT_CALL(client, setReceiver(testing::_));
198 209
199 V8TestingScope scope; 210 V8TestingScope scope;
200 new PresentationReceiver(&scope.frame(), &client); 211 new PresentationReceiver(&scope.frame(), &client);
201 } 212 }
202 213
214 TEST_F(PresentationReceiverTest, didReceiveSessionTextMessage)
215 {
216 V8TestingScope scope;
217 auto receiver = new PresentationReceiver(&scope.frame(), nullptr);
218
219 // Receive first connection.
220 auto connectionClient1 = new TestWebPresentationConnectionClient();
221 receiver->onReceiverConnectionAvailable(connectionClient1);
222
223 // verify onMessage event
224 StrictMock<MockEventListener>* eventHandler = new StrictMock<MockEventListen er>();
225 addOnMessageEventListener(eventHandler, receiver);
226 EXPECT_CALL(*eventHandler, handleEvent(testing::_, testing::_))
227 .Times(1);
228
229 // Receive second connection.
230 auto connectionClient2 = new TestWebPresentationConnectionClient();
231 receiver->didReceiveSessionTextMessage(connectionClient2, "Hello World");
232 }
233
203 } // namespace blink 234 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698