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

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

Issue 339923005: Clip tabs in overflow mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Unit tests Created 6 years, 6 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 | « chrome/browser/ui/views/tabs/tab_strip.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 "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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 // the tab that was removed. 198 // the tab that was removed.
199 tab_strip_->Layout(); 199 tab_strip_->Layout();
200 EXPECT_EQ(child_view_count - 1, tab_strip_->child_count()); 200 EXPECT_EQ(child_view_count - 1, tab_strip_->child_count());
201 201
202 // Remove the last tab to make sure things are cleaned up correctly when 202 // Remove the last tab to make sure things are cleaned up correctly when
203 // the TabStrip is destroyed and an animation is ongoing. 203 // the TabStrip is destroyed and an animation is ongoing.
204 controller_->RemoveTab(0); 204 controller_->RemoveTab(0);
205 EXPECT_EQ(0, observer.last_tab_removed()); 205 EXPECT_EQ(0, observer.last_tab_removed());
206 } 206 }
207 207
208 TEST_F(TabStripTest, VisibilityInOverflow) {
209 tab_strip_->SetBounds(0, 0, 200, 20);
210
211 // The first tab added to a reasonable-width strip should be visible. If we
212 // add enough additional tabs, eventually one should be invisible due to
213 // overflow.
214 int invisible_tab_index = 0;
215 for (; invisible_tab_index < 100; ++invisible_tab_index) {
216 controller_->AddTab(invisible_tab_index, false);
217 if (!tab_strip_->tab_at(invisible_tab_index)->visible())
218 break;
219 }
220 EXPECT_GT(invisible_tab_index, 0);
221 EXPECT_LT(invisible_tab_index, 100);
222
223 // The tabs before the invisible tab should still be visible.
224 for (int i = 0; i < invisible_tab_index; ++i)
225 EXPECT_TRUE(tab_strip_->tab_at(i)->visible());
226
227 // Enlarging the strip should result in the last tab becoming visible.
228 tab_strip_->SetBounds(0, 0, 400, 20);
229 EXPECT_TRUE(tab_strip_->tab_at(invisible_tab_index)->visible());
230
231 // Shrinking it again should re-hide the last tab.
232 tab_strip_->SetBounds(0, 0, 200, 20);
233 EXPECT_FALSE(tab_strip_->tab_at(invisible_tab_index)->visible());
234
235 // Shrinking it still more should make more tabs invisible, though not all.
236 // All the invisible tabs should be at the end of the strip.
237 tab_strip_->SetBounds(0, 0, 100, 20);
238 int i = 0;
239 for (; i < invisible_tab_index; ++i) {
240 if (!tab_strip_->tab_at(i)->visible())
241 break;
242 }
243 ASSERT_GT(i, 0);
244 EXPECT_LT(i, invisible_tab_index);
245 invisible_tab_index = i;
246 for (int i = invisible_tab_index + 1; i < tab_strip_->tab_count(); ++i)
247 EXPECT_FALSE(tab_strip_->tab_at(i)->visible());
248
249 // When we're already in overflow, adding tabs at the beginning or end of
250 // the strip should not change how many tabs are visible.
251 controller_->AddTab(tab_strip_->tab_count(), false);
252 EXPECT_TRUE(tab_strip_->tab_at(invisible_tab_index - 1)->visible());
253 EXPECT_FALSE(tab_strip_->tab_at(invisible_tab_index)->visible());
254 controller_->AddTab(0, false);
255 EXPECT_TRUE(tab_strip_->tab_at(invisible_tab_index - 1)->visible());
256 EXPECT_FALSE(tab_strip_->tab_at(invisible_tab_index)->visible());
257
258 // If we remove enough tabs, all the tabs should be visible.
259 for (int i = tab_strip_->tab_count() - 1; i >= invisible_tab_index; --i)
260 controller_->RemoveTab(i);
261 EXPECT_TRUE(tab_strip_->tab_at(tab_strip_->tab_count() - 1)->visible());
262 }
263
208 TEST_F(TabStripTest, ImmersiveMode) { 264 TEST_F(TabStripTest, ImmersiveMode) {
209 // Immersive mode defaults to off. 265 // Immersive mode defaults to off.
210 EXPECT_FALSE(tab_strip_->IsImmersiveStyle()); 266 EXPECT_FALSE(tab_strip_->IsImmersiveStyle());
211 267
212 // Tab strip defaults to normal tab height. 268 // Tab strip defaults to normal tab height.
213 int normal_height = Tab::GetMinimumUnselectedSize().height(); 269 int normal_height = Tab::GetMinimumUnselectedSize().height();
214 EXPECT_EQ(normal_height, tab_strip_->GetPreferredSize().height()); 270 EXPECT_EQ(normal_height, tab_strip_->GetPreferredSize().height());
215 271
216 // Tab strip can toggle immersive mode. 272 // Tab strip can toggle immersive mode.
217 tab_strip_->SetImmersiveStyle(true); 273 tab_strip_->SetImmersiveStyle(true);
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap)); 597 ASSERT_TRUE(IsPointInTab(most_right_tab, unactive_overlap));
542 598
543 EXPECT_EQ( 599 EXPECT_EQ(
544 right_tab, 600 right_tab,
545 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap))); 601 FindTabView(tab_strip_->GetTooltipHandlerForPoint(unactive_overlap)));
546 602
547 // Confirm that tab strip doe not return tooltip handler for points that 603 // Confirm that tab strip doe not return tooltip handler for points that
548 // don't hit it. 604 // don't hit it.
549 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2))); 605 EXPECT_FALSE(tab_strip_->GetTooltipHandlerForPoint(gfx::Point(-1, 2)));
550 } 606 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab_strip.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698