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

Side by Side Diff: third_party/WebKit/Source/core/html/AutoplayUmaHelperTest.cpp

Issue 2780403004: Create core/html/media/ and move auxiliary media files in it. (Closed)
Patch Set: actually add autoplay files Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "core/html/AutoplayUmaHelper.h"
6
7 #include "core/dom/Document.h"
8 #include "core/html/HTMLMediaElement.h"
9 #include "core/html/HTMLVideoElement.h"
10 #include "core/testing/DummyPageHolder.h"
11
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace blink {
16
17 using ::testing::Invoke;
18
19 class MockAutoplayUmaHelper : public AutoplayUmaHelper {
20 public:
21 MockAutoplayUmaHelper(HTMLMediaElement* element)
22 : AutoplayUmaHelper(element) {
23 ON_CALL(*this, handleContextDestroyed())
24 .WillByDefault(
25 Invoke(this, &MockAutoplayUmaHelper::reallyHandleContextDestroyed));
26 }
27
28 void handlePlayingEvent() { AutoplayUmaHelper::handlePlayingEvent(); }
29
30 MOCK_METHOD0(handleContextDestroyed, void());
31
32 // Making this a wrapper function to avoid calling the mocked version.
33 void reallyHandleContextDestroyed() {
34 AutoplayUmaHelper::handleContextDestroyed();
35 }
36 };
37
38 class AutoplayUmaHelperTest : public testing::Test {
39 protected:
40 Document& document() { return m_pageHolder->document(); }
41
42 HTMLMediaElement& mediaElement() {
43 Element* element = document().getElementById("video");
44 DCHECK(element);
45 return toHTMLVideoElement(*element);
46 }
47
48 MockAutoplayUmaHelper& umaHelper() { return *m_umaHelper; }
49
50 std::unique_ptr<DummyPageHolder>& pageHolder() { return m_pageHolder; }
51
52 private:
53 void SetUp() override {
54 m_pageHolder = DummyPageHolder::create(IntSize(800, 600));
55 document().documentElement()->setInnerHTML("<video id=video></video>",
56 ASSERT_NO_EXCEPTION);
57 HTMLMediaElement& element = mediaElement();
58 m_umaHelper = new MockAutoplayUmaHelper(&element);
59 element.m_autoplayUmaHelper = m_umaHelper;
60 ::testing::Mock::AllowLeak(&umaHelper());
61 }
62
63 void TearDown() override { m_umaHelper.clear(); }
64
65 std::unique_ptr<DummyPageHolder> m_pageHolder;
66 Persistent<MockAutoplayUmaHelper> m_umaHelper;
67 };
68
69 TEST_F(AutoplayUmaHelperTest, VisibilityChangeWhenUnload) {
70 EXPECT_CALL(umaHelper(), handleContextDestroyed());
71
72 mediaElement().setMuted(true);
73 umaHelper().onAutoplayInitiated(AutoplaySource::Method);
74 umaHelper().handlePlayingEvent();
75 pageHolder().reset();
76 ::testing::Mock::VerifyAndClear(&umaHelper());
77 }
78
79 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698