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 "base/files/file_util.h" | 5 #include "base/files/file_util.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" | 10 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
(...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 SetReady(); | 1304 SetReady(); |
1305 // Run tasks posted to TestExtensionSystem. | 1305 // Run tasks posted to TestExtensionSystem. |
1306 base::RunLoop().RunUntilIdle(); | 1306 base::RunLoop().RunUntilIdle(); |
1307 | 1307 |
1308 // We should still have no insertions, but should have an initialized count. | 1308 // We should still have no insertions, but should have an initialized count. |
1309 EXPECT_TRUE(toolbar_model->extensions_initialized()); | 1309 EXPECT_TRUE(toolbar_model->extensions_initialized()); |
1310 EXPECT_EQ(0u, model_observer.inserted_count()); | 1310 EXPECT_EQ(0u, model_observer.inserted_count()); |
1311 EXPECT_EQ(1u, model_observer.initialized_count()); | 1311 EXPECT_EQ(1u, model_observer.initialized_count()); |
1312 } | 1312 } |
1313 | 1313 |
| 1314 // Check that the toolbar model correctly clears and reorders when it detects |
| 1315 // a preference change. |
| 1316 TEST_F(ExtensionToolbarModelUnitTest, ToolbarModelPrefChange) { |
| 1317 Init(); |
| 1318 |
| 1319 ASSERT_TRUE(AddBrowserActionExtensions()); |
| 1320 |
| 1321 // We should start in the basic A B C order. |
| 1322 ASSERT_TRUE(browser_action_a()); |
| 1323 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(0)); |
| 1324 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(1)); |
| 1325 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(2)); |
| 1326 // Record the difference between the inserted and removed counts. The actual |
| 1327 // value of the counts is not important, but we need to be sure that if we |
| 1328 // call to remove any, we also add them back. |
| 1329 size_t inserted_and_removed_difference = |
| 1330 observer()->inserted_count() - observer()->removed_count(); |
| 1331 |
| 1332 // Assign a new order, B C A, and write it in the prefs. |
| 1333 ExtensionIdList new_order; |
| 1334 new_order.push_back(browser_action_b()->id()); |
| 1335 new_order.push_back(browser_action_c()->id()); |
| 1336 new_order.push_back(browser_action_a()->id()); |
| 1337 ExtensionPrefs::Get(profile())->SetToolbarOrder(new_order); |
| 1338 |
| 1339 // Ensure everything has time to run. |
| 1340 base::RunLoop().RunUntilIdle(); |
| 1341 |
| 1342 // The new order should be reflected in the model. |
| 1343 EXPECT_EQ(browser_action_b(), GetExtensionAtIndex(0)); |
| 1344 EXPECT_EQ(browser_action_c(), GetExtensionAtIndex(1)); |
| 1345 EXPECT_EQ(browser_action_a(), GetExtensionAtIndex(2)); |
| 1346 EXPECT_EQ(inserted_and_removed_difference, |
| 1347 observer()->inserted_count() - observer()->removed_count()); |
| 1348 } |
| 1349 |
1314 } // namespace extensions | 1350 } // namespace extensions |
OLD | NEW |