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

Side by Side Diff: chrome/browser/ui/views/tabs/tab_strip_unittest.cc

Issue 393033006: Added tab notification to accessibility_event_router_views. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GetTabCount returns 1 in test class Created 6 years, 5 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
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 "chrome/browser/ui/views/tabs/tab_strip.h" 5 #include "chrome/browser/ui/views/tabs/tab_strip.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h" 8 #include "chrome/browser/ui/views/tabs/fake_base_tab_strip_controller.h"
9 #include "chrome/browser/ui/views/tabs/tab.h" 9 #include "chrome/browser/ui/views/tabs/tab.h"
10 #include "chrome/browser/ui/views/tabs/tab_strip.h" 10 #include "chrome/browser/ui/views/tabs/tab_strip.h"
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 TEST_F(TabStripTest, GetModelCount) { 172 TEST_F(TabStripTest, GetModelCount) {
173 EXPECT_EQ(0, tab_strip_->GetModelCount()); 173 EXPECT_EQ(0, tab_strip_->GetModelCount());
174 } 174 }
175 175
176 TEST_F(TabStripTest, IsValidModelIndex) { 176 TEST_F(TabStripTest, IsValidModelIndex) {
177 EXPECT_FALSE(tab_strip_->IsValidModelIndex(0)); 177 EXPECT_FALSE(tab_strip_->IsValidModelIndex(0));
178 } 178 }
179 179
180 TEST_F(TabStripTest, tab_count) { 180 TEST_F(TabStripTest, tab_count) {
181 EXPECT_EQ(0, tab_strip_->tab_count()); 181 EXPECT_EQ(0, tab_strip_->GetTabCount());
182 } 182 }
183 183
184 TEST_F(TabStripTest, AddTabAt) { 184 TEST_F(TabStripTest, AddTabAt) {
185 TestTabStripObserver observer(tab_strip_); 185 TestTabStripObserver observer(tab_strip_);
186 tab_strip_->AddTabAt(0, TabRendererData(), false); 186 tab_strip_->AddTabAt(0, TabRendererData(), false);
187 ASSERT_EQ(1, tab_strip_->tab_count()); 187 ASSERT_EQ(1, tab_strip_->GetTabCount());
188 EXPECT_EQ(0, observer.last_tab_added()); 188 EXPECT_EQ(0, observer.last_tab_added());
189 Tab* tab = tab_strip_->tab_at(0); 189 Tab* tab = tab_strip_->tab_at(0);
190 EXPECT_FALSE(tab == NULL); 190 EXPECT_FALSE(tab == NULL);
191 } 191 }
192 192
193 // Confirms that TabStripObserver::TabStripDeleted() is sent. 193 // Confirms that TabStripObserver::TabStripDeleted() is sent.
194 TEST_F(TabStripTest, TabStripDeleted) { 194 TEST_F(TabStripTest, TabStripDeleted) {
195 FakeBaseTabStripController* controller = new FakeBaseTabStripController; 195 FakeBaseTabStripController* controller = new FakeBaseTabStripController;
196 TabStrip* tab_strip = new TabStrip(controller); 196 TabStrip* tab_strip = new TabStrip(controller);
197 controller->set_tab_strip(tab_strip); 197 controller->set_tab_strip(tab_strip);
198 TestTabStripObserver observer(tab_strip); 198 TestTabStripObserver observer(tab_strip);
199 delete tab_strip; 199 delete tab_strip;
200 EXPECT_TRUE(observer.tabstrip_deleted()); 200 EXPECT_TRUE(observer.tabstrip_deleted());
201 } 201 }
202 202
203 TEST_F(TabStripTest, MoveTab) { 203 TEST_F(TabStripTest, MoveTab) {
204 TestTabStripObserver observer(tab_strip_); 204 TestTabStripObserver observer(tab_strip_);
205 tab_strip_->AddTabAt(0, TabRendererData(), false); 205 tab_strip_->AddTabAt(0, TabRendererData(), false);
206 tab_strip_->AddTabAt(1, TabRendererData(), false); 206 tab_strip_->AddTabAt(1, TabRendererData(), false);
207 tab_strip_->AddTabAt(2, TabRendererData(), false); 207 tab_strip_->AddTabAt(2, TabRendererData(), false);
208 ASSERT_EQ(3, tab_strip_->tab_count()); 208 ASSERT_EQ(3, tab_strip_->GetTabCount());
209 EXPECT_EQ(2, observer.last_tab_added()); 209 EXPECT_EQ(2, observer.last_tab_added());
210 Tab* tab = tab_strip_->tab_at(0); 210 Tab* tab = tab_strip_->tab_at(0);
211 tab_strip_->MoveTab(0, 1, TabRendererData()); 211 tab_strip_->MoveTab(0, 1, TabRendererData());
212 EXPECT_EQ(0, observer.last_tab_moved_from()); 212 EXPECT_EQ(0, observer.last_tab_moved_from());
213 EXPECT_EQ(1, observer.last_tab_moved_to()); 213 EXPECT_EQ(1, observer.last_tab_moved_to());
214 EXPECT_EQ(tab, tab_strip_->tab_at(1)); 214 EXPECT_EQ(tab, tab_strip_->tab_at(1));
215 } 215 }
216 216
217 // Verifies child views are deleted after an animation completes. 217 // Verifies child views are deleted after an animation completes.
218 TEST_F(TabStripTest, RemoveTab) { 218 TEST_F(TabStripTest, RemoveTab) {
219 TestTabStripObserver observer(tab_strip_); 219 TestTabStripObserver observer(tab_strip_);
220 controller_->AddTab(0, false); 220 controller_->AddTab(0, false);
221 controller_->AddTab(1, false); 221 controller_->AddTab(1, false);
222 const int child_view_count = tab_strip_->child_count(); 222 const int child_view_count = tab_strip_->child_count();
223 EXPECT_EQ(2, tab_strip_->tab_count()); 223 EXPECT_EQ(2, tab_strip_->GetTabCount());
224 controller_->RemoveTab(0); 224 controller_->RemoveTab(0);
225 EXPECT_EQ(0, observer.last_tab_removed()); 225 EXPECT_EQ(0, observer.last_tab_removed());
226 // When removing a tab the tabcount should immediately decrement. 226 // When removing a tab the tabcount should immediately decrement.
227 EXPECT_EQ(1, tab_strip_->tab_count()); 227 EXPECT_EQ(1, tab_strip_->GetTabCount());
228 // But the number of views should remain the same (it's animatining closed). 228 // But the number of views should remain the same (it's animatining closed).
229 EXPECT_EQ(child_view_count, tab_strip_->child_count()); 229 EXPECT_EQ(child_view_count, tab_strip_->child_count());
230 tab_strip_->SetBounds(0, 0, 200, 20); 230 tab_strip_->SetBounds(0, 0, 200, 20);
231 // Layout at a different size should force the animation to end and delete 231 // Layout at a different size should force the animation to end and delete
232 // the tab that was removed. 232 // the tab that was removed.
233 tab_strip_->Layout(); 233 tab_strip_->Layout();
234 EXPECT_EQ(child_view_count - 1, tab_strip_->child_count()); 234 EXPECT_EQ(child_view_count - 1, tab_strip_->child_count());
235 235
236 // Remove the last tab to make sure things are cleaned up correctly when 236 // Remove the last tab to make sure things are cleaned up correctly when
237 // the TabStrip is destroyed and an animation is ongoing. 237 // the TabStrip is destroyed and an animation is ongoing.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 // All the invisible tabs should be at the end of the strip. 270 // All the invisible tabs should be at the end of the strip.
271 tab_strip_->SetBounds(0, 0, 100, 20); 271 tab_strip_->SetBounds(0, 0, 100, 20);
272 int i = 0; 272 int i = 0;
273 for (; i < invisible_tab_index; ++i) { 273 for (; i < invisible_tab_index; ++i) {
274 if (!tab_strip_->tab_at(i)->visible()) 274 if (!tab_strip_->tab_at(i)->visible())
275 break; 275 break;
276 } 276 }
277 ASSERT_GT(i, 0); 277 ASSERT_GT(i, 0);
278 EXPECT_LT(i, invisible_tab_index); 278 EXPECT_LT(i, invisible_tab_index);
279 invisible_tab_index = i; 279 invisible_tab_index = i;
280 for (int i = invisible_tab_index + 1; i < tab_strip_->tab_count(); ++i) 280 for (int i = invisible_tab_index + 1; i < tab_strip_->GetTabCount(); ++i)
281 EXPECT_FALSE(tab_strip_->tab_at(i)->visible()); 281 EXPECT_FALSE(tab_strip_->tab_at(i)->visible());
282 282
283 // When we're already in overflow, adding tabs at the beginning or end of 283 // When we're already in overflow, adding tabs at the beginning or end of
284 // the strip should not change how many tabs are visible. 284 // the strip should not change how many tabs are visible.
285 controller_->AddTab(tab_strip_->tab_count(), false); 285 controller_->AddTab(tab_strip_->GetTabCount(), false);
286 EXPECT_TRUE(tab_strip_->tab_at(invisible_tab_index - 1)->visible()); 286 EXPECT_TRUE(tab_strip_->tab_at(invisible_tab_index - 1)->visible());
287 EXPECT_FALSE(tab_strip_->tab_at(invisible_tab_index)->visible()); 287 EXPECT_FALSE(tab_strip_->tab_at(invisible_tab_index)->visible());
288 controller_->AddTab(0, false); 288 controller_->AddTab(0, false);
289 EXPECT_TRUE(tab_strip_->tab_at(invisible_tab_index - 1)->visible()); 289 EXPECT_TRUE(tab_strip_->tab_at(invisible_tab_index - 1)->visible());
290 EXPECT_FALSE(tab_strip_->tab_at(invisible_tab_index)->visible()); 290 EXPECT_FALSE(tab_strip_->tab_at(invisible_tab_index)->visible());
291 291
292 // If we remove enough tabs, all the tabs should be visible. 292 // If we remove enough tabs, all the tabs should be visible.
293 for (int i = tab_strip_->tab_count() - 1; i >= invisible_tab_index; --i) 293 for (int i = tab_strip_->GetTabCount() - 1; i >= invisible_tab_index; --i)
294 controller_->RemoveTab(i); 294 controller_->RemoveTab(i);
295 EXPECT_TRUE(tab_strip_->tab_at(tab_strip_->tab_count() - 1)->visible()); 295 EXPECT_TRUE(tab_strip_->tab_at(tab_strip_->GetTabCount() - 1)->visible());
296 } 296 }
297 297
298 TEST_F(TabStripTest, ImmersiveMode) { 298 TEST_F(TabStripTest, ImmersiveMode) {
299 // Immersive mode defaults to off. 299 // Immersive mode defaults to off.
300 EXPECT_FALSE(tab_strip_->IsImmersiveStyle()); 300 EXPECT_FALSE(tab_strip_->IsImmersiveStyle());
301 301
302 // Tab strip defaults to normal tab height. 302 // Tab strip defaults to normal tab height.
303 int normal_height = Tab::GetMinimumUnselectedSize().height(); 303 int normal_height = Tab::GetMinimumUnselectedSize().height();
304 EXPECT_EQ(normal_height, tab_strip_->GetPreferredSize().height()); 304 EXPECT_EQ(normal_height, tab_strip_->GetPreferredSize().height());
305 305
(...skipping 12 matching lines...) Expand all
318 // Creates a tab strip in stacked layout mode and verifies the correctness 318 // Creates a tab strip in stacked layout mode and verifies the correctness
319 // of hit tests against the visible/occluded regions of a tab and 319 // of hit tests against the visible/occluded regions of a tab and
320 // visible/occluded tab close buttons. 320 // visible/occluded tab close buttons.
321 TEST_F(TabStripTest, TabHitTestMaskWhenStacked) { 321 TEST_F(TabStripTest, TabHitTestMaskWhenStacked) {
322 tab_strip_->SetBounds(0, 0, 300, 20); 322 tab_strip_->SetBounds(0, 0, 300, 20);
323 323
324 controller_->AddTab(0, false); 324 controller_->AddTab(0, false);
325 controller_->AddTab(1, true); 325 controller_->AddTab(1, true);
326 controller_->AddTab(2, false); 326 controller_->AddTab(2, false);
327 controller_->AddTab(3, false); 327 controller_->AddTab(3, false);
328 ASSERT_EQ(4, tab_strip_->tab_count()); 328 ASSERT_EQ(4, tab_strip_->GetTabCount());
329 329
330 Tab* left_tab = tab_strip_->tab_at(0); 330 Tab* left_tab = tab_strip_->tab_at(0);
331 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20))); 331 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20)));
332 332
333 Tab* active_tab = tab_strip_->tab_at(1); 333 Tab* active_tab = tab_strip_->tab_at(1);
334 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(150, 0), gfx::Size(200, 20))); 334 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(150, 0), gfx::Size(200, 20)));
335 ASSERT_TRUE(active_tab->IsActive()); 335 ASSERT_TRUE(active_tab->IsActive());
336 336
337 Tab* right_tab = tab_strip_->tab_at(2); 337 Tab* right_tab = tab_strip_->tab_at(2);
338 right_tab->SetBoundsRect(gfx::Rect(gfx::Point(300, 0), gfx::Size(200, 20))); 338 right_tab->SetBoundsRect(gfx::Rect(gfx::Point(300, 0), gfx::Size(200, 20)));
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 } 451 }
452 452
453 // Creates a tab strip in stacked layout mode and verifies the correctness 453 // Creates a tab strip in stacked layout mode and verifies the correctness
454 // of hit tests against the visible/occluded region of a partially-occluded 454 // of hit tests against the visible/occluded region of a partially-occluded
455 // tab close button. 455 // tab close button.
456 TEST_F(TabStripTest, ClippedTabCloseButton) { 456 TEST_F(TabStripTest, ClippedTabCloseButton) {
457 tab_strip_->SetBounds(0, 0, 220, 20); 457 tab_strip_->SetBounds(0, 0, 220, 20);
458 458
459 controller_->AddTab(0, false); 459 controller_->AddTab(0, false);
460 controller_->AddTab(1, true); 460 controller_->AddTab(1, true);
461 ASSERT_EQ(2, tab_strip_->tab_count()); 461 ASSERT_EQ(2, tab_strip_->GetTabCount());
462 462
463 Tab* left_tab = tab_strip_->tab_at(0); 463 Tab* left_tab = tab_strip_->tab_at(0);
464 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20))); 464 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20)));
465 465
466 Tab* active_tab = tab_strip_->tab_at(1); 466 Tab* active_tab = tab_strip_->tab_at(1);
467 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(180, 0), gfx::Size(200, 20))); 467 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(180, 0), gfx::Size(200, 20)));
468 ASSERT_TRUE(active_tab->IsActive()); 468 ASSERT_TRUE(active_tab->IsActive());
469 469
470 // Switch to stacked layout mode and force a layout to ensure tabs stack. 470 // Switch to stacked layout mode and force a layout to ensure tabs stack.
471 tab_strip_->SetStackedLayout(true); 471 tab_strip_->SetStackedLayout(true);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(16, 10, 20, 20))); 508 EXPECT_FALSE(left_close->HitTestRect(gfx::Rect(16, 10, 20, 20)));
509 } 509 }
510 510
511 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) { 511 TEST_F(TabStripTest, GetEventHandlerForOverlappingArea) {
512 tab_strip_->SetBounds(0, 0, 1000, 20); 512 tab_strip_->SetBounds(0, 0, 1000, 20);
513 513
514 controller_->AddTab(0, false); 514 controller_->AddTab(0, false);
515 controller_->AddTab(1, true); 515 controller_->AddTab(1, true);
516 controller_->AddTab(2, false); 516 controller_->AddTab(2, false);
517 controller_->AddTab(3, false); 517 controller_->AddTab(3, false);
518 ASSERT_EQ(4, tab_strip_->tab_count()); 518 ASSERT_EQ(4, tab_strip_->GetTabCount());
519 519
520 // Verify that the active tab will be a tooltip handler for points that hit 520 // Verify that the active tab will be a tooltip handler for points that hit
521 // it. 521 // it.
522 Tab* left_tab = tab_strip_->tab_at(0); 522 Tab* left_tab = tab_strip_->tab_at(0);
523 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20))); 523 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20)));
524 524
525 Tab* active_tab = tab_strip_->tab_at(1); 525 Tab* active_tab = tab_strip_->tab_at(1);
526 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(150, 0), gfx::Size(200, 20))); 526 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(150, 0), gfx::Size(200, 20)));
527 ASSERT_TRUE(active_tab->IsActive()); 527 ASSERT_TRUE(active_tab->IsActive());
528 528
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 FindTabView(tab_strip_->GetEventHandlerForPoint(unactive_overlap))); 571 FindTabView(tab_strip_->GetEventHandlerForPoint(unactive_overlap)));
572 } 572 }
573 573
574 TEST_F(TabStripTest, GetTooltipHandler) { 574 TEST_F(TabStripTest, GetTooltipHandler) {
575 tab_strip_->SetBounds(0, 0, 1000, 20); 575 tab_strip_->SetBounds(0, 0, 1000, 20);
576 576
577 controller_->AddTab(0, false); 577 controller_->AddTab(0, false);
578 controller_->AddTab(1, true); 578 controller_->AddTab(1, true);
579 controller_->AddTab(2, false); 579 controller_->AddTab(2, false);
580 controller_->AddTab(3, false); 580 controller_->AddTab(3, false);
581 ASSERT_EQ(4, tab_strip_->tab_count()); 581 ASSERT_EQ(4, tab_strip_->GetTabCount());
582 582
583 // Verify that the active tab will be a tooltip handler for points that hit 583 // Verify that the active tab will be a tooltip handler for points that hit
584 // it. 584 // it.
585 Tab* left_tab = tab_strip_->tab_at(0); 585 Tab* left_tab = tab_strip_->tab_at(0);
586 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20))); 586 left_tab->SetBoundsRect(gfx::Rect(gfx::Point(0, 0), gfx::Size(200, 20)));
587 587
588 Tab* active_tab = tab_strip_->tab_at(1); 588 Tab* active_tab = tab_strip_->tab_at(1);
589 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(150, 0), gfx::Size(200, 20))); 589 active_tab->SetBoundsRect(gfx::Rect(gfx::Point(150, 0), gfx::Size(200, 20)));
590 ASSERT_TRUE(active_tab->IsActive()); 590 ASSERT_TRUE(active_tab->IsActive());
591 591
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap)); 631 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap));
632 632
633 EXPECT_EQ( 633 EXPECT_EQ(
634 right_tab, 634 right_tab,
635 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); 635 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap)));
636 636
637 // Confirm that tab strip doe not return tooltip handler for points that 637 // Confirm that tab strip doe not return tooltip handler for points that
638 // don't hit it. 638 // don't hit it.
639 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); 639 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2)));
640 } 640 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698