Chromium Code Reviews| Index: chrome/browser/ui/panels/base_panel_browser_test.h |
| =================================================================== |
| --- chrome/browser/ui/panels/base_panel_browser_test.h (revision 0) |
| +++ chrome/browser/ui/panels/base_panel_browser_test.h (revision 0) |
| @@ -0,0 +1,206 @@ |
| +// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_UI_PANELS_BASE_PANEL_BROWSER_TEST_H_ |
| +#define CHROME_BROWSER_UI_PANELS_BASE_PANEL_BROWSER_TEST_H_ |
| +#pragma once |
| + |
| +#include "base/command_line.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/message_loop.h" |
| +#include "base/task.h" |
| +#include "chrome/common/chrome_switches.h" |
| +#include "chrome/browser/extensions/extension_service.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/browser.h" |
| +#include "chrome/browser/ui/panels/auto_hide_bottom_bar.h" |
| +#include "chrome/browser/ui/panels/panel_manager.h" |
| +#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| +#include "chrome/common/extensions/extension.h" |
| +#include "chrome/test/base/in_process_browser_test.h" |
| +#include "content/browser/tab_contents/test_tab_contents.h" |
| +#include "ui/gfx/rect.h" |
| + |
| +#if defined(OS_MACOSX) |
| +#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h" |
| +#endif |
| + |
| +namespace { |
| +const int kTestingWorkAreaWidth = 800; |
| +const int kTestingWorkAreaHeight = 600; |
| +const int kDefaultBottomBarHeight = 40; |
| +const int kDefaultPanelWidth = 150; |
| +const int kDefaultPanelHeight = 120; |
| +} |
| + |
| +class BasePanelBrowserTest : public InProcessBrowserTest { |
| + private: |
| + class MockAutoHideBottomBar; |
| + |
| + public: |
| + BasePanelBrowserTest() |
| + : InProcessBrowserTest(), |
| + testing_work_area_(0, 0, kTestingWorkAreaWidth, |
| + kTestingWorkAreaHeight) { |
| +#if defined(OS_MACOSX) |
| + FindBarBridge::disable_animations_during_testing_ = true; |
| +#endif |
| + } |
| + |
| + virtual ~BasePanelBrowserTest() { } |
| + |
| + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| + command_line->AppendSwitch(switches::kEnablePanels); |
| + } |
| + |
| + virtual void SetUp() OVERRIDE { |
| + // Note: our setup should be done before InProcessBrowserTest::SetUp since |
| + // it will start the main browser loop. |
| + mock_auto_hide_bottom_bar_ = new MockAutoHideBottomBar(); |
|
jennb
2011/08/22 21:00:16
Hmm...now even tests that don't care about auto hi
jianli
2011/08/22 23:28:10
As discussed, this is needed to setup a consistent
|
| + PanelManager::CreateForTesting(testing_work_area_, |
| + mock_auto_hide_bottom_bar_.get()); |
| + mock_auto_hide_bottom_bar_->set_observer(PanelManager::GetInstance()); |
| + |
| + InProcessBrowserTest::SetUp(); |
| + } |
| + |
| + protected: |
| + enum ShowFlag { SHOW_AS_ACTIVE, SHOW_AS_INACTIVE }; |
| + |
| + Panel* CreatePanel(const std::string& panel_name, |
|
jennb
2011/08/22 21:00:16
Usually, panels will be active when created in tes
jianli
2011/08/22 23:28:10
Done.
|
| + const gfx::Rect& bounds, |
| + ShowFlag show_flag) { |
| + gfx::Rect panel_bounds = bounds; |
| + if (bounds.IsEmpty()) |
| + panel_bounds.set_size(gfx::Size(kDefaultPanelWidth, kDefaultPanelHeight)); |
| + Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL, |
| + panel_name, |
| + panel_bounds, |
| + browser()->profile()); |
| + EXPECT_TRUE(panel_browser->is_type_panel()); |
| + |
| + TabContentsWrapper* tab_contents = |
| + new TabContentsWrapper(new TestTabContents(browser()->profile(), NULL)); |
| + panel_browser->AddTab(tab_contents, PageTransition::LINK); |
| + |
| + Panel* panel = static_cast<Panel*>(panel_browser->window()); |
| + if (show_flag == SHOW_AS_ACTIVE) |
| + panel->Show(); |
| + else |
| + panel->ShowInactive(); |
| + MessageLoopForUI::current()->RunAllPending(); |
| + |
| + return panel; |
| + } |
| + |
| + scoped_refptr<Extension> CreateExtension(const FilePath::StringType& path, |
| + Extension::Location location, |
| + const DictionaryValue& extra_value) { |
| +#if defined(OS_WIN) |
| + FilePath full_path(FILE_PATH_LITERAL("c:\\")); |
| +#else |
| + FilePath full_path(FILE_PATH_LITERAL("/")); |
| +#endif |
| + full_path = full_path.Append(path); |
| + |
| + scoped_ptr<DictionaryValue> input_value(extra_value.DeepCopy()); |
| + input_value->SetString(extension_manifest_keys::kVersion, "1.0.0.0"); |
| + input_value->SetString(extension_manifest_keys::kName, "Sample Extension"); |
| + |
| + std::string error; |
| + scoped_refptr<Extension> extension = Extension::Create( |
| + full_path, location, *input_value, |
| + Extension::STRICT_ERROR_CHECKS, &error); |
| + EXPECT_TRUE(extension.get()); |
| + EXPECT_STREQ("", error.c_str()); |
| + browser()->GetProfile()->GetExtensionService()->OnLoadSingleExtension( |
| + extension.get(), false); |
| + return extension; |
| + } |
| + |
| + gfx::Rect testing_work_area() const { return testing_work_area_; } |
| + |
| + MockAutoHideBottomBar* mock_auto_hide_bottom_bar() const { |
| + return mock_auto_hide_bottom_bar_.get(); |
| + } |
| + |
| + private: |
| + class MockAutoHideBottomBar : public AutoHideBottomBar { |
| + public: |
| + MockAutoHideBottomBar() |
| + : enabled_(false), |
| + height_(kDefaultBottomBarHeight), |
| + visibility_(VISIBLE), |
| + ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)) { |
| + } |
| + |
| + virtual ~MockAutoHideBottomBar() { } |
| + |
| + virtual void UpdateWorkArea(const gfx::Rect& work_area) OVERRIDE { |
| + } |
| + |
| + virtual bool Exists() OVERRIDE { |
| + return enabled_; |
| + } |
| + |
| + virtual int GetHeight() OVERRIDE { |
| + return height_; |
| + } |
| + |
| + virtual Visibility GetVisibility() OVERRIDE { |
| + return visibility_; |
| + } |
| + |
| + void enable_auto_hide(bool enabled) { |
| + if (enabled == enabled_) |
| + return; |
| + enabled_ = enabled; |
| + visibility_ = enabled_ ? HIDDEN : VISIBLE; |
| + } |
| + |
| + void SetVisibility(Visibility visibility) { |
| + if (!enabled_ || visibility == visibility_) |
| + return; |
| + visibility_ = visibility; |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + method_factory_.NewRunnableMethod( |
| + &MockAutoHideBottomBar::NotifyVisibilityChange)); |
| + } |
| + |
| + void SetHeight(int height) { |
| + if (!enabled_ || height == height_) |
| + return; |
| + height_ = height; |
| + MessageLoop::current()->PostTask( |
| + FROM_HERE, |
| + method_factory_.NewRunnableMethod( |
| + &MockAutoHideBottomBar::NotifyHeightChange)); |
| + } |
| + |
| + void set_observer(Observer* observer) { observer_ = observer; } |
| + |
| + private: |
| + void NotifyVisibilityChange() { |
| + observer_->OnAutoHideBottomBarVisibilityChanged(visibility_); |
| + } |
| + |
| + void NotifyHeightChange() { |
| + observer_->OnAutoHideBottomBarHeightChanged(height_); |
| + } |
| + |
| + Observer* observer_; |
| + bool enabled_; |
| + int height_; // If 0, auto-hide is disabled. |
| + Visibility visibility_; |
| + ScopedRunnableMethodFactory<MockAutoHideBottomBar> method_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(MockAutoHideBottomBar); |
| + }; |
| + |
| + gfx::Rect testing_work_area_; |
| + scoped_refptr<MockAutoHideBottomBar> mock_auto_hide_bottom_bar_; |
| +}; |
| + |
| +#endif // CHROME_BROWSER_UI_PANELS_BASE_PANEL_BROWSER_TEST_H_ |
| Property changes on: chrome\browser\ui\panels\base_panel_browser_test.h |
| ___________________________________________________________________ |
| Added: svn:eol-style |
| + LF |