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

Side by Side 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, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 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 "ui/views/accessibility/ax_aura_obj_cache.h"
6 #include "ui/views/test/widget_test.h"
7
8 namespace views {
9 namespace test {
10
11 namespace {
12
13 // This class can be used as a deleter for scoped_ptr<Widget>
14 // to call function Widget::CloseNow automatically.
15 struct WidgetCloser {
16 inline void operator()(Widget* widget) const { widget->CloseNow(); }
17 };
18
19 using WidgetAutoclosePtr = scoped_ptr<Widget, WidgetCloser>;
20 }
21
22 class AXAuraObjCacheTest : public WidgetTest {
23 public:
24 AXAuraObjCacheTest() {}
25 ~AXAuraObjCacheTest() override {}
26 };
27
28 TEST_F(AXAuraObjCacheTest, TestViewRemoval) {
29 WidgetAutoclosePtr widget(CreateTopLevelPlatformWidget());
30 View* parent = new View();
31 widget->GetRootView()->AddChildView(parent);
32 View* child = new View();
33 parent->AddChildView(child);
34
35 AXAuraObjCache* cache = AXAuraObjCache::GetInstance();
36 AXAuraObjWrapper* ax_widget = cache->GetOrCreate(widget.get());
37 ASSERT_NE(nullptr, ax_widget);
38 AXAuraObjWrapper* ax_parent = cache->GetOrCreate(parent);
39 ASSERT_NE(nullptr, ax_parent);
40 AXAuraObjWrapper* ax_child = cache->GetOrCreate(child);
41 ASSERT_NE(nullptr, ax_child);
42
43 // Everything should have an ID, indicating it's in the cache.
44 ASSERT_GT(cache->GetID(widget.get()), 0);
45 ASSERT_GT(cache->GetID(parent), 0);
46 ASSERT_GT(cache->GetID(child), 0);
47
48 // Removing the parent view should remove both the parent and child
49 // from the cache, but leave the widget.
50 widget->GetRootView()->RemoveChildView(parent);
51 ASSERT_GT(cache->GetID(widget.get()), 0);
52 ASSERT_EQ(-1, cache->GetID(parent));
53 ASSERT_EQ(-1, cache->GetID(child));
54 }
55
56 } // namespace test
57 } // namespace views
OLDNEW
« 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