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

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: cleanup 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
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 void ClickOnNotification() { 59 void ClickOnNotification() {
60 message_center::MessageCenter::Get()->ClickOnNotification( 60 message_center::MessageCenter::Get()->ClickOnNotification(
61 ResolutionNotificationController::kNotificationId); 61 ResolutionNotificationController::kNotificationId);
62 } 62 }
63 63
64 void ClickOnNotificationButton(int index) { 64 void ClickOnNotificationButton(int index) {
65 message_center::MessageCenter::Get()->ClickOnNotificationButton( 65 message_center::MessageCenter::Get()->ClickOnNotificationButton(
66 ResolutionNotificationController::kNotificationId, index); 66 ResolutionNotificationController::kNotificationId, index);
67 } 67 }
68 68
69 void CloseNotification() {
70 message_center::MessageCenter::Get()->RemoveNotification(
71 ResolutionNotificationController::kNotificationId, true /* by_user */);
72 }
73
69 bool IsNotificationVisible() { 74 bool IsNotificationVisible() {
70 return message_center::MessageCenter::Get()->HasNotification( 75 return message_center::MessageCenter::Get()->HasNotification(
71 ResolutionNotificationController::kNotificationId); 76 ResolutionNotificationController::kNotificationId);
72 } 77 }
73 78
74 void TickTimer() { 79 void TickTimer() {
75 controller()->OnTimerTick(); 80 controller()->OnTimerTick();
76 } 81 }
77 82
78 ResolutionNotificationController* controller() { 83 ResolutionNotificationController* controller() {
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 192
188 EXPECT_TRUE(controller()->DoesNotificationTimeout()); 193 EXPECT_TRUE(controller()->DoesNotificationTimeout());
189 ClickOnNotificationButton(1); 194 ClickOnNotificationButton(1);
190 EXPECT_FALSE(IsNotificationVisible()); 195 EXPECT_FALSE(IsNotificationVisible());
191 EXPECT_EQ(1, accept_count()); 196 EXPECT_EQ(1, accept_count());
192 EXPECT_TRUE(display_manager->GetSelectedResolutionForDisplayId( 197 EXPECT_TRUE(display_manager->GetSelectedResolutionForDisplayId(
193 display.id(), &resolution)); 198 display.id(), &resolution));
194 EXPECT_EQ("100x100", resolution.ToString()); 199 EXPECT_EQ("100x100", resolution.ToString());
195 } 200 }
196 201
202 TEST_F(ResolutionNotificationControllerTest, Close) {
203 if (!SupportsMultipleDisplays())
204 return;
205
206 UpdateDisplay("100x100,150x150");
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("100x100"); 235 UpdateDisplay("100x100");
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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 RunAllPendingInMessageLoop(); 308 RunAllPendingInMessageLoop();
275 EXPECT_FALSE(IsNotificationVisible()); 309 EXPECT_FALSE(IsNotificationVisible());
276 EXPECT_EQ(0, accept_count()); 310 EXPECT_EQ(0, accept_count());
277 EXPECT_TRUE( 311 EXPECT_TRUE(
278 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution)); 312 display_manager->GetSelectedResolutionForDisplayId(id2, &resolution));
279 EXPECT_EQ("150x150", resolution.ToString()); 313 EXPECT_EQ("150x150", resolution.ToString());
280 } 314 }
281 315
282 } // namespace internal 316 } // namespace internal
283 } // namespace ash 317 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698