1 // Copyright 2014 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.
5 #include "athena/env/public/athena_env.h"
7 #include "athena/test/athena_test_base.h"
9 #include "ui/gfx/display.h"
10 #include "ui/gfx/screen.h"
14 typedef test::AthenaTestBase AthenaEnvTest
;
18 class TerminatingCallback
{
21 : on_terminating_count_(0),
22 on_terminating_2_count_(0) {
25 void OnTerminating() {
26 on_terminating_count_
++;
29 void OnTerminating2() {
30 on_terminating_2_count_
++;
33 int on_terminating_count() const { return on_terminating_count_
; }
34 int on_terminating_2_count() const { return on_terminating_2_count_
; }
37 on_terminating_count_
= 0;
38 on_terminating_2_count_
= 0;
42 int on_terminating_count_
;
43 int on_terminating_2_count_
;
45 DISALLOW_COPY_AND_ASSIGN(TerminatingCallback
);
50 TEST_F(AthenaEnvTest
, TerminatingCallback
) {
51 TerminatingCallback callback_1
;
52 TerminatingCallback callback_2
;
53 AthenaEnv
* env
= AthenaEnv::Get();
54 base::Closure cb_1_1
=
55 base::Bind(&TerminatingCallback::OnTerminating
,
56 base::Unretained(&callback_1
));
57 base::Closure cb_1_2
=
58 base::Bind(&TerminatingCallback::OnTerminating2
,
59 base::Unretained(&callback_1
));
60 base::Closure cb_2_1
=
61 base::Bind(&TerminatingCallback::OnTerminating
,
62 base::Unretained(&callback_2
));
64 env
->AddTerminatingCallback(cb_1_1
);
65 env
->AddTerminatingCallback(cb_1_2
);
66 env
->AddTerminatingCallback(cb_2_1
);
69 EXPECT_EQ(1, callback_1
.on_terminating_count());
70 EXPECT_EQ(1, callback_1
.on_terminating_2_count());
71 EXPECT_EQ(1, callback_2
.on_terminating_count());
76 env
->RemoveTerminatingCallback(cb_1_2
);
78 EXPECT_EQ(1, callback_1
.on_terminating_count());
79 EXPECT_EQ(0, callback_1
.on_terminating_2_count());
80 EXPECT_EQ(1, callback_2
.on_terminating_count());
84 env
->RemoveTerminatingCallback(cb_1_1
);
86 EXPECT_EQ(0, callback_1
.on_terminating_count());
87 EXPECT_EQ(0, callback_1
.on_terminating_2_count());
88 EXPECT_EQ(1, callback_2
.on_terminating_count());
90 // Add removed callback.
93 env
->AddTerminatingCallback(cb_1_2
);
95 EXPECT_EQ(0, callback_1
.on_terminating_count());
96 EXPECT_EQ(1, callback_1
.on_terminating_2_count());
97 EXPECT_EQ(1, callback_2
.on_terminating_count());
99 // Adding empty callback should not fail.
100 env
->AddTerminatingCallback(base::Closure());
101 env
->OnTerminating();
106 class AthenaShutdownTest
: public test::AthenaTestBase
{
108 AthenaShutdownTest() {}
109 virtual ~AthenaShutdownTest() {}
111 virtual void TearDown() {
112 test::AthenaTestBase::TearDown();
114 gfx::Display::kInvalidDisplayID
,
115 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
119 DISALLOW_COPY_AND_ASSIGN(AthenaShutdownTest
);
124 // gfx::Screen should be accessible after shutdown.
125 TEST_F(AthenaShutdownTest
, Shutdown
) {
128 } // namespace athena