| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 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 "chrome/browser/android/vr_shell/ui_elements/exit_prompt.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/macros.h" |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "chrome/browser/android/vr_shell/textures/exit_prompt_texture.h" |
| 11 #include "testing/gmock/include/gmock/gmock.h" |
| 12 #include "testing/gtest/include/gtest/gtest.h" |
| 13 #include "ui/gfx/test/gfx_util.h" |
| 14 |
| 15 using ::testing::Return; |
| 16 |
| 17 namespace vr_shell { |
| 18 |
| 19 namespace { |
| 20 |
| 21 class MockExitPromptTexture : public ExitPromptTexture { |
| 22 public: |
| 23 MockExitPromptTexture() : ExitPromptTexture() {} |
| 24 ~MockExitPromptTexture() override {} |
| 25 |
| 26 MOCK_CONST_METHOD1(HitsPrimaryButton, bool(const gfx::PointF&)); |
| 27 MOCK_CONST_METHOD1(HitsSecondaryButton, bool(const gfx::PointF&)); |
| 28 |
| 29 MOCK_CONST_METHOD1(GetPreferredTextureSize, gfx::Size(int)); |
| 30 MOCK_CONST_METHOD0(GetDrawnSize, gfx::SizeF()); |
| 31 MOCK_METHOD2(Draw, void(SkCanvas*, const gfx::Size&)); |
| 32 |
| 33 private: |
| 34 DISALLOW_COPY_AND_ASSIGN(MockExitPromptTexture); |
| 35 }; |
| 36 |
| 37 } // namespace |
| 38 |
| 39 class TestExitPrompt : public ExitPrompt { |
| 40 public: |
| 41 TestExitPrompt(); |
| 42 ~TestExitPrompt() override {} |
| 43 |
| 44 bool primary_button_pressed() const { return primary_button_pressed_; } |
| 45 bool secondary_button_pressed() const { return secondary_button_pressed_; } |
| 46 |
| 47 private: |
| 48 void OnPrimaryButtonPressed() { primary_button_pressed_ = true; } |
| 49 void OnSecondaryButtonPressed() { secondary_button_pressed_ = true; } |
| 50 |
| 51 bool primary_button_pressed_ = false; |
| 52 bool secondary_button_pressed_ = false; |
| 53 }; |
| 54 |
| 55 TestExitPrompt::TestExitPrompt() |
| 56 : ExitPrompt(512, |
| 57 base::Bind(&TestExitPrompt::OnPrimaryButtonPressed, |
| 58 base::Unretained(this)), |
| 59 base::Bind(&TestExitPrompt::OnSecondaryButtonPressed, |
| 60 base::Unretained(this))) {} |
| 61 |
| 62 TEST(ExitPromptTest, PrimaryButtonCallbackCalled) { |
| 63 TestExitPrompt prompt; |
| 64 MockExitPromptTexture* texture = new MockExitPromptTexture(); |
| 65 // Called twice from OnButtonDown and twice from OnButtonUp. |
| 66 EXPECT_CALL(*texture, HitsPrimaryButton(gfx::PointF())) |
| 67 .Times(4) |
| 68 .WillRepeatedly(Return(true)); |
| 69 // Called once from OnButtonDown and once from OnButtonUp (via OnStatUpdated). |
| 70 EXPECT_CALL(*texture, HitsSecondaryButton(gfx::PointF())) |
| 71 .Times(2) |
| 72 .WillRepeatedly(Return(false)); |
| 73 prompt.SetTextureForTesting(std::move(texture)); |
| 74 |
| 75 prompt.OnButtonDown(gfx::PointF()); |
| 76 prompt.OnButtonUp(gfx::PointF()); |
| 77 |
| 78 EXPECT_TRUE(prompt.primary_button_pressed()); |
| 79 EXPECT_FALSE(prompt.secondary_button_pressed()); |
| 80 } |
| 81 |
| 82 TEST(ExitPromptTest, SecondaryButtonCallbackCalled) { |
| 83 TestExitPrompt prompt; |
| 84 MockExitPromptTexture* texture = new MockExitPromptTexture(); |
| 85 // Called twice from OnButtonDown and once from OnButtonUp. |
| 86 EXPECT_CALL(*texture, HitsPrimaryButton(gfx::PointF())) |
| 87 .Times(3) |
| 88 .WillRepeatedly(Return(false)); |
| 89 // Called twice from OnButtonDown and twice from OnButtonUp. |
| 90 EXPECT_CALL(*texture, HitsSecondaryButton(gfx::PointF())) |
| 91 .Times(4) |
| 92 .WillRepeatedly(Return(true)); |
| 93 prompt.SetTextureForTesting(std::move(texture)); |
| 94 |
| 95 prompt.OnButtonDown(gfx::PointF()); |
| 96 prompt.OnButtonUp(gfx::PointF()); |
| 97 |
| 98 EXPECT_FALSE(prompt.primary_button_pressed()); |
| 99 EXPECT_TRUE(prompt.secondary_button_pressed()); |
| 100 } |
| 101 |
| 102 } // namespace vr_shell |
| OLD | NEW |