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

Side by Side Diff: ash/launcher/launcher_tooltip_manager_unittest.cc

Issue 11801027: More work to make ash_unittests pass when we require context. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix TableViewTest by making it a ViewsTestBase. Created 7 years, 11 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/drag_drop/drag_image_view.cc ('k') | ash/launcher/launcher_view_unittest.cc » ('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/launcher/launcher_tooltip_manager.h" 5 #include "ash/launcher/launcher_tooltip_manager.h"
6 6
7 #include "ash/root_window_controller.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h"
9 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
10 #include "ash/wm/shelf_layout_manager.h" 11 #include "ash/wm/shelf_layout_manager.h"
11 #include "ash/wm/window_util.h" 12 #include "ash/wm/window_util.h"
12 #include "base/string16.h" 13 #include "base/string16.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "ui/aura/root_window.h" 15 #include "ui/aura/root_window.h"
15 #include "ui/base/events/event.h" 16 #include "ui/base/events/event.h"
16 #include "ui/base/events/event_constants.h" 17 #include "ui/base/events/event_constants.h"
17 #include "ui/base/events/event_handler.h" 18 #include "ui/base/events/event_handler.h"
18 #include "ui/base/keycodes/keyboard_codes.h" 19 #include "ui/base/keycodes/keyboard_codes.h"
(...skipping 25 matching lines...) Expand all
44 controller->shelf(), 45 controller->shelf(),
45 controller->launcher()->GetLauncherViewForTest())); 46 controller->launcher()->GetLauncherViewForTest()));
46 } 47 }
47 48
48 virtual void TearDown() OVERRIDE { 49 virtual void TearDown() OVERRIDE {
49 tooltip_manager_.reset(); 50 tooltip_manager_.reset();
50 AshTestBase::TearDown(); 51 AshTestBase::TearDown();
51 } 52 }
52 53
53 void ShowDelayed() { 54 void ShowDelayed() {
54 dummy_anchor_.reset(new views::View); 55 CreateWidget();
55 tooltip_manager_->ShowDelayed(dummy_anchor_.get(), string16()); 56 tooltip_manager_->ShowDelayed(dummy_anchor_.get(), string16());
56 } 57 }
57 58
58 void ShowImmediately() { 59 void ShowImmediately() {
59 dummy_anchor_.reset(new views::View); 60 CreateWidget();
60 tooltip_manager_->ShowImmediately(dummy_anchor_.get(), string16()); 61 tooltip_manager_->ShowImmediately(dummy_anchor_.get(), string16());
61 } 62 }
62 63
63 bool TooltipIsVisible() { 64 bool TooltipIsVisible() {
64 return tooltip_manager_->IsVisible(); 65 return tooltip_manager_->IsVisible();
65 } 66 }
66 67
67 bool IsTimerRunning() { 68 bool IsTimerRunning() {
68 return tooltip_manager_->timer_.get() != NULL; 69 return tooltip_manager_->timer_.get() != NULL;
69 } 70 }
70 71
71 ui::EventHandler* GetEventHandler() { 72 ui::EventHandler* GetEventHandler() {
72 return tooltip_manager_.get(); 73 return tooltip_manager_.get();
73 } 74 }
74 75
75 views::Widget* GetTooltipWidget() { 76 views::Widget* GetTooltipWidget() {
76 return tooltip_manager_->widget_; 77 return tooltip_manager_->widget_;
77 } 78 }
78 79
79 protected: 80 protected:
81 scoped_ptr<views::Widget> widget_;
80 scoped_ptr<views::View> dummy_anchor_; 82 scoped_ptr<views::View> dummy_anchor_;
81 scoped_ptr<internal::LauncherTooltipManager> tooltip_manager_; 83 scoped_ptr<internal::LauncherTooltipManager> tooltip_manager_;
82 84
83 private: 85 private:
86 void CreateWidget() {
87 dummy_anchor_.reset(new views::View);
88
89 widget_.reset(new views::Widget);
90 views::Widget::InitParams params(
91 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
92 params.transparent = true;
93 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
94 params.parent = Shell::GetContainer(
95 Shell::GetPrimaryRootWindow(),
96 ash::internal::kShellWindowId_LauncherContainer);
97
98 widget_->Init(params);
99 widget_->SetContentsView(dummy_anchor_.get());
100 }
101
84 DISALLOW_COPY_AND_ASSIGN(LauncherTooltipManagerTest); 102 DISALLOW_COPY_AND_ASSIGN(LauncherTooltipManagerTest);
85 }; 103 };
86 104
87 TEST_F(LauncherTooltipManagerTest, ShowingBasics) { 105 TEST_F(LauncherTooltipManagerTest, ShowingBasics) {
88 // ShowDelayed() should just start the timer instead of showing immediately. 106 // ShowDelayed() should just start the timer instead of showing immediately.
89 ShowDelayed(); 107 ShowDelayed();
90 EXPECT_FALSE(TooltipIsVisible()); 108 EXPECT_FALSE(TooltipIsVisible());
91 EXPECT_TRUE(IsTimerRunning()); 109 EXPECT_TRUE(IsTimerRunning());
92 110
93 ShowImmediately(); 111 ShowImmediately();
94 EXPECT_TRUE(TooltipIsVisible()); 112 EXPECT_TRUE(TooltipIsVisible());
95 EXPECT_FALSE(IsTimerRunning()); 113 EXPECT_FALSE(IsTimerRunning());
96 } 114 }
97 115
98 TEST_F(LauncherTooltipManagerTest, HideWhenShelfIsHidden) { 116 TEST_F(LauncherTooltipManagerTest, HideWhenShelfIsHidden) {
99 ShowImmediately(); 117 ShowImmediately();
100 ASSERT_TRUE(TooltipIsVisible()); 118 ASSERT_TRUE(TooltipIsVisible());
101 119
102 // Create a full-screen window to hide the shelf. 120 // Create a full-screen window to hide the shelf.
103 scoped_ptr<views::Widget> widget(new views::Widget); 121 scoped_ptr<views::Widget> widget(new views::Widget);
104 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); 122 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
105 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 123 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
124 params.context = CurrentContext();
106 widget->Init(params); 125 widget->Init(params);
107 widget->SetFullscreen(true); 126 widget->SetFullscreen(true);
108 widget->Show(); 127 widget->Show();
109 128
110 // Once the shelf is hidden, the tooltip should be invisible. 129 // Once the shelf is hidden, the tooltip should be invisible.
111 ASSERT_EQ( 130 ASSERT_EQ(
112 SHELF_HIDDEN, 131 SHELF_HIDDEN,
113 Shell::GetPrimaryRootWindowController()->shelf()->visibility_state()); 132 Shell::GetPrimaryRootWindowController()->shelf()->visibility_state());
114 EXPECT_FALSE(TooltipIsVisible()); 133 EXPECT_FALSE(TooltipIsVisible());
115 134
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 // Should hide if the mouse is out of the tooltip. 230 // Should hide if the mouse is out of the tooltip.
212 test_api.set_location(tooltip_rect.origin() + gfx::Vector2d(-1, -1)); 231 test_api.set_location(tooltip_rect.origin() + gfx::Vector2d(-1, -1));
213 event_handler->OnMouseEvent(&mouse_event); 232 event_handler->OnMouseEvent(&mouse_event);
214 EXPECT_FALSE(mouse_event.handled()); 233 EXPECT_FALSE(mouse_event.handled());
215 RunAllPendingInMessageLoop(); 234 RunAllPendingInMessageLoop();
216 EXPECT_FALSE(TooltipIsVisible()); 235 EXPECT_FALSE(TooltipIsVisible());
217 } 236 }
218 237
219 } // namespace test 238 } // namespace test
220 } // namespace ash 239 } // namespace ash
OLDNEW
« no previous file with comments | « ash/drag_drop/drag_image_view.cc ('k') | ash/launcher/launcher_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698