1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66

ash / system / network / network_feature_pod_button_unittest.cc [blame]

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ash/system/network/network_feature_pod_button.h"

#include <memory>

#include "ash/system/unified/feature_pod_button.h"
#include "ash/test/ash_test_base.h"

namespace ash {
namespace {

class FakeNetworkFeaturePodButtonDelegate
    : public NetworkFeaturePodButton::Delegate {
 public:
  size_t feature_pod_button_theme_changed_count() {
    return feature_pod_button_theme_changed_count_;
  }

 private:
  // NetworkFeaturePodButton::Delegate:
  void OnFeaturePodButtonThemeChanged() override {
    ++feature_pod_button_theme_changed_count_;
  }

  size_t feature_pod_button_theme_changed_count_ = 0;
};

}  // namespace

class NetworkFeaturePodButtonTest : public AshTestBase {
 public:
  void SetUp() override {
    AshTestBase::SetUp();

    network_feature_pod_button_ =
        std::make_unique<NetworkFeaturePodButton>(/*controller=*/nullptr,
                                                  /*delegate=*/delegate());
  }

  void TearDown() override {
    network_feature_pod_button_.reset();

    AshTestBase::TearDown();
  }

  void CallOnThemeChanged() { network_feature_pod_button_->OnThemeChanged(); }

  FakeNetworkFeaturePodButtonDelegate* delegate() {
    return &fake_network_feature_pod_button_delegate_;
  }

 private:
  std::unique_ptr<NetworkFeaturePodButton> network_feature_pod_button_;
  FakeNetworkFeaturePodButtonDelegate fake_network_feature_pod_button_delegate_;
};

TEST_F(NetworkFeaturePodButtonTest, NotifiesDelegateWhenThemeChanges) {
  EXPECT_EQ(0u, delegate()->feature_pod_button_theme_changed_count());
  CallOnThemeChanged();
  EXPECT_EQ(1u, delegate()->feature_pod_button_theme_changed_count());
}

}  // namespace ash