summaryrefslogtreecommitdiffstats
path: root/mash/wm/layout_manager_unittest.cc
blob: 1b6b2d08265973a874eafcade290efed62df99a2 (plain)
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
// Copyright 2015 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 "mash/wm/layout_manager.h"

#include "base/macros.h"
#include "components/mus/public/cpp/tests/test_window.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace mash {
namespace wm {

class TestLayoutManager : public LayoutManager {
 public:
  explicit TestLayoutManager(mus::Window* window)
      : LayoutManager(window), layout_called_(false) {}
  ~TestLayoutManager() override {}

  bool GetAndResetLayoutCalled() {
    bool was_layout_called = layout_called_;
    layout_called_ = false;
    return was_layout_called;
  }

 private:
  // LayoutManager:
  void LayoutWindow(mus::Window* window) override {
    layout_called_ = true;
  }

  bool layout_called_;

  DISALLOW_COPY_AND_ASSIGN(TestLayoutManager);
};

// Tests that owning window can be destroyed before the layout manager.
TEST(LayoutManagerTest, OwningWindowDestroyedFirst) {
  scoped_ptr<mus::TestWindow> parent(new mus::TestWindow(1));
  mus::TestWindow child(2);
  TestLayoutManager layout_manager(parent.get());
  parent->AddChild(&child);
  EXPECT_TRUE(layout_manager.GetAndResetLayoutCalled());
  parent.reset();
  child.SetBounds(gfx::Rect(100, 200));
}

// Tests that the layout manager can be destroyed before the owning window.
TEST(LayoutManagerTest, LayoutManagerDestroyedFirst) {
  mus::TestWindow parent(1);
  mus::TestWindow child(2);
  scoped_ptr<TestLayoutManager> layout_manager(new TestLayoutManager(&parent));
  parent.AddChild(&child);
  EXPECT_TRUE(layout_manager->GetAndResetLayoutCalled());

  parent.SetBounds(gfx::Rect(100, 200));
  EXPECT_TRUE(layout_manager->GetAndResetLayoutCalled());

  layout_manager.reset();
  parent.SetBounds(gfx::Rect(200, 100));
}

}  // namespace wm
}  // namespace mash