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

Side by Side Diff: ash/tooltips/tooltip_controller_unittest.cc

Issue 10832194: aura: Fix crash when the aura window hosting a tooltip is destroyed. We fix (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 8 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/tooltips/tooltip_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 (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/display/display_controller.h"
5 #include "ash/shell.h" 6 #include "ash/shell.h"
6 #include "ash/test/ash_test_base.h" 7 #include "ash/test/ash_test_base.h"
7 #include "ash/tooltips/tooltip_controller.h" 8 #include "ash/tooltips/tooltip_controller.h"
8 #include "ash/wm/cursor_manager.h" 9 #include "ash/wm/cursor_manager.h"
9 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
10 #include "ui/aura/client/tooltip_client.h" 11 #include "ui/aura/client/tooltip_client.h"
11 #include "ui/aura/env.h" 12 #include "ui/aura/env.h"
12 #include "ui/aura/root_window.h" 13 #include "ui/aura/root_window.h"
13 #include "ui/aura/test/event_generator.h" 14 #include "ui/aura/test/event_generator.h"
14 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
(...skipping 21 matching lines...) Expand all
36 *tooltip = tooltip_text_; 37 *tooltip = tooltip_text_;
37 return true; 38 return true;
38 } 39 }
39 40
40 private: 41 private:
41 string16 tooltip_text_; 42 string16 tooltip_text_;
42 43
43 DISALLOW_COPY_AND_ASSIGN(TooltipTestView); 44 DISALLOW_COPY_AND_ASSIGN(TooltipTestView);
44 }; 45 };
45 46
46 views::Widget* CreateNewWidget() { 47 views::Widget* CreateNewWidgetWithBounds(const gfx::Rect& bounds) {
47 views::Widget* widget = new views::Widget; 48 views::Widget* widget = new views::Widget;
48 views::Widget::InitParams params; 49 views::Widget::InitParams params;
49 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; 50 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
50 params.accept_events = true; 51 params.accept_events = true;
51 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 52 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
52 params.parent = Shell::GetPrimaryRootWindow(); 53 params.parent_widget = NULL;
53 params.child = true; 54 params.child = true;
55 params.bounds = bounds;
54 widget->Init(params); 56 widget->Init(params);
55 widget->Show(); 57 widget->Show();
56 return widget; 58 return widget;
57 } 59 }
58 60
61 views::Widget* CreateNewWidget() {
62 return CreateNewWidgetWithBounds(gfx::Rect());
63 }
64
59 void AddViewToWidgetAndResize(views::Widget* widget, views::View* view) { 65 void AddViewToWidgetAndResize(views::Widget* widget, views::View* view) {
60 if (!widget->GetContentsView()) { 66 if (!widget->GetContentsView()) {
61 views::View* contents_view = new views::View; 67 views::View* contents_view = new views::View;
62 widget->SetContentsView(contents_view); 68 widget->SetContentsView(contents_view);
63 } 69 }
64 70
65 views::View* contents_view = widget->GetContentsView(); 71 views::View* contents_view = widget->GetContentsView();
66 contents_view->AddChildView(view); 72 contents_view->AddChildView(view);
67 view->SetBounds(contents_view->width(), 0, 100, 100); 73 view->SetBounds(contents_view->width(), 0, 100, 100);
68 gfx::Rect contents_view_bounds = contents_view->bounds(); 74 gfx::Rect contents_view_bounds = contents_view->bounds();
69 contents_view_bounds = contents_view_bounds.Union(view->bounds()); 75 contents_view_bounds = contents_view_bounds.Union(view->bounds());
70 contents_view->SetBoundsRect(contents_view_bounds); 76 contents_view->SetBoundsRect(contents_view_bounds);
71 widget->SetBounds(contents_view_bounds); 77 widget->SetBounds(gfx::Rect(widget->GetWindowBoundsInScreen().origin(),
78 contents_view_bounds.size()));
72 } 79 }
73 80
74 ash::internal::TooltipController* GetController() { 81 ash::internal::TooltipController* GetController() {
75 return static_cast<ash::internal::TooltipController*>( 82 return static_cast<ash::internal::TooltipController*>(
76 aura::client::GetTooltipClient(Shell::GetPrimaryRootWindow())); 83 aura::client::GetTooltipClient(Shell::GetPrimaryRootWindow()));
77 } 84 }
78 85
79 gfx::Font GetDefaultFont() { 86 gfx::Font GetDefaultFont() {
80 return ui::ResourceBundle::GetSharedInstance().GetFont( 87 return ui::ResourceBundle::GetSharedInstance().GetFont(
81 ui::ResourceBundle::BaseFont); 88 ui::ResourceBundle::BaseFont);
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 EXPECT_TRUE(IsTooltipTimerRunning()); 471 EXPECT_TRUE(IsTooltipTimerRunning());
465 FireTooltipTimer(); 472 FireTooltipTimer();
466 EXPECT_TRUE(IsTooltipVisible()); 473 EXPECT_TRUE(IsTooltipVisible());
467 EXPECT_TRUE(IsTooltipShownTimerRunning()); 474 EXPECT_TRUE(IsTooltipShownTimerRunning());
468 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 2"); 475 string16 expected_tooltip = ASCIIToUTF16("Tooltip Text for view 2");
469 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window)); 476 EXPECT_EQ(expected_tooltip, aura::client::GetTooltipText(window));
470 EXPECT_EQ(expected_tooltip, GetTooltipText()); 477 EXPECT_EQ(expected_tooltip, GetTooltipText());
471 EXPECT_EQ(window, GetTooltipWindow()); 478 EXPECT_EQ(window, GetTooltipWindow());
472 } 479 }
473 480
481 TEST_F(TooltipControllerTest, TooltipsOnMultiDisplayShouldNotCrash) {
482 internal::DisplayController::SetExtendedDesktopEnabled(true);
483 UpdateDisplay("1000x600,600x400");
484 Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
485 scoped_ptr<views::Widget> widget1(CreateNewWidgetWithBounds(
486 gfx::Rect(10, 10, 100, 100)));
487 TooltipTestView* view1 = new TooltipTestView;
488 AddViewToWidgetAndResize(widget1.get(), view1);
489 view1->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 1"));
490 EXPECT_EQ(widget1->GetNativeView()->GetRootWindow(), root_windows[0]);
491
492 scoped_ptr<views::Widget> widget2(CreateNewWidgetWithBounds(
493 gfx::Rect(1200, 10, 100, 100)));
494 TooltipTestView* view2 = new TooltipTestView;
495 AddViewToWidgetAndResize(widget2.get(), view2);
496 view2->set_tooltip_text(ASCIIToUTF16("Tooltip Text for view 2"));
497 EXPECT_EQ(widget2->GetNativeView()->GetRootWindow(), root_windows[1]);
498
499 // Show tooltip on second display.
500 aura::test::EventGenerator generator(root_windows[1]);
501 generator.MoveMouseRelativeTo(widget2->GetNativeView(),
502 view2->bounds().CenterPoint());
503 FireTooltipTimer();
504 EXPECT_TRUE(IsTooltipVisible());
505
506 // Get rid of secondary display. This destroy's the tooltip's aura window. If
507 // we have handled this case, we will not crash in the following statement.
508 UpdateDisplay("1000x600");
509 EXPECT_FALSE(IsTooltipVisible());
510 EXPECT_EQ(widget2->GetNativeView()->GetRootWindow(), root_windows[0]);
511
512 // The tooltip should create a new aura window for itself, so we should still
513 // be able to show tooltips on the primary display.
514 aura::test::EventGenerator generator1(root_windows[0]);
515 generator1.MoveMouseRelativeTo(widget1->GetNativeView(),
516 view1->bounds().CenterPoint());
517 FireTooltipTimer();
518 EXPECT_TRUE(IsTooltipVisible());
519 }
520
474 } // namespace test 521 } // namespace test
475 } // namespace ash 522 } // namespace ash
OLDNEW
« no previous file with comments | « ash/tooltips/tooltip_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698