| OLD | NEW |
| 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 "chrome/browser/ui/toolbar/toolbar_actions_model.h" | 5 #include "chrome/browser/ui/toolbar/toolbar_actions_model.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 | 10 |
| (...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u)); | 1449 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(3u)); |
| 1450 | 1450 |
| 1451 // Remove the component action. Extension C should stay in the overflow. | 1451 // Remove the component action. Extension C should stay in the overflow. |
| 1452 // The icons should be: A, B, [C]. | 1452 // The icons should be: A, B, [C]. |
| 1453 toolbar_model()->RemoveComponentAction(component_action_id()); | 1453 toolbar_model()->RemoveComponentAction(component_action_id()); |
| 1454 EXPECT_EQ(3u, num_toolbar_items()); | 1454 EXPECT_EQ(3u, num_toolbar_items()); |
| 1455 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); | 1455 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); |
| 1456 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u)); | 1456 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u)); |
| 1457 } | 1457 } |
| 1458 | 1458 |
| 1459 TEST_F(ToolbarActionsModelUnitTest, AddComponentActionInIncognito) { |
| 1460 Init(); |
| 1461 // Add three extension actions: A, B, C. |
| 1462 ASSERT_TRUE(AddBrowserActionExtensions()); |
| 1463 EXPECT_EQ(3u, num_toolbar_items()); |
| 1464 |
| 1465 // Enable extension C in incognito. |
| 1466 extensions::ExtensionPrefs* extension_prefs = |
| 1467 extensions::ExtensionPrefs::Get(profile()); |
| 1468 extension_prefs->SetIsIncognitoEnabled(browser_action_c()->id(), true); |
| 1469 extensions::util::SetIsIncognitoEnabled(browser_action_c()->id(), profile(), |
| 1470 true); |
| 1471 |
| 1472 // Get an incognito toolbar. |
| 1473 ToolbarActionsModel* incognito_model = |
| 1474 extensions::extension_action_test_util::CreateToolbarModelForProfile( |
| 1475 profile()->GetOffTheRecordProfile()); |
| 1476 |
| 1477 // The incognito toolbar should only have extension C. |
| 1478 EXPECT_EQ(1u, incognito_model->toolbar_items().size()); |
| 1479 |
| 1480 // Add a component action to the incognito toolbar. It shouldn't appear on the |
| 1481 // non-incognito toolbar. |
| 1482 incognito_model->AddComponentAction(component_action_id()); |
| 1483 EXPECT_EQ(2u, incognito_model->toolbar_items().size()); |
| 1484 EXPECT_EQ(2u, incognito_model->visible_icon_count()); |
| 1485 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u, incognito_model)); |
| 1486 EXPECT_EQ(3u, num_toolbar_items()); |
| 1487 incognito_model->RemoveComponentAction(component_action_id()); |
| 1488 |
| 1489 // Set visible count to 2 so that C is overflowed on the non-incognito |
| 1490 // toolbar. Its state is A, B, [C]. C stays visible on the incognito toolbar. |
| 1491 toolbar_model()->SetVisibleIconCount(2); |
| 1492 EXPECT_EQ(1u, incognito_model->toolbar_items().size()); |
| 1493 EXPECT_EQ(1u, incognito_model->visible_icon_count()); |
| 1494 |
| 1495 // Add a component action to the incognito toolbar. It shouldn't appear in the |
| 1496 // overflow menu. |
| 1497 incognito_model->AddComponentAction(component_action_id()); |
| 1498 EXPECT_EQ(2u, incognito_model->toolbar_items().size()); |
| 1499 EXPECT_EQ(2u, incognito_model->visible_icon_count()); |
| 1500 EXPECT_EQ(component_action_id(), GetActionIdAtIndex(1u, incognito_model)); |
| 1501 } |
| 1502 |
| 1459 TEST_F(ToolbarActionsModelUnitTest, | 1503 TEST_F(ToolbarActionsModelUnitTest, |
| 1460 TestUninstallVisibleExtensionDoesntBringOutOther) { | 1504 TestUninstallVisibleExtensionDoesntBringOutOther) { |
| 1461 Init(); | 1505 Init(); |
| 1462 ASSERT_TRUE(AddBrowserActionExtensions()); | 1506 ASSERT_TRUE(AddBrowserActionExtensions()); |
| 1463 toolbar_model()->SetVisibleIconCount(2u); | 1507 toolbar_model()->SetVisibleIconCount(2u); |
| 1464 EXPECT_EQ(3u, num_toolbar_items()); | 1508 EXPECT_EQ(3u, num_toolbar_items()); |
| 1465 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); | 1509 EXPECT_EQ(2u, toolbar_model()->visible_icon_count()); |
| 1466 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u)); | 1510 EXPECT_EQ(browser_action_a()->id(), GetActionIdAtIndex(0u)); |
| 1467 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(1u)); | 1511 EXPECT_EQ(browser_action_b()->id(), GetActionIdAtIndex(1u)); |
| 1468 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u)); | 1512 EXPECT_EQ(browser_action_c()->id(), GetActionIdAtIndex(2u)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 } | 1585 } |
| 1542 | 1586 |
| 1543 TEST_F(ToolbarActionsModelUnitTest, | 1587 TEST_F(ToolbarActionsModelUnitTest, |
| 1544 MigrationToExtensionWithoutExtensionActionRedesign) { | 1588 MigrationToExtensionWithoutExtensionActionRedesign) { |
| 1545 InitForMigrationTest(MigrationStatus::FEATURE_DISABLED_WITH_PREF_TRUE); | 1589 InitForMigrationTest(MigrationStatus::FEATURE_DISABLED_WITH_PREF_TRUE); |
| 1546 | 1590 |
| 1547 // Initialization re-enables the extension. | 1591 // Initialization re-enables the extension. |
| 1548 EXPECT_EQ(1u, num_toolbar_items()); | 1592 EXPECT_EQ(1u, num_toolbar_items()); |
| 1549 EXPECT_EQ(browser_action_migrated()->id(), GetActionIdAtIndex(0u)); | 1593 EXPECT_EQ(browser_action_migrated()->id(), GetActionIdAtIndex(0u)); |
| 1550 } | 1594 } |
| OLD | NEW |