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

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

Issue 2736573002: chromeos: Move files in //ash/common to //ash, part 2 (Closed)
Patch Set: 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
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 "ash/common/wm_window_user_data.h"
6
7 #include <memory>
8
9 #include "ash/common/test/ash_test.h"
10 #include "ash/common/wm_shell.h"
11 #include "ash/common/wm_window.h"
12 #include "ash/common/wm_window_user_data.h"
13 #include "base/memory/ptr_util.h"
14
15 namespace ash {
16 namespace {
17
18 // Class that sets a bool* to true from the destructor. Used to track
19 // destruction.
20 class Data {
21 public:
22 explicit Data(bool* delete_setter) : delete_setter_(delete_setter) {}
23 ~Data() { *delete_setter_ = true; }
24
25 private:
26 bool* delete_setter_;
27
28 DISALLOW_COPY_AND_ASSIGN(Data);
29 };
30
31 } // namespace
32
33 using WmWindowUserDataTest = AshTest;
34
35 // Verifies clear() deletes the data associated with a window.
36 TEST_F(WmWindowUserDataTest, ClearDestroys) {
37 WmWindowUserData<Data> user_data;
38 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN,
39 ui::LAYER_NOT_DRAWN);
40 bool data_deleted = false;
41 user_data.Set(window, base::MakeUnique<Data>(&data_deleted));
42 EXPECT_FALSE(data_deleted);
43 user_data.clear();
44 EXPECT_TRUE(data_deleted);
45 window->Destroy();
46 }
47
48 // Verifies Set() called with an existing window replaces the existing data.
49 TEST_F(WmWindowUserDataTest, ReplaceDestroys) {
50 WmWindowUserData<Data> user_data;
51 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN,
52 ui::LAYER_NOT_DRAWN);
53 bool data1_deleted = false;
54 user_data.Set(window, base::MakeUnique<Data>(&data1_deleted));
55 EXPECT_FALSE(data1_deleted);
56 bool data2_deleted = false;
57 user_data.Set(window, base::MakeUnique<Data>(&data2_deleted));
58 EXPECT_TRUE(data1_deleted);
59 EXPECT_FALSE(data2_deleted);
60 ASSERT_EQ(1u, user_data.GetWindows().size());
61 EXPECT_EQ(window, *user_data.GetWindows().begin());
62 window->Destroy();
63 EXPECT_TRUE(data2_deleted);
64 EXPECT_TRUE(user_data.GetWindows().empty());
65 }
66
67 // Verifies Set() with null deletes existing data.
68 TEST_F(WmWindowUserDataTest, NullClears) {
69 WmWindowUserData<Data> user_data;
70 WmWindow* window = WmShell::Get()->NewWindow(ui::wm::WINDOW_TYPE_UNKNOWN,
71 ui::LAYER_NOT_DRAWN);
72 bool data1_deleted = false;
73 user_data.Set(window, base::MakeUnique<Data>(&data1_deleted));
74 EXPECT_FALSE(data1_deleted);
75 user_data.Set(window, nullptr);
76 EXPECT_TRUE(data1_deleted);
77 EXPECT_TRUE(user_data.GetWindows().empty());
78 window->Destroy();
79 }
80
81 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm_window_user_data.h ('k') | ash/content/display/screen_orientation_controller_chromeos_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698