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

Side by Side Diff: ash/accelerators/accelerator_controller_unittest.cc

Issue 23122003: Fix crash on signing out with exit warning bubble open. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 | « no previous file | ash/accelerators/exit_warning_handler.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/accelerators/accelerator_controller.h" 5 #include "ash/accelerators/accelerator_controller.h"
6 #include "ash/accelerators/accelerator_table.h" 6 #include "ash/accelerators/accelerator_table.h"
7 #include "ash/caps_lock_delegate.h" 7 #include "ash/caps_lock_delegate.h"
8 #include "ash/display/display_manager.h" 8 #include "ash/display/display_manager.h"
9 #include "ash/ime_control_delegate.h" 9 #include "ash/ime_control_delegate.h"
10 #include "ash/screenshot_delegate.h" 10 #include "ash/screenshot_delegate.h"
(...skipping 17 matching lines...) Expand all
28 #include <X11/Xlib.h> 28 #include <X11/Xlib.h>
29 #include "ui/base/x/x11_util.h" 29 #include "ui/base/x/x11_util.h"
30 #endif 30 #endif
31 31
32 namespace ash { 32 namespace ash {
33 33
34 namespace { 34 namespace {
35 35
36 class TestTarget : public ui::AcceleratorTarget { 36 class TestTarget : public ui::AcceleratorTarget {
37 public: 37 public:
38 TestTarget() : accelerator_pressed_count_(0) {}; 38 TestTarget() : accelerator_pressed_count_(0) {}
39 virtual ~TestTarget() {}; 39 virtual ~TestTarget() {}
40 40
41 int accelerator_pressed_count() const { 41 int accelerator_pressed_count() const {
42 return accelerator_pressed_count_; 42 return accelerator_pressed_count_;
43 } 43 }
44 44
45 void set_accelerator_pressed_count(int accelerator_pressed_count) { 45 void set_accelerator_pressed_count(int accelerator_pressed_count) {
46 accelerator_pressed_count_ = accelerator_pressed_count; 46 accelerator_pressed_count_ = accelerator_pressed_count;
47 } 47 }
48 48
49 // Overridden from ui::AcceleratorTarget: 49 // Overridden from ui::AcceleratorTarget:
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 291 }
292 292
293 bool TestTarget::CanHandleAccelerators() const { 293 bool TestTarget::CanHandleAccelerators() const {
294 return true; 294 return true;
295 } 295 }
296 296
297 } // namespace 297 } // namespace
298 298
299 class AcceleratorControllerTest : public test::AshTestBase { 299 class AcceleratorControllerTest : public test::AshTestBase {
300 public: 300 public:
301 AcceleratorControllerTest() {}; 301 AcceleratorControllerTest() {}
302 virtual ~AcceleratorControllerTest() {}; 302 virtual ~AcceleratorControllerTest() {}
303 303
304 protected: 304 protected:
305 void EnableInternalDisplay() { 305 void EnableInternalDisplay() {
306 test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()). 306 test::DisplayManagerTestApi(Shell::GetInstance()->display_manager()).
307 SetFirstDisplayAsInternalDisplay(); 307 SetFirstDisplayAsInternalDisplay();
308 } 308 }
309 309
310 static AcceleratorController* GetController(); 310 static AcceleratorController* GetController();
311 static bool ProcessWithContext(const ui::Accelerator& accelerator); 311 static bool ProcessWithContext(const ui::Accelerator& accelerator);
312 312
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 release.set_type(ui::ET_KEY_RELEASED); 353 release.set_type(ui::ET_KEY_RELEASED);
354 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); 354 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest();
355 ASSERT_TRUE(!!ewh); 355 ASSERT_TRUE(!!ewh);
356 StubForTest(ewh); 356 StubForTest(ewh);
357 EXPECT_TRUE(is_idle(ewh)); 357 EXPECT_TRUE(is_idle(ewh));
358 EXPECT_FALSE(is_ui_shown(ewh)); 358 EXPECT_FALSE(is_ui_shown(ewh));
359 EXPECT_TRUE(ProcessWithContext(press)); 359 EXPECT_TRUE(ProcessWithContext(press));
360 EXPECT_FALSE(ProcessWithContext(release)); 360 EXPECT_FALSE(ProcessWithContext(release));
361 EXPECT_FALSE(is_idle(ewh)); 361 EXPECT_FALSE(is_idle(ewh));
362 EXPECT_TRUE(is_ui_shown(ewh)); 362 EXPECT_TRUE(is_ui_shown(ewh));
363 EXPECT_TRUE(ProcessWithContext(press)); // second press before timer. 363 EXPECT_TRUE(ProcessWithContext(press)); // second press before timer.
364 EXPECT_FALSE(ProcessWithContext(release)); 364 EXPECT_FALSE(ProcessWithContext(release));
365 SimulateTimerExpired(ewh); 365 SimulateTimerExpired(ewh);
366 EXPECT_TRUE(is_exiting(ewh)); 366 EXPECT_TRUE(is_exiting(ewh));
367 EXPECT_FALSE(is_ui_shown(ewh)); 367 EXPECT_FALSE(is_ui_shown(ewh));
368 Reset(ewh); 368 Reset(ewh);
369 } 369 }
370 370
371 // Single press of exit shortcut before timer => idle 371 // Single press of exit shortcut before timer => idle
372 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestSinglePress) { 372 TEST_F(AcceleratorControllerTest, ExitWarningHandlerTestSinglePress) {
373 ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN); 373 ui::Accelerator press(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN);
374 ui::Accelerator release(press); 374 ui::Accelerator release(press);
375 release.set_type(ui::ET_KEY_RELEASED); 375 release.set_type(ui::ET_KEY_RELEASED);
376 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); 376 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest();
377 ASSERT_TRUE(!!ewh); 377 ASSERT_TRUE(!!ewh);
378 StubForTest(ewh); 378 StubForTest(ewh);
379 EXPECT_TRUE(is_idle(ewh)); 379 EXPECT_TRUE(is_idle(ewh));
380 EXPECT_FALSE(is_ui_shown(ewh)); 380 EXPECT_FALSE(is_ui_shown(ewh));
381 EXPECT_TRUE(ProcessWithContext(press)); 381 EXPECT_TRUE(ProcessWithContext(press));
382 EXPECT_FALSE(ProcessWithContext(release)); 382 EXPECT_FALSE(ProcessWithContext(release));
383 EXPECT_FALSE(is_idle(ewh)); 383 EXPECT_FALSE(is_idle(ewh));
384 EXPECT_TRUE(is_ui_shown(ewh)); 384 EXPECT_TRUE(is_ui_shown(ewh));
385 SimulateTimerExpired(ewh); 385 SimulateTimerExpired(ewh);
386 EXPECT_TRUE(is_idle(ewh)); 386 EXPECT_TRUE(is_idle(ewh));
387 EXPECT_FALSE(is_ui_shown(ewh)); 387 EXPECT_FALSE(is_ui_shown(ewh));
388 Reset(ewh); 388 Reset(ewh);
389 } 389 }
390
391 // Shutdown ash with exit warning bubble open should not crash.
392 TEST_F(AcceleratorControllerTest, LingeringExitWarningBubble) {
393 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest();
394 ASSERT_TRUE(!!ewh);
395 StubForTest(ewh);
396
397 // Trigger once to show the bubble.
398 ewh->HandleAccelerator();
399 EXPECT_FALSE(is_idle(ewh));
400 EXPECT_TRUE(is_ui_shown(ewh));
401
402 // Exit ash and there should be no crash
403 }
390 #endif // !defined(OS_WIN) 404 #endif // !defined(OS_WIN)
391 405
392 TEST_F(AcceleratorControllerTest, Register) { 406 TEST_F(AcceleratorControllerTest, Register) {
393 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE); 407 const ui::Accelerator accelerator_a(ui::VKEY_A, ui::EF_NONE);
394 TestTarget target; 408 TestTarget target;
395 GetController()->Register(accelerator_a, &target); 409 GetController()->Register(accelerator_a, &target);
396 410
397 // The registered accelerator is processed. 411 // The registered accelerator is processed.
398 EXPECT_TRUE(ProcessWithContext(accelerator_a)); 412 EXPECT_TRUE(ProcessWithContext(accelerator_a));
399 EXPECT_EQ(1, target.accelerator_pressed_count()); 413 EXPECT_EQ(1, target.accelerator_pressed_count());
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 #endif 915 #endif
902 916
903 #if !defined(NDEBUG) 917 #if !defined(NDEBUG)
904 // ToggleDesktopBackgroundMode 918 // ToggleDesktopBackgroundMode
905 EXPECT_TRUE(ProcessWithContext( 919 EXPECT_TRUE(ProcessWithContext(
906 ui::Accelerator(ui::VKEY_B, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN))); 920 ui::Accelerator(ui::VKEY_B, ui::EF_CONTROL_DOWN | ui::EF_ALT_DOWN)));
907 #if !defined(OS_LINUX) 921 #if !defined(OS_LINUX)
908 // ToggleDesktopFullScreen (not implemented yet on Linux) 922 // ToggleDesktopFullScreen (not implemented yet on Linux)
909 EXPECT_TRUE(ProcessWithContext( 923 EXPECT_TRUE(ProcessWithContext(
910 ui::Accelerator(ui::VKEY_F11, ui::EF_CONTROL_DOWN))); 924 ui::Accelerator(ui::VKEY_F11, ui::EF_CONTROL_DOWN)));
911 #endif // OS_LINUX 925 #endif // OS_LINUX
912 #endif // !NDEBUG 926 #endif // !NDEBUG
913 927
914 #if !defined(OS_WIN) 928 #if !defined(OS_WIN)
915 // Exit 929 // Exit
916 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest(); 930 ExitWarningHandler* ewh = GetController()->GetExitWarningHandlerForTest();
917 ASSERT_TRUE(!!ewh); 931 ASSERT_TRUE(!!ewh);
918 StubForTest(ewh); 932 StubForTest(ewh);
919 EXPECT_TRUE(is_idle(ewh)); 933 EXPECT_TRUE(is_idle(ewh));
920 EXPECT_FALSE(is_ui_shown(ewh)); 934 EXPECT_FALSE(is_ui_shown(ewh));
921 EXPECT_TRUE(ProcessWithContext( 935 EXPECT_TRUE(ProcessWithContext(
922 ui::Accelerator(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); 936 ui::Accelerator(ui::VKEY_Q, ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)));
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 scoped_ptr<ScreenshotDelegate>(delegate).Pass()); 1241 scoped_ptr<ScreenshotDelegate>(delegate).Pass());
1228 EXPECT_EQ(0, delegate->handle_take_screenshot_count()); 1242 EXPECT_EQ(0, delegate->handle_take_screenshot_count());
1229 EXPECT_TRUE(ProcessWithContext( 1243 EXPECT_TRUE(ProcessWithContext(
1230 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN))); 1244 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, ui::EF_CONTROL_DOWN)));
1231 EXPECT_EQ(1, delegate->handle_take_screenshot_count()); 1245 EXPECT_EQ(1, delegate->handle_take_screenshot_count());
1232 EXPECT_TRUE(ProcessWithContext( 1246 EXPECT_TRUE(ProcessWithContext(
1233 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE))); 1247 ui::Accelerator(ui::VKEY_PRINT, ui::EF_NONE)));
1234 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); 1248 EXPECT_EQ(2, delegate->handle_take_screenshot_count());
1235 EXPECT_TRUE(ProcessWithContext( 1249 EXPECT_TRUE(ProcessWithContext(
1236 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1, 1250 ui::Accelerator(ui::VKEY_MEDIA_LAUNCH_APP1,
1237 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN))); 1251 ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN)));
1238 EXPECT_EQ(2, delegate->handle_take_screenshot_count()); 1252 EXPECT_EQ(2, delegate->handle_take_screenshot_count());
1239 } 1253 }
1240 // Brightness 1254 // Brightness
1241 const ui::Accelerator brightness_down(ui::VKEY_BRIGHTNESS_DOWN, ui::EF_NONE); 1255 const ui::Accelerator brightness_down(ui::VKEY_BRIGHTNESS_DOWN, ui::EF_NONE);
1242 const ui::Accelerator brightness_up(ui::VKEY_BRIGHTNESS_UP, ui::EF_NONE); 1256 const ui::Accelerator brightness_up(ui::VKEY_BRIGHTNESS_UP, ui::EF_NONE);
1243 { 1257 {
1244 EXPECT_FALSE(ProcessWithContext(brightness_down)); 1258 EXPECT_FALSE(ProcessWithContext(brightness_down));
1245 EXPECT_FALSE(ProcessWithContext(brightness_up)); 1259 EXPECT_FALSE(ProcessWithContext(brightness_up));
1246 DummyBrightnessControlDelegate* delegate = 1260 DummyBrightnessControlDelegate* delegate =
1247 new DummyBrightnessControlDelegate(true); 1261 new DummyBrightnessControlDelegate(true);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 EXPECT_EQ(volume_down, delegate->last_accelerator()); 1334 EXPECT_EQ(volume_down, delegate->last_accelerator());
1321 EXPECT_EQ(0, delegate->handle_volume_up_count()); 1335 EXPECT_EQ(0, delegate->handle_volume_up_count());
1322 EXPECT_TRUE(ProcessWithContext(volume_up)); 1336 EXPECT_TRUE(ProcessWithContext(volume_up));
1323 EXPECT_EQ(1, delegate->handle_volume_up_count()); 1337 EXPECT_EQ(1, delegate->handle_volume_up_count());
1324 EXPECT_EQ(volume_up, delegate->last_accelerator()); 1338 EXPECT_EQ(volume_up, delegate->last_accelerator());
1325 } 1339 }
1326 } 1340 }
1327 #endif 1341 #endif
1328 1342
1329 } // namespace ash 1343 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/accelerators/exit_warning_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698