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

Side by Side Diff: ash/display/resolution_notification_controller_unittest.cc

Issue 22960004: Fix the crash bug of close button for the resolution change notification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix the new test Created 7 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « ash/display/resolution_notification_controller.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/display/resolution_notification_controller.h" 5 #include "ash/display/resolution_notification_controller.h"
6 6
7 #include "ash/display/display_manager.h" 7 #include "ash/display/display_manager.h"
8 #include "ash/screen_ash.h" 8 #include "ash/screen_ash.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 void ClickOnNotification() { 61 void ClickOnNotification() {
62 message_center::MessageCenter::Get()->ClickOnNotification( 62 message_center::MessageCenter::Get()->ClickOnNotification(
63 ResolutionNotificationController::kNotificationId); 63 ResolutionNotificationController::kNotificationId);
64 } 64 }
65 65
66 void ClickOnNotificationButton(int index) { 66 void ClickOnNotificationButton(int index) {
67 message_center::MessageCenter::Get()->ClickOnNotificationButton( 67 message_center::MessageCenter::Get()->ClickOnNotificationButton(
68 ResolutionNotificationController::kNotificationId, index); 68 ResolutionNotificationController::kNotificationId, index);
69 } 69 }
70 70
71 void CloseNotification() {
72 message_center::MessageCenter::Get()->RemoveNotification(
73 ResolutionNotificationController::kNotificationId, true /* by_user */);
74 }
75
71 bool IsNotificationVisible() { 76 bool IsNotificationVisible() {
72 return message_center::MessageCenter::Get()->HasNotification( 77 return message_center::MessageCenter::Get()->HasNotification(
73 ResolutionNotificationController::kNotificationId); 78 ResolutionNotificationController::kNotificationId);
74 } 79 }
75 80
76 void TickTimer() { 81 void TickTimer() {
77 controller()->OnTimerTick(); 82 controller()->OnTimerTick();
78 } 83 }
79 84
80 ResolutionNotificationController* controller() { 85 ResolutionNotificationController* controller() {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 EXPECT_TRUE(IsNotificationVisible()); 192 EXPECT_TRUE(IsNotificationVisible());
188 193
189 EXPECT_TRUE(controller()->DoesNotificationTimeout()); 194 EXPECT_TRUE(controller()->DoesNotificationTimeout());
190 ClickOnNotificationButton(1); 195 ClickOnNotificationButton(1);
191 EXPECT_FALSE(IsNotificationVisible()); 196 EXPECT_FALSE(IsNotificationVisible());
192 EXPECT_EQ(1, accept_count()); 197 EXPECT_EQ(1, accept_count());
193 EXPECT_FALSE(display_manager->GetSelectedResolutionForDisplayId( 198 EXPECT_FALSE(display_manager->GetSelectedResolutionForDisplayId(
194 display.id(), &resolution)); 199 display.id(), &resolution));
195 } 200 }
196 201
202 TEST_F(ResolutionNotificationControllerTest, Close) {
203 if (!SupportsMultipleDisplays())
204 return;
205
206 UpdateDisplay("100x100,150x150#150x150|200x200");
207 int64 id2 = ash::ScreenAsh::GetSecondaryDisplay().id();
208 ash::internal::DisplayManager* display_manager =
209 ash::Shell::GetInstance()->display_manager();
210 ASSERT_EQ(0, accept_count());
211 EXPECT_FALSE(IsNotificationVisible());
212
213 // Changes the resolution and apply the result.
214 SetDisplayResolutionAndNotify(
215 ScreenAsh::GetSecondaryDisplay(), gfx::Size(200, 200));
216 EXPECT_TRUE(IsNotificationVisible());
217 EXPECT_FALSE(controller()->DoesNotificationTimeout());
218 gfx::Size resolution;
219 EXPECT_TRUE(
220 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution));
221 EXPECT_EQ("200x200", resolution.ToString());
222
223 // Close the notification (imitates clicking [x] button). Also verifies if
224 // this does not cause a crash. See crbug.com/271784
225 CloseNotification();
226 RunAllPendingInMessageLoop();
227 EXPECT_FALSE(IsNotificationVisible());
228 EXPECT_EQ(1, accept_count());
229 }
230
197 TEST_F(ResolutionNotificationControllerTest, Timeout) { 231 TEST_F(ResolutionNotificationControllerTest, Timeout) {
198 if (!SupportsMultipleDisplays()) 232 if (!SupportsMultipleDisplays())
199 return; 233 return;
200 234
201 UpdateDisplay("300x300#300x300|200x200"); 235 UpdateDisplay("300x300#300x300|200x200");
202 const gfx::Display& display = ash::Shell::GetScreen()->GetPrimaryDisplay(); 236 const gfx::Display& display = ash::Shell::GetScreen()->GetPrimaryDisplay();
203 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); 237 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200));
204 238
205 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { 239 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) {
206 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " 240 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after "
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 ClickOnNotificationButton(0); 305 ClickOnNotificationButton(0);
272 RunAllPendingInMessageLoop(); 306 RunAllPendingInMessageLoop();
273 EXPECT_FALSE(IsNotificationVisible()); 307 EXPECT_FALSE(IsNotificationVisible());
274 EXPECT_EQ(0, accept_count()); 308 EXPECT_EQ(0, accept_count());
275 EXPECT_FALSE( 309 EXPECT_FALSE(
276 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); 310 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution));
277 } 311 }
278 312
279 } // namespace internal 313 } // namespace internal
280 } // namespace ash 314 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/resolution_notification_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698