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

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

Issue 2415443004: [Blink, RemotePlayback]Split onstatechange to separate events (Closed)
Patch Set: Fixed global-interface-listing test 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/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 "core/html/HTMLMediaElement.h" 9 #include "core/html/HTMLMediaElement.h"
10 #include "core/html/HTMLVideoElement.h" 10 #include "core/html/HTMLVideoElement.h"
11 #include "core/testing/DummyPageHolder.h" 11 #include "core/testing/DummyPageHolder.h"
12 #include "platform/testing/UnitTestHelpers.h" 12 #include "platform/testing/UnitTestHelpers.h"
13 #include "public/platform/modules/remoteplayback/WebRemotePlaybackState.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 namespace blink { 17 namespace blink {
17 18
18 class MockFunction : public ScriptFunction { 19 class MockFunction : public ScriptFunction {
19 public: 20 public:
20 static MockFunction* create(ScriptState* scriptState) { 21 static MockFunction* create(ScriptState* scriptState) {
21 return new MockFunction(scriptState); 22 return new MockFunction(scriptState);
22 } 23 }
23 24
24 v8::Local<v8::Function> bind() { return bindToV8Function(); } 25 v8::Local<v8::Function> bind() { return bindToV8Function(); }
25 26
26 MOCK_METHOD1(call, ScriptValue(ScriptValue)); 27 MOCK_METHOD1(call, ScriptValue(ScriptValue));
27 28
28 private: 29 private:
29 explicit MockFunction(ScriptState* scriptState) 30 explicit MockFunction(ScriptState* scriptState)
30 : ScriptFunction(scriptState) {} 31 : ScriptFunction(scriptState) {}
31 }; 32 };
32 33
34 class MockEventListener : public EventListener {
35 public:
36 MockEventListener() : EventListener(CPPEventListenerType) {}
37
38 bool operator==(const EventListener& other) const final {
39 return this == &other;
40 }
41
42 MOCK_METHOD2(handleEvent, void(ExecutionContext* executionContext, Event*));
43 };
44
33 class RemotePlaybackTest : public ::testing::Test { 45 class RemotePlaybackTest : public ::testing::Test {
34 protected: 46 protected:
35 void cancelPrompt(RemotePlayback* remotePlayback) { 47 void cancelPrompt(RemotePlayback* remotePlayback) {
36 remotePlayback->promptCancelled(); 48 remotePlayback->promptCancelled();
37 } 49 }
50
51 void setState(RemotePlayback* remotePlayback, WebRemotePlaybackState state) {
52 remotePlayback->stateChanged(state);
53 }
38 }; 54 };
39 55
40 TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) { 56 TEST_F(RemotePlaybackTest, PromptCancelledRejectsWithNotAllowedError) {
41 V8TestingScope scope; 57 V8TestingScope scope;
42 58
43 auto pageHolder = DummyPageHolder::create(); 59 auto pageHolder = DummyPageHolder::create();
44 60
45 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document()); 61 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
46 RemotePlayback* remotePlayback = RemotePlayback::create(*element); 62 RemotePlayback* remotePlayback = RemotePlayback::create(*element);
47 63
48 MockFunction* resolve = MockFunction::create(scope.getScriptState()); 64 MockFunction* resolve = MockFunction::create(scope.getScriptState());
49 MockFunction* reject = MockFunction::create(scope.getScriptState()); 65 MockFunction* reject = MockFunction::create(scope.getScriptState());
50 66
51 EXPECT_CALL(*resolve, call(::testing::_)).Times(0); 67 EXPECT_CALL(*resolve, call(::testing::_)).Times(0);
52 EXPECT_CALL(*reject, call(::testing::_)).Times(1); 68 EXPECT_CALL(*reject, call(::testing::_)).Times(1);
53 69
54 remotePlayback->prompt(scope.getScriptState()) 70 remotePlayback->prompt(scope.getScriptState())
55 .then(resolve->bind(), reject->bind()); 71 .then(resolve->bind(), reject->bind());
56 cancelPrompt(remotePlayback); 72 cancelPrompt(remotePlayback);
57 } 73 }
58 74
75 TEST_F(RemotePlaybackTest, StateChangeEvents) {
76 V8TestingScope scope;
77
78 auto pageHolder = DummyPageHolder::create();
79
80 HTMLMediaElement* element = HTMLVideoElement::create(pageHolder->document());
81 RemotePlayback* remotePlayback = RemotePlayback::create(*element);
82
83 auto connectingHandler = new ::testing::StrictMock<MockEventListener>();
84 auto connectHandler = new ::testing::StrictMock<MockEventListener>();
85 auto disconnectHandler = new ::testing::StrictMock<MockEventListener>();
86
87 remotePlayback->addEventListener(EventTypeNames::connecting,
88 connectingHandler);
89 remotePlayback->addEventListener(EventTypeNames::connect, connectHandler);
90 remotePlayback->addEventListener(EventTypeNames::disconnect,
91 disconnectHandler);
92
93 EXPECT_CALL(*connectingHandler, handleEvent(::testing::_, ::testing::_))
94 .Times(1);
95 EXPECT_CALL(*connectHandler, handleEvent(::testing::_, ::testing::_))
96 .Times(1);
97 EXPECT_CALL(*disconnectHandler, handleEvent(::testing::_, ::testing::_))
98 .Times(1);
99
100 setState(remotePlayback, WebRemotePlaybackState::Connecting);
101 setState(remotePlayback, WebRemotePlaybackState::Connected);
102 setState(remotePlayback, WebRemotePlaybackState::Disconnected);
mlamouri (slow - plz ping) 2016/10/13 14:37:45 Can you add double-calls? Like: setState(remote
103 }
104
59 } // namespace blink 105 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698