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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/accessibility/accessibility_alert_window.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer_type.h"
#include "ui/views/accessibility/ax_aura_obj_cache.h"
#include "ui/views/accessibility/ax_aura_obj_wrapper.h"
#include "ui/views/test/views_test_base.h"
namespace views {
class FakeAXAuraObjCacheDelegate : public AXAuraObjCache::Delegate {
public:
FakeAXAuraObjCacheDelegate() = default;
FakeAXAuraObjCacheDelegate(const FakeAXAuraObjCacheDelegate&) = delete;
FakeAXAuraObjCacheDelegate& operator=(const FakeAXAuraObjCacheDelegate&) =
delete;
~FakeAXAuraObjCacheDelegate() override = default;
void OnChildWindowRemoved(AXAuraObjWrapper* parent) override {}
void OnEvent(AXAuraObjWrapper* aura_obj,
ax::mojom::Event event_type) override {
if (event_type == ax::mojom::Event::kAlert) {
count_++;
}
}
int count() { return count_; }
void set_count(int count) { count_ = count; }
private:
int count_ = 0;
};
class AccessibilityAlertWindowTest : public ViewsTestBase {
public:
AccessibilityAlertWindowTest() = default;
AccessibilityAlertWindowTest(const AccessibilityAlertWindowTest&) = delete;
AccessibilityAlertWindowTest& operator=(const AccessibilityAlertWindowTest&) =
delete;
~AccessibilityAlertWindowTest() override = default;
protected:
void SetUp() override {
ViewsTestBase::SetUp();
parent_ = std::make_unique<aura::Window>(nullptr);
parent_->Init(ui::LAYER_SOLID_COLOR);
}
std::unique_ptr<aura::Window> parent_;
AXAuraObjCache cache;
};
TEST_F(AccessibilityAlertWindowTest, HandleAlert) {
FakeAXAuraObjCacheDelegate delegate;
cache.SetDelegate(&delegate);
AccessibilityAlertWindow window(parent_.get(), &cache);
window.HandleAlert("test");
EXPECT_EQ(1, delegate.count());
delegate.set_count(0);
window.OnWillDestroyEnv();
window.HandleAlert("test");
EXPECT_EQ(0, delegate.count());
}
TEST_F(AccessibilityAlertWindowTest, OnWillDestroyEnv) {
AccessibilityAlertWindow window(parent_.get(), &cache);
window.OnWillDestroyEnv();
EXPECT_FALSE(window.observation_.IsObserving());
EXPECT_FALSE(window.alert_window_);
}
} // namespace views
|