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

Side by Side Diff: mojo/services/view_manager/server_view_drawn_tracker_unittest.cc

Issue 1092033003: Pulls display related changes from mojo to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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 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.
4
5 #include "mojo/services/view_manager/server_view_drawn_tracker.h"
6
7 #include "mojo/services/view_manager/server_view.h"
8 #include "mojo/services/view_manager/server_view_drawn_tracker_observer.h"
9 #include "mojo/services/view_manager/test_server_view_delegate.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11
12 namespace view_manager {
13 namespace {
14
15 class TestServerViewDrawnTrackerObserver
16 : public ServerViewDrawnTrackerObserver {
17 public:
18 TestServerViewDrawnTrackerObserver()
19 : change_count_(0u),
20 ancestor_(nullptr),
21 view_(nullptr),
22 is_drawn_(false) {}
23
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_; }
29
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;
39 }
40
41 size_t change_count_;
42 const ServerView* ancestor_;
43 const ServerView* view_;
44 bool is_drawn_;
45
46 DISALLOW_COPY_AND_ASSIGN(TestServerViewDrawnTrackerObserver);
47 };
48
49 } // namespace
50
51 TEST(ServerViewDrawnTrackerTest, ChangeBecauseOfDeletionAndVisibility) {
52 TestServerViewDelegate server_view_delegate;
53 scoped_ptr<ServerView> view(new ServerView(&server_view_delegate, ViewId()));
54 TestServerViewDrawnTrackerObserver drawn_observer;
55 ServerViewDrawnTracker tracker(view.get(), view.get(), &drawn_observer);
56 view->SetVisible(true);
57 EXPECT_EQ(1u, drawn_observer.change_count());
58 EXPECT_EQ(view.get(), drawn_observer.view());
59 EXPECT_EQ(nullptr, drawn_observer.ancestor());
60 EXPECT_TRUE(drawn_observer.is_drawn());
61 drawn_observer.clear_change_count();
62
63 view->SetVisible(false);
64 EXPECT_EQ(1u, drawn_observer.change_count());
65 EXPECT_EQ(view.get(), drawn_observer.view());
66 EXPECT_EQ(nullptr, drawn_observer.ancestor());
67 EXPECT_FALSE(drawn_observer.is_drawn());
68 drawn_observer.clear_change_count();
69
70 view->SetVisible(true);
71 EXPECT_EQ(1u, drawn_observer.change_count());
72 EXPECT_EQ(view.get(), drawn_observer.view());
73 EXPECT_EQ(nullptr, drawn_observer.ancestor());
74 EXPECT_TRUE(drawn_observer.is_drawn());
75 drawn_observer.clear_change_count();
76
77 view.reset();
78 EXPECT_EQ(1u, drawn_observer.change_count());
79 EXPECT_EQ(view.get(), drawn_observer.view());
80 EXPECT_EQ(nullptr, drawn_observer.ancestor());
81 EXPECT_FALSE(drawn_observer.is_drawn());
82 }
83
84 TEST(ServerViewDrawnTrackerTest, ChangeBecauseOfRemovingFromRoot) {
85 TestServerViewDelegate server_view_delegate;
86 ServerView root(&server_view_delegate, ViewId());
87 root.SetVisible(true);
88 ServerView child(&server_view_delegate, ViewId());
89 child.SetVisible(true);
90 root.Add(&child);
91
92 TestServerViewDrawnTrackerObserver drawn_observer;
93 ServerViewDrawnTracker tracker(&root, &child, &drawn_observer);
94 root.Remove(&child);
95 EXPECT_EQ(1u, drawn_observer.change_count());
96 EXPECT_EQ(&child, drawn_observer.view());
97 EXPECT_EQ(&root, drawn_observer.ancestor());
98 EXPECT_FALSE(drawn_observer.is_drawn());
99 drawn_observer.clear_change_count();
100
101 root.Add(&child);
102 EXPECT_EQ(1u, drawn_observer.change_count());
103 EXPECT_EQ(&child, drawn_observer.view());
104 EXPECT_EQ(nullptr, drawn_observer.ancestor());
105 EXPECT_TRUE(drawn_observer.is_drawn());
106 }
107
108 TEST(ServerViewDrawnTrackerTest, ChangeBecauseOfRemovingAncestorFromRoot) {
109 TestServerViewDelegate server_view_delegate;
110 ServerView root(&server_view_delegate, ViewId());
111 root.SetVisible(true);
112 ServerView child(&server_view_delegate, ViewId());
113 child.SetVisible(true);
114 root.Add(&child);
115
116 ServerView child_child(&server_view_delegate, ViewId());
117 child_child.SetVisible(true);
118 child.Add(&child_child);
119
120 TestServerViewDrawnTrackerObserver drawn_observer;
121 ServerViewDrawnTracker tracker(&root, &child_child, &drawn_observer);
122 root.Remove(&child);
123 EXPECT_EQ(1u, drawn_observer.change_count());
124 EXPECT_EQ(&child_child, drawn_observer.view());
125 EXPECT_EQ(&root, drawn_observer.ancestor());
126 EXPECT_FALSE(drawn_observer.is_drawn());
127 drawn_observer.clear_change_count();
128
129 root.Add(&child_child);
130 EXPECT_EQ(1u, drawn_observer.change_count());
131 EXPECT_EQ(&child_child, drawn_observer.view());
132 EXPECT_EQ(nullptr, drawn_observer.ancestor());
133 EXPECT_TRUE(drawn_observer.is_drawn());
134 }
135
136 } // namespace view_manager
OLDNEW
« no previous file with comments | « mojo/services/view_manager/server_view_drawn_tracker_observer.h ('k') | mojo/services/view_manager/server_view_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698