Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(706)

Unified Diff: chrome/browser/android/vr_shell/ui_scene_manager_unittest.cc

Issue 2833773005: Pause drawing webvr when the App button is pressed (Closed)
Patch Set: Add unittest + cleanup Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/ui_scene_manager_unittest.cc
diff --git a/chrome/browser/android/vr_shell/ui_scene_manager_unittest.cc b/chrome/browser/android/vr_shell/ui_scene_manager_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5a649024d89c76bbe4ccacfd64ff07ff5d1d3ffc
--- /dev/null
+++ b/chrome/browser/android/vr_shell/ui_scene_manager_unittest.cc
@@ -0,0 +1,86 @@
+// 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_scene_manager.h"
+
+#include "base/macros.h"
+#include "base/threading/thread_task_runner_handle.h"
+#include "chrome/browser/android/vr_shell/ui_scene.h"
+#include "chrome/browser/android/vr_shell/vr_thread_envoy.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace vr_shell {
+
+namespace {
+
+using testing::Return;
+
+class FakeTaskRunner : public base::SingleThreadTaskRunner {
+ public:
+ FakeTaskRunner() : thread_id_(base::PlatformThread::CurrentId()) {}
+
+ bool PostDelayedTask(const tracked_objects::Location& from_here,
+ base::OnceClosure task,
+ base::TimeDelta delay) override {
+ // Drop the delayed task.
+ return false;
+ }
+
+ bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
+ base::OnceClosure task,
+ base::TimeDelta delay) override {
+ // Drop the delayed task.
+ return false;
+ }
+
+ bool RunsTasksOnCurrentThread() const override {
+ return thread_id_ == base::PlatformThread::CurrentId();
+ }
+
+ protected:
+ ~FakeTaskRunner() override {}
+
+ base::PlatformThreadId thread_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeTaskRunner);
+};
+
+class MockVrThreadEnvoy : public VrThreadEnvoy {
+ public:
+ MockVrThreadEnvoy() : weak_ptr_factory_(this) {}
+ ~MockVrThreadEnvoy() override{};
+
+ base::WeakPtr<VrThreadEnvoy> GetWeakPtr() {
+ return weak_ptr_factory_.GetWeakPtr();
+ }
+
+ MOCK_METHOD0(GetVrShell, base::WeakPtr<VrShell>());
+ MOCK_METHOD0(GetMainThreadTaskRunner,
+ scoped_refptr<base::SingleThreadTaskRunner>());
+
+ private:
+ base::WeakPtrFactory<VrThreadEnvoy> weak_ptr_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockVrThreadEnvoy);
+};
+
+} // namespace
+
+TEST(UiSceneManager, AppButtonPressed) {
+ std::unique_ptr<MockVrThreadEnvoy> envoy =
cjgrant 2017/04/28 18:25:23 A scene manager test base class should probably ma
ymalik 2017/05/02 17:46:00 Done.
+ base::MakeUnique<MockVrThreadEnvoy>();
+ std::unique_ptr<UiScene> scene = base::MakeUnique<UiScene>();
+ EXPECT_CALL(*envoy, GetMainThreadTaskRunner())
+ .Times(1)
+ .WillOnce(Return(
+ scoped_refptr<base::SingleThreadTaskRunner>(new FakeTaskRunner)));
+ EXPECT_CALL(*envoy, GetVrShell()).Times(1).WillOnce(Return(nullptr));
cjgrant 2017/04/28 18:25:23 Based on my top level comment, I figure this would
ymalik 2017/05/02 17:46:00 Done.
+
+ std::unique_ptr<UiSceneManager> manager =
+ base::MakeUnique<UiSceneManager>(envoy->GetWeakPtr(), scene.get());
+ manager->AppButtonPressed();
+}
+
+} // namespace vr_shell

Powered by Google App Engine
This is Rietveld 408576698