Update mojo sdk to rev c02a28868825edfa57ab77947b8cb15e741c5598
[chromium-blink-merge.git] / components / view_manager / server_view_drawn_tracker_unittest.cc
blob45a0ecd5b03c519afef6a78ca42478ea4dc8f960
1 // Copyright 2015 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.
5 #include "components/view_manager/server_view_drawn_tracker.h"
7 #include "components/view_manager/server_view.h"
8 #include "components/view_manager/server_view_drawn_tracker_observer.h"
9 #include "components/view_manager/test_server_view_delegate.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 namespace view_manager {
13 namespace {
15 class TestServerViewDrawnTrackerObserver
16 : public ServerViewDrawnTrackerObserver {
17 public:
18 TestServerViewDrawnTrackerObserver()
19 : change_count_(0u),
20 ancestor_(nullptr),
21 view_(nullptr),
22 is_drawn_(false) {}
24 void clear_change_count() { change_count_ = 0u; }
25 size_t change_count() const { return change_count_; }
26 const ServerView* ancestor() const { return ancestor_; }
27 const ServerView* view() const { return view_; }
28 bool is_drawn() const { return is_drawn_; }
30 private:
31 // ServerViewDrawnTrackerObserver:
32 void OnDrawnStateChanged(ServerView* ancestor,
33 ServerView* view,
34 bool is_drawn) override {
35 change_count_++;
36 ancestor_ = ancestor;
37 view_ = view;
38 is_drawn_ = is_drawn;
41 size_t change_count_;
42 const ServerView* ancestor_;
43 const ServerView* view_;
44 bool is_drawn_;
46 DISALLOW_COPY_AND_ASSIGN(TestServerViewDrawnTrackerObserver);
49 } // namespace
51 TEST(ServerViewDrawnTrackerTest, ChangeBecauseOfDeletionAndVisibility) {
52 TestServerViewDelegate server_view_delegate;
53 scoped_ptr<ServerView> view(new ServerView(&server_view_delegate, ViewId()));
54 server_view_delegate.set_root_view(view.get());
55 TestServerViewDrawnTrackerObserver drawn_observer;
56 ServerViewDrawnTracker tracker(view.get(), &drawn_observer);
57 view->SetVisible(true);
58 EXPECT_EQ(1u, drawn_observer.change_count());
59 EXPECT_EQ(view.get(), drawn_observer.view());
60 EXPECT_EQ(nullptr, drawn_observer.ancestor());
61 EXPECT_TRUE(drawn_observer.is_drawn());
62 drawn_observer.clear_change_count();
64 view->SetVisible(false);
65 EXPECT_EQ(1u, drawn_observer.change_count());
66 EXPECT_EQ(view.get(), drawn_observer.view());
67 EXPECT_EQ(nullptr, drawn_observer.ancestor());
68 EXPECT_FALSE(drawn_observer.is_drawn());
69 drawn_observer.clear_change_count();
71 view->SetVisible(true);
72 EXPECT_EQ(1u, drawn_observer.change_count());
73 EXPECT_EQ(view.get(), drawn_observer.view());
74 EXPECT_EQ(nullptr, drawn_observer.ancestor());
75 EXPECT_TRUE(drawn_observer.is_drawn());
76 drawn_observer.clear_change_count();
78 view.reset();
79 EXPECT_EQ(1u, drawn_observer.change_count());
80 EXPECT_EQ(view.get(), drawn_observer.view());
81 EXPECT_EQ(nullptr, drawn_observer.ancestor());
82 EXPECT_FALSE(drawn_observer.is_drawn());
85 TEST(ServerViewDrawnTrackerTest, ChangeBecauseOfRemovingFromRoot) {
86 TestServerViewDelegate server_view_delegate;
87 ServerView root(&server_view_delegate, ViewId());
88 server_view_delegate.set_root_view(&root);
89 root.SetVisible(true);
90 ServerView child(&server_view_delegate, ViewId());
91 child.SetVisible(true);
92 root.Add(&child);
94 TestServerViewDrawnTrackerObserver drawn_observer;
95 ServerViewDrawnTracker tracker(&child, &drawn_observer);
96 root.Remove(&child);
97 EXPECT_EQ(1u, drawn_observer.change_count());
98 EXPECT_EQ(&child, drawn_observer.view());
99 EXPECT_EQ(&root, drawn_observer.ancestor());
100 EXPECT_FALSE(drawn_observer.is_drawn());
101 drawn_observer.clear_change_count();
103 root.Add(&child);
104 EXPECT_EQ(1u, drawn_observer.change_count());
105 EXPECT_EQ(&child, drawn_observer.view());
106 EXPECT_EQ(nullptr, drawn_observer.ancestor());
107 EXPECT_TRUE(drawn_observer.is_drawn());
110 TEST(ServerViewDrawnTrackerTest, ChangeBecauseOfRemovingAncestorFromRoot) {
111 TestServerViewDelegate server_view_delegate;
112 ServerView root(&server_view_delegate, ViewId());
113 server_view_delegate.set_root_view(&root);
114 root.SetVisible(true);
115 ServerView child(&server_view_delegate, ViewId());
116 child.SetVisible(true);
117 root.Add(&child);
119 ServerView child_child(&server_view_delegate, ViewId());
120 child_child.SetVisible(true);
121 child.Add(&child_child);
123 TestServerViewDrawnTrackerObserver drawn_observer;
124 ServerViewDrawnTracker tracker(&child_child, &drawn_observer);
125 root.Remove(&child);
126 EXPECT_EQ(1u, drawn_observer.change_count());
127 EXPECT_EQ(&child_child, drawn_observer.view());
128 EXPECT_EQ(&root, drawn_observer.ancestor());
129 EXPECT_FALSE(drawn_observer.is_drawn());
130 drawn_observer.clear_change_count();
132 root.Add(&child_child);
133 EXPECT_EQ(1u, drawn_observer.change_count());
134 EXPECT_EQ(&child_child, drawn_observer.view());
135 EXPECT_EQ(nullptr, drawn_observer.ancestor());
136 EXPECT_TRUE(drawn_observer.is_drawn());
139 } // namespace view_manager