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

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

Issue 754473003: [Extensions Toolbar Mac] More cleanup of BrowserActionsController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years 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"
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); 224 EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions());
225 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); 225 EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions());
226 action_view = container->GetToolbarActionViewAt(0); 226 action_view = container->GetToolbarActionViewAt(0);
227 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point)); 227 EXPECT_TRUE(container->CanStartDragForView(action_view, point, point));
228 } 228 }
229 229
230 // Test the behavior of the overflow container for Extension Actions. 230 // Test the behavior of the overflow container for Extension Actions.
231 class BrowserActionsContainerOverflowTest 231 class BrowserActionsContainerOverflowTest
232 : public BrowserActionsBarBrowserTest { 232 : public BrowserActionsBarBrowserTest {
233 public: 233 public:
234 BrowserActionsContainerOverflowTest() : main_bar_(NULL), model_(NULL) { 234 BrowserActionsContainerOverflowTest() : main_bar_(nullptr),
235 overflow_bar_(nullptr),
236 model_(nullptr) {
235 } 237 }
236 ~BrowserActionsContainerOverflowTest() override {} 238 ~BrowserActionsContainerOverflowTest() override {}
237 239
238 protected: 240 protected:
239 // Returns true if the order of the ToolbarActionViews in |main_bar_| 241 // Returns true if the order of the ToolbarActionViews in |main_bar_|
240 // and |overflow_bar_| match. 242 // and |overflow_bar_| match.
241 bool ViewOrdersMatch(); 243 bool ViewOrdersMatch();
242 244
243 // Returns Success if the visible count matches |expected_visible|. This means 245 // Returns Success if the visible count matches |expected_visible|. This means
244 // that the number of visible browser actions in |main_bar_| is 246 // that the number of visible browser actions in |main_bar_| is
245 // |expected_visible| and shows the first icons, and that the overflow bar 247 // |expected_visible| and shows the first icons, and that the overflow bar
246 // shows all (and only) the remainder. 248 // shows all (and only) the remainder.
247 testing::AssertionResult VerifyVisibleCount(size_t expected_visible); 249 testing::AssertionResult VerifyVisibleCount(size_t expected_visible)
250 WARN_UNUSED_RESULT;
248 251
249 // Accessors. 252 // Accessors.
250 BrowserActionsContainer* main_bar() { return main_bar_; } 253 BrowserActionsContainer* main_bar() { return main_bar_; }
251 BrowserActionsContainer* overflow_bar() { return overflow_bar_.get(); } 254 BrowserActionsContainer* overflow_bar() { return overflow_bar_; }
252 extensions::ExtensionToolbarModel* model() { return model_; } 255 extensions::ExtensionToolbarModel* model() { return model_; }
253 256
254 private: 257 private:
255 void SetUpCommandLine(base::CommandLine* command_line) override; 258 void SetUpCommandLine(base::CommandLine* command_line) override;
256 void SetUpOnMainThread() override; 259 void SetUpOnMainThread() override;
257 void TearDownOnMainThread() override; 260 void TearDownOnMainThread() override;
258 261
259 // The main BrowserActionsContainer (owned by the browser view). 262 // The main BrowserActionsContainer (owned by the browser view).
260 BrowserActionsContainer* main_bar_; 263 BrowserActionsContainer* main_bar_;
261 264
265 // A parent view for the overflow menu.
266 scoped_ptr<views::View> overflow_parent_;
267
262 // The overflow BrowserActionsContainer. We manufacture this so that we don't 268 // The overflow BrowserActionsContainer. We manufacture this so that we don't
263 // have to open the wrench menu. 269 // have to open the wrench menu.
264 scoped_ptr<BrowserActionsContainer> overflow_bar_; 270 // Owned by the |overflow_parent_|.
271 BrowserActionsContainer* overflow_bar_;
265 272
266 // The associated toolbar model. 273 // The associated toolbar model.
267 extensions::ExtensionToolbarModel* model_; 274 extensions::ExtensionToolbarModel* model_;
268 275
269 // Enable the feature redesign switch. 276 // Enable the feature redesign switch.
270 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_; 277 scoped_ptr<extensions::FeatureSwitch::ScopedOverride> enable_redesign_;
271 278
272 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainerOverflowTest); 279 DISALLOW_COPY_AND_ASSIGN(BrowserActionsContainerOverflowTest);
273 }; 280 };
274 281
275 void BrowserActionsContainerOverflowTest::SetUpCommandLine( 282 void BrowserActionsContainerOverflowTest::SetUpCommandLine(
276 base::CommandLine* command_line) { 283 base::CommandLine* command_line) {
277 BrowserActionsBarBrowserTest::SetUpCommandLine(command_line); 284 BrowserActionsBarBrowserTest::SetUpCommandLine(command_line);
278 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride( 285 enable_redesign_.reset(new extensions::FeatureSwitch::ScopedOverride(
279 extensions::FeatureSwitch::extension_action_redesign(), 286 extensions::FeatureSwitch::extension_action_redesign(),
280 true)); 287 true));
281 } 288 }
282 289
283 void BrowserActionsContainerOverflowTest::SetUpOnMainThread() { 290 void BrowserActionsContainerOverflowTest::SetUpOnMainThread() {
284 BrowserActionsBarBrowserTest::SetUpOnMainThread(); 291 BrowserActionsBarBrowserTest::SetUpOnMainThread();
285 main_bar_ = BrowserView::GetBrowserViewForBrowser(browser()) 292 main_bar_ = BrowserView::GetBrowserViewForBrowser(browser())
286 ->toolbar()->browser_actions(); 293 ->toolbar()->browser_actions();
287 overflow_bar_.reset(new BrowserActionsContainer(browser(), main_bar_)); 294 overflow_parent_.reset(new views::View());
288 overflow_bar_->set_owned_by_client(); 295 overflow_parent_->set_owned_by_client();
296 overflow_bar_ = new BrowserActionsContainer(browser(), main_bar_);
297 overflow_parent_->AddChildView(overflow_bar_);
289 model_ = extensions::ExtensionToolbarModel::Get(profile()); 298 model_ = extensions::ExtensionToolbarModel::Get(profile());
290 } 299 }
291 300
292 void BrowserActionsContainerOverflowTest::TearDownOnMainThread() { 301 void BrowserActionsContainerOverflowTest::TearDownOnMainThread() {
293 overflow_bar_.reset(); 302 overflow_parent_.reset();
294 enable_redesign_.reset(); 303 enable_redesign_.reset();
295 BrowserActionsBarBrowserTest::TearDownOnMainThread(); 304 BrowserActionsBarBrowserTest::TearDownOnMainThread();
296 } 305 }
297 306
298 bool BrowserActionsContainerOverflowTest::ViewOrdersMatch() { 307 bool BrowserActionsContainerOverflowTest::ViewOrdersMatch() {
299 if (main_bar_->num_toolbar_actions() != 308 if (main_bar_->num_toolbar_actions() !=
300 overflow_bar_->num_toolbar_actions()) 309 overflow_bar_->num_toolbar_actions())
301 return false; 310 return false;
302 for (size_t i = 0; i < main_bar_->num_toolbar_actions(); ++i) { 311 for (size_t i = 0; i < main_bar_->num_toolbar_actions(); ++i) {
303 if (main_bar_->GetIdAt(i) != overflow_bar_->GetIdAt(i)) 312 if (main_bar_->GetIdAt(i) != overflow_bar_->GetIdAt(i))
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); 416 drop_data, location, location, ui::DragDropTypes::DRAG_MOVE);
408 417
409 overflow_bar()->OnDragUpdated(target_event); 418 overflow_bar()->OnDragUpdated(target_event);
410 overflow_bar()->OnPerformDrop(target_event); 419 overflow_bar()->OnPerformDrop(target_event);
411 overflow_bar()->Layout(); 420 overflow_bar()->Layout();
412 421
413 // Order should now be B [A C]. 422 // Order should now be B [A C].
414 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(0u)); 423 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(0u));
415 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(1u)); 424 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(1u));
416 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); 425 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u));
417 VerifyVisibleCount(1u); 426 EXPECT_TRUE(VerifyVisibleCount(1u));
418 427
419 // Drag extension A back from overflow to the main bar. 428 // Drag extension A back from overflow to the main bar.
420 ui::OSExchangeData drop_data2; 429 ui::OSExchangeData drop_data2;
421 BrowserActionDragData browser_action_drag_data2(extension_a()->id(), 1u); 430 BrowserActionDragData browser_action_drag_data2(extension_a()->id(), 1u);
422 browser_action_drag_data2.Write(profile(), &drop_data2); 431 browser_action_drag_data2.Write(profile(), &drop_data2);
423 view = main_bar()->GetViewForId(extension_b()->id()); 432 view = main_bar()->GetViewForId(extension_b()->id());
424 location = gfx::Point(view->x(), view->y()); 433 location = gfx::Point(view->x(), view->y());
425 ui::DropTargetEvent target_event2( 434 ui::DropTargetEvent target_event2(
426 drop_data2, location, location, ui::DragDropTypes::DRAG_MOVE); 435 drop_data2, location, location, ui::DragDropTypes::DRAG_MOVE);
427 436
428 main_bar()->OnDragUpdated(target_event2); 437 main_bar()->OnDragUpdated(target_event2);
429 main_bar()->OnPerformDrop(target_event2); 438 main_bar()->OnPerformDrop(target_event2);
430 439
431 // Order should be A B [C] again. 440 // Order should be A B [C] again.
432 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); 441 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u));
433 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u)); 442 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(1u));
434 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u)); 443 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(2u));
435 VerifyVisibleCount(2u); 444 EXPECT_TRUE(VerifyVisibleCount(2u));
436 445
437 // Drag extension C from overflow to the main bar (before extension B). 446 // Drag extension C from overflow to the main bar (before extension B).
438 ui::OSExchangeData drop_data3; 447 ui::OSExchangeData drop_data3;
439 BrowserActionDragData browser_action_drag_data3(extension_c()->id(), 2u); 448 BrowserActionDragData browser_action_drag_data3(extension_c()->id(), 2u);
440 browser_action_drag_data3.Write(profile(), &drop_data3); 449 browser_action_drag_data3.Write(profile(), &drop_data3);
441 location = gfx::Point(view->x(), view->y()); 450 location = gfx::Point(view->x(), view->y());
442 ui::DropTargetEvent target_event3( 451 ui::DropTargetEvent target_event3(
443 drop_data3, location, location, ui::DragDropTypes::DRAG_MOVE); 452 drop_data3, location, location, ui::DragDropTypes::DRAG_MOVE);
444 453
445 main_bar()->OnDragUpdated(target_event3); 454 main_bar()->OnDragUpdated(target_event3);
446 main_bar()->OnPerformDrop(target_event3); 455 main_bar()->OnPerformDrop(target_event3);
447 456
448 // Order should be A C B, and there should be no extensions in overflow. 457 // Order should be A C B, and there should be no extensions in overflow.
449 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u)); 458 EXPECT_EQ(extension_a()->id(), main_bar()->GetIdAt(0u));
450 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(1u)); 459 EXPECT_EQ(extension_c()->id(), main_bar()->GetIdAt(1u));
451 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u)); 460 EXPECT_EQ(extension_b()->id(), main_bar()->GetIdAt(2u));
452 VerifyVisibleCount(3u); 461 EXPECT_TRUE(VerifyVisibleCount(3u));
453 } 462 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698