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

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

Issue 2867693004: Snapshot of all changes to get jumbo in blink and content.
Patch Set: Rebased again Created 3 years, 5 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 <memory> 7 #include <memory>
8 8
9 #include "bindings/core/v8/ScriptPromiseResolver.h" 9 #include "bindings/core/v8/ScriptPromiseResolver.h"
10 #include "bindings/core/v8/V8BindingForTesting.h" 10 #include "bindings/core/v8/V8BindingForTesting.h"
11 #include "core/frame/LocalFrame.h" 11 #include "core/frame/LocalFrame.h"
12 #include "core/testing/DummyPageHolder.h" 12 #include "core/testing/DummyPageHolder.h"
13 #include "modules/presentation/MockWebPresentationClient.h" 13 #include "modules/presentation/MockWebPresentationClient.h"
14 #include "modules/presentation/PresentationConnection.h" 14 #include "modules/presentation/PresentationConnection.h"
15 #include "modules/presentation/PresentationConnectionList.h" 15 #include "modules/presentation/PresentationConnectionList.h"
16 #include "platform/testing/URLTestHelpers.h" 16 #include "platform/testing/URLTestHelpers.h"
17 #include "public/platform/modules/presentation/WebPresentationClient.h" 17 #include "public/platform/modules/presentation/WebPresentationClient.h"
18 #include "public/platform/modules/presentation/WebPresentationConnectionCallback s.h" 18 #include "public/platform/modules/presentation/WebPresentationConnectionCallback s.h"
19 #include "public/platform/modules/presentation/WebPresentationConnectionProxy.h" 19 #include "public/platform/modules/presentation/WebPresentationConnectionProxy.h"
20 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "v8/include/v8.h" 22 #include "v8/include/v8.h"
23 23
24 namespace blink { 24 namespace blink {
25 25
26 class MockEventListener : public EventListener { 26 class MockEventListenerForPresentationReceiver : public EventListener {
27 public: 27 public:
28 MockEventListener() : EventListener(kCPPEventListenerType) {} 28 MockEventListenerForPresentationReceiver()
29 : EventListener(kCPPEventListenerType) {}
29 30
30 bool operator==(const EventListener& other) const final { 31 bool operator==(const EventListener& other) const final {
31 return this == &other; 32 return this == &other;
32 } 33 }
33 34
34 MOCK_METHOD2(handleEvent, void(ExecutionContext* executionContext, Event*)); 35 MOCK_METHOD2(handleEvent, void(ExecutionContext* executionContext, Event*));
35 }; 36 };
36 37
37 class PresentationReceiverTest : public ::testing::Test { 38 class PresentationReceiverTest : public ::testing::Test {
38 public: 39 public:
(...skipping 23 matching lines...) Expand all
62 const PresentationReceiver* receiver) { 63 const PresentationReceiver* receiver) {
63 EXPECT_EQ(expected_size, receiver->connection_list_->connections_.size()); 64 EXPECT_EQ(expected_size, receiver->connection_list_->connections_.size());
64 } 65 }
65 66
66 using ::testing::StrictMock; 67 using ::testing::StrictMock;
67 68
68 TEST_F(PresentationReceiverTest, NoConnectionUnresolvedConnectionList) { 69 TEST_F(PresentationReceiverTest, NoConnectionUnresolvedConnectionList) {
69 V8TestingScope scope; 70 V8TestingScope scope;
70 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); 71 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr);
71 72
72 auto event_handler = new StrictMock<MockEventListener>(); 73 auto event_handler =
74 new StrictMock<MockEventListenerForPresentationReceiver>();
73 AddConnectionavailableEventListener(event_handler, receiver); 75 AddConnectionavailableEventListener(event_handler, receiver);
74 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(0); 76 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(0);
75 77
76 receiver->connectionList(scope.GetScriptState()); 78 receiver->connectionList(scope.GetScriptState());
77 79
78 VerifyConnectionListPropertyState(ScriptPromisePropertyBase::kPending, 80 VerifyConnectionListPropertyState(ScriptPromisePropertyBase::kPending,
79 receiver); 81 receiver);
80 VerifyConnectionListSize(0, receiver); 82 VerifyConnectionListSize(0, receiver);
81 } 83 }
82 84
83 TEST_F(PresentationReceiverTest, OneConnectionResolvedConnectionListNoEvent) { 85 TEST_F(PresentationReceiverTest, OneConnectionResolvedConnectionListNoEvent) {
84 V8TestingScope scope; 86 V8TestingScope scope;
85 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); 87 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr);
86 88
87 auto event_handler = new StrictMock<MockEventListener>(); 89 auto event_handler =
90 new StrictMock<MockEventListenerForPresentationReceiver>();
88 AddConnectionavailableEventListener(event_handler, receiver); 91 AddConnectionavailableEventListener(event_handler, receiver);
89 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(0); 92 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(0);
90 93
91 receiver->connectionList(scope.GetScriptState()); 94 receiver->connectionList(scope.GetScriptState());
92 95
93 // Receive first connection. 96 // Receive first connection.
94 receiver->OnReceiverConnectionAvailable( 97 receiver->OnReceiverConnectionAvailable(
95 WebPresentationInfo(KURL(NullURL(), "http://example.com"), "id")); 98 WebPresentationInfo(KURL(NullURL(), "http://example.com"), "id"));
96 99
97 VerifyConnectionListPropertyState(ScriptPromisePropertyBase::kResolved, 100 VerifyConnectionListPropertyState(ScriptPromisePropertyBase::kResolved,
98 receiver); 101 receiver);
99 VerifyConnectionListSize(1, receiver); 102 VerifyConnectionListSize(1, receiver);
100 } 103 }
101 104
102 TEST_F(PresentationReceiverTest, TwoConnectionsFireOnconnectionavailableEvent) { 105 TEST_F(PresentationReceiverTest, TwoConnectionsFireOnconnectionavailableEvent) {
103 V8TestingScope scope; 106 V8TestingScope scope;
104 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); 107 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr);
105 108
106 StrictMock<MockEventListener>* event_handler = 109 StrictMock<MockEventListenerForPresentationReceiver>* event_handler =
107 new StrictMock<MockEventListener>(); 110 new StrictMock<MockEventListenerForPresentationReceiver>();
108 AddConnectionavailableEventListener(event_handler, receiver); 111 AddConnectionavailableEventListener(event_handler, receiver);
109 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(1); 112 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(1);
110 113
111 receiver->connectionList(scope.GetScriptState()); 114 receiver->connectionList(scope.GetScriptState());
112 115
113 WebPresentationInfo presentation_info(KURL(NullURL(), "http://example.com"), 116 WebPresentationInfo presentation_info(KURL(NullURL(), "http://example.com"),
114 "id"); 117 "id");
115 // Receive first connection. 118 // Receive first connection.
116 receiver->OnReceiverConnectionAvailable(presentation_info); 119 receiver->OnReceiverConnectionAvailable(presentation_info);
117 // Receive second connection. 120 // Receive second connection.
118 receiver->OnReceiverConnectionAvailable(presentation_info); 121 receiver->OnReceiverConnectionAvailable(presentation_info);
119 122
120 VerifyConnectionListSize(2, receiver); 123 VerifyConnectionListSize(2, receiver);
121 } 124 }
122 125
123 TEST_F(PresentationReceiverTest, TwoConnectionsNoEvent) { 126 TEST_F(PresentationReceiverTest, TwoConnectionsNoEvent) {
124 V8TestingScope scope; 127 V8TestingScope scope;
125 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr); 128 auto receiver = new PresentationReceiver(&scope.GetFrame(), nullptr);
126 129
127 StrictMock<MockEventListener>* event_handler = 130 StrictMock<MockEventListenerForPresentationReceiver>* event_handler =
128 new StrictMock<MockEventListener>(); 131 new StrictMock<MockEventListenerForPresentationReceiver>();
129 AddConnectionavailableEventListener(event_handler, receiver); 132 AddConnectionavailableEventListener(event_handler, receiver);
130 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(0); 133 EXPECT_CALL(*event_handler, handleEvent(::testing::_, ::testing::_)).Times(0);
131 134
132 WebPresentationInfo presentation_info(KURL(NullURL(), "http://example.com"), 135 WebPresentationInfo presentation_info(KURL(NullURL(), "http://example.com"),
133 "id"); 136 "id");
134 // Receive first connection. 137 // Receive first connection.
135 auto* connection1 = 138 auto* connection1 =
136 receiver->OnReceiverConnectionAvailable(presentation_info); 139 receiver->OnReceiverConnectionAvailable(presentation_info);
137 EXPECT_TRUE(connection1); 140 EXPECT_TRUE(connection1);
138 141
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 EXPECT_TRUE(connection2); 177 EXPECT_TRUE(connection2);
175 178
176 receiver->connectionList(scope.GetScriptState()); 179 receiver->connectionList(scope.GetScriptState());
177 VerifyConnectionListSize(2, receiver); 180 VerifyConnectionListSize(2, receiver);
178 181
179 receiver->RemoveConnection(connection1); 182 receiver->RemoveConnection(connection1);
180 VerifyConnectionListSize(1, receiver); 183 VerifyConnectionListSize(1, receiver);
181 } 184 }
182 185
183 } // namespace blink 186 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698