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

Side by Side Diff: chrome/browser/ui/views/toolbar/browser_actions_container_browsertest.cc

Issue 653933003: Resubmit: Rename BrowserActionView to ToolbarActionView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/toolbar/browser_actions_container.h" 5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
6 6
7 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" 7 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h"
8 #include "chrome/browser/extensions/browser_action_test_util.h" 8 #include "chrome/browser/extensions/browser_action_test_util.h"
9 #include "chrome/browser/extensions/extension_toolbar_model.h" 9 #include "chrome/browser/extensions/extension_toolbar_model.h"
10 #include "chrome/browser/ui/browser_window.h" 10 #include "chrome/browser/ui/browser_window.h"
11 #include "chrome/browser/ui/browser_window_testing_views.h" 11 #include "chrome/browser/ui/browser_window_testing_views.h"
12 #include "chrome/browser/ui/toolbar/browser_actions_bar_browsertest.h" 12 #include "chrome/browser/ui/toolbar/browser_actions_bar_browsertest.h"
13 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" 13 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
14 #include "chrome/browser/ui/views/frame/browser_view.h" 14 #include "chrome/browser/ui/views/frame/browser_view.h"
15 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" 15 #include "chrome/browser/ui/views/toolbar/toolbar_action_view.h"
16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
17 #include "extensions/browser/extension_prefs.h" 17 #include "extensions/browser/extension_prefs.h"
18 #include "extensions/common/extension.h" 18 #include "extensions/common/extension.h"
19 #include "ui/base/dragdrop/drop_target_event.h" 19 #include "ui/base/dragdrop/drop_target_event.h"
20 #include "ui/base/dragdrop/os_exchange_data.h" 20 #include "ui/base/dragdrop/os_exchange_data.h"
21 #include "ui/gfx/geometry/point.h" 21 #include "ui/gfx/geometry/point.h"
22 #include "ui/views/view.h" 22 #include "ui/views/view.h"
23 23
24 // TODO(devlin): Continue moving any tests that should be platform independent 24 // TODO(devlin): Continue moving any tests that should be platform independent
25 // from this file to the crossplatform tests in 25 // from this file to the crossplatform tests in
(...skipping 14 matching lines...) Expand all
40 40
41 BrowserActionsContainer* container = 41 BrowserActionsContainer* container =
42 BrowserView::GetBrowserViewForBrowser(browser()) 42 BrowserView::GetBrowserViewForBrowser(browser())
43 ->toolbar()->browser_actions(); 43 ->toolbar()->browser_actions();
44 44
45 // Simulate a drag and drop to the right. 45 // Simulate a drag and drop to the right.
46 ui::OSExchangeData drop_data; 46 ui::OSExchangeData drop_data;
47 // Drag extension A from index 0... 47 // Drag extension A from index 0...
48 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); 48 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u);
49 browser_action_drag_data.Write(profile(), &drop_data); 49 browser_action_drag_data.Write(profile(), &drop_data);
50 BrowserActionView* view = container->GetViewForExtension(extension_b()); 50 ToolbarActionView* view = container->GetViewForExtension(extension_b());
51 // ...to the right of extension B. 51 // ...to the right of extension B.
52 gfx::Point location(view->x() + view->width(), view->y()); 52 gfx::Point location(view->x() + view->width(), view->y());
53 ui::DropTargetEvent target_event( 53 ui::DropTargetEvent target_event(
54 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); 54 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE);
55 55
56 // Drag and drop. 56 // Drag and drop.
57 container->OnDragUpdated(target_event); 57 container->OnDragUpdated(target_event);
58 container->OnPerformDrop(target_event); 58 container->OnPerformDrop(target_event);
59 59
60 // The order should now be B A C, since A was dragged to the right of B. 60 // The order should now be B A C, since A was dragged to the right of B.
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 EXPECT_EQ(extension_b()->id(), first->GetIdAt(1u)); 246 EXPECT_EQ(extension_b()->id(), first->GetIdAt(1u));
247 EXPECT_EQ(extension_b()->id(), second->GetIdAt(1u)); 247 EXPECT_EQ(extension_b()->id(), second->GetIdAt(1u));
248 EXPECT_EQ(extension_c()->id(), first->GetIdAt(2u)); 248 EXPECT_EQ(extension_c()->id(), first->GetIdAt(2u));
249 EXPECT_EQ(extension_c()->id(), second->GetIdAt(2u)); 249 EXPECT_EQ(extension_c()->id(), second->GetIdAt(2u));
250 250
251 // Simulate a drag and drop to the right. 251 // Simulate a drag and drop to the right.
252 ui::OSExchangeData drop_data; 252 ui::OSExchangeData drop_data;
253 // Drag extension A from index 0... 253 // Drag extension A from index 0...
254 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); 254 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u);
255 browser_action_drag_data.Write(profile(), &drop_data); 255 browser_action_drag_data.Write(profile(), &drop_data);
256 BrowserActionView* view = first->GetViewForExtension(extension_b()); 256 ToolbarActionView* view = first->GetViewForExtension(extension_b());
257 // ...to the right of extension B. 257 // ...to the right of extension B.
258 gfx::Point location(view->x() + view->width(), view->y()); 258 gfx::Point location(view->x() + view->width(), view->y());
259 ui::DropTargetEvent target_event( 259 ui::DropTargetEvent target_event(
260 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); 260 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE);
261 261
262 // Drag and drop. 262 // Drag and drop.
263 first->OnDragUpdated(target_event); 263 first->OnDragUpdated(target_event);
264 first->OnPerformDrop(target_event); 264 first->OnPerformDrop(target_event);
265 265
266 // The new order, B A C, should be reflected in *both* containers, even 266 // The new order, B A C, should be reflected in *both* containers, even
(...skipping 22 matching lines...) Expand all
289 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); 289 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
290 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); 290 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
291 291
292 BrowserActionsContainer* container = browser() 292 BrowserActionsContainer* container = browser()
293 ->window() 293 ->window()
294 ->GetBrowserWindowTesting() 294 ->GetBrowserWindowTesting()
295 ->GetToolbarView() 295 ->GetToolbarView()
296 ->browser_actions(); 296 ->browser_actions();
297 297
298 // Currently, dragging should be enabled. 298 // Currently, dragging should be enabled.
299 BrowserActionView* action_view = container->GetBrowserActionViewAt(0); 299 ToolbarActionView* action_view = container->GetToolbarActionViewAt(0);
300 ASSERT_TRUE(action_view); 300 ASSERT_TRUE(action_view);
301 gfx::Point point(action_view->x(), action_view->y()); 301 gfx::Point point(action_view->x(), action_view->y());
302 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point)); 302 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point));
303 303
304 extensions::ExtensionToolbarModel* model = 304 extensions::ExtensionToolbarModel* model =
305 extensions::ExtensionToolbarModel::Get(profile()); 305 extensions::ExtensionToolbarModel::Get(profile());
306 306
307 extensions::ExtensionIdList extension_ids; 307 extensions::ExtensionIdList extension_ids;
308 extension_ids.push_back(extension_a()->id()); 308 extension_ids.push_back(extension_a()->id());
309 extension_ids.push_back(extension_b()->id()); 309 extension_ids.push_back(extension_b()->id());
310 model->HighlightExtensions(extension_ids); 310 model->HighlightExtensions(extension_ids);
311 311
312 // Only two browser actions should be visible. 312 // Only two browser actions should be visible.
313 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); 313 EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions());
314 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions()); 314 EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions());
315 315
316 // We shouldn't be able to drag in highlight mode. 316 // We shouldn't be able to drag in highlight mode.
317 action_view = container->GetBrowserActionViewAt(0); 317 action_view = container->GetToolbarActionViewAt(0);
318 EXPECT_FALSE(container->CanStartDragForView(action_view, point, point)); 318 EXPECT_FALSE(container->CanStartDragForView(action_view, point, point));
319 319
320 // We should go back to normal after leaving highlight mode. 320 // We should go back to normal after leaving highlight mode.
321 model->StopHighlighting(); 321 model->StopHighlighting();
322 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); 322 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
323 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); 323 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
324 action_view = container->GetBrowserActionViewAt(0); 324 action_view = container->GetToolbarActionViewAt(0);
325 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point)); 325 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point));
326 } 326 }
327 327
328 // Test the behavior of the overflow container for Extension Actions. 328 // Test the behavior of the overflow container for Extension Actions.
329 class BrowserActionsContainerOverflowTest 329 class BrowserActionsContainerOverflowTest
330 : public BrowserActionsBarBrowserTest { 330 : public BrowserActionsBarBrowserTest {
331 public: 331 public:
332 BrowserActionsContainerOverflowTest() : main_bar_(NULL), model_(NULL) { 332 BrowserActionsContainerOverflowTest() : main_bar_(NULL), model_(NULL) {
333 } 333 }
334 ~BrowserActionsContainerOverflowTest() override {} 334 ~BrowserActionsContainerOverflowTest() override {}
335 335
336 protected: 336 protected:
337 // Returns true if the order of the BrowserActionViews in |main_bar_| 337 // Returns true if the order of the ToolbarActionViews in |main_bar_|
338 // and |overflow_bar_| match. 338 // and |overflow_bar_| match.
339 bool ViewOrdersMatch(); 339 bool ViewOrdersMatch();
340 340
341 // Returns Success if the visible count matches |expected_visible|. This means 341 // Returns Success if the visible count matches |expected_visible|. This means
342 // that the number of visible browser actions in |main_bar_| is 342 // that the number of visible browser actions in |main_bar_| is
343 // |expected_visible| and shows the first icons, and that the overflow bar 343 // |expected_visible| and shows the first icons, and that the overflow bar
344 // shows all (and only) the remainder. 344 // shows all (and only) the remainder.
345 testing::AssertionResult VerifyVisibleCount(size_t expected_visible); 345 testing::AssertionResult VerifyVisibleCount(size_t expected_visible);
346 346
347 // Accessors. 347 // Accessors.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 model_ = extensions::ExtensionToolbarModel::Get(profile()); 387 model_ = extensions::ExtensionToolbarModel::Get(profile());
388 } 388 }
389 389
390 void BrowserActionsContainerOverflowTest::TearDownOnMainThread() { 390 void BrowserActionsContainerOverflowTest::TearDownOnMainThread() {
391 overflow_bar_.reset(); 391 overflow_bar_.reset();
392 enable_redesign_.reset(); 392 enable_redesign_.reset();
393 BrowserActionsBarBrowserTest::TearDownOnMainThread(); 393 BrowserActionsBarBrowserTest::TearDownOnMainThread();
394 } 394 }
395 395
396 bool BrowserActionsContainerOverflowTest::ViewOrdersMatch() { 396 bool BrowserActionsContainerOverflowTest::ViewOrdersMatch() {
397 if (main_bar_->num_browser_actions() != 397 if (main_bar_->num_toolbar_actions() !=
398 overflow_bar_->num_browser_actions()) 398 overflow_bar_->num_toolbar_actions())
399 return false; 399 return false;
400 for (size_t i = 0; i < main_bar_->num_browser_actions(); ++i) { 400 for (size_t i = 0; i < main_bar_->num_toolbar_actions(); ++i) {
401 if (main_bar_->GetIdAt(i) != overflow_bar_->GetIdAt(i)) 401 if (main_bar_->GetIdAt(i) != overflow_bar_->GetIdAt(i))
402 return false; 402 return false;
403 } 403 }
404 return true; 404 return true;
405 } 405 }
406 406
407 testing::AssertionResult 407 testing::AssertionResult
408 BrowserActionsContainerOverflowTest::VerifyVisibleCount( 408 BrowserActionsContainerOverflowTest::VerifyVisibleCount(
409 size_t expected_visible) { 409 size_t expected_visible) {
410 // Views order should always match (as it is based directly off the model). 410 // Views order should always match (as it is based directly off the model).
411 if (!ViewOrdersMatch()) 411 if (!ViewOrdersMatch())
412 return testing::AssertionFailure() << "View orders don't match"; 412 return testing::AssertionFailure() << "View orders don't match";
413 413
414 // Loop through and check each browser action for proper visibility (which 414 // Loop through and check each browser action for proper visibility (which
415 // implicitly also guarantees that the proper number are visible). 415 // implicitly also guarantees that the proper number are visible).
416 for (size_t i = 0; i < overflow_bar_->num_browser_actions(); ++i) { 416 for (size_t i = 0; i < overflow_bar_->num_toolbar_actions(); ++i) {
417 bool visible = i < expected_visible; 417 bool visible = i < expected_visible;
418 if (main_bar_->GetBrowserActionViewAt(i)->visible() != visible) { 418 if (main_bar_->GetToolbarActionViewAt(i)->visible() != visible) {
419 return testing::AssertionFailure() << "Index " << i << 419 return testing::AssertionFailure() << "Index " << i <<
420 " has improper visibility in main: " << !visible; 420 " has improper visibility in main: " << !visible;
421 } 421 }
422 if (overflow_bar_->GetBrowserActionViewAt(i)->visible() == visible) { 422 if (overflow_bar_->GetToolbarActionViewAt(i)->visible() == visible) {
423 return testing::AssertionFailure() << "Index " << i << 423 return testing::AssertionFailure() << "Index " << i <<
424 " has improper visibility in overflow: " << visible; 424 " has improper visibility in overflow: " << visible;
425 } 425 }
426 } 426 }
427 return testing::AssertionSuccess(); 427 return testing::AssertionSuccess();
428 } 428 }
429 429
430 // Test the basic functionality of the BrowserActionsContainer in overflow mode. 430 // Test the basic functionality of the BrowserActionsContainer in overflow mode.
431 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, 431 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest,
432 TestBasicActionOverflow) { 432 TestBasicActionOverflow) {
433 LoadExtensions(); 433 LoadExtensions();
434 434
435 // Since the overflow bar isn't attached to a view, we have to kick it in 435 // Since the overflow bar isn't attached to a view, we have to kick it in
436 // order to retrigger layout each time we change the number of icons in the 436 // order to retrigger layout each time we change the number of icons in the
437 // bar. 437 // bar.
438 overflow_bar()->Layout(); 438 overflow_bar()->Layout();
439 439
440 // All actions are showing, and are in the installation order. 440 // All actions are showing, and are in the installation order.
441 EXPECT_EQ(-1, model()->GetVisibleIconCount()); 441 EXPECT_EQ(-1, model()->GetVisibleIconCount());
442 ASSERT_EQ(3u, main_bar()->num_browser_actions()); 442 ASSERT_EQ(3u, main_bar()->num_toolbar_actions());
443 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); 443 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u));
444 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); 444 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u));
445 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); 445 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u));
446 EXPECT_TRUE(VerifyVisibleCount(3u)); 446 EXPECT_TRUE(VerifyVisibleCount(3u));
447 447
448 // Reduce the visible count to 2. Order should be unchanged (A B C), but 448 // Reduce the visible count to 2. Order should be unchanged (A B C), but
449 // only A and B should be visible on the main bar. 449 // only A and B should be visible on the main bar.
450 model()->SetVisibleIconCount(2u); 450 model()->SetVisibleIconCount(2u);
451 overflow_bar()->Layout(); // Kick. 451 overflow_bar()->Layout(); // Kick.
452 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); 452 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u));
(...skipping 27 matching lines...) Expand all
480 // Test drag and drop between the overflow container and the main container. 480 // Test drag and drop between the overflow container and the main container.
481 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, 481 IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest,
482 TestOverflowDragging) { 482 TestOverflowDragging) {
483 LoadExtensions(); 483 LoadExtensions();
484 484
485 // Start with one extension in overflow. 485 // Start with one extension in overflow.
486 model()->SetVisibleIconCount(2u); 486 model()->SetVisibleIconCount(2u);
487 overflow_bar()->Layout(); 487 overflow_bar()->Layout();
488 488
489 // Verify starting state is A B [C]. 489 // Verify starting state is A B [C].
490 ASSERT_EQ(3u, main_bar()->num_browser_actions()); 490 ASSERT_EQ(3u, main_bar()->num_toolbar_actions());
491 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); 491 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u));
492 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); 492 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u));
493 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); 493 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u));
494 EXPECT_TRUE(VerifyVisibleCount(2u)); 494 EXPECT_TRUE(VerifyVisibleCount(2u));
495 495
496 // Drag extension A (on the main bar) to the left of extension C (in 496 // Drag extension A (on the main bar) to the left of extension C (in
497 // overflow). 497 // overflow).
498 ui::OSExchangeData drop_data; 498 ui::OSExchangeData drop_data;
499 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); 499 BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u);
500 browser_action_drag_data.Write(profile(), &drop_data); 500 browser_action_drag_data.Write(profile(), &drop_data);
501 BrowserActionView* view = overflow_bar()->GetViewForExtension(extension_c()); 501 ToolbarActionView* view = overflow_bar()->GetViewForExtension(extension_c());
502 gfx::Point location(view->x(), view->y()); 502 gfx::Point location(view->x(), view->y());
503 ui::DropTargetEvent target_event( 503 ui::DropTargetEvent target_event(
504 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); 504 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE);
505 505
506 overflow_bar()->OnDragUpdated(target_event); 506 overflow_bar()->OnDragUpdated(target_event);
507 overflow_bar()->OnPerformDrop(target_event); 507 overflow_bar()->OnPerformDrop(target_event);
508 overflow_bar()->Layout(); 508 overflow_bar()->Layout();
509 509
510 // Order should now be B [A C]. 510 // Order should now be B [A C].
511 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(0u)); 511 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(0u));
(...skipping 29 matching lines...) Expand all
541 541
542 main_bar()->OnDragUpdated(target_event3); 542 main_bar()->OnDragUpdated(target_event3);
543 main_bar()->OnPerformDrop(target_event3); 543 main_bar()->OnPerformDrop(target_event3);
544 544
545 // Order should be A C B, and there should be no extensions in overflow. 545 // Order should be A C B, and there should be no extensions in overflow.
546 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); 546 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u));
547 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(1u)); 547 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(1u));
548 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); 548 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u));
549 VerifyVisibleCount(3u); 549 VerifyVisibleCount(3u);
550 } 550 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/toolbar/browser_actions_container.cc ('k') | chrome/browser/ui/views/toolbar/chevron_menu_button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698