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

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

Issue 2562683004: Fix gmock leak issue in AutoplayUmaHelperTest (Closed)
Patch Set: removed AllowLeak Created 4 years 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "core/html/AutoplayUmaHelper.h" 5 #include "core/html/AutoplayUmaHelper.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/html/HTMLMediaElement.h" 8 #include "core/html/HTMLMediaElement.h"
9 #include "core/html/HTMLVideoElement.h" 9 #include "core/html/HTMLVideoElement.h"
10 #include "core/testing/DummyPageHolder.h" 10 #include "core/testing/DummyPageHolder.h"
(...skipping 27 matching lines...) Expand all
38 class AutoplayUmaHelperTest : public testing::Test { 38 class AutoplayUmaHelperTest : public testing::Test {
39 protected: 39 protected:
40 Document& document() { return m_pageHolder->document(); } 40 Document& document() { return m_pageHolder->document(); }
41 41
42 HTMLMediaElement& mediaElement() { 42 HTMLMediaElement& mediaElement() {
43 Element* element = document().getElementById("video"); 43 Element* element = document().getElementById("video");
44 DCHECK(element); 44 DCHECK(element);
45 return toHTMLVideoElement(*element); 45 return toHTMLVideoElement(*element);
46 } 46 }
47 47
48 MockAutoplayUmaHelper& umaHelper() { 48 MockAutoplayUmaHelper& umaHelper() { return *m_umaHelper; }
49 return *(static_cast<MockAutoplayUmaHelper*>(
50 mediaElement().m_autoplayUmaHelper.get()));
51 }
52 49
53 std::unique_ptr<DummyPageHolder>& pageHolder() { return m_pageHolder; } 50 std::unique_ptr<DummyPageHolder>& pageHolder() { return m_pageHolder; }
54 51
55 MOCK_METHOD0(TestEnded, void());
56
57 private: 52 private:
58 void SetUp() override { 53 void SetUp() override {
59 m_pageHolder = DummyPageHolder::create(IntSize(800, 600)); 54 m_pageHolder = DummyPageHolder::create(IntSize(800, 600));
60 document().documentElement()->setInnerHTML("<video id=video></video>", 55 document().documentElement()->setInnerHTML("<video id=video></video>",
61 ASSERT_NO_EXCEPTION); 56 ASSERT_NO_EXCEPTION);
62 HTMLMediaElement& element = mediaElement(); 57 HTMLMediaElement& element = mediaElement();
63 element.m_autoplayUmaHelper = new MockAutoplayUmaHelper(&element); 58 m_umaHelper = new MockAutoplayUmaHelper(&element);
59 element.m_autoplayUmaHelper = m_umaHelper;
64 } 60 }
65 61
62 void TearDown() override { m_umaHelper.clear(); }
63
66 std::unique_ptr<DummyPageHolder> m_pageHolder; 64 std::unique_ptr<DummyPageHolder> m_pageHolder;
65 Persistent<MockAutoplayUmaHelper> m_umaHelper;
67 }; 66 };
68 67
69 TEST_F(AutoplayUmaHelperTest, VisibilityChangeWhenUnload) { 68 TEST_F(AutoplayUmaHelperTest, VisibilityChangeWhenUnload) {
70 // This is to avoid handleContextDestroyed() to be called during TearDown(). 69 EXPECT_CALL(umaHelper(), handleContextDestroyed());
71 EXPECT_CALL(*this, TestEnded())
72 .After(EXPECT_CALL(umaHelper(), handleContextDestroyed()));
73 70
74 mediaElement().setMuted(true); 71 mediaElement().setMuted(true);
75 umaHelper().onAutoplayInitiated(AutoplaySource::Attribute); 72 umaHelper().onAutoplayInitiated(AutoplaySource::Attribute);
76 umaHelper().handlePlayingEvent(); 73 umaHelper().handlePlayingEvent();
77 pageHolder().reset(); 74 pageHolder().reset();
78 TestEnded(); 75 ::testing::Mock::VerifyAndClear(&umaHelper());
79 } 76 }
80 77
81 } // namespace blink 78 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698