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

Side by Side Diff: chrome/browser/ui/toolbar/toolbar_actions_model_unittest.cc

Issue 1761913003: [Extensions] Default-enable the toolbar redesign on trunk (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 void ToolbarActionsModelUnitTest::SetMockActionsFactory( 399 void ToolbarActionsModelUnitTest::SetMockActionsFactory(
400 MockComponentToolbarActionsFactory* factory) { 400 MockComponentToolbarActionsFactory* factory) {
401 mock_actions_factory_.reset(factory); 401 mock_actions_factory_.reset(factory);
402 } 402 }
403 403
404 // A basic test for component actions and extensions with browser actions 404 // A basic test for component actions and extensions with browser actions
405 // showing up in the toolbar. 405 // showing up in the toolbar.
406 TEST_F(ToolbarActionsModelUnitTest, BasicToolbarActionsModelTest) { 406 TEST_F(ToolbarActionsModelUnitTest, BasicToolbarActionsModelTest) {
407 Init(); 407 Init();
408 408
409 // Load an extension with no browser action.
410 scoped_refptr<const extensions::Extension> extension1 =
411 extensions::extension_action_test_util::CreateActionExtension(
412 "no_action", extensions::extension_action_test_util::NO_ACTION);
413 ASSERT_TRUE(AddExtension(extension1));
414
415 // This extension should not be in the model (has no browser action).
416 EXPECT_EQ(0u, observer()->inserted_count());
417 EXPECT_EQ(0u, num_toolbar_items());
418 EXPECT_EQ(std::string(), GetActionIdAtIndex(0u));
419
420 // Load an extension with a browser action. 409 // Load an extension with a browser action.
421 scoped_refptr<const extensions::Extension> extension2 = 410 scoped_refptr<const extensions::Extension> extension =
422 extensions::extension_action_test_util::CreateActionExtension( 411 extensions::extension_action_test_util::CreateActionExtension(
423 "browser_action", 412 "browser_action",
424 extensions::extension_action_test_util::BROWSER_ACTION); 413 extensions::extension_action_test_util::BROWSER_ACTION);
425 ASSERT_TRUE(AddExtension(extension2)); 414 ASSERT_TRUE(AddExtension(extension));
426 415
427 // We should now find our extension in the model. 416 // We should now find our extension in the model.
428 EXPECT_EQ(1u, observer()->inserted_count()); 417 EXPECT_EQ(1u, observer()->inserted_count());
429 EXPECT_EQ(1u, num_toolbar_items()); 418 EXPECT_EQ(1u, num_toolbar_items());
430 EXPECT_EQ(extension2->id(), GetActionIdAtIndex(0u)); 419 EXPECT_EQ(extension->id(), GetActionIdAtIndex(0u));
431 420
432 // Should be a no-op, but still fires the events. 421 // Should be a no-op, but still fires the events.
433 toolbar_model()->MoveActionIcon(extension2->id(), 0); 422 toolbar_model()->MoveActionIcon(extension->id(), 0);
434 EXPECT_EQ(1u, observer()->moved_count()); 423 EXPECT_EQ(1u, observer()->moved_count());
435 EXPECT_EQ(1u, num_toolbar_items()); 424 EXPECT_EQ(1u, num_toolbar_items());
436 EXPECT_EQ(extension2->id(), GetActionIdAtIndex(0u)); 425 EXPECT_EQ(extension->id(), GetActionIdAtIndex(0u));
437 426
438 // Remove the extension and verify. 427 // Remove the extension and verify.
439 ASSERT_TRUE(RemoveExtension(extension2)); 428 ASSERT_TRUE(RemoveExtension(extension));
440 EXPECT_EQ(1u, observer()->removed_count()); 429 EXPECT_EQ(1u, observer()->removed_count());
441 EXPECT_EQ(0u, num_toolbar_items()); 430 EXPECT_EQ(0u, num_toolbar_items());
442 EXPECT_EQ(std::string(), GetActionIdAtIndex(0u)); 431 EXPECT_EQ(std::string(), GetActionIdAtIndex(0u));
443 } 432 }
444 433
445 // Test various different reorderings, removals, and reinsertions. 434 // Test various different reorderings, removals, and reinsertions.
446 TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarReorderAndReinsert) { 435 TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarReorderAndReinsert) {
447 Init(); 436 Init();
448 437
449 // Add the three browser action extensions. 438 // Add the three browser action extensions.
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 EXPECT_TRUE(toolbar_model()->all_icons_visible()); 879 EXPECT_TRUE(toolbar_model()->all_icons_visible());
891 EXPECT_EQ(num_toolbar_items(), toolbar_model()->visible_icon_count()); 880 EXPECT_EQ(num_toolbar_items(), toolbar_model()->visible_icon_count());
892 toolbar_model()->OnActionToolbarPrefChange(); 881 toolbar_model()->OnActionToolbarPrefChange();
893 // Should still be at max size. 882 // Should still be at max size.
894 EXPECT_TRUE(toolbar_model()->all_icons_visible()); 883 EXPECT_TRUE(toolbar_model()->all_icons_visible());
895 EXPECT_EQ(num_toolbar_items(), toolbar_model()->visible_icon_count()); 884 EXPECT_EQ(num_toolbar_items(), toolbar_model()->visible_icon_count());
896 } 885 }
897 886
898 // Test that, in the absence of the extension-action-redesign switch, the 887 // Test that, in the absence of the extension-action-redesign switch, the
899 // model only contains extensions with browser actions and component actions. 888 // model only contains extensions with browser actions and component actions.
900 TEST_F(ToolbarActionsModelUnitTest, TestToolbarExtensionTypesNoSwitch) { 889 TEST_F(ToolbarActionsModelUnitTest, TestToolbarExtensionTypesDisabledSwitch) {
890 extensions::FeatureSwitch::ScopedOverride enable_redesign(
891 extensions::FeatureSwitch::extension_action_redesign(), false);
901 Init(); 892 Init();
902 ASSERT_TRUE(AddActionExtensions()); 893 ASSERT_TRUE(AddActionExtensions());
903 894
904 EXPECT_EQ(1u, num_toolbar_items()); 895 EXPECT_EQ(1u, num_toolbar_items());
905 EXPECT_EQ(browser_action()->id(), GetActionIdAtIndex(0u)); 896 EXPECT_EQ(browser_action()->id(), GetActionIdAtIndex(0u));
906 } 897 }
907 898
908 // Test that, with the extension-action-redesign switch, the model contains 899 // Test that, with the extension-action-redesign switch, the model contains
909 // all types of extensions, except those which should not be displayed on the 900 // all types of extensions, except those which should not be displayed on the
910 // toolbar (like component extensions). 901 // toolbar (like component extensions).
911 TEST_F(ToolbarActionsModelUnitTest, TestToolbarExtensionTypesSwitch) { 902 TEST_F(ToolbarActionsModelUnitTest, TestToolbarExtensionTypesEnabledSwitch) {
912 extensions::FeatureSwitch::ScopedOverride enable_redesign( 903 extensions::FeatureSwitch::ScopedOverride enable_redesign(
913 extensions::FeatureSwitch::extension_action_redesign(), true); 904 extensions::FeatureSwitch::extension_action_redesign(), true);
914 Init(); 905 Init();
915 906
916 ASSERT_TRUE(AddActionExtensions()); 907 ASSERT_TRUE(AddActionExtensions());
917 908
918 // With the switch on, extensions with page actions and no action should also 909 // With the switch on, extensions with page actions and no action should also
919 // be displayed in the toolbar. 910 // be displayed in the toolbar.
920 EXPECT_EQ(3u, num_toolbar_items()); 911 EXPECT_EQ(3u, num_toolbar_items());
921 EXPECT_EQ(browser_action()->id(), GetActionIdAtIndex(0u)); 912 EXPECT_EQ(browser_action()->id(), GetActionIdAtIndex(0u));
922 EXPECT_EQ(page_action()->id(), GetActionIdAtIndex(1u)); 913 EXPECT_EQ(page_action()->id(), GetActionIdAtIndex(1u));
923 EXPECT_EQ(no_action()->id(), GetActionIdAtIndex(2u)); 914 EXPECT_EQ(no_action()->id(), GetActionIdAtIndex(2u));
924 } 915 }
925 916
926 // Test that hiding actions on the toolbar results in their removal from the 917 // Test that hiding actions on the toolbar results in their removal from the
927 // model when the redesign switch is not enabled. 918 // model when the redesign switch is not enabled.
928 TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarActionsVisibilityNoSwitch) { 919 TEST_F(ToolbarActionsModelUnitTest, ActionsToolbarActionsVisibilityNoSwitch) {
920 extensions::FeatureSwitch::ScopedOverride enable_redesign(
921 extensions::FeatureSwitch::extension_action_redesign(), false);
929 Init(); 922 Init();
930 923
931 extensions::ExtensionActionAPI* action_api = 924 extensions::ExtensionActionAPI* action_api =
932 extensions::ExtensionActionAPI::Get(profile()); 925 extensions::ExtensionActionAPI::Get(profile());
933 926
934 ASSERT_TRUE(AddBrowserActionExtensions()); 927 ASSERT_TRUE(AddBrowserActionExtensions());
935 // Sanity check: Order should start as A , B, C. 928 // Sanity check: Order should start as A , B, C.
936 EXPECT_EQ(3u, num_toolbar_items()); 929 EXPECT_EQ(3u, num_toolbar_items());
937 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u)); 930 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u));
938 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(1u)); 931 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(1u));
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
1492 } 1485 }
1493 1486
1494 TEST_F(ToolbarActionsModelUnitTest, 1487 TEST_F(ToolbarActionsModelUnitTest,
1495 MigrationToExtensionWithoutExtensionActionRedesign) { 1488 MigrationToExtensionWithoutExtensionActionRedesign) {
1496 InitForMigrationTest(MigrationStatus::FEATURE_DISABLED_WITH_PREF_TRUE); 1489 InitForMigrationTest(MigrationStatus::FEATURE_DISABLED_WITH_PREF_TRUE);
1497 1490
1498 // Initialization re-enables the extension. 1491 // Initialization re-enables the extension.
1499 EXPECT_EQ(1u, num_toolbar_items()); 1492 EXPECT_EQ(1u, num_toolbar_items());
1500 EXPECT_EQ(browser_action_migrated()->id(), GetActionIdAtIndex(0u)); 1493 EXPECT_EQ(browser_action_migrated()->id(), GetActionIdAtIndex(0u));
1501 } 1494 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/toolbar_actions_bar_unittest.cc ('k') | extensions/common/feature_switch.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698