| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/dom/Document.h" | 5 #include "core/dom/Document.h" |
| 6 #include "core/html/AutoplayExperimentHelper.h" | 6 #include "core/html/AutoplayExperimentHelper.h" |
| 7 #include "platform/UserGestureIndicator.h" | 7 #include "platform/UserGestureIndicator.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 public: | 103 public: |
| 104 AutoplayExperimentTest() {} | 104 AutoplayExperimentTest() {} |
| 105 | 105 |
| 106 ~AutoplayExperimentTest() {} | 106 ~AutoplayExperimentTest() {} |
| 107 | 107 |
| 108 bool isEligible() | 108 bool isEligible() |
| 109 { | 109 { |
| 110 return m_helper->isEligible(); | 110 return m_helper->isEligible(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 bool meetsVisibilityRequirements() |
| 114 { |
| 115 return m_helper->meetsVisibilityRequirements(); |
| 116 } |
| 117 |
| 113 void setInterface(MockAutoplayClient* client) | 118 void setInterface(MockAutoplayClient* client) |
| 114 { | 119 { |
| 115 m_client = client; | 120 m_client = client; |
| 116 | 121 |
| 117 // Set some defaults. | 122 // Set some defaults. |
| 118 setUserGestureRequiredForPlay(true); | 123 setUserGestureRequiredForPlay(true); |
| 119 setShouldAutoplay(true); | 124 setShouldAutoplay(true); |
| 120 setIsMuted(false); | 125 setIsMuted(false); |
| 121 | 126 |
| 122 m_helper = AutoplayExperimentHelper::create(m_client.get()); | 127 m_helper = AutoplayExperimentHelper::create(m_client.get()); |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 | 454 |
| 450 TEST_F(AutoplayExperimentTest, WithoutSameOriginTests) | 455 TEST_F(AutoplayExperimentTest, WithoutSameOriginTests) |
| 451 { | 456 { |
| 452 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl
ayClient::Video)); | 457 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl
ayClient::Video)); |
| 453 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(false)); | 458 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(false)); |
| 454 EXPECT_TRUE(isEligible()); | 459 EXPECT_TRUE(isEligible()); |
| 455 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(true)); | 460 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(true)); |
| 456 EXPECT_TRUE(isEligible()); | 461 EXPECT_TRUE(isEligible()); |
| 457 } | 462 } |
| 458 | 463 |
| 464 TEST_F(AutoplayExperimentTest, AudioPageVisibility) |
| 465 { |
| 466 setInterface(new NiceMock<MockAutoplayClient>("enabled-foraudio-ifpagevisibl
e", MockAutoplayClient::Audio)); |
| 467 ON_CALL(*m_client, pageVisibilityState()).WillByDefault(Return(PageVisibilit
yStateVisible)); |
| 468 EXPECT_TRUE(isEligible()); |
| 469 EXPECT_TRUE(meetsVisibilityRequirements()); |
| 470 |
| 471 ON_CALL(*m_client, pageVisibilityState()).WillByDefault(Return(PageVisibilit
yStateHidden)); |
| 472 EXPECT_TRUE(isEligible()); |
| 473 EXPECT_FALSE(meetsVisibilityRequirements()); |
| 459 } | 474 } |
| 475 |
| 476 } |
| OLD | NEW |