Introduce new SPDY Version UMA histogram.
[chromium-blink-merge.git] / athena / env / athena_env_unittest.cc
blobe852f45fcee972632ffb77b1aef4ee028e2d95b9
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"
8 #include "base/bind.h"
9 #include "ui/gfx/display.h"
10 #include "ui/gfx/screen.h"
12 namespace athena {
14 typedef test::AthenaTestBase AthenaEnvTest;
16 namespace {
18 class TerminatingCallback {
19 public:
20 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_; }
36 void Reset() {
37 on_terminating_count_ = 0;
38 on_terminating_2_count_ = 0;
41 private:
42 int on_terminating_count_;
43 int on_terminating_2_count_;
45 DISALLOW_COPY_AND_ASSIGN(TerminatingCallback);
48 } // namespace
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);
67 env->OnTerminating();
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());
73 // Remove callbacks.
74 callback_1.Reset();
75 callback_2.Reset();
76 env->RemoveTerminatingCallback(cb_1_2);
77 env->OnTerminating();
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());
82 callback_1.Reset();
83 callback_2.Reset();
84 env->RemoveTerminatingCallback(cb_1_1);
85 env->OnTerminating();
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.
91 callback_1.Reset();
92 callback_2.Reset();
93 env->AddTerminatingCallback(cb_1_2);
94 env->OnTerminating();
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();
104 namespace {
106 class AthenaShutdownTest : public test::AthenaTestBase {
107 public:
108 AthenaShutdownTest() {}
109 virtual ~AthenaShutdownTest() {}
111 virtual void TearDown() {
112 test::AthenaTestBase::TearDown();
113 ASSERT_NE(
114 gfx::Display::kInvalidDisplayID,
115 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay().id());
118 private:
119 DISALLOW_COPY_AND_ASSIGN(AthenaShutdownTest);
122 } // namespace
124 // gfx::Screen should be accessible after shutdown.
125 TEST_F(AthenaShutdownTest, Shutdown) {
128 } // namespace athena