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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // Default to "not optimized for mobile" page. | 46 // Default to "not optimized for mobile" page. |
47 ON_CALL(*this, isLegacyViewportType()) | 47 ON_CALL(*this, isLegacyViewportType()) |
48 .WillByDefault(Return(false)); | 48 .WillByDefault(Return(false)); |
49 | 49 |
50 // Other handy defaults. | 50 // Other handy defaults. |
51 ON_CALL(*this, ended()) | 51 ON_CALL(*this, ended()) |
52 .WillByDefault(Return(false)); | 52 .WillByDefault(Return(false)); |
53 ON_CALL(*this, pageVisibilityState()) | 53 ON_CALL(*this, pageVisibilityState()) |
54 .WillByDefault(Return(PageVisibilityStateVisible)); | 54 .WillByDefault(Return(PageVisibilityStateVisible)); |
| 55 ON_CALL(*this, isCrossOrigin()) |
| 56 .WillByDefault(Return(false)); |
55 ON_CALL(*this, absoluteBoundingBoxRect()) | 57 ON_CALL(*this, absoluteBoundingBoxRect()) |
56 .WillByDefault(Return( | 58 .WillByDefault(Return( |
57 IntRect(10, 10, 100, 100))); | 59 IntRect(10, 10, 100, 100))); |
58 | 60 |
59 // Normally, the autoplay experiment should not modify lots of other | 61 // Normally, the autoplay experiment should not modify lots of other |
60 // state unless we explicitly expect it. | 62 // state unless we explicitly expect it. |
61 EXPECT_CALL(*this, setMuted(_)) | 63 EXPECT_CALL(*this, setMuted(_)) |
62 .Times(0); | 64 .Times(0); |
63 EXPECT_CALL(*this, removeUserGestureRequirement()) | 65 EXPECT_CALL(*this, removeUserGestureRequirement()) |
64 .Times(0); | 66 .Times(0); |
(...skipping 13 matching lines...) Expand all Loading... |
78 MOCK_METHOD0(playInternal, void()); | 80 MOCK_METHOD0(playInternal, void()); |
79 MOCK_CONST_METHOD0(isUserGestureRequiredForPlay, bool()); | 81 MOCK_CONST_METHOD0(isUserGestureRequiredForPlay, bool()); |
80 MOCK_METHOD0(removeUserGestureRequirement, void()); | 82 MOCK_METHOD0(removeUserGestureRequirement, void()); |
81 MOCK_METHOD1(recordAutoplayMetric, void(AutoplayMetrics)); | 83 MOCK_METHOD1(recordAutoplayMetric, void(AutoplayMetrics)); |
82 MOCK_METHOD0(shouldAutoplay, bool()); | 84 MOCK_METHOD0(shouldAutoplay, bool()); |
83 MOCK_CONST_METHOD0(isHTMLVideoElement, bool()); | 85 MOCK_CONST_METHOD0(isHTMLVideoElement, bool()); |
84 MOCK_CONST_METHOD0(isHTMLAudioElement, bool()); | 86 MOCK_CONST_METHOD0(isHTMLAudioElement, bool()); |
85 MOCK_METHOD0(isLegacyViewportType, bool()); | 87 MOCK_METHOD0(isLegacyViewportType, bool()); |
86 MOCK_CONST_METHOD0(pageVisibilityState, PageVisibilityState()); | 88 MOCK_CONST_METHOD0(pageVisibilityState, PageVisibilityState()); |
87 MOCK_CONST_METHOD0(autoplayExperimentMode, String()); | 89 MOCK_CONST_METHOD0(autoplayExperimentMode, String()); |
| 90 MOCK_CONST_METHOD0(isCrossOrigin, bool()); |
88 MOCK_METHOD1(setRequestPositionUpdates, void(bool)); | 91 MOCK_METHOD1(setRequestPositionUpdates, void(bool)); |
89 MOCK_CONST_METHOD0(absoluteBoundingBoxRect, IntRect()); | 92 MOCK_CONST_METHOD0(absoluteBoundingBoxRect, IntRect()); |
90 | 93 |
91 const char* m_mode; | 94 const char* m_mode; |
92 // const since changes to it won't affect the mocked value. | 95 // const since changes to it won't affect the mocked value. |
93 const double m_duration; | 96 const double m_duration; |
94 }; | 97 }; |
95 | 98 |
96 class AutoplayExperimentTest : public ::testing::Test { | 99 class AutoplayExperimentTest : public ::testing::Test { |
97 public: | 100 public: |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 m_helper->becameReadyToPlay(); | 427 m_helper->becameReadyToPlay(); |
425 | 428 |
426 EXPECT_CALL(*m_client, removeUserGestureRequirement()) | 429 EXPECT_CALL(*m_client, removeUserGestureRequirement()) |
427 .Times(1); | 430 .Times(1); |
428 EXPECT_CALL(*m_client, playInternal()) | 431 EXPECT_CALL(*m_client, playInternal()) |
429 .Times(1); | 432 .Times(1); |
430 EXPECT_CALL(*m_client, setRequestPositionUpdates(false)) | 433 EXPECT_CALL(*m_client, setRequestPositionUpdates(false)) |
431 .Times(1); | 434 .Times(1); |
432 moveIntoViewport(); | 435 moveIntoViewport(); |
433 } | 436 } |
| 437 |
| 438 TEST_F(AutoplayExperimentTest, WithSameOriginTests) |
| 439 { |
| 440 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo-ifsameorigin
", MockAutoplayClient::Video)); |
| 441 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(false)); |
| 442 EXPECT_TRUE(isEligible()); |
| 443 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(true)); |
| 444 EXPECT_FALSE(isEligible()); |
434 } | 445 } |
| 446 |
| 447 TEST_F(AutoplayExperimentTest, WithoutSameOriginTests) |
| 448 { |
| 449 setInterface(new NiceMock<MockAutoplayClient>("enabled-forvideo", MockAutopl
ayClient::Video)); |
| 450 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(false)); |
| 451 EXPECT_TRUE(isEligible()); |
| 452 ON_CALL(*m_client, isCrossOrigin()).WillByDefault(Return(true)); |
| 453 EXPECT_TRUE(isEligible()); |
| 454 } |
| 455 |
| 456 } |
OLD | NEW |