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/system/toast/toast_manager_unittest.cc

Issue 2506583005: Hide dismiss button on toast when doing partial screenshot using stylus tools. (Closed)
Patch Set: Add DCHECK Created 4 years, 1 month 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/system/toast/toast_overlay.cc ('k') | no next file » | 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/shelf/shelf_constants.h" 5 #include "ash/common/shelf/shelf_constants.h"
6 #include "ash/common/shelf/wm_shelf.h" 6 #include "ash/common/shelf/wm_shelf.h"
7 #include "ash/common/system/toast/toast_manager.h" 7 #include "ash/common/system/toast/toast_manager.h"
8 #include "ash/common/wm/wm_screen_util.h" 8 #include "ash/common/wm/wm_screen_util.h"
9 #include "ash/common/wm_shell.h" 9 #include "ash/common/wm_shell.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 ToastOverlay* GetCurrentOverlay() { 48 ToastOverlay* GetCurrentOverlay() {
49 return manager_->GetCurrentOverlayForTesting(); 49 return manager_->GetCurrentOverlayForTesting();
50 } 50 }
51 51
52 views::Widget* GetCurrentWidget() { 52 views::Widget* GetCurrentWidget() {
53 ToastOverlay* overlay = GetCurrentOverlay(); 53 ToastOverlay* overlay = GetCurrentOverlay();
54 return overlay ? overlay->widget_for_testing() : nullptr; 54 return overlay ? overlay->widget_for_testing() : nullptr;
55 } 55 }
56 56
57 ToastOverlayButton* GetDismissButton() {
58 ToastOverlay* overlay = GetCurrentOverlay();
59 DCHECK(overlay);
60 return overlay->dismiss_button_for_testing();
61 }
62
57 base::string16 GetCurrentText() { 63 base::string16 GetCurrentText() {
58 ToastOverlay* overlay = GetCurrentOverlay(); 64 ToastOverlay* overlay = GetCurrentOverlay();
59 return overlay ? overlay->text_ : base::string16(); 65 return overlay ? overlay->text_ : base::string16();
60 } 66 }
61 67
62 base::string16 GetCurrentDismissText() { 68 base::Optional<base::string16> GetCurrentDismissText() {
63 ToastOverlay* overlay = GetCurrentOverlay(); 69 ToastOverlay* overlay = GetCurrentOverlay();
64 return overlay ? overlay->dismiss_text_ : base::string16(); 70 return overlay ? overlay->dismiss_text_ : base::string16();
65 } 71 }
66 72
67 void ClickDismissButton() { 73 void ClickDismissButton() {
68 ToastOverlay* overlay = GetCurrentOverlay(); 74 ToastOverlay* overlay = GetCurrentOverlay();
69 if (overlay) 75 if (overlay)
70 overlay->ClickDismissButtonForTesting(DummyEvent()); 76 overlay->ClickDismissButtonForTesting(DummyEvent());
71 } 77 }
72 78
73 std::string ShowToast(const std::string& text, int32_t duration) { 79 std::string ShowToast(const std::string& text, int32_t duration) {
74 std::string id = "TOAST_ID_" + base::UintToString(serial_++); 80 std::string id = "TOAST_ID_" + base::UintToString(serial_++);
75 manager()->Show( 81 manager()->Show(
76 ToastData(id, base::ASCIIToUTF16(text), duration, base::string16())); 82 ToastData(id, base::ASCIIToUTF16(text), duration, base::string16()));
77 return id; 83 return id;
78 } 84 }
79 85
80 std::string ShowToastWithDismiss(const std::string& text, 86 std::string ShowToastWithDismiss(
81 int32_t duration, 87 const std::string& text,
82 const std::string& dismiss_text) { 88 int32_t duration,
89 const base::Optional<std::string>& dismiss_text) {
90 base::Optional<base::string16> localized_dismiss;
91 if (dismiss_text.has_value())
92 localized_dismiss = base::ASCIIToUTF16(dismiss_text.value());
93
83 std::string id = "TOAST_ID_" + base::UintToString(serial_++); 94 std::string id = "TOAST_ID_" + base::UintToString(serial_++);
84 manager()->Show(ToastData(id, base::ASCIIToUTF16(text), duration, 95 manager()->Show(
85 base::ASCIIToUTF16(dismiss_text))); 96 ToastData(id, base::ASCIIToUTF16(text), duration, localized_dismiss));
86 return id; 97 return id;
87 } 98 }
88 99
89 void CancelToast(const std::string& id) { manager()->Cancel(id); } 100 void CancelToast(const std::string& id) { manager()->Cancel(id); }
90 101
91 private: 102 private:
92 ToastManager* manager_ = nullptr; 103 ToastManager* manager_ = nullptr;
93 unsigned int serial_ = 0; 104 unsigned int serial_ = 0;
94 105
95 DISALLOW_COPY_AND_ASSIGN(ToastManagerTest); 106 DISALLOW_COPY_AND_ASSIGN(ToastManagerTest);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 // Try to close it during animation. 141 // Try to close it during animation.
131 ClickDismissButton(); 142 ClickDismissButton();
132 143
133 while (GetCurrentWidget()->GetLayer()->GetAnimator()->is_animating()) 144 while (GetCurrentWidget()->GetLayer()->GetAnimator()->is_animating())
134 base::RunLoop().RunUntilIdle(); 145 base::RunLoop().RunUntilIdle();
135 146
136 // Toast isn't closed. 147 // Toast isn't closed.
137 EXPECT_TRUE(GetCurrentOverlay() != nullptr); 148 EXPECT_TRUE(GetCurrentOverlay() != nullptr);
138 } 149 }
139 150
151 TEST_F(ToastManagerTest, NullMessageHasNoDismissButton) {
152 ShowToastWithDismiss("DUMMY", 10, base::Optional<std::string>());
153 base::RunLoop().RunUntilIdle();
154 EXPECT_FALSE(GetDismissButton());
155 }
156
140 TEST_F(ToastManagerTest, QueueMessage) { 157 TEST_F(ToastManagerTest, QueueMessage) {
141 ShowToast("DUMMY1", 10); 158 ShowToast("DUMMY1", 10);
142 ShowToast("DUMMY2", 10); 159 ShowToast("DUMMY2", 10);
143 ShowToast("DUMMY3", 10); 160 ShowToast("DUMMY3", 10);
144 161
145 EXPECT_EQ(1, GetToastSerial()); 162 EXPECT_EQ(1, GetToastSerial());
146 EXPECT_EQ(base::ASCIIToUTF16("DUMMY1"), GetCurrentText()); 163 EXPECT_EQ(base::ASCIIToUTF16("DUMMY1"), GetCurrentText());
147 164
148 while (GetToastSerial() != 2) 165 while (GetToastSerial() != 2)
149 base::RunLoop().RunUntilIdle(); 166 base::RunLoop().RunUntilIdle();
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 EXPECT_EQ(base::ASCIIToUTF16("TEXT3"), GetCurrentText()); 298 EXPECT_EQ(base::ASCIIToUTF16("TEXT3"), GetCurrentText());
282 // Cancel the shown toast. 299 // Cancel the shown toast.
283 CancelToast(id3); 300 CancelToast(id3);
284 // Confirm that the shown toast disappears. 301 // Confirm that the shown toast disappears.
285 EXPECT_FALSE(GetCurrentOverlay()); 302 EXPECT_FALSE(GetCurrentOverlay());
286 // Confirm that only 1 toast is shown. 303 // Confirm that only 1 toast is shown.
287 EXPECT_EQ(2, GetToastSerial()); 304 EXPECT_EQ(2, GetToastSerial());
288 } 305 }
289 306
290 } // namespace ash 307 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/toast/toast_overlay.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698