| OLD | NEW |
| 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/media/AutoplayUmaHelper.h" | 5 #include "core/html/media/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/html/media/AutoplayPolicy.h" |
| 10 #include "core/testing/DummyPageHolder.h" | 11 #include "core/testing/DummyPageHolder.h" |
| 11 | 12 |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 using ::testing::Invoke; | 18 using ::testing::Invoke; |
| 18 | 19 |
| 19 class MockAutoplayUmaHelper : public AutoplayUmaHelper { | 20 class MockAutoplayUmaHelper : public AutoplayUmaHelper { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 49 | 50 |
| 50 std::unique_ptr<DummyPageHolder>& PageHolder() { return page_holder_; } | 51 std::unique_ptr<DummyPageHolder>& PageHolder() { return page_holder_; } |
| 51 | 52 |
| 52 private: | 53 private: |
| 53 void SetUp() override { | 54 void SetUp() override { |
| 54 page_holder_ = DummyPageHolder::Create(IntSize(800, 600)); | 55 page_holder_ = DummyPageHolder::Create(IntSize(800, 600)); |
| 55 GetDocument().documentElement()->setInnerHTML("<video id=video></video>", | 56 GetDocument().documentElement()->setInnerHTML("<video id=video></video>", |
| 56 ASSERT_NO_EXCEPTION); | 57 ASSERT_NO_EXCEPTION); |
| 57 HTMLMediaElement& element = MediaElement(); | 58 HTMLMediaElement& element = MediaElement(); |
| 58 uma_helper_ = new MockAutoplayUmaHelper(&element); | 59 uma_helper_ = new MockAutoplayUmaHelper(&element); |
| 59 element.autoplay_uma_helper_ = uma_helper_; | 60 element.autoplay_policy_->autoplay_uma_helper_ = uma_helper_; |
| 60 ::testing::Mock::AllowLeak(&UmaHelper()); | 61 ::testing::Mock::AllowLeak(&UmaHelper()); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void TearDown() override { uma_helper_.Clear(); } | 64 void TearDown() override { uma_helper_.Clear(); } |
| 64 | 65 |
| 65 std::unique_ptr<DummyPageHolder> page_holder_; | 66 std::unique_ptr<DummyPageHolder> page_holder_; |
| 66 Persistent<MockAutoplayUmaHelper> uma_helper_; | 67 Persistent<MockAutoplayUmaHelper> uma_helper_; |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 TEST_F(AutoplayUmaHelperTest, VisibilityChangeWhenUnload) { | 70 TEST_F(AutoplayUmaHelperTest, VisibilityChangeWhenUnload) { |
| 70 EXPECT_CALL(UmaHelper(), HandleContextDestroyed()); | 71 EXPECT_CALL(UmaHelper(), HandleContextDestroyed()); |
| 71 | 72 |
| 72 MediaElement().setMuted(true); | 73 MediaElement().setMuted(true); |
| 73 UmaHelper().OnAutoplayInitiated(AutoplaySource::kMethod); | 74 UmaHelper().OnAutoplayInitiated(AutoplaySource::kMethod); |
| 74 UmaHelper().HandlePlayingEvent(); | 75 UmaHelper().HandlePlayingEvent(); |
| 75 PageHolder().reset(); | 76 PageHolder().reset(); |
| 76 ::testing::Mock::VerifyAndClear(&UmaHelper()); | 77 ::testing::Mock::VerifyAndClear(&UmaHelper()); |
| 77 } | 78 } |
| 78 | 79 |
| 79 } // namespace blink | 80 } // namespace blink |
| OLD | NEW |