diff options
author | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 21:46:30 +0000 |
---|---|---|
committer | kkania@chromium.org <kkania@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-19 21:46:30 +0000 |
commit | d024cd138a51e9edd551b6c527e587958b7782c0 (patch) | |
tree | f47980174aaddf12951b713d29b39002441c52b9 /chrome/browser/automation | |
parent | 068d487c7a5e00d44097e976a3d14a5a15a68600 (diff) | |
download | chromium_src-d024cd138a51e9edd551b6c527e587958b7782c0.zip chromium_src-d024cd138a51e9edd551b6c527e587958b7782c0.tar.gz chromium_src-d024cd138a51e9edd551b6c527e587958b7782c0.tar.bz2 |
Addded testcases for bookmarks i.e creating/removing/editing bookmarks in multiprofiles and also with icognito window. Also added new hook 'OpenProfileWindow'. This hook allows to open browser window with existing profile.This hook was needed as for most of multiprofile testcases we need to open existing profile in order to validate the changes, and also to make sure changes in one profile does not breed with another profile.
Review URL: https://chromiumcodereview.appspot.com/10489002
Patch from Prachi Jain <prachij@chromium.org>.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143057 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/automation')
4 files changed, 122 insertions, 0 deletions
diff --git a/chrome/browser/automation/automation_provider_observers.cc b/chrome/browser/automation/automation_provider_observers.cc index cf18d7b..c7a494a 100644 --- a/chrome/browser/automation/automation_provider_observers.cc +++ b/chrome/browser/automation/automation_provider_observers.cc @@ -3049,3 +3049,54 @@ void WindowMaximizedObserver::Observe( } #endif // defined(OS_LINUX) +BrowserOpenedWithExistingProfileNotificationObserver:: + BrowserOpenedWithExistingProfileNotificationObserver( + AutomationProvider* automation, + IPC::Message* reply_message, + int num_loads) + : automation_(automation->AsWeakPtr()), + reply_message_(reply_message), + new_window_id_(extension_misc::kUnknownWindowId), + num_loads_(num_loads) { + registrar_.Add(this, chrome::NOTIFICATION_BROWSER_OPENED, + content::NotificationService::AllBrowserContextsAndSources()); + registrar_.Add(this, content::NOTIFICATION_LOAD_STOP, + content::NotificationService::AllBrowserContextsAndSources()); +} + +BrowserOpenedWithExistingProfileNotificationObserver:: + ~BrowserOpenedWithExistingProfileNotificationObserver() { +} + +void BrowserOpenedWithExistingProfileNotificationObserver::Observe( + int type, + const content::NotificationSource& source, + const content::NotificationDetails& details) { + if (!automation_) { + delete this; + return; + } + + if (type == chrome::NOTIFICATION_BROWSER_OPENED) { + // Store the new browser ID and continue waiting for NOTIFICATION_LOAD_STOP. + new_window_id_ = ExtensionTabUtil::GetWindowId( + content::Source<Browser>(source).ptr()); + } else if (type == content::NOTIFICATION_LOAD_STOP) { + // Only consider if the loaded tab is in the new window. + NavigationController* controller = + content::Source<NavigationController>(source).ptr(); + TabContents* tab = TabContents::FromWebContents( + controller->GetWebContents()); + int window_id = tab ? tab->restore_tab_helper()->window_id().id() : -1; + if (window_id == new_window_id_ && --num_loads_ == 0) { + if (automation_) { + AutomationJSONReply(automation_, reply_message_.release()) + .SendSuccess(NULL); + } + delete this; + } + } else { + NOTREACHED(); + } +} + diff --git a/chrome/browser/automation/automation_provider_observers.h b/chrome/browser/automation/automation_provider_observers.h index 12d80f2..d5e31db 100644 --- a/chrome/browser/automation/automation_provider_observers.h +++ b/chrome/browser/automation/automation_provider_observers.h @@ -1952,6 +1952,29 @@ class WindowMaximizedObserver : public content::NotificationObserver { }; #endif // defined(OS_LINUX) +// Wait for a new browser window to get created (for an existing profile). +// Useful when reopening a multi-profile window. +class BrowserOpenedWithExistingProfileNotificationObserver + : public content::NotificationObserver { + public: + BrowserOpenedWithExistingProfileNotificationObserver( + AutomationProvider* automation, + IPC::Message* reply_message, + int num_loads); + virtual ~BrowserOpenedWithExistingProfileNotificationObserver(); + virtual void Observe(int type, + const content::NotificationSource& source, + const content::NotificationDetails& details); + private: + content::NotificationRegistrar registrar_; + base::WeakPtr<AutomationProvider> automation_; + scoped_ptr<IPC::Message> reply_message_; + int new_window_id_; + int num_loads_; + + DISALLOW_COPY_AND_ASSIGN( + BrowserOpenedWithExistingProfileNotificationObserver); +}; #endif // CHROME_BROWSER_AUTOMATION_AUTOMATION_PROVIDER_OBSERVERS_H_ diff --git a/chrome/browser/automation/testing_automation_provider.cc b/chrome/browser/automation/testing_automation_provider.cc index 509ff8f..fd51fcd 100644 --- a/chrome/browser/automation/testing_automation_provider.cc +++ b/chrome/browser/automation/testing_automation_provider.cc @@ -115,6 +115,7 @@ #include "chrome/browser/ui/omnibox/omnibox_view.h" #include "chrome/browser/ui/search_engines/keyword_editor_controller.h" #include "chrome/browser/ui/tab_contents/tab_contents.h" +#include "chrome/browser/ui/startup/startup_types.h" #include "chrome/browser/view_type_utils.h" #include "chrome/common/automation_constants.h" #include "chrome/common/automation_events.h" @@ -1201,6 +1202,47 @@ void TestingAutomationProvider::OpenNewBrowserWindowOfType( browser->window()->Show(); } +void TestingAutomationProvider::OpenProfileWindow( + base::DictionaryValue* args, IPC::Message* reply_message) { + ProfileManager* profile_manager = g_browser_process->profile_manager(); + FilePath::StringType path; + if (!args->GetString("path", &path)) { + AutomationJSONReply(this, reply_message).SendError( + "Invalid or missing arg: 'path'"); + return; + } + Profile* profile = profile_manager->GetProfileByPath(FilePath(path)); + if (!profile) { + AutomationJSONReply(this, reply_message).SendError( + StringPrintf("Invalid profile path: %s", path.c_str())); + return; + } + int num_loads; + if (!args->GetInteger("num_loads", &num_loads)) { + AutomationJSONReply(this, reply_message).SendError( + "Invalid or missing arg: 'num_loads'"); + return; + } + Browser* browser = browser::FindTabbedBrowser(profile, false); + if (browser) { + // Already have browser. Need to just activate. + ProfileManager::FindOrCreateNewWindowForProfile( + profile, + browser::startup::IS_NOT_PROCESS_STARTUP, + browser::startup::IS_NOT_FIRST_RUN, + 0); + AutomationJSONReply(this, reply_message).SendSuccess(NULL); + } else { + new BrowserOpenedWithExistingProfileNotificationObserver( + this, reply_message, num_loads); + ProfileManager::FindOrCreateNewWindowForProfile( + profile, + browser::startup::IS_NOT_PROCESS_STARTUP, + browser::startup::IS_NOT_FIRST_RUN, + 0); + } +} + void TestingAutomationProvider::GetWindowForBrowser(int browser_handle, bool* success, int* handle) { @@ -1742,6 +1784,8 @@ void TestingAutomationProvider::SendJSONRequest(int handle, &TestingAutomationProvider::OpenNewBrowserWindowWithNewProfile; handler_map["GetMultiProfileInfo"] = &TestingAutomationProvider::GetMultiProfileInfo; + handler_map["OpenProfileWindow"] = + &TestingAutomationProvider::OpenProfileWindow; handler_map["GetProcessInfo"] = &TestingAutomationProvider::GetProcessInfo; handler_map["GetPolicyDefinitionList"] = diff --git a/chrome/browser/automation/testing_automation_provider.h b/chrome/browser/automation/testing_automation_provider.h index ebe1154..a723303 100644 --- a/chrome/browser/automation/testing_automation_provider.h +++ b/chrome/browser/automation/testing_automation_provider.h @@ -298,6 +298,10 @@ class TestingAutomationProvider : public AutomationProvider, void GetMultiProfileInfo( base::DictionaryValue* args, IPC::Message* reply_message); + // Open a new browser window for an existing profile. + // Uses the JSON interface for input/output. + void OpenProfileWindow( + base::DictionaryValue* args, IPC::Message* reply_message); // Get info about the chromium/chrome in use. // This includes things like version, executable name, executable path. |