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

Side by Side 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, 7 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 unified diff | Download patch
OLDNEW
(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_scene_manager.h"
6
7 #include "base/macros.h"
8 #include "base/threading/thread_task_runner_handle.h"
9 #include "chrome/browser/android/vr_shell/ui_scene.h"
10 #include "chrome/browser/android/vr_shell/vr_thread_envoy.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace vr_shell {
15
16 namespace {
17
18 using testing::Return;
19
20 class FakeTaskRunner : public base::SingleThreadTaskRunner {
21 public:
22 FakeTaskRunner() : thread_id_(base::PlatformThread::CurrentId()) {}
23
24 bool PostDelayedTask(const tracked_objects::Location& from_here,
25 base::OnceClosure task,
26 base::TimeDelta delay) override {
27 // Drop the delayed task.
28 return false;
29 }
30
31 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
32 base::OnceClosure task,
33 base::TimeDelta delay) override {
34 // Drop the delayed task.
35 return false;
36 }
37
38 bool RunsTasksOnCurrentThread() const override {
39 return thread_id_ == base::PlatformThread::CurrentId();
40 }
41
42 protected:
43 ~FakeTaskRunner() override {}
44
45 base::PlatformThreadId thread_id_;
46
47 DISALLOW_COPY_AND_ASSIGN(FakeTaskRunner);
48 };
49
50 class MockVrThreadEnvoy : public VrThreadEnvoy {
51 public:
52 MockVrThreadEnvoy() : weak_ptr_factory_(this) {}
53 ~MockVrThreadEnvoy() override{};
54
55 base::WeakPtr<VrThreadEnvoy> GetWeakPtr() {
56 return weak_ptr_factory_.GetWeakPtr();
57 }
58
59 MOCK_METHOD0(GetVrShell, base::WeakPtr<VrShell>());
60 MOCK_METHOD0(GetMainThreadTaskRunner,
61 scoped_refptr<base::SingleThreadTaskRunner>());
62
63 private:
64 base::WeakPtrFactory<VrThreadEnvoy> weak_ptr_factory_;
65
66 DISALLOW_COPY_AND_ASSIGN(MockVrThreadEnvoy);
67 };
68
69 } // namespace
70
71 TEST(UiSceneManager, AppButtonPressed) {
72 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.
73 base::MakeUnique<MockVrThreadEnvoy>();
74 std::unique_ptr<UiScene> scene = base::MakeUnique<UiScene>();
75 EXPECT_CALL(*envoy, GetMainThreadTaskRunner())
76 .Times(1)
77 .WillOnce(Return(
78 scoped_refptr<base::SingleThreadTaskRunner>(new FakeTaskRunner)));
79 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.
80
81 std::unique_ptr<UiSceneManager> manager =
82 base::MakeUnique<UiSceneManager>(envoy->GetWeakPtr(), scene.get());
83 manager->AppButtonPressed();
84 }
85
86 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698