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

Side by Side Diff: ash/common/wm_window_user_data_unittest.cc

Issue 2733303004: Removes WmShell::NewWindow() (Closed)
Patch Set: merge and feedback Created 3 years, 9 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
« no previous file with comments | « ash/common/wm_shell.h ('k') | ash/mus/bridge/wm_shell_mus.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/common/wm_window_user_data.h" 5 #include "ash/common/wm_window_user_data.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/common/test/ash_test.h" 9 #include "ash/common/test/ash_test.h"
10 #include "ash/common/wm_shell.h" 10 #include "ash/common/wm_shell.h"
11 #include "ash/common/wm_window.h" 11 #include "ash/common/wm_window.h"
12 #include "ash/common/wm_window_user_data.h" 12 #include "ash/common/wm_window_user_data.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "ui/aura/window.h"
15 #include "ui/compositor/layer_type.h"
14 16
15 namespace ash { 17 namespace ash {
16 namespace { 18 namespace {
17 19
18 // Class that sets a bool* to true from the destructor. Used to track 20 // Class that sets a bool* to true from the destructor. Used to track
19 // destruction. 21 // destruction.
20 class Data { 22 class Data {
21 public: 23 public:
22 explicit Data(bool* delete_setter) : delete_setter_(delete_setter) {} 24 explicit Data(bool* delete_setter) : delete_setter_(delete_setter) {}
23 ~Data() { *delete_setter_ = true; } 25 ~Data() { *delete_setter_ = true; }
24 26
25 private: 27 private:
26 bool* delete_setter_; 28 bool* delete_setter_;
27 29
28 DISALLOW_COPY_AND_ASSIGN(Data); 30 DISALLOW_COPY_AND_ASSIGN(Data);
29 }; 31 };
30 32
31 } // namespace 33 } // namespace
32 34
33 using WmWindowUserDataTest = AshTest; 35 using WmWindowUserDataTest = AshTest;
34 36
35 // Verifies clear() deletes the data associated with a window. 37 // Verifies clear() deletes the data associated with a window.
36 TEST_F(WmWindowUserDataTest, ClearDestroys) { 38 TEST_F(WmWindowUserDataTest, ClearDestroys) {
37 WmWindowUserData<Data> user_data; 39 WmWindowUserData<Data> user_data;
38 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN, 40 std::unique_ptr<aura::Window> window(
39 ui::LAYER_NOT_DRAWN); 41 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_UNKNOWN));
42 window->Init(ui::LAYER_NOT_DRAWN);
40 bool data_deleted = false; 43 bool data_deleted = false;
41 user_data.Set(window, base::MakeUnique<Data>(&data_deleted)); 44 user_data.Set(WmWindow::Get(window.get()),
45 base::MakeUnique<Data>(&data_deleted));
42 EXPECT_FALSE(data_deleted); 46 EXPECT_FALSE(data_deleted);
43 user_data.clear(); 47 user_data.clear();
44 EXPECT_TRUE(data_deleted); 48 EXPECT_TRUE(data_deleted);
45 window->Destroy();
46 } 49 }
47 50
48 // Verifies Set() called with an existing window replaces the existing data. 51 // Verifies Set() called with an existing window replaces the existing data.
49 TEST_F(WmWindowUserDataTest, ReplaceDestroys) { 52 TEST_F(WmWindowUserDataTest, ReplaceDestroys) {
50 WmWindowUserData<Data> user_data; 53 WmWindowUserData<Data> user_data;
51 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN, 54 std::unique_ptr<aura::Window> window(
52 ui::LAYER_NOT_DRAWN); 55 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_UNKNOWN));
56 window->Init(ui::LAYER_NOT_DRAWN);
53 bool data1_deleted = false; 57 bool data1_deleted = false;
54 user_data.Set(window, base::MakeUnique<Data>(&data1_deleted)); 58 user_data.Set(WmWindow::Get(window.get()),
59 base::MakeUnique<Data>(&data1_deleted));
55 EXPECT_FALSE(data1_deleted); 60 EXPECT_FALSE(data1_deleted);
56 bool data2_deleted = false; 61 bool data2_deleted = false;
57 user_data.Set(window, base::MakeUnique<Data>(&data2_deleted)); 62 user_data.Set(WmWindow::Get(window.get()),
63 base::MakeUnique<Data>(&data2_deleted));
58 EXPECT_TRUE(data1_deleted); 64 EXPECT_TRUE(data1_deleted);
59 EXPECT_FALSE(data2_deleted); 65 EXPECT_FALSE(data2_deleted);
60 ASSERT_EQ(1u, user_data.GetWindows().size()); 66 ASSERT_EQ(1u, user_data.GetWindows().size());
61 EXPECT_EQ(window, *user_data.GetWindows().begin()); 67 EXPECT_EQ(WmWindow::Get(window.get()), *user_data.GetWindows().begin());
62 window->Destroy(); 68 window.reset();
63 EXPECT_TRUE(data2_deleted); 69 EXPECT_TRUE(data2_deleted);
64 EXPECT_TRUE(user_data.GetWindows().empty()); 70 EXPECT_TRUE(user_data.GetWindows().empty());
65 } 71 }
66 72
67 // Verifies Set() with null deletes existing data. 73 // Verifies Set() with null deletes existing data.
68 TEST_F(WmWindowUserDataTest, NullClears) { 74 TEST_F(WmWindowUserDataTest, NullClears) {
69 WmWindowUserData<Data> user_data; 75 WmWindowUserData<Data> user_data;
70 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN, 76 std::unique_ptr<aura::Window> window(
71 ui::LAYER_NOT_DRAWN); 77 base::MakeUnique<aura::Window>(nullptr, ui::wm::WINDOW_TYPE_UNKNOWN));
78 window->Init(ui::LAYER_NOT_DRAWN);
72 bool data1_deleted = false; 79 bool data1_deleted = false;
73 user_data.Set(window, base::MakeUnique<Data>(&data1_deleted)); 80 user_data.Set(WmWindow::Get(window.get()),
81 base::MakeUnique<Data>(&data1_deleted));
74 EXPECT_FALSE(data1_deleted); 82 EXPECT_FALSE(data1_deleted);
75 user_data.Set(window, nullptr); 83 user_data.Set(WmWindow::Get(window.get()), nullptr);
76 EXPECT_TRUE(data1_deleted); 84 EXPECT_TRUE(data1_deleted);
77 EXPECT_TRUE(user_data.GetWindows().empty()); 85 EXPECT_TRUE(user_data.GetWindows().empty());
78 window->Destroy();
79 } 86 }
80 87
81 } // namespace ash 88 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm_shell.h ('k') | ash/mus/bridge/wm_shell_mus.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698