diff options
author | rdevlin.cronin <rdevlin.cronin@chromium.org> | 2014-10-03 06:39:38 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-03 13:40:11 +0000 |
commit | 13cabc71d6358f3cf0b6b1e52a2be210bf5b4b14 (patch) | |
tree | a5832c6a67c1a0cc47b56f4af79c45a1b7512910 /chrome/browser/ui | |
parent | 9f4a7b41f32d0eb162f5df82887c443b6350e322 (diff) | |
download | chromium_src-13cabc71d6358f3cf0b6b1e52a2be210bf5b4b14.zip chromium_src-13cabc71d6358f3cf0b6b1e52a2be210bf5b4b14.tar.gz chromium_src-13cabc71d6358f3cf0b6b1e52a2be210bf5b4b14.tar.bz2 |
Clean up BrowserActionsContainer Browser Tests
Make BrowserActionsContainer browsertests create extensions
dynamically, rather than loading them. This results in
increased stability (doesn't rely on external files),
better speed (don't have to load files; results in about a
33% speed-up according to $ time), and a few less
lines.
Review URL: https://codereview.chromium.org/626673002
Cr-Commit-Position: refs/heads/master@{#298027}
Diffstat (limited to 'chrome/browser/ui')
-rw-r--r-- | chrome/browser/ui/views/toolbar/browser_actions_container_browsertest.cc | 364 |
1 files changed, 166 insertions, 198 deletions
diff --git a/chrome/browser/ui/views/toolbar/browser_actions_container_browsertest.cc b/chrome/browser/ui/views/toolbar/browser_actions_container_browsertest.cc index 76191e9..078759a 100644 --- a/chrome/browser/ui/views/toolbar/browser_actions_container_browsertest.cc +++ b/chrome/browser/ui/views/toolbar/browser_actions_container_browsertest.cc @@ -8,6 +8,7 @@ #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" #include "chrome/browser/extensions/browser_action_test_util.h" #include "chrome/browser/extensions/extension_browsertest.h" +#include "chrome/browser/extensions/extension_service.h" #include "chrome/browser/extensions/extension_toolbar_model.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window_testing_views.h" @@ -15,9 +16,13 @@ #include "chrome/browser/ui/views/frame/browser_view.h" #include "chrome/browser/ui/views/toolbar/browser_action_view.h" #include "chrome/browser/ui/views/toolbar/toolbar_view.h" +#include "components/crx_file/id_util.h" #include "content/public/test/test_utils.h" #include "extensions/browser/extension_prefs.h" +#include "extensions/browser/extension_registry.h" #include "extensions/common/extension.h" +#include "extensions/common/extension_builder.h" +#include "extensions/common/value_builder.h" #include "ui/base/dragdrop/drop_target_event.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/gfx/geometry/point.h" @@ -25,12 +30,32 @@ using extensions::Extension; +namespace { + +scoped_refptr<const Extension> CreateExtension(const std::string& name, + bool has_browser_action) { + extensions::DictionaryBuilder manifest; + manifest.Set("name", name). + Set("description", "an extension"). + Set("manifest_version", 2). + Set("version", "1.0"); + if (has_browser_action) + manifest.Set("browser_action", extensions::DictionaryBuilder().Pass()); + return extensions::ExtensionBuilder(). + SetManifest(manifest.Pass()). + SetID(crx_file::id_util::GenerateId(name)). + Build(); +} + +} // namespace + class BrowserActionsContainerTest : public ExtensionBrowserTest { public: BrowserActionsContainerTest() { } virtual ~BrowserActionsContainerTest() {} + protected: virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE { BrowserActionsContainer::disable_animations_during_testing_ = true; ExtensionBrowserTest::SetUpCommandLine(command_line); @@ -43,38 +68,67 @@ class BrowserActionsContainerTest : public ExtensionBrowserTest { virtual void TearDownOnMainThread() OVERRIDE { BrowserActionsContainer::disable_animations_during_testing_ = false; + ExtensionBrowserTest::TearDownOnMainThread(); } BrowserActionTestUtil* browser_actions_bar() { return browser_actions_bar_.get(); } + // Creates three different extensions, each with a browser action, and adds + // them to associated ExtensionService. These can then be accessed via + // extension_[a|b|c](). + void LoadExtensions(); + + const Extension* extension_a() const { return extension_a_.get(); } + const Extension* extension_b() const { return extension_b_.get(); } + const Extension* extension_c() const { return extension_c_.get(); } + private: scoped_ptr<BrowserActionTestUtil> browser_actions_bar_; + + // Extensions with browser actions used for testing. + scoped_refptr<const Extension> extension_a_; + scoped_refptr<const Extension> extension_b_; + scoped_refptr<const Extension> extension_c_; }; +void BrowserActionsContainerTest::LoadExtensions() { + // Create three extensions with browser actions. + extension_a_ = CreateExtension("alpha", true); + extension_b_ = CreateExtension("beta", true); + extension_c_ = CreateExtension("gamma", true); + + const Extension* extensions[] = + { extension_a(), extension_b(), extension_c() }; + extensions::ExtensionRegistry* registry = + extensions::ExtensionRegistry::Get(profile()); + // Add each, and verify that it is both correctly added to the extension + // registry and to the browser actions container. + for (size_t i = 0; i < arraysize(extensions); ++i) { + extension_service()->AddExtension(extensions[i]); + EXPECT_TRUE(registry->enabled_extensions().GetByID(extensions[i]->id())) << + extensions[i]->name(); + EXPECT_EQ(static_cast<int>(i + 1), + browser_actions_bar_->NumberOfBrowserActions()); + EXPECT_TRUE(browser_actions_bar_->HasIcon(i)); + EXPECT_EQ(static_cast<int>(i + 1), + browser_actions_bar()->VisibleBrowserActions()); + } +} + // Test the basic functionality. -// http://crbug.com/120770 -#if defined(OS_WIN) -IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, DISABLED_Basic) { -#else IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, Basic) { -#endif // Load an extension with no browser action. - ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") - .AppendASCII("browser_action") - .AppendASCII("none"))); + extension_service()->AddExtension(CreateExtension("alpha", false).get()); // This extension should not be in the model (has no browser action). EXPECT_EQ(0, browser_actions_bar()->NumberOfBrowserActions()); // Load an extension with a browser action. - ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") - .AppendASCII("browser_action") - .AppendASCII("basics"))); + extension_service()->AddExtension(CreateExtension("beta", true).get()); EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions()); EXPECT_TRUE(browser_actions_bar()->HasIcon(0)); - // Unload the extension. std::string id = browser_actions_bar()->GetExtensionId(0); UnloadExtension(id); @@ -83,20 +137,8 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, Basic) { // Test moving various browser actions. This is not to check the logic of the // move (that's in the toolbar model tests), but just to check our ui. -IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, - MoveBrowserActions) { - base::FilePath data_dir = - test_data_dir_.AppendASCII("api_test").AppendASCII("browser_action"); - // Load three extensions with browser actions. - const extensions::Extension* extension_a = - LoadExtension(data_dir.AppendASCII("basics")); - ASSERT_TRUE(extension_a); - const extensions::Extension* extension_b = - LoadExtension(data_dir.AppendASCII("add_popup")); - ASSERT_TRUE(extension_b); - const extensions::Extension* extension_c = - LoadExtension(data_dir.AppendASCII("remove_popup")); - ASSERT_TRUE(extension_c); +IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, MoveBrowserActions) { + LoadExtensions(); EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); @@ -106,52 +148,41 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, ASSERT_TRUE(model); // Order is now A B C. - EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(0)); - EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(1)); - EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(2)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1)); + EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(2)); // Move C to first position. Order is C A B. - model->MoveExtensionIcon(extension_c, 0); - EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(0)); - EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(1)); - EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(2)); + model->MoveExtensionIcon(extension_c(), 0); + EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(1)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(2)); // Move B to third position. Order is still C A B. - model->MoveExtensionIcon(extension_b, 2); - EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(0)); - EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(1)); - EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(2)); + model->MoveExtensionIcon(extension_b(), 2); + EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(1)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(2)); // Move B to middle position. Order is C B A. - model->MoveExtensionIcon(extension_b, 1); - EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(0)); - EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(1)); - EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(2)); + model->MoveExtensionIcon(extension_b(), 1); + EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(2)); } // Test that dragging browser actions works, and that dragging a browser action // from the overflow menu results in it "popping" out (growing the container // size by 1), rather than just reordering the extensions. IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, DragBrowserActions) { - base::FilePath data_dir = - test_data_dir_.AppendASCII("api_test").AppendASCII("browser_action"); - // Load three extensions with browser actions. - const extensions::Extension* extension_a = - LoadExtension(data_dir.AppendASCII("basics")); - ASSERT_TRUE(extension_a); - const extensions::Extension* extension_b = - LoadExtension(data_dir.AppendASCII("add_popup")); - ASSERT_TRUE(extension_b); - const extensions::Extension* extension_c = - LoadExtension(data_dir.AppendASCII("remove_popup")); - ASSERT_TRUE(extension_c); + LoadExtensions(); // Sanity check: All extensions showing; order is A B C. EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); - EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(0)); - EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(1)); - EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(2)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1)); + EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(2)); BrowserActionsContainer* container = BrowserView::GetBrowserViewForBrowser(browser()) @@ -160,9 +191,9 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, DragBrowserActions) { // Simulate a drag and drop to the right. ui::OSExchangeData drop_data; // Drag extension A from index 0... - BrowserActionDragData browser_action_drag_data(extension_a->id(), 0u); + BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); browser_action_drag_data.Write(profile(), &drop_data); - BrowserActionView* view = container->GetViewForExtension(extension_b); + BrowserActionView* view = container->GetViewForExtension(extension_b()); // ...to the right of extension B. gfx::Point location(view->x() + view->width(), view->y()); ui::DropTargetEvent target_event( @@ -173,21 +204,21 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, DragBrowserActions) { container->OnPerformDrop(target_event); // The order should now be B A C, since A was dragged to the right of B. - EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(0)); - EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(1)); - EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(2)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(1)); + EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(2)); // This order should be reflected in the underlying model. extensions::ExtensionToolbarModel* model = extensions::ExtensionToolbarModel::Get(profile()); - EXPECT_EQ(extension_b, model->toolbar_items()[0].get()); - EXPECT_EQ(extension_a, model->toolbar_items()[1].get()); - EXPECT_EQ(extension_c, model->toolbar_items()[2].get()); + EXPECT_EQ(extension_b(), model->toolbar_items()[0].get()); + EXPECT_EQ(extension_a(), model->toolbar_items()[1].get()); + EXPECT_EQ(extension_c(), model->toolbar_items()[2].get()); // Simulate a drag and drop to the left. ui::OSExchangeData drop_data2; // Drag extension A from index 1... - BrowserActionDragData browser_action_drag_data2(extension_a->id(), 1u); + BrowserActionDragData browser_action_drag_data2(extension_a()->id(), 1u); browser_action_drag_data2.Write(profile(), &drop_data2); // ...to the left of extension B (which is now at index 0). location = gfx::Point(view->x(), view->y()); @@ -199,9 +230,9 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, DragBrowserActions) { container->OnPerformDrop(target_event2); // Order should be restored to A B C. - EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(0)); - EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(1)); - EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(2)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1)); + EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(2)); // Shrink the size of the container so we have an overflow menu. model->SetVisibleIconCountForTest(2u); @@ -212,7 +243,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, DragBrowserActions) { // Simulate a drag and drop from the overflow menu. ui::OSExchangeData drop_data3; // Drag extension C from index 2 (in the overflow menu)... - BrowserActionDragData browser_action_drag_data3(extension_c->id(), 2u); + BrowserActionDragData browser_action_drag_data3(extension_c()->id(), 2u); browser_action_drag_data3.Write(profile(), &drop_data3); // ...to the left of extension B (which is back in index 1 on the main bar). location = gfx::Point(view->x(), view->y()); @@ -226,9 +257,9 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, DragBrowserActions) { // The order should have changed *and* the container should have grown to // accommodate extension C. The new order should be A C B, and all three // extensions should be visible, with no overflow menu. - EXPECT_EQ(extension_a->id(), browser_actions_bar()->GetExtensionId(0)); - EXPECT_EQ(extension_c->id(), browser_actions_bar()->GetExtensionId(1)); - EXPECT_EQ(extension_b->id(), browser_actions_bar()->GetExtensionId(2)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(1)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(2)); EXPECT_EQ(3u, container->VisibleBrowserActions()); EXPECT_FALSE(container->chevron()->visible()); EXPECT_EQ(-1, model->GetVisibleIconCount()); @@ -240,92 +271,65 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, DragBrowserActions) { } IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, Visibility) { - // Load extension A (contains browser action). - ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") - .AppendASCII("browser_action") - .AppendASCII("basics"))); - EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions()); - EXPECT_TRUE(browser_actions_bar()->HasIcon(0)); - EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions()); - std::string idA = browser_actions_bar()->GetExtensionId(0); - - // Load extension B (contains browser action). - ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") - .AppendASCII("browser_action") - .AppendASCII("add_popup"))); - EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions()); - EXPECT_TRUE(browser_actions_bar()->HasIcon(0)); - EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); - std::string idB = browser_actions_bar()->GetExtensionId(1); - - EXPECT_NE(idA, idB); - - // Load extension C (contains browser action). - ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") - .AppendASCII("browser_action") - .AppendASCII("remove_popup"))); - EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); - EXPECT_TRUE(browser_actions_bar()->HasIcon(2)); - EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); - std::string idC = browser_actions_bar()->GetExtensionId(2); + LoadExtensions(); // Change container to show only one action, rest in overflow: A, [B, C]. browser_actions_bar()->SetIconVisibilityCount(1); EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions()); // Disable extension A (should disappear). State becomes: B [C]. - DisableExtension(idA); + DisableExtension(extension_a()->id()); EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions()); EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions()); - EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(0)); // Enable A again. A should get its spot in the same location and the bar // should not grow (chevron is showing). For details: http://crbug.com/35349. // State becomes: A, [B, C]. - EnableExtension(idA); + EnableExtension(extension_a()->id()); EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions()); - EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0)); // Disable C (in overflow). State becomes: A, [B]. - DisableExtension(idC); + DisableExtension(extension_c()->id()); EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions()); EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions()); - EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0)); // Enable C again. State becomes: A, [B, C]. - EnableExtension(idC); + EnableExtension(extension_c()->id()); EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions()); - EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0)); // Now we have 3 extensions. Make sure they are all visible. State: A, B, C. browser_actions_bar()->SetIconVisibilityCount(3); EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); // Disable extension A (should disappear). State becomes: B, C. - DisableExtension(idA); + DisableExtension(extension_a()->id()); EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions()); EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); - EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(0)); // Disable extension B (should disappear). State becomes: C. - DisableExtension(idB); + DisableExtension(extension_b()->id()); EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions()); EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions()); - EXPECT_EQ(idC, browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_c()->id(), browser_actions_bar()->GetExtensionId(0)); // Enable B. State becomes: B, C. - EnableExtension(idB); + EnableExtension(extension_b()->id()); EXPECT_EQ(2, browser_actions_bar()->NumberOfBrowserActions()); EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); - EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(0)); // Enable A. State becomes: A, B, C. - EnableExtension(idA); + EnableExtension(extension_a()->id()); EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); - EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0)); // Shrink the browser actions bar to zero visible icons. // No icons should be visible, but we *should* show the chevron and have a @@ -343,32 +347,30 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, Visibility) { // should be visible. browser_actions_bar()->SetIconVisibilityCount(2); EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); - EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0)); - EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(1)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1)); EXPECT_TRUE(container->chevron()->visible()); // Disable C (the overflowed extension). State should now be A, B, and the // chevron should be hidden. - DisableExtension(idC); + DisableExtension(extension_c()->id()); EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); - EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0)); - EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(1)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1)); EXPECT_FALSE(container->chevron()->visible()); // Re-enable C. We should still only have 2 visible icons, and the chevron // should be visible. - EnableExtension(idC); + EnableExtension(extension_c()->id()); EXPECT_EQ(2, browser_actions_bar()->VisibleBrowserActions()); - EXPECT_EQ(idA, browser_actions_bar()->GetExtensionId(0)); - EXPECT_EQ(idB, browser_actions_bar()->GetExtensionId(1)); + EXPECT_EQ(extension_a()->id(), browser_actions_bar()->GetExtensionId(0)); + EXPECT_EQ(extension_b()->id(), browser_actions_bar()->GetExtensionId(1)); EXPECT_TRUE(container->chevron()->visible()); } IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, ForceHide) { - // Load extension A (contains browser action). - ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") - .AppendASCII("browser_action") - .AppendASCII("basics"))); + // Load extension A (with a browser action). + extension_service()->AddExtension(CreateExtension("alpha", true).get()); EXPECT_EQ(1, browser_actions_bar()->NumberOfBrowserActions()); EXPECT_TRUE(browser_actions_bar()->HasIcon(0)); EXPECT_EQ(1, browser_actions_bar()->VisibleBrowserActions()); @@ -385,18 +387,7 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, ForceHide) { // highlight mode. (Highlight mode itself it tested more thoroughly in the // ExtensionToolbarModel browsertests). IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, HighlightMode) { - // Load three extensions with browser actions. - ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") - .AppendASCII("browser_action") - .AppendASCII("basics"))); - std::string id_a = browser_actions_bar()->GetExtensionId(0); - ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") - .AppendASCII("browser_action") - .AppendASCII("add_popup"))); - std::string id_b = browser_actions_bar()->GetExtensionId(1); - ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("api_test") - .AppendASCII("browser_action") - .AppendASCII("remove_popup"))); + LoadExtensions(); EXPECT_EQ(3, browser_actions_bar()->VisibleBrowserActions()); EXPECT_EQ(3, browser_actions_bar()->NumberOfBrowserActions()); @@ -417,8 +408,8 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerTest, HighlightMode) { extensions::ExtensionToolbarModel::Get(profile()); extensions::ExtensionIdList extension_ids; - extension_ids.push_back(id_a); - extension_ids.push_back(id_b); + extension_ids.push_back(extension_a()->id()); + extension_ids.push_back(extension_b()->id()); model->HighlightExtensions(extension_ids); // Only two browser actions should be visible. @@ -543,53 +534,37 @@ BrowserActionsContainerOverflowTest::VerifyVisibleCount( // Test the basic functionality of the BrowserActionsContainer in overflow mode. IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, TestBasicActionOverflow) { - // Load three extensions with browser actions. - // TODO(devlin): Make a method to load these, and generate them rather than - // using files. - base::FilePath test_data_path = - test_data_dir_.AppendASCII("api_test").AppendASCII("browser_action"); - const extensions::Extension* extension_a = - LoadExtension(test_data_path.AppendASCII("basics")); - const extensions::Extension* extension_b = - LoadExtension(test_data_path.AppendASCII("add_popup")); - const extensions::Extension* extension_c = - LoadExtension(test_data_path.AppendASCII("remove_popup")); + LoadExtensions(); // Since the overflow bar isn't attached to a view, we have to kick it in // order to retrigger layout each time we change the number of icons in the // bar. overflow_bar()->Layout(); - // Sanity checks: - // All extensions loaded. - ASSERT_TRUE(extension_a); - ASSERT_TRUE(extension_b); - ASSERT_TRUE(extension_c); - // All actions are showing, and are in the installation order. EXPECT_EQ(-1, model()->GetVisibleIconCount()); ASSERT_EQ(3u, main_bar()->num_browser_actions()); - EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(0)->extension()); - EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(1)->extension()); - EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(2)->extension()); + EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(0)->extension()); + EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(1)->extension()); + EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(2)->extension()); EXPECT_TRUE(VerifyVisibleCount(3u)); // Reduce the visible count to 2. Order should be unchanged (A B C), but // only A and B should be visible on the main bar. model()->SetVisibleIconCountForTest(2u); overflow_bar()->Layout(); // Kick. - EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(0)->extension()); - EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(1)->extension()); - EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(2)->extension()); + EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(0)->extension()); + EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(1)->extension()); + EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(2)->extension()); EXPECT_TRUE(VerifyVisibleCount(2u)); // Move extension C to the first position. Order should now be C A B, with // C and A visible in the main bar. - model()->MoveExtensionIcon(extension_c, 0); + model()->MoveExtensionIcon(extension_c(), 0); overflow_bar()->Layout(); // Kick. - EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(0)->extension()); - EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(1)->extension()); - EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(2)->extension()); + EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(0)->extension()); + EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(1)->extension()); + EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(2)->extension()); EXPECT_TRUE(VerifyVisibleCount(2u)); // Hide action A. This results in it being sent to overflow, and reducing the @@ -597,26 +572,19 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, // main bar. extensions::ExtensionActionAPI::SetBrowserActionVisibility( extensions::ExtensionPrefs::Get(profile()), - extension_a->id(), + extension_a()->id(), false); overflow_bar()->Layout(); // Kick. - EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(0)->extension()); - EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(1)->extension()); - EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(2)->extension()); + EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(0)->extension()); + EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(1)->extension()); + EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(2)->extension()); EXPECT_TRUE(VerifyVisibleCount(1u)); } // Test drag and drop between the overflow container and the main container. IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, TestOverflowDragging) { - base::FilePath test_data_path = - test_data_dir_.AppendASCII("api_test").AppendASCII("browser_action"); - const extensions::Extension* extension_a = - LoadExtension(test_data_path.AppendASCII("basics")); - const extensions::Extension* extension_b = - LoadExtension(test_data_path.AppendASCII("add_popup")); - const extensions::Extension* extension_c = - LoadExtension(test_data_path.AppendASCII("remove_popup")); + LoadExtensions(); // Start with one extension in overflow. model()->SetVisibleIconCountForTest(2u); @@ -624,17 +592,17 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, // Verify starting state is A B [C]. ASSERT_EQ(3u, main_bar()->num_browser_actions()); - EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(0)->extension()); - EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(1)->extension()); - EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(2)->extension()); + EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(0)->extension()); + EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(1)->extension()); + EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(2)->extension()); EXPECT_TRUE(VerifyVisibleCount(2u)); // Drag extension A (on the main bar) to the left of extension C (in // overflow). ui::OSExchangeData drop_data; - BrowserActionDragData browser_action_drag_data(extension_a->id(), 0u); + BrowserActionDragData browser_action_drag_data(extension_a()->id(), 0u); browser_action_drag_data.Write(profile(), &drop_data); - BrowserActionView* view = overflow_bar()->GetViewForExtension(extension_c); + BrowserActionView* view = overflow_bar()->GetViewForExtension(extension_c()); gfx::Point location(view->x(), view->y()); ui::DropTargetEvent target_event( drop_data, location, location, ui::DragDropTypes::DRAG_MOVE); @@ -644,16 +612,16 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, overflow_bar()->Layout(); // Order should now be B [A C]. - EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(0)->extension()); - EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(1)->extension()); - EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(2)->extension()); + EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(0)->extension()); + EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(1)->extension()); + EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(2)->extension()); VerifyVisibleCount(1u); // Drag extension A back from overflow to the main bar. ui::OSExchangeData drop_data2; - BrowserActionDragData browser_action_drag_data2(extension_a->id(), 1u); + BrowserActionDragData browser_action_drag_data2(extension_a()->id(), 1u); browser_action_drag_data2.Write(profile(), &drop_data2); - view = main_bar()->GetViewForExtension(extension_b); + view = main_bar()->GetViewForExtension(extension_b()); location = gfx::Point(view->x(), view->y()); ui::DropTargetEvent target_event2( drop_data2, location, location, ui::DragDropTypes::DRAG_MOVE); @@ -662,14 +630,14 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, main_bar()->OnPerformDrop(target_event2); // Order should be A B [C] again. - EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(0)->extension()); - EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(1)->extension()); - EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(2)->extension()); + EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(0)->extension()); + EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(1)->extension()); + EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(2)->extension()); VerifyVisibleCount(2u); // Drag extension C from overflow to the main bar (before extension B). ui::OSExchangeData drop_data3; - BrowserActionDragData browser_action_drag_data3(extension_c->id(), 2u); + BrowserActionDragData browser_action_drag_data3(extension_c()->id(), 2u); browser_action_drag_data3.Write(profile(), &drop_data3); location = gfx::Point(view->x(), view->y()); ui::DropTargetEvent target_event3( @@ -679,8 +647,8 @@ IN_PROC_BROWSER_TEST_F(BrowserActionsContainerOverflowTest, main_bar()->OnPerformDrop(target_event3); // Order should be A C B, and there should be no extensions in overflow. - EXPECT_EQ(extension_a, main_bar()->GetBrowserActionViewAt(0)->extension()); - EXPECT_EQ(extension_c, main_bar()->GetBrowserActionViewAt(1)->extension()); - EXPECT_EQ(extension_b, main_bar()->GetBrowserActionViewAt(2)->extension()); + EXPECT_EQ(extension_a(), main_bar()->GetBrowserActionViewAt(0)->extension()); + EXPECT_EQ(extension_c(), main_bar()->GetBrowserActionViewAt(1)->extension()); + EXPECT_EQ(extension_b(), main_bar()->GetBrowserActionViewAt(2)->extension()); VerifyVisibleCount(3u); } |