| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/macros.h" | 5 #include "base/macros.h" |
| 6 #include "chrome/browser/extensions/extension_browsertest.h" | 6 #include "chrome/browser/extensions/extension_browsertest.h" |
| 7 #include "chrome/browser/extensions/extension_toolbar_model.h" | 7 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/test/base/in_process_browser_test.h" | 10 #include "chrome/test/base/in_process_browser_test.h" |
| 11 | 11 |
| 12 namespace extensions { | 12 namespace extensions { |
| 13 | 13 |
| 14 // An InProcessBrowserTest for testing the ExtensionToolbarModel. | 14 // An InProcessBrowserTest for testing the ExtensionToolbarModel. |
| 15 // TODO(erikkay) It's unfortunate that this needs to be an in-proc browser test. | 15 // TODO(erikkay) It's unfortunate that this needs to be an in-proc browser test. |
| 16 // It would be nice to refactor things so that ExtensionService could run | 16 // It would be nice to refactor things so that ExtensionService could run |
| 17 // without so much of the browser in place. | 17 // without so much of the browser in place. |
| 18 class ExtensionToolbarModelTest : public ExtensionBrowserTest, | 18 class ExtensionToolbarModelTest : public ExtensionBrowserTest, |
| 19 public ExtensionToolbarModel::Observer { | 19 public ExtensionToolbarModel::Observer { |
| 20 public: | 20 public: |
| 21 virtual void SetUp() { | 21 virtual void SetUp() { |
| 22 inserted_count_ = 0; | 22 inserted_count_ = 0; |
| 23 removed_count_ = 0; | 23 removed_count_ = 0; |
| 24 moved_count_ = 0; | 24 moved_count_ = 0; |
| 25 highlight_mode_count_ = 0; | 25 highlight_mode_count_ = 0; |
| 26 | 26 |
| 27 ExtensionBrowserTest::SetUp(); | 27 ExtensionBrowserTest::SetUp(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
| 31 ExtensionBrowserTest::SetUpCommandLine(command_line); | |
| 32 #if defined(OS_LINUX) || defined(OS_CHROMEOS) | |
| 33 command_line->AppendSwitchNative( | |
| 34 "vmodule", "*extension_toolbar_model*=4,*browser_actions_container*=4"); | |
| 35 #endif // defined(OS_LINUX) || defined(OS_CHROMEOS) | |
| 36 } | |
| 37 | |
| 38 virtual void SetUpOnMainThread() OVERRIDE { | 30 virtual void SetUpOnMainThread() OVERRIDE { |
| 39 model_ = ExtensionToolbarModel::Get(browser()->profile()); | 31 model_ = ExtensionToolbarModel::Get(browser()->profile()); |
| 40 model_->AddObserver(this); | 32 model_->AddObserver(this); |
| 41 } | 33 } |
| 42 | 34 |
| 43 virtual void CleanUpOnMainThread() OVERRIDE { | 35 virtual void CleanUpOnMainThread() OVERRIDE { |
| 44 model_->RemoveObserver(this); | 36 model_->RemoveObserver(this); |
| 45 } | 37 } |
| 46 | 38 |
| 47 virtual void BrowserActionAdded(const Extension* extension, | 39 virtual void BrowserActionAdded(const Extension* extension, |
| (...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 592 EXPECT_EQ(id_c, ExtensionAt(2)->id()); | 584 EXPECT_EQ(id_c, ExtensionAt(2)->id()); |
| 593 } | 585 } |
| 594 | 586 |
| 595 // Test is flaky (see crbug.com/379170), but currently enabled to gather traces. | 587 // Test is flaky (see crbug.com/379170), but currently enabled to gather traces. |
| 596 // If it fails, ping Finnur. | 588 // If it fails, ping Finnur. |
| 597 IN_PROC_BROWSER_TEST_F(ExtensionToolbarModelTest, SizeAfterPrefChange) { | 589 IN_PROC_BROWSER_TEST_F(ExtensionToolbarModelTest, SizeAfterPrefChange) { |
| 598 // Load two extensions with browser action. | 590 // Load two extensions with browser action. |
| 599 base::FilePath extension_a_path(test_data_dir_.AppendASCII("api_test") | 591 base::FilePath extension_a_path(test_data_dir_.AppendASCII("api_test") |
| 600 .AppendASCII("browser_action") | 592 .AppendASCII("browser_action") |
| 601 .AppendASCII("basics")); | 593 .AppendASCII("basics")); |
| 602 VLOG(4) << "Loading [basics]"; | |
| 603 ASSERT_TRUE(LoadExtension(extension_a_path)); | 594 ASSERT_TRUE(LoadExtension(extension_a_path)); |
| 604 base::FilePath extension_b_path(test_data_dir_.AppendASCII("api_test") | 595 base::FilePath extension_b_path(test_data_dir_.AppendASCII("api_test") |
| 605 .AppendASCII("browser_action") | 596 .AppendASCII("browser_action") |
| 606 .AppendASCII("popup")); | 597 .AppendASCII("popup")); |
| 607 VLOG(4) << "Loading [popup]"; | |
| 608 ASSERT_TRUE(LoadExtension(extension_b_path)); | 598 ASSERT_TRUE(LoadExtension(extension_b_path)); |
| 609 std::string id_a = ExtensionAt(0)->id(); | 599 std::string id_a = ExtensionAt(0)->id(); |
| 610 std::string id_b = ExtensionAt(1)->id(); | 600 std::string id_b = ExtensionAt(1)->id(); |
| 611 | 601 |
| 612 VLOG(4) << "GetVisibleIconCount"; | |
| 613 | |
| 614 // Should be at max size (-1). | 602 // Should be at max size (-1). |
| 615 EXPECT_EQ(-1, model_->GetVisibleIconCount()); | 603 EXPECT_EQ(-1, model_->GetVisibleIconCount()); |
| 616 | 604 |
| 617 VLOG(4) << "OnExtensionToolbarPrefChange"; | |
| 618 model_->OnExtensionToolbarPrefChange(); | 605 model_->OnExtensionToolbarPrefChange(); |
| 619 | 606 |
| 620 VLOG(4) << "GetVisibleIconCount"; | |
| 621 | |
| 622 // Should still be at max size. | 607 // Should still be at max size. |
| 623 EXPECT_EQ(-1, model_->GetVisibleIconCount()); | 608 EXPECT_EQ(-1, model_->GetVisibleIconCount()); |
| 624 } | 609 } |
| 625 | 610 |
| 626 } // namespace extensions | 611 } // namespace extensions |
| OLD | NEW |