Tetsui Ohkubo | 56307e3 | 2018-05-18 07:36:26 | [diff] [blame] | 1 | // Copyright 2018 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 "ash/system/tracing_notification_controller.h" |
| 6 | |
| 7 | #include "ash/public/cpp/ash_features.h" |
| 8 | #include "ash/shell.h" |
Tetsui Ohkubo | 3679446 | 2018-06-29 07:26:02 | [diff] [blame] | 9 | #include "ash/system/model/system_tray_model.h" |
Tetsui Ohkubo | 56307e3 | 2018-05-18 07:36:26 | [diff] [blame] | 10 | #include "ash/test/ash_test_base.h" |
| 11 | #include "base/test/scoped_feature_list.h" |
| 12 | #include "ui/message_center/message_center.h" |
| 13 | |
| 14 | namespace ash { |
| 15 | |
| 16 | class TracingNotificationControllerTest : public AshTestBase { |
| 17 | public: |
| 18 | TracingNotificationControllerTest() = default; |
| 19 | ~TracingNotificationControllerTest() override = default; |
| 20 | |
| 21 | void SetUp() override { |
| 22 | scoped_feature_list_.InitAndEnableFeature(features::kSystemTrayUnified); |
| 23 | AshTestBase::SetUp(); |
| 24 | } |
| 25 | |
| 26 | protected: |
| 27 | bool HasNotification() { |
| 28 | return message_center::MessageCenter::Get()->FindVisibleNotificationById( |
| 29 | TracingNotificationController::kNotificationId); |
| 30 | } |
| 31 | |
| 32 | private: |
| 33 | base::test::ScopedFeatureList scoped_feature_list_; |
| 34 | |
| 35 | DISALLOW_COPY_AND_ASSIGN(TracingNotificationControllerTest); |
| 36 | }; |
| 37 | |
Tetsui Ohkubo | 3679446 | 2018-06-29 07:26:02 | [diff] [blame] | 38 | // Tests that the notification becomes visible when the tray model toggles |
Tetsui Ohkubo | 56307e3 | 2018-05-18 07:36:26 | [diff] [blame] | 39 | // it. |
| 40 | TEST_F(TracingNotificationControllerTest, Visibility) { |
| 41 | // The system starts with tracing off, so the notification isn't visible. |
| 42 | EXPECT_FALSE(HasNotification()); |
| 43 | |
| 44 | // Simulate turning on tracing. |
Tetsui Ohkubo | 3679446 | 2018-06-29 07:26:02 | [diff] [blame] | 45 | SystemTrayModel* model = Shell::Get()->system_tray_model(); |
| 46 | model->SetPerformanceTracingIconVisible(true); |
Tetsui Ohkubo | 56307e3 | 2018-05-18 07:36:26 | [diff] [blame] | 47 | EXPECT_TRUE(HasNotification()); |
| 48 | |
| 49 | // Simulate turning off tracing. |
Tetsui Ohkubo | 3679446 | 2018-06-29 07:26:02 | [diff] [blame] | 50 | model->SetPerformanceTracingIconVisible(false); |
Tetsui Ohkubo | 56307e3 | 2018-05-18 07:36:26 | [diff] [blame] | 51 | EXPECT_FALSE(HasNotification()); |
| 52 | } |
| 53 | |
| 54 | } // namespace ash |