Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Unified Diff: chrome/browser/ui/panels/base_panel_browser_test.h

Issue 7646003: Support auto-hide taskbar for panels on Windows. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,231 @@
+// 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"
jennb 2011/08/23 20:28:34 alpha ordering wrong
jianli 2011/08/26 00:18:16 Done.
+#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 {
jennb 2011/08/23 20:28:34 Comments in InProcessBrowserTest header say to ove
jianli 2011/08/26 00:18:16 Changed to override SetUpOnMainThread since the me
+ // Setup the work area and bottom bar so that we have consistent testing
+ // environment for all panel related tests.
+ // Note: our setup should be done before InProcessBrowserTest::SetUp since
+ // it will start the main browser loop.
+ mock_auto_hide_bottom_bar_ = new MockAutoHideBottomBar();
+ 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 };
+
+ struct CreatePanelParams {
+ std::string name;
+ gfx::Rect bounds;
+ ShowFlag show_flag;
+
+ CreatePanelParams(const std::string& name,
+ const gfx::Rect& bounds,
+ ShowFlag show_flag)
+ : name(name),
+ bounds(bounds),
+ show_flag(show_flag) {
+ }
+ };
+
+ Panel* CreatePanelWithParams(const CreatePanelParams& params) {
+ gfx::Rect bounds = params.bounds;
+ if (bounds.IsEmpty())
+ bounds.set_size(gfx::Size(kDefaultPanelWidth, kDefaultPanelHeight));
jennb 2011/08/23 20:28:34 Is this necessary? PanelManager will pick default
jianli 2011/08/26 00:18:16 Done.
+ Browser* panel_browser = Browser::CreateForApp(Browser::TYPE_PANEL,
+ params.name,
+ 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 (params.show_flag == SHOW_AS_ACTIVE)
+ panel->Show();
+ else
+ panel->ShowInactive();
+ MessageLoopForUI::current()->RunAllPending();
+
+ return panel;
+ }
+
+ Panel* CreatePanelWithBounds(const std::string& panel_name,
+ const gfx::Rect& bounds) {
+ CreatePanelParams params(panel_name, bounds, SHOW_AS_ACTIVE);
+ return CreatePanelWithParams(params);
+ }
+
+ Panel* CreatePanel(const std::string& panel_name) {
+ CreatePanelParams params(panel_name, gfx::Rect(), SHOW_AS_ACTIVE);
+ return CreatePanelWithParams(params);
+ }
+
+ 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 {
jennb 2011/08/23 20:28:34 Would code be cleaner if this class was NOT nested
jianli 2011/08/26 00:18:16 Done.
+ 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 IsEnabled() 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_;
+ 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

Powered by Google App Engine
This is Rietveld 408576698