Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(789)

Unified Diff: ui/views/accessibility/ax_aura_obj_cache_unittest.cc

Issue 1629403004: Remove all descendant views from AXAuraObjCache when a view is removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only compile unit tests on aura platforms Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/accessibility/ax_aura_obj_cache.cc ('k') | ui/views/accessibility/ax_widget_obj_wrapper.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/accessibility/ax_aura_obj_cache_unittest.cc
diff --git a/ui/views/accessibility/ax_aura_obj_cache_unittest.cc b/ui/views/accessibility/ax_aura_obj_cache_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0013e96196a1bf2505481f0ce3393b9f50d62d6a
--- /dev/null
+++ b/ui/views/accessibility/ax_aura_obj_cache_unittest.cc
@@ -0,0 +1,57 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/views/accessibility/ax_aura_obj_cache.h"
+#include "ui/views/test/widget_test.h"
+
+namespace views {
+namespace test {
+
+namespace {
+
+// This class can be used as a deleter for scoped_ptr<Widget>
+// to call function Widget::CloseNow automatically.
+struct WidgetCloser {
+ inline void operator()(Widget* widget) const { widget->CloseNow(); }
+};
+
+using WidgetAutoclosePtr = scoped_ptr<Widget, WidgetCloser>;
+}
+
+class AXAuraObjCacheTest : public WidgetTest {
+ public:
+ AXAuraObjCacheTest() {}
+ ~AXAuraObjCacheTest() override {}
+};
+
+TEST_F(AXAuraObjCacheTest, TestViewRemoval) {
+ WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget());
+ View* parent = new View();
+ widget->GetRootView()->AddChildView(parent);
+ View* child = new View();
+ parent->AddChildView(child);
+
+ AXAuraObjCache* cache = AXAuraObjCache::GetInstance();
+ AXAuraObjWrapper* ax_widget = cache->GetOrCreate(widget.get());
+ ASSERT_NE(nullptr, ax_widget);
+ AXAuraObjWrapper* ax_parent = cache->GetOrCreate(parent);
+ ASSERT_NE(nullptr, ax_parent);
+ AXAuraObjWrapper* ax_child = cache->GetOrCreate(child);
+ ASSERT_NE(nullptr, ax_child);
+
+ // Everything should have an ID, indicating it's in the cache.
+ ASSERT_GT(cache->GetID(widget.get()), 0);
+ ASSERT_GT(cache->GetID(parent), 0);
+ ASSERT_GT(cache->GetID(child), 0);
+
+ // Removing the parent view should remove both the parent and child
+ // from the cache, but leave the widget.
+ widget->GetRootView()->RemoveChildView(parent);
+ ASSERT_GT(cache->GetID(widget.get()), 0);
+ ASSERT_EQ(-1, cache->GetID(parent));
+ ASSERT_EQ(-1, cache->GetID(child));
+}
+
+} // namespace test
+} // namespace views
« no previous file with comments | « ui/views/accessibility/ax_aura_obj_cache.cc ('k') | ui/views/accessibility/ax_widget_obj_wrapper.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698