Chromium Code Reviews| 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 | |
|
cjgrant
2017/06/05 17:33:53
Drop extra line?
ymalik
2017/06/05 20:02:42
Done.
| |
| 50 void OnSecondaryButtonPressed() { secondary_button_pressed_ = true; } | |
| 51 | |
| 52 bool primary_button_pressed_ = false; | |
| 53 bool secondary_button_pressed_ = false; | |
| 54 }; | |
| 55 | |
| 56 TestExitPrompt::TestExitPrompt() | |
| 57 : ExitPrompt(512, | |
| 58 base::Bind(&TestExitPrompt::OnPrimaryButtonPressed, | |
| 59 base::Unretained(this)), | |
| 60 base::Bind(&TestExitPrompt::OnSecondaryButtonPressed, | |
| 61 base::Unretained(this))) {} | |
| 62 | |
| 63 TEST(ExitPromptTest, PrimaryButtonCallbackCalled) { | |
| 64 TestExitPrompt prompt; | |
| 65 MockExitPromptTexture* texture = new MockExitPromptTexture(); | |
| 66 // Called twice from OnButtonDown and twice from OnButtonUp. | |
| 67 EXPECT_CALL(*texture, HitsPrimaryButton(gfx::PointF())) | |
| 68 .Times(4) | |
| 69 .WillRepeatedly(Return(true)); | |
| 70 // Called once from OnButtonDown and once from OnButtonUp (via OnStatUpdated). | |
| 71 EXPECT_CALL(*texture, HitsSecondaryButton(gfx::PointF())) | |
| 72 .Times(2) | |
| 73 .WillRepeatedly(Return(false)); | |
| 74 prompt.SetTextureForTesting(std::move(texture)); | |
| 75 | |
| 76 prompt.OnButtonDown(gfx::PointF()); | |
| 77 prompt.OnButtonUp(gfx::PointF()); | |
| 78 | |
| 79 EXPECT_EQ(true, prompt.primary_button_pressed()); | |
| 80 EXPECT_EQ(false, prompt.secondary_button_pressed()); | |
| 81 } | |
| 82 | |
| 83 TEST(ExitPromptTest, SecondaryButtonCallbackCalled) { | |
| 84 TestExitPrompt prompt; | |
| 85 MockExitPromptTexture* texture = new MockExitPromptTexture(); | |
| 86 // Called twice from OnButtonDown and once from OnButtonUp. | |
| 87 EXPECT_CALL(*texture, HitsPrimaryButton(gfx::PointF())) | |
| 88 .Times(3) | |
| 89 .WillRepeatedly(Return(false)); | |
| 90 // Called twice from OnButtonDown and twice from OnButtonUp. | |
| 91 EXPECT_CALL(*texture, HitsSecondaryButton(gfx::PointF())) | |
| 92 .Times(4) | |
| 93 .WillRepeatedly(Return(true)); | |
| 94 prompt.SetTextureForTesting(std::move(texture)); | |
| 95 | |
| 96 prompt.OnButtonDown(gfx::PointF()); | |
| 97 prompt.OnButtonUp(gfx::PointF()); | |
| 98 | |
| 99 EXPECT_EQ(false, prompt.primary_button_pressed()); | |
| 100 EXPECT_EQ(true, prompt.secondary_button_pressed()); | |
| 101 } | |
| 102 | |
| 103 } // namespace vr_shell | |
| OLD | NEW |