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

Side by Side Diff: third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp

Issue 2480003002: [RemotePlayback] Keep track of source compatibility and reject prompt() correspondingly (Closed)
Patch Set: Fixed failing tests Created 4 years, 1 month 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/remoteplayback/RemotePlayback.h" 5 #include "modules/remoteplayback/RemotePlayback.h"
6 6
7 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 7 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
8 #include "bindings/core/v8/V8BindingForTesting.h" 8 #include "bindings/core/v8/V8BindingForTesting.h"
9 #include "bindings/modules/v8/RemotePlaybackAvailabilityCallback.h" 9 #include "bindings/modules/v8/RemotePlaybackAvailabilityCallback.h"
10 #include "core/dom/DocumentUserGestureToken.h" 10 #include "core/dom/DocumentUserGestureToken.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 class RemotePlaybackTest : public ::testing::Test { 49 class RemotePlaybackTest : public ::testing::Test {
50 protected: 50 protected:
51 void cancelPrompt(RemotePlayback* remotePlayback) { 51 void cancelPrompt(RemotePlayback* remotePlayback) {
52 remotePlayback->promptCancelled(); 52 remotePlayback->promptCancelled();
53 } 53 }
54 54
55 void setState(RemotePlayback* remotePlayback, WebRemotePlaybackState state) { 55 void setState(RemotePlayback* remotePlayback, WebRemotePlaybackState state) {
56 remotePlayback->stateChanged(state); 56 remotePlayback->stateChanged(state);
57 } 57 }
58 58
59 void setAvailability(RemotePlayback* remotePlayback, bool available) { 59 void setAvailability(RemotePlayback* remotePlayback,
60 remotePlayback->availabilityChanged(available); 60 bool routeAvailable,
61 bool sourceCompatible) {
62 remotePlayback->availabilityChanged(routeAvailable, sourceCompatible);
61 } 63 }
62 }; 64 };
63 65
64 TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) { 66 TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) {
65 V8TestingScope scope; 67 V8TestingScope scope;
66 68
67 auto pageHolder = DummyPageHolder::create(); 69 auto pageHolder = DummyPageHolder::create();
68 70
69 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document()); 71 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
70 RemotePlayback* remotePlayback = 72 RemotePlayback* remotePlayback =
71 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element); 73 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element);
74 setAvailability(remotePlayback, true, true);
72 75
73 auto resolve = MockFunction::create(scope.getScriptState()); 76 auto resolve = MockFunction::create(scope.getScriptState());
74 auto reject = MockFunction::create(scope.getScriptState()); 77 auto reject = MockFunction::create(scope.getScriptState());
75 78
76 EXPECT_CALL(*resolve, call(::testing::_)).Times(0); 79 EXPECT_CALL(*resolve, call(::testing::_)).Times(0);
77 EXPECT_CALL(*reject, call(::testing::_)).Times(1); 80 EXPECT_CALL(*reject, call(::testing::_)).Times(1);
78 81
79 UserGestureIndicator indicator(DocumentUserGestureToken::create( 82 UserGestureIndicator indicator(DocumentUserGestureToken::create(
80 &pageHolder->document(), UserGestureToken::NewGesture)); 83 &pageHolder->document(), UserGestureToken::NewGesture));
81 remotePlayback->prompt().then(resolve->bind(), reject->bind()); 84 remotePlayback->prompt().then(resolve->bind(), reject->bind());
82 cancelPrompt(remotePlayback); 85 cancelPrompt(remotePlayback);
83 86
84 // Runs pending promises. 87 // Runs pending promises.
85 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); 88 v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
86 89
87 // Verify mock expectations explicitly as the mock objects are garbage 90 // Verify mock expectations explicitly as the mock objects are garbage
88 // collected. 91 // collected.
89 ::testing::Mock::VerifyAndClear(resolve); 92 ::testing::Mock::VerifyAndClear(resolve);
90 ::testing::Mock::VerifyAndClear(reject); 93 ::testing::Mock::VerifyAndClear(reject);
91 } 94 }
92 95
93 TEST_F(RemotePlaybackTest, PromptConnectedRejectsWhenCancelled) { 96 TEST_F(RemotePlaybackTest, PromptConnectedRejectsWhenCancelled) {
94 V8TestingScope scope; 97 V8TestingScope scope;
95 98
96 auto pageHolder = DummyPageHolder::create(); 99 auto pageHolder = DummyPageHolder::create();
97 100
98 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document()); 101 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
99 RemotePlayback* remotePlayback = 102 RemotePlayback* remotePlayback =
100 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element); 103 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element);
104 setAvailability(remotePlayback, true, true);
101 105
102 auto resolve = MockFunction::create(scope.getScriptState()); 106 auto resolve = MockFunction::create(scope.getScriptState());
103 auto reject = MockFunction::create(scope.getScriptState()); 107 auto reject = MockFunction::create(scope.getScriptState());
104 108
105 EXPECT_CALL(*resolve, call(::testing::_)).Times(0); 109 EXPECT_CALL(*resolve, call(::testing::_)).Times(0);
106 EXPECT_CALL(*reject, call(::testing::_)).Times(1); 110 EXPECT_CALL(*reject, call(::testing::_)).Times(1);
107 111
108 setState(remotePlayback, WebRemotePlaybackState::Connected); 112 setState(remotePlayback, WebRemotePlaybackState::Connected);
109 113
110 UserGestureIndicator indicator(DocumentUserGestureToken::create( 114 UserGestureIndicator indicator(DocumentUserGestureToken::create(
(...skipping 11 matching lines...) Expand all
122 } 126 }
123 127
124 TEST_F(RemotePlaybackTest, PromptConnectedResolvesWhenDisconnected) { 128 TEST_F(RemotePlaybackTest, PromptConnectedResolvesWhenDisconnected) {
125 V8TestingScope scope; 129 V8TestingScope scope;
126 130
127 auto pageHolder = DummyPageHolder::create(); 131 auto pageHolder = DummyPageHolder::create();
128 132
129 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document()); 133 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
130 RemotePlayback* remotePlayback = 134 RemotePlayback* remotePlayback =
131 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element); 135 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element);
136 setAvailability(remotePlayback, true, true);
132 137
133 auto resolve = MockFunction::create(scope.getScriptState()); 138 auto resolve = MockFunction::create(scope.getScriptState());
134 auto reject = MockFunction::create(scope.getScriptState()); 139 auto reject = MockFunction::create(scope.getScriptState());
135 140
136 EXPECT_CALL(*resolve, call(::testing::_)).Times(1); 141 EXPECT_CALL(*resolve, call(::testing::_)).Times(1);
137 EXPECT_CALL(*reject, call(::testing::_)).Times(0); 142 EXPECT_CALL(*reject, call(::testing::_)).Times(0);
138 143
139 setState(remotePlayback, WebRemotePlaybackState::Connected); 144 setState(remotePlayback, WebRemotePlaybackState::Connected);
140 145
141 UserGestureIndicator indicator(DocumentUserGestureToken::create( 146 UserGestureIndicator indicator(DocumentUserGestureToken::create(
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 200
196 TEST_F(RemotePlaybackTest, 201 TEST_F(RemotePlaybackTest,
197 DisableRemotePlaybackRejectsPromptWithInvalidStateError) { 202 DisableRemotePlaybackRejectsPromptWithInvalidStateError) {
198 V8TestingScope scope; 203 V8TestingScope scope;
199 204
200 auto pageHolder = DummyPageHolder::create(); 205 auto pageHolder = DummyPageHolder::create();
201 206
202 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document()); 207 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
203 RemotePlayback* remotePlayback = 208 RemotePlayback* remotePlayback =
204 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element); 209 HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element);
210 setAvailability(remotePlayback, true, true);
205 211
206 MockFunction* resolve = MockFunction::create(scope.getScriptState()); 212 MockFunction* resolve = MockFunction::create(scope.getScriptState());
207 MockFunction* reject = MockFunction::create(scope.getScriptState()); 213 MockFunction* reject = MockFunction::create(scope.getScriptState());
208 214
209 EXPECT_CALL(*resolve, call(::testing::_)).Times(0); 215 EXPECT_CALL(*resolve, call(::testing::_)).Times(0);
210 EXPECT_CALL(*reject, call(::testing::_)).Times(1); 216 EXPECT_CALL(*reject, call(::testing::_)).Times(1);
211 217
212 UserGestureIndicator indicator(DocumentUserGestureToken::create( 218 UserGestureIndicator indicator(DocumentUserGestureToken::create(
213 &pageHolder->document(), UserGestureToken::NewGesture)); 219 &pageHolder->document(), UserGestureToken::NewGesture));
214 remotePlayback->prompt().then(resolve->bind(), reject->bind()); 220 remotePlayback->prompt().then(resolve->bind(), reject->bind());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 MockFunction* reject = MockFunction::create(scope.getScriptState()); 252 MockFunction* reject = MockFunction::create(scope.getScriptState());
247 253
248 EXPECT_CALL(*resolve, call(::testing::_)).Times(1); 254 EXPECT_CALL(*resolve, call(::testing::_)).Times(1);
249 EXPECT_CALL(*reject, call(::testing::_)).Times(0); 255 EXPECT_CALL(*reject, call(::testing::_)).Times(0);
250 256
251 remotePlayback->watchAvailability(availabilityCallback) 257 remotePlayback->watchAvailability(availabilityCallback)
252 .then(resolve->bind(), reject->bind()); 258 .then(resolve->bind(), reject->bind());
253 259
254 HTMLMediaElementRemotePlayback::setBooleanAttribute( 260 HTMLMediaElementRemotePlayback::setBooleanAttribute(
255 HTMLNames::disableremoteplaybackAttr, *element, true); 261 HTMLNames::disableremoteplaybackAttr, *element, true);
256 setAvailability(remotePlayback, true); 262 setAvailability(remotePlayback, true, true);
257 263
258 // Runs pending promises. 264 // Runs pending promises.
259 v8::MicrotasksScope::PerformCheckpoint(scope.isolate()); 265 v8::MicrotasksScope::PerformCheckpoint(scope.isolate());
260 266
261 // Verify mock expectations explicitly as the mock objects are garbage 267 // Verify mock expectations explicitly as the mock objects are garbage
262 // collected. 268 // collected.
263 ::testing::Mock::VerifyAndClear(resolve); 269 ::testing::Mock::VerifyAndClear(resolve);
264 ::testing::Mock::VerifyAndClear(reject); 270 ::testing::Mock::VerifyAndClear(reject);
265 ::testing::Mock::VerifyAndClear(callbackFunction); 271 ::testing::Mock::VerifyAndClear(callbackFunction);
266 } 272 }
267 273
268 } // namespace blink 274 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698