diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 18:33:00 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-18 18:33:00 +0000 |
commit | cce6f1b3b3d54334bf116084fadfe5b828c87227 (patch) | |
tree | 8180245c526a4a6c7679197f15f930184c1b1540 /chrome/browser | |
parent | d832c34a518a1cf072fe4e0f7e00ac158eb8cadd (diff) | |
download | chromium_src-cce6f1b3b3d54334bf116084fadfe5b828c87227.zip chromium_src-cce6f1b3b3d54334bf116084fadfe5b828c87227.tar.gz chromium_src-cce6f1b3b3d54334bf116084fadfe5b828c87227.tar.bz2 |
GTTF: Move TestingAutomationProvider to its own file.
Use "svn cp" to preserve svn metadata.
TEST=compile, no code change
BUG=52097
Review URL: http://codereview.chromium.org/3112014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56559 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/automation/automation_provider.cc | 123 | ||||
-rw-r--r-- | chrome/browser/automation/automation_provider.h | 39 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.cc | 137 | ||||
-rw-r--r-- | chrome/browser/automation/testing_automation_provider.h | 51 | ||||
-rw-r--r-- | chrome/browser/browser_init.cc | 1 |
5 files changed, 189 insertions, 162 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc index 746261f..b841434 100644 --- a/chrome/browser/automation/automation_provider.cc +++ b/chrome/browser/automation/automation_provider.cc @@ -3764,129 +3764,6 @@ TabContents* AutomationProvider::GetTabContentsForHandle( return NULL; } -TestingAutomationProvider::TestingAutomationProvider(Profile* profile) - : AutomationProvider(profile) { - BrowserList::AddObserver(this); - registrar_.Add(this, NotificationType::SESSION_END, - NotificationService::AllSources()); -} - -TestingAutomationProvider::~TestingAutomationProvider() { - BrowserList::RemoveObserver(this); -} - -void TestingAutomationProvider::OnMessageReceived( - const IPC::Message& message) { - IPC_BEGIN_MESSAGE_MAP(TestingAutomationProvider, message) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser) - IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync, - CloseBrowserAsync) - IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab) - IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab) - - IPC_MESSAGE_UNHANDLED(AutomationProvider::OnMessageReceived(message)); - IPC_END_MESSAGE_MAP() -} - -void TestingAutomationProvider::OnChannelError() { - BrowserList::CloseAllBrowsersAndExit(); - AutomationProvider::OnChannelError(); -} - -void TestingAutomationProvider::CloseBrowser(int browser_handle, - IPC::Message* reply_message) { - if (browser_tracker_->ContainsHandle(browser_handle)) { - Browser* browser = browser_tracker_->GetResource(browser_handle); - new BrowserClosedNotificationObserver(browser, this, - reply_message); - browser->window()->Close(); - } else { - NOTREACHED(); - } -} - -void TestingAutomationProvider::CloseBrowserAsync(int browser_handle) { - if (browser_tracker_->ContainsHandle(browser_handle)) { - Browser* browser = browser_tracker_->GetResource(browser_handle); - browser->window()->Close(); - } else { - NOTREACHED(); - } -} - -void TestingAutomationProvider::ActivateTab(int handle, - int at_index, - int* status) { - *status = -1; - if (browser_tracker_->ContainsHandle(handle) && at_index > -1) { - Browser* browser = browser_tracker_->GetResource(handle); - if (at_index >= 0 && at_index < browser->tab_count()) { - browser->SelectTabContentsAt(at_index, true); - *status = 0; - } - } -} - -void TestingAutomationProvider::AppendTab(int handle, const GURL& url, - IPC::Message* reply_message) { - int append_tab_response = -1; // -1 is the error code - NotificationObserver* observer = NULL; - - if (browser_tracker_->ContainsHandle(handle)) { - Browser* browser = browser_tracker_->GetResource(handle); - observer = AddTabStripObserver(browser, reply_message); - TabContents* tab_contents = browser->AddTabWithURL( - url, GURL(), PageTransition::TYPED, -1, TabStripModel::ADD_SELECTED, - NULL, std::string(), &browser); - if (tab_contents) { - append_tab_response = - GetIndexForNavigationController(&tab_contents->controller(), browser); - } - } - - if (append_tab_response < 0) { - // The append tab failed. Remove the TabStripObserver - if (observer) { - RemoveTabStripObserver(observer); - delete observer; - } - - AutomationMsg_AppendTab::WriteReplyParams(reply_message, - append_tab_response); - Send(reply_message); - } -} - -void TestingAutomationProvider::OnBrowserAdded(const Browser* browser) { -} - -void TestingAutomationProvider::OnBrowserRemoving(const Browser* browser) { - // For backwards compatibility with the testing automation interface, we - // want the automation provider (and hence the process) to go away when the - // last browser goes away. - if (BrowserList::size() == 1 && !CommandLine::ForCurrentProcess()->HasSwitch( - switches::kKeepAliveForTest)) { - // If you change this, update Observer for NotificationType::SESSION_END - // below. - MessageLoop::current()->PostTask(FROM_HERE, - NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); - } -} - -void TestingAutomationProvider::Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - DCHECK(type == NotificationType::SESSION_END); - // OnBrowserRemoving does a ReleaseLater. When session end is received we exit - // before the task runs resulting in this object not being deleted. This - // Release balance out the Release scheduled by OnBrowserRemoving. - Release(); -} - -void TestingAutomationProvider::OnRemoveProvider() { - AutomationProviderList::GetInstance()->RemoveProvider(this); -} - void AutomationProvider::GetInfoBarCount(int handle, int* count) { *count = -1; // -1 means error. if (tab_tracker_->ContainsHandle(handle)) { diff --git a/chrome/browser/automation/automation_provider.h b/chrome/browser/automation/automation_provider.h index fa3504b..c93c2c9 100644 --- a/chrome/browser/automation/automation_provider.h +++ b/chrome/browser/automation/automation_provider.h @@ -963,43 +963,4 @@ class AutomationProvider : public base::RefCounted<AutomationProvider>, DISALLOW_COPY_AND_ASSIGN(AutomationProvider); }; -// When life started, the AutomationProvider class was a singleton and was meant -// only for UI tests. It had specific behavior (like for example, when the -// channel was shut down. it closed all open Browsers). The new -// AutomationProvider serves other purposes than just UI testing. This class is -// meant to provide the OLD functionality for backward compatibility -class TestingAutomationProvider : public AutomationProvider, - public BrowserList::Observer, - public NotificationObserver { - public: - explicit TestingAutomationProvider(Profile* profile); - - // BrowserList::Observer implementation - // Called immediately after a browser is added to the list - virtual void OnBrowserAdded(const Browser* browser); - // Called immediately before a browser is removed from the list - virtual void OnBrowserRemoving(const Browser* browser); - - // IPC implementations - virtual void OnMessageReceived(const IPC::Message& msg); - virtual void OnChannelError(); - - private: - virtual ~TestingAutomationProvider(); - - // IPC Message callbacks. - void CloseBrowser(int handle, IPC::Message* reply_message); - void CloseBrowserAsync(int browser_handle); - void ActivateTab(int handle, int at_index, int* status); - void AppendTab(int handle, const GURL& url, IPC::Message* reply_message); - - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details); - - void OnRemoveProvider(); // Called via PostTask - - NotificationRegistrar registrar_; -}; - #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_H_ diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc new file mode 100644 index 0000000..92afdb9 --- /dev/null +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -0,0 +1,137 @@ +// Copyright (c) 2010 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. + +#include "chrome/browser/automation/testing_automation_provider.h" + +#include "base/command_line.h" +#include "chrome/browser/automation/automation_browser_tracker.h" +#include "chrome/browser/automation/automation_provider_list.h" +#include "chrome/browser/automation/automation_provider_observers.h" +#include "chrome/browser/browser_window.h" +#include "chrome/common/chrome_switches.h" +#include "chrome/common/notification_service.h" +#include "chrome/test/automation/automation_messages.h" + +TestingAutomationProvider::TestingAutomationProvider(Profile* profile) + : AutomationProvider(profile) { + BrowserList::AddObserver(this); + registrar_.Add(this, NotificationType::SESSION_END, + NotificationService::AllSources()); +} + +TestingAutomationProvider::~TestingAutomationProvider() { + BrowserList::RemoveObserver(this); +} + +void TestingAutomationProvider::OnMessageReceived( + const IPC::Message& message) { + IPC_BEGIN_MESSAGE_MAP(TestingAutomationProvider, message) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_CloseBrowser, CloseBrowser) + IPC_MESSAGE_HANDLER(AutomationMsg_CloseBrowserRequestAsync, + CloseBrowserAsync) + IPC_MESSAGE_HANDLER(AutomationMsg_ActivateTab, ActivateTab) + IPC_MESSAGE_HANDLER_DELAY_REPLY(AutomationMsg_AppendTab, AppendTab) + + IPC_MESSAGE_UNHANDLED(AutomationProvider::OnMessageReceived(message)); + IPC_END_MESSAGE_MAP() +} + +void TestingAutomationProvider::OnChannelError() { + BrowserList::CloseAllBrowsersAndExit(); + AutomationProvider::OnChannelError(); +} + +void TestingAutomationProvider::CloseBrowser(int browser_handle, + IPC::Message* reply_message) { + if (browser_tracker_->ContainsHandle(browser_handle)) { + Browser* browser = browser_tracker_->GetResource(browser_handle); + new BrowserClosedNotificationObserver(browser, this, + reply_message); + browser->window()->Close(); + } else { + NOTREACHED(); + } +} + +void TestingAutomationProvider::CloseBrowserAsync(int browser_handle) { + if (browser_tracker_->ContainsHandle(browser_handle)) { + Browser* browser = browser_tracker_->GetResource(browser_handle); + browser->window()->Close(); + } else { + NOTREACHED(); + } +} + +void TestingAutomationProvider::ActivateTab(int handle, + int at_index, + int* status) { + *status = -1; + if (browser_tracker_->ContainsHandle(handle) && at_index > -1) { + Browser* browser = browser_tracker_->GetResource(handle); + if (at_index >= 0 && at_index < browser->tab_count()) { + browser->SelectTabContentsAt(at_index, true); + *status = 0; + } + } +} + +void TestingAutomationProvider::AppendTab(int handle, const GURL& url, + IPC::Message* reply_message) { + int append_tab_response = -1; // -1 is the error code + NotificationObserver* observer = NULL; + + if (browser_tracker_->ContainsHandle(handle)) { + Browser* browser = browser_tracker_->GetResource(handle); + observer = AddTabStripObserver(browser, reply_message); + TabContents* tab_contents = browser->AddTabWithURL( + url, GURL(), PageTransition::TYPED, -1, TabStripModel::ADD_SELECTED, + NULL, std::string(), &browser); + if (tab_contents) { + append_tab_response = + GetIndexForNavigationController(&tab_contents->controller(), browser); + } + } + + if (append_tab_response < 0) { + // The append tab failed. Remove the TabStripObserver + if (observer) { + RemoveTabStripObserver(observer); + delete observer; + } + + AutomationMsg_AppendTab::WriteReplyParams(reply_message, + append_tab_response); + Send(reply_message); + } +} + +void TestingAutomationProvider::OnBrowserAdded(const Browser* browser) { +} + +void TestingAutomationProvider::OnBrowserRemoving(const Browser* browser) { + // For backwards compatibility with the testing automation interface, we + // want the automation provider (and hence the process) to go away when the + // last browser goes away. + if (BrowserList::size() == 1 && !CommandLine::ForCurrentProcess()->HasSwitch( + switches::kKeepAliveForTest)) { + // If you change this, update Observer for NotificationType::SESSION_END + // below. + MessageLoop::current()->PostTask(FROM_HERE, + NewRunnableMethod(this, &TestingAutomationProvider::OnRemoveProvider)); + } +} + +void TestingAutomationProvider::Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::SESSION_END); + // OnBrowserRemoving does a ReleaseLater. When session end is received we exit + // before the task runs resulting in this object not being deleted. This + // Release balance out the Release scheduled by OnBrowserRemoving. + Release(); +} + +void TestingAutomationProvider::OnRemoveProvider() { + AutomationProviderList::GetInstance()->RemoveProvider(this); +} diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h new file mode 100644 index 0000000..0050437 --- /dev/null +++ b/chrome/browser/automation/testing_automation_provider.h @@ -0,0 +1,51 @@ +// Copyright (c) 2010 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_AUTOMATION_TESTING_AUTOMATION_PROVIDER_H_ +#define CHROME_BROWSER_AUTOMATION_TESTING_AUTOMATION_PROVIDER_H_ +#pragma once + +#include "base/basictypes.h" +#include "chrome/browser/automation/automation_provider.h" +#include "chrome/browser/browser_list.h" +#include "chrome/common/notification_registrar.h" + +// This is an automation provider containing testing calls. +class TestingAutomationProvider : public AutomationProvider, + public BrowserList::Observer, + public NotificationObserver { + public: + explicit TestingAutomationProvider(Profile* profile); + + // BrowserList::Observer implementation + // Called immediately after a browser is added to the list + virtual void OnBrowserAdded(const Browser* browser); + // Called immediately before a browser is removed from the list + virtual void OnBrowserRemoving(const Browser* browser); + + // IPC implementations + virtual void OnMessageReceived(const IPC::Message& msg); + virtual void OnChannelError(); + + private: + virtual ~TestingAutomationProvider(); + + // IPC Message callbacks. + void CloseBrowser(int handle, IPC::Message* reply_message); + void CloseBrowserAsync(int browser_handle); + void ActivateTab(int handle, int at_index, int* status); + void AppendTab(int handle, const GURL& url, IPC::Message* reply_message); + + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + void OnRemoveProvider(); // Called via PostTask + + NotificationRegistrar registrar_; + + DISALLOW_COPY_AND_ASSIGN(TestingAutomationProvider); +}; + +#endif // CHROME_BROWSER_AUTOMATION_TESTING_AUTOMATION_PROVIDER_H_ diff --git a/chrome/browser/browser_init.cc b/chrome/browser/browser_init.cc index eaa83ae..8dbe4a9 100644 --- a/chrome/browser/browser_init.cc +++ b/chrome/browser/browser_init.cc @@ -19,6 +19,7 @@ #include "chrome/browser/automation/automation_provider.h" #include "chrome/browser/automation/automation_provider_list.h" #include "chrome/browser/automation/chrome_frame_automation_provider.h" +#include "chrome/browser/automation/testing_automation_provider.h" #include "chrome/browser/browser_list.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/browser_window.h" |