Chromium Code Reviews| Index: chrome/browser/android/vr_shell/ui_elements/exit_prompt_unittest.cc |
| diff --git a/chrome/browser/android/vr_shell/ui_elements/exit_prompt_unittest.cc b/chrome/browser/android/vr_shell/ui_elements/exit_prompt_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b3871ee54dfb8704237726e3a2273213fc4e8af5 |
| --- /dev/null |
| +++ b/chrome/browser/android/vr_shell/ui_elements/exit_prompt_unittest.cc |
| @@ -0,0 +1,103 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/android/vr_shell/ui_elements/exit_prompt.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/macros.h" |
| +#include "base/memory/ptr_util.h" |
| +#include "chrome/browser/android/vr_shell/textures/exit_prompt_texture.h" |
| +#include "testing/gmock/include/gmock/gmock.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "ui/gfx/test/gfx_util.h" |
| + |
| +using ::testing::Return; |
| + |
| +namespace vr_shell { |
| + |
| +namespace { |
| + |
| +class MockExitPromptTexture : public ExitPromptTexture { |
| + public: |
| + MockExitPromptTexture() : ExitPromptTexture() {} |
| + ~MockExitPromptTexture() override {} |
| + |
| + MOCK_CONST_METHOD1(HitsPrimaryButton, bool(const gfx::PointF&)); |
| + MOCK_CONST_METHOD1(HitsSecondaryButton, bool(const gfx::PointF&)); |
| + |
| + MOCK_CONST_METHOD1(GetPreferredTextureSize, gfx::Size(int)); |
| + MOCK_CONST_METHOD0(GetDrawnSize, gfx::SizeF()); |
| + MOCK_METHOD2(Draw, void(SkCanvas*, const gfx::Size&)); |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(MockExitPromptTexture); |
| +}; |
| + |
| +} // namespace |
| + |
| +class TestExitPrompt : public ExitPrompt { |
| + public: |
| + TestExitPrompt(); |
| + ~TestExitPrompt() override {} |
| + |
| + bool primary_button_pressed() const { return primary_button_pressed_; } |
| + bool secondary_button_pressed() const { return secondary_button_pressed_; } |
| + |
| + private: |
| + void OnPrimaryButtonPressed() { primary_button_pressed_ = true; } |
| + |
|
cjgrant
2017/06/05 17:33:53
Drop extra line?
ymalik
2017/06/05 20:02:42
Done.
|
| + void OnSecondaryButtonPressed() { secondary_button_pressed_ = true; } |
| + |
| + bool primary_button_pressed_ = false; |
| + bool secondary_button_pressed_ = false; |
| +}; |
| + |
| +TestExitPrompt::TestExitPrompt() |
| + : ExitPrompt(512, |
| + base::Bind(&TestExitPrompt::OnPrimaryButtonPressed, |
| + base::Unretained(this)), |
| + base::Bind(&TestExitPrompt::OnSecondaryButtonPressed, |
| + base::Unretained(this))) {} |
| + |
| +TEST(ExitPromptTest, PrimaryButtonCallbackCalled) { |
| + TestExitPrompt prompt; |
| + MockExitPromptTexture* texture = new MockExitPromptTexture(); |
| + // Called twice from OnButtonDown and twice from OnButtonUp. |
| + EXPECT_CALL(*texture, HitsPrimaryButton(gfx::PointF())) |
| + .Times(4) |
| + .WillRepeatedly(Return(true)); |
| + // Called once from OnButtonDown and once from OnButtonUp (via OnStatUpdated). |
| + EXPECT_CALL(*texture, HitsSecondaryButton(gfx::PointF())) |
| + .Times(2) |
| + .WillRepeatedly(Return(false)); |
| + prompt.SetTextureForTesting(std::move(texture)); |
| + |
| + prompt.OnButtonDown(gfx::PointF()); |
| + prompt.OnButtonUp(gfx::PointF()); |
| + |
| + EXPECT_EQ(true, prompt.primary_button_pressed()); |
| + EXPECT_EQ(false, prompt.secondary_button_pressed()); |
| +} |
| + |
| +TEST(ExitPromptTest, SecondaryButtonCallbackCalled) { |
| + TestExitPrompt prompt; |
| + MockExitPromptTexture* texture = new MockExitPromptTexture(); |
| + // Called twice from OnButtonDown and once from OnButtonUp. |
| + EXPECT_CALL(*texture, HitsPrimaryButton(gfx::PointF())) |
| + .Times(3) |
| + .WillRepeatedly(Return(false)); |
| + // Called twice from OnButtonDown and twice from OnButtonUp. |
| + EXPECT_CALL(*texture, HitsSecondaryButton(gfx::PointF())) |
| + .Times(4) |
| + .WillRepeatedly(Return(true)); |
| + prompt.SetTextureForTesting(std::move(texture)); |
| + |
| + prompt.OnButtonDown(gfx::PointF()); |
| + prompt.OnButtonUp(gfx::PointF()); |
| + |
| + EXPECT_EQ(false, prompt.primary_button_pressed()); |
| + EXPECT_EQ(true, prompt.secondary_button_pressed()); |
| +} |
| + |
| +} // namespace vr_shell |