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

Unified Diff: third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp

Issue 2432173006: [Blink, RemotePlayback] Handle disabling remote playback (Closed)
Patch Set: Fixed the static method calls 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp
diff --git a/third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp b/third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp
index 9039d78c99b513c542a462d89ed9ff6822ca80fc..5a7bb3b0080163ee4b9d0f48f60428a565efb1f8 100644
--- a/third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp
+++ b/third_party/WebKit/Source/modules/remoteplayback/RemotePlaybackTest.cpp
@@ -6,9 +6,12 @@
#include "bindings/core/v8/ExceptionStatePlaceholder.h"
#include "bindings/core/v8/V8BindingForTesting.h"
+#include "bindings/modules/v8/RemotePlaybackAvailabilityCallback.h"
#include "core/html/HTMLMediaElement.h"
#include "core/html/HTMLVideoElement.h"
#include "core/testing/DummyPageHolder.h"
+#include "modules/remoteplayback/HTMLMediaElementRemotePlayback.h"
+#include "platform/UserGestureIndicator.h"
#include "platform/testing/UnitTestHelpers.h"
#include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h"
#include "testing/gmock/include/gmock/gmock.h"
@@ -51,6 +54,10 @@ class RemotePlaybackTest : public ::testing::Test {
void setState(RemotePlayback* remotePlayback, WebRemotePlaybackState state) {
remotePlayback->stateChanged(state);
}
+
+ void setAvailability(RemotePlayback* remotePlayback, bool available) {
+ remotePlayback->availabilityChanged(available);
+ }
};
TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) {
@@ -60,7 +67,7 @@ TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) {
HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
RemotePlayback* remotePlayback =
- RemotePlayback::create(scope.getScriptState(), *element);
+ HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element);
MockFunction* resolve = MockFunction::create(scope.getScriptState());
MockFunction* reject = MockFunction::create(scope.getScriptState());
@@ -68,6 +75,8 @@ TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) {
EXPECT_CALL(*resolve, call(::testing::_)).Times(0);
EXPECT_CALL(*reject, call(::testing::_)).Times(1);
+ UserGestureIndicator indicator(
+ UserGestureToken::create(UserGestureToken::NewGesture));
remotePlayback->prompt().then(resolve->bind(), reject->bind());
cancelPrompt(remotePlayback);
}
@@ -79,7 +88,7 @@ TEST_F(RemotePlaybackTest, StateChangeEvents) {
HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
RemotePlayback* remotePlayback =
- RemotePlayback::create(scope.getScriptState(), *element);
+ HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element);
auto connectingHandler = new ::testing::StrictMock<MockEventListener>();
auto connectHandler = new ::testing::StrictMock<MockEventListener>();
@@ -106,4 +115,59 @@ TEST_F(RemotePlaybackTest, StateChangeEvents) {
setState(remotePlayback, WebRemotePlaybackState::Disconnected);
}
+TEST_F(RemotePlaybackTest,
+ DisableRemotePlaybackRejectsPromptWithInvalidStateError) {
+ V8TestingScope scope;
+
+ auto pageHolder = DummyPageHolder::create();
+
+ HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
+ RemotePlayback* remotePlayback =
+ HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element);
+
+ MockFunction* resolve = MockFunction::create(scope.getScriptState());
+ MockFunction* reject = MockFunction::create(scope.getScriptState());
+
+ EXPECT_CALL(*resolve, call(::testing::_)).Times(0);
+ EXPECT_CALL(*reject, call(::testing::_)).Times(1);
+
+ UserGestureIndicator indicator(
+ UserGestureToken::create(UserGestureToken::NewGesture));
+ remotePlayback->prompt().then(resolve->bind(), reject->bind());
+ HTMLMediaElementRemotePlayback::setBooleanAttribute(
+ HTMLNames::disableremoteplaybackAttr, *element, true);
+}
+
+TEST_F(RemotePlaybackTest, DisableRemotePlaybackCancelsAvailabilityCallbacks) {
+ V8TestingScope scope;
+
+ auto pageHolder = DummyPageHolder::create();
+
+ HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
+ RemotePlayback* remotePlayback =
+ HTMLMediaElementRemotePlayback::remote(scope.getScriptState(), *element);
+
+ MockFunction* callbackFunction = MockFunction::create(scope.getScriptState());
+ RemotePlaybackAvailabilityCallback* availabilityCallback =
+ RemotePlaybackAvailabilityCallback::create(scope.isolate(),
+ callbackFunction->bind());
+
+ // The initial call upon registering will not happen as it's posted on the
+ // message loop.
+ EXPECT_CALL(*callbackFunction, call(::testing::_)).Times(0);
+
+ MockFunction* watchResolve = MockFunction::create(scope.getScriptState());
+ MockFunction* watchReject = MockFunction::create(scope.getScriptState());
+
+ EXPECT_CALL(*watchResolve, call(::testing::_)).Times(1);
+ EXPECT_CALL(*watchReject, call(::testing::_)).Times(0);
+
+ remotePlayback->watchAvailability(availabilityCallback)
+ .then(watchResolve->bind(), watchReject->bind());
+
+ HTMLMediaElementRemotePlayback::setBooleanAttribute(
+ HTMLNames::disableremoteplaybackAttr, *element, true);
+ setAvailability(remotePlayback, true);
+}
+
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/modules/remoteplayback/RemotePlayback.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698