diff options
Diffstat (limited to 'chrome/test')
35 files changed, 407 insertions, 256 deletions
diff --git a/chrome/test/accessibility/accessibility_tests.cc b/chrome/test/accessibility/accessibility_tests.cc index 7393f85..8b0cafb 100644 --- a/chrome/test/accessibility/accessibility_tests.cc +++ b/chrome/test/accessibility/accessibility_tests.cc @@ -133,12 +133,12 @@ TEST_F(AccessibilityTest, DISABLED_TestBackBtnStatusOnNewTab) { GetState(acc_obj)); // Now check Back status in different situations. - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); int tab_count = -1; // Set URL and check button status. - scoped_ptr<TabProxy> tab1(window->GetTab(0)); + scoped_refptr<TabProxy> tab1(window->GetTab(0)); ASSERT_TRUE(tab1.get()); FilePath test_file1(test_data_directory_); test_file1 = test_file1.AppendASCII("title1.html"); @@ -235,12 +235,12 @@ TEST_F(AccessibilityTest, DISABLED_TestForwardBtnStatusOnNewTab) { } // Now check Back status in different situations. - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); int tab_count = -1; // Set URL and check button status. - scoped_ptr<TabProxy> tab1(window->GetTab(0)); + scoped_refptr<TabProxy> tab1(window->GetTab(0)); ASSERT_TRUE(tab1.get()); FilePath test_file1(test_data_directory_); test_file1 = test_file1.AppendASCII("title1.html"); @@ -322,11 +322,11 @@ TEST_F(AccessibilityTest, DISABLED_TestStarBtnStatusOnNewTab) { EXPECT_EQ(STATE_SYSTEM_FOCUSABLE, GetState(acc_obj)); // Now, check Star status in different situations. - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); // Set URL and check button status. - scoped_ptr<TabProxy> tab1(window->GetTab(0)); + scoped_refptr<TabProxy> tab1(window->GetTab(0)); ASSERT_TRUE(tab1.get()); FilePath test_file1(test_data_directory_); test_file1 = test_file1.AppendASCII("title1.html"); diff --git a/chrome/test/automated_ui_tests/automated_ui_test_base.cc b/chrome/test/automated_ui_tests/automated_ui_test_base.cc index abd0cf3..bb96fd32 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_base.cc +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.cc @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/scoped_ptr.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/test/automated_ui_tests/automated_ui_test_base.h" #include "chrome/test/automation/browser_proxy.h" @@ -66,8 +65,8 @@ bool AutomatedUITestBase::CloseActiveWindow() { LogErrorMessage("Application closed unexpectedly."); return false; } - BrowserProxy* browser = automation()->FindNormalBrowserWindow(); - if (browser == NULL) { + scoped_refptr<BrowserProxy> browser(automation()->FindNormalBrowserWindow()); + if (!browser.get()) { LogErrorMessage("Can't find browser window."); return false; } @@ -88,7 +87,7 @@ bool AutomatedUITestBase::GoOffTheRecord() { } bool AutomatedUITestBase::OpenAndActivateNewBrowserWindow( - BrowserProxy** previous_browser) { + scoped_refptr<BrowserProxy>* previous_browser) { if (!automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)) { LogWarningMessage("failed_to_open_new_browser_window"); return false; @@ -97,7 +96,7 @@ bool AutomatedUITestBase::OpenAndActivateNewBrowserWindow( automation()->GetBrowserWindowCount(&num_browser_windows); // Get the most recently opened browser window and activate the tab // in order to activate this browser window. - scoped_ptr<BrowserProxy> browser( + scoped_refptr<BrowserProxy> browser( automation()->GetBrowserWindow(num_browser_windows - 1)); if (browser.get() == NULL) { LogErrorMessage("browser_window_not_found"); @@ -110,14 +109,17 @@ bool AutomatedUITestBase::OpenAndActivateNewBrowserWindow( return false; } + if (previous_browser) { + DCHECK(previous_browser->get() == NULL); + active_browser_.swap(*previous_browser); + } + active_browser_.swap(browser); - if (previous_browser) - *previous_browser = browser.release(); return true; } bool AutomatedUITestBase::Navigate(const GURL& url) { - scoped_ptr<TabProxy> tab(GetActiveTab()); + scoped_refptr<TabProxy> tab(GetActiveTab()); if (tab.get() == NULL) { LogErrorMessage("active_tab_not_found"); return false; @@ -176,7 +178,7 @@ bool AutomatedUITestBase::RunCommand(int browser_command) { return true; } -TabProxy* AutomatedUITestBase::GetActiveTab() { +scoped_refptr<TabProxy> AutomatedUITestBase::GetActiveTab() { BrowserProxy* browser = active_browser(); if (browser == NULL) { LogErrorMessage("browser_window_not_found"); @@ -184,7 +186,7 @@ TabProxy* AutomatedUITestBase::GetActiveTab() { } bool did_timeout; - TabProxy* tab = + scoped_refptr<TabProxy> tab = browser->GetActiveTabWithTimeout(action_max_timeout_ms(), &did_timeout); if (did_timeout) return NULL; diff --git a/chrome/test/automated_ui_tests/automated_ui_test_base.h b/chrome/test/automated_ui_tests/automated_ui_test_base.h index 731bf40..4724f83 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_base.h +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.h @@ -62,7 +62,8 @@ class AutomatedUITestBase : public UITest { // If optional parameter previous_browser is passed in, it is set to be the // previous browser window when new window is successfully created, and the // caller owns previous_browser. - bool OpenAndActivateNewBrowserWindow(BrowserProxy** previous_browser); + bool OpenAndActivateNewBrowserWindow( + scoped_refptr<BrowserProxy>* previous_browser); // Reload the active tab. // Returns true if successful, false otherwise. @@ -89,7 +90,7 @@ class AutomatedUITestBase : public UITest { bool RunCommand(int browser_command); void set_active_browser(BrowserProxy* browser) { - active_browser_.reset(browser); + active_browser_ = browser; } BrowserProxy* active_browser() const { return active_browser_.get(); } @@ -97,9 +98,9 @@ class AutomatedUITestBase : public UITest { // create a corresponding TabProxy and transfer the ownership to caller. // If success return the pointer to the newly created TabProxy and the // caller owns the TabProxy. Return NULL otherwise. - TabProxy* GetActiveTab(); + scoped_refptr<TabProxy> GetActiveTab(); private: - scoped_ptr<BrowserProxy> active_browser_; + scoped_refptr<BrowserProxy> active_browser_; DISALLOW_COPY_AND_ASSIGN(AutomatedUITestBase); }; diff --git a/chrome/test/automated_ui_tests/automated_ui_test_test.cc b/chrome/test/automated_ui_tests/automated_ui_test_test.cc index bbdd042..3110aae 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_test.cc +++ b/chrome/test/automated_ui_tests/automated_ui_test_test.cc @@ -104,9 +104,8 @@ TEST_F(AutomatedUITestBase, OpenBrowserWindow) { active_browser()->GetTabCount(&tab_count); ASSERT_EQ(1, tab_count); - BrowserProxy* previous_browser; - ASSERT_TRUE(OpenAndActivateNewBrowserWindow(&previous_browser)); - scoped_ptr<BrowserProxy>browser_1(previous_browser); + scoped_refptr<BrowserProxy> browser_1; + ASSERT_TRUE(OpenAndActivateNewBrowserWindow(&browser_1)); automation()->GetBrowserWindowCount(&num_browser_windows); ASSERT_EQ(2, num_browser_windows); active_browser()->GetTabCount(&tab_count); @@ -117,8 +116,8 @@ TEST_F(AutomatedUITestBase, OpenBrowserWindow) { active_browser()->GetTabCount(&tab_count); ASSERT_EQ(2, tab_count); - ASSERT_TRUE(OpenAndActivateNewBrowserWindow(&previous_browser)); - scoped_ptr<BrowserProxy>browser_2(previous_browser); + scoped_refptr<BrowserProxy> browser_2; + ASSERT_TRUE(OpenAndActivateNewBrowserWindow(&browser_2)); automation()->GetBrowserWindowCount(&num_browser_windows); ASSERT_EQ(3, num_browser_windows); active_browser()->GetTabCount(&tab_count); diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc index d935387..23c1ae4 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.cc +++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc @@ -591,7 +591,7 @@ bool AutomatedUITest::FuzzyTestDialog(int num_actions) { } bool AutomatedUITest::ForceCrash() { - scoped_ptr<TabProxy> tab(GetActiveTab()); + scoped_refptr<TabProxy> tab(GetActiveTab()); GURL test_url("about:crash"); bool did_timeout; tab->NavigateToURLWithTimeout(test_url, kDebuggingTimeoutMsec, &did_timeout); @@ -609,7 +609,7 @@ bool AutomatedUITest::DragActiveTab(bool drag_right, bool drag_out) { return false; } - scoped_ptr<WindowProxy> window( + scoped_refptr<WindowProxy> window( GetAndActivateWindowForBrowser(browser)); if (window.get() == NULL) { AddErrorAttribute("active_window_not_found"); @@ -688,7 +688,7 @@ bool AutomatedUITest::DragActiveTab(bool drag_right, bool drag_out) { return true; } -WindowProxy* AutomatedUITest::GetAndActivateWindowForBrowser( +scoped_refptr<WindowProxy> AutomatedUITest::GetAndActivateWindowForBrowser( BrowserProxy* browser) { bool did_timeout; if (!browser->BringToFrontWithTimeout(action_max_timeout_ms(), @@ -697,13 +697,12 @@ WindowProxy* AutomatedUITest::GetAndActivateWindowForBrowser( return NULL; } - WindowProxy* window = browser->GetWindow(); - return window; + return browser->GetWindow(); } bool AutomatedUITest::SimulateKeyPressInActiveWindow(wchar_t key, int flags) { - scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); + scoped_refptr<WindowProxy> window(automation()->GetActiveWindow()); if (window.get() == NULL) { AddErrorAttribute("active_window_not_found"); return false; diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.h b/chrome/test/automated_ui_tests/automated_ui_tests.h index 39c12c4..9b35349 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.h +++ b/chrome/test/automated_ui_tests/automated_ui_tests.h @@ -342,7 +342,7 @@ class AutomatedUITest : public AutomatedUITestBase { // Returns the WindowProxy associated with the given BrowserProxy // (transferring ownership of the pointer to the caller) and brings that // window to the top. - WindowProxy* GetAndActivateWindowForBrowser(BrowserProxy* browser); + scoped_refptr<WindowProxy> GetAndActivateWindowForBrowser(BrowserProxy* browser); // Calls SimulateOSKeyPress on the active window. Simulates a key press at // the OS level. |key| is the key pressed and |flags| specifies which diff --git a/chrome/test/automation/automation_handle_tracker.cc b/chrome/test/automation/automation_handle_tracker.cc index b843218..db688cc 100644 --- a/chrome/test/automation/automation_handle_tracker.cc +++ b/chrome/test/automation/automation_handle_tracker.cc @@ -33,40 +33,36 @@ AutomationHandleTracker::~AutomationHandleTracker() { } void AutomationHandleTracker::Add(AutomationResourceProxy* proxy) { + AutoLock lock(map_lock_); handle_to_object_.insert(MapEntry(proxy->handle(), proxy)); } void AutomationHandleTracker::Remove(AutomationResourceProxy* proxy) { + AutoLock lock(map_lock_); HandleToObjectMap::iterator iter = handle_to_object_.find(proxy->handle()); - if (iter == handle_to_object_.end()) - return; - - HandleToObjectMap::iterator end_of_matching_objects = - handle_to_object_.upper_bound(proxy->handle()); - - while(iter != end_of_matching_objects) { - if (iter->second == proxy) { - handle_to_object_.erase(iter); - - // If we have no more proxy objects using this handle, tell the - // app that it can clean up that handle. If the proxy isn't valid, - // that means that the app has already discarded this handle, and - // thus doesn't need to be notified that the handle is unused. - if (proxy->is_valid() && handle_to_object_.count(proxy->handle()) == 0) { - sender_->Send(new AutomationMsg_HandleUnused(0, proxy->handle())); - } - return; - } - ++iter; + if (iter != handle_to_object_.end()) { + handle_to_object_.erase(iter); + sender_->Send(new AutomationMsg_HandleUnused(0, proxy->handle())); } } void AutomationHandleTracker::InvalidateHandle(AutomationHandle handle) { - HandleToObjectMap::iterator iter = handle_to_object_.lower_bound(handle); - HandleToObjectMap::const_iterator end_of_matching_objects = - handle_to_object_.upper_bound(handle); - - for (; iter != end_of_matching_objects; ++iter) { + // Called in background thread. + AutoLock lock(map_lock_); + HandleToObjectMap::iterator iter = handle_to_object_.find(handle); + if (iter != handle_to_object_.end()) { iter->second->Invalidate(); } } + +AutomationResourceProxy* AutomationHandleTracker::GetResource( + AutomationHandle handle) { + DCHECK(handle); + AutoLock lock(map_lock_); + HandleToObjectMap::iterator iter = handle_to_object_.find(handle); + if (iter == handle_to_object_.end()) + return NULL; + + iter->second->AddRef(); + return iter->second; +} diff --git a/chrome/test/automation/automation_handle_tracker.h b/chrome/test/automation/automation_handle_tracker.h index 44eacab..98a9fb9 100644 --- a/chrome/test/automation/automation_handle_tracker.h +++ b/chrome/test/automation/automation_handle_tracker.h @@ -11,6 +11,8 @@ #include <map> #include "base/basictypes.h" +#include "base/lock.h" +#include "base/ref_counted.h" // This represents a value that the app's AutomationProvider returns // when asked for a resource (like a window or tab). @@ -19,7 +21,8 @@ typedef int AutomationHandle; class AutomationHandleTracker; class AutomationMessageSender; -class AutomationResourceProxy { +class AutomationResourceProxy + : public base::RefCountedThreadSafe<AutomationResourceProxy> { public: AutomationResourceProxy(AutomationHandleTracker* tracker, AutomationMessageSender* sender, @@ -88,15 +91,16 @@ class AutomationHandleTracker { // identified that resource. void InvalidateHandle(AutomationHandle handle); + AutomationResourceProxy* GetResource(AutomationHandle handle); private: typedef - std::multimap<AutomationHandle, AutomationResourceProxy*> HandleToObjectMap; + std::map<AutomationHandle, AutomationResourceProxy*> HandleToObjectMap; typedef std::pair<AutomationHandle, AutomationResourceProxy*> MapEntry; HandleToObjectMap handle_to_object_; AutomationMessageSender* sender_; - + Lock map_lock_; DISALLOW_EVIL_CONSTRUCTORS(AutomationHandleTracker); }; diff --git a/chrome/test/automation/automation_proxy.cc b/chrome/test/automation/automation_proxy.cc index 9fc8193..13e0957 100644 --- a/chrome/test/automation/automation_proxy.cc +++ b/chrome/test/automation/automation_proxy.cc @@ -75,6 +75,62 @@ class AutomationMessageFilter : public IPC::ChannelProxy::MessageFilter { AutomationProxy* server_; }; +class TabProxyNotificationMessageFilter + : public IPC::ChannelProxy::MessageFilter { + public: + TabProxyNotificationMessageFilter(AutomationHandleTracker* tracker) + : tracker_ (tracker) { + } + + virtual bool OnMessageReceived(const IPC::Message& message) { + if (message.is_sync()) + return false; + + if (message.is_reply()) + return false; + + bool tab_message = IsTabNotifyMessage(message); + if (tab_message == false) + return false; + + // Read tab handle from the message. + int tab_handle = 0; + void* iter = NULL; + if (!message.ReadInt(&iter, &tab_handle)) + return false; + + // Get AddRef-ed pointer to corresponding TabProxy object + TabProxy* tab = static_cast<TabProxy*>(tracker_->GetResource(tab_handle)); + if (tab) { + tab->OnMessageReceived(message); + tab->Release(); + } + return true; + } + + static bool IsTabNotifyMessage(const IPC::Message& message) { + bool tab_message = true; + IPC_BEGIN_MESSAGE_MAP(TabProxyNotificationMessageFilter, message) + IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_NavigationStateChanged, ) + IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_UpdateTargetUrl, ) +#if defined(OS_WIN) + IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_HandleAccelerator, ) +#endif + IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_TabbedOut, ) + IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_OpenURL, ) + IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_DidNavigate, ) + IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_NavigationFailed, ) + IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_TabLoaded, ) + IPC_MESSAGE_HANDLER_GENERIC(AutomationMsg_ForwardMessageToExternalHost, ) + + IPC_MESSAGE_UNHANDLED(tab_message = false); + IPC_END_MESSAGE_MAP() + return tab_message; + } + + private: + AutomationHandleTracker* tracker_; +}; } // anonymous namespace @@ -339,8 +395,8 @@ bool AutomationProxy::WaitForURLDisplayed(GURL url, int wait_timeout) { return false; for (int i = 0; i < window_count; i++) { - BrowserProxy* window = GetBrowserWindow(i); - if (!window) + scoped_refptr<BrowserProxy> window = GetBrowserWindow(i); + if (!window.get()) break; int tab_count; @@ -348,8 +404,8 @@ bool AutomationProxy::WaitForURLDisplayed(GURL url, int wait_timeout) { continue; for (int j = 0; j < tab_count; j++) { - TabProxy* tab = window->GetTab(j); - if (!tab) + scoped_refptr<TabProxy> tab = window->GetTab(j); + if (!tab.get()) break; GURL tab_url; @@ -388,7 +444,7 @@ void AutomationProxy::OnChannelError() { DLOG(ERROR) << "Channel error in AutomationProxy."; } -WindowProxy* AutomationProxy::GetActiveWindow() { +scoped_refptr<WindowProxy> AutomationProxy::GetActiveWindow() { int handle = 0; if (!SendWithTimeout(new AutomationMsg_ActiveWindow(0, &handle), @@ -396,10 +452,11 @@ WindowProxy* AutomationProxy::GetActiveWindow() { return NULL; } - return new WindowProxy(this, tracker_.get(), handle); + return ProxyObjectFromHandle<WindowProxy>(handle); } -BrowserProxy* AutomationProxy::GetBrowserWindow(int window_index) { +scoped_refptr<BrowserProxy> AutomationProxy::GetBrowserWindow( + int window_index) { int handle = 0; if (!SendWithTimeout(new AutomationMsg_BrowserWindow(0, window_index, @@ -409,14 +466,10 @@ BrowserProxy* AutomationProxy::GetBrowserWindow(int window_index) { return NULL; } - if (handle == 0) { - return NULL; - } - - return new BrowserProxy(this, tracker_.get(), handle); + return ProxyObjectFromHandle<BrowserProxy>(handle); } -BrowserProxy* AutomationProxy::FindNormalBrowserWindow() { +scoped_refptr<BrowserProxy> AutomationProxy::FindNormalBrowserWindow() { int handle = 0; if (!SendWithTimeout(new AutomationMsg_FindNormalBrowserWindow(0, &handle), @@ -424,14 +477,10 @@ BrowserProxy* AutomationProxy::FindNormalBrowserWindow() { return NULL; } - if (handle == 0) { - return NULL; - } - - return new BrowserProxy(this, tracker_.get(), handle); + return ProxyObjectFromHandle<BrowserProxy>(handle); } -BrowserProxy* AutomationProxy::GetLastActiveBrowserWindow() { +scoped_refptr<BrowserProxy> AutomationProxy::GetLastActiveBrowserWindow() { int handle = 0; if (!SendWithTimeout(new AutomationMsg_LastActiveBrowserWindow( @@ -441,7 +490,7 @@ BrowserProxy* AutomationProxy::GetLastActiveBrowserWindow() { return NULL; } - return new BrowserProxy(this, tracker_.get(), handle); + return ProxyObjectFromHandle<BrowserProxy>(handle); } #if defined(OS_POSIX) @@ -491,11 +540,9 @@ bool AutomationProxy::OpenNewBrowserWindow(bool show) { #if defined(OS_WIN) // TODO(port): Replace HWNDs. -TabProxy* AutomationProxy::CreateExternalTab(HWND parent, - const gfx::Rect& dimensions, - unsigned int style, - bool incognito, - HWND* external_tab_container) { +scoped_refptr<TabProxy> AutomationProxy::CreateExternalTab(HWND parent, + const gfx::Rect& dimensions, unsigned int style, bool incognito, + HWND* external_tab_container) { IPC::Message* response = NULL; int handle = 0; @@ -509,7 +556,25 @@ TabProxy* AutomationProxy::CreateExternalTab(HWND parent, } DCHECK(IsWindow(*external_tab_container)); - + DCHECK(tracker_->GetResource(handle) == NULL); return new TabProxy(this, tracker_.get(), handle); } #endif // defined(OS_WIN) + +template <class T> scoped_refptr<T> AutomationProxy::ProxyObjectFromHandle( + int handle) { + if (!handle) + return NULL; + + // Get AddRef-ed pointer to the object if handle is already seen. + T* p = static_cast<T*>(tracker_->GetResource(handle)); + if (!p) { + p = new T(this, tracker_.get(), handle); + p->AddRef(); + } + + // Since there is no scoped_refptr::attach. + scoped_refptr<T> result; + result.swap(&p); + return result; +} diff --git a/chrome/test/automation/automation_proxy.h b/chrome/test/automation/automation_proxy.h index 75c76cd..ca193e9 100644 --- a/chrome/test/automation/automation_proxy.h +++ b/chrome/test/automation/automation_proxy.h @@ -120,13 +120,13 @@ class AutomationProxy : public IPC::Channel::Listener, // // Use GetBrowserWindowCount to see how many browser windows you can ask for. // Window numbers are 0-based. - BrowserProxy* GetBrowserWindow(int window_index); + scoped_refptr<BrowserProxy> GetBrowserWindow(int window_index); // Finds the first browser window that is not incognito mode and of type // TYPE_NORMAL, and returns its corresponding BrowserProxy, transferring // ownership of the pointer to the caller. // On failure, returns NULL. - BrowserProxy* FindNormalBrowserWindow(); + scoped_refptr<BrowserProxy> FindNormalBrowserWindow(); // Returns the BrowserProxy for the browser window which was last active, // transferring ownership of the pointer to the caller. @@ -134,12 +134,12 @@ class AutomationProxy : public IPC::Channel::Listener, // browser window no longer exists (for example, if it was closed), // returns GetBrowserWindow(0). See crbug.com/10501. As for now this // function is flakey. - BrowserProxy* GetLastActiveBrowserWindow(); + scoped_refptr<BrowserProxy> GetLastActiveBrowserWindow(); // Returns the WindowProxy for the currently active window, transferring // ownership of the pointer to the caller. // On failure, returns NULL. - WindowProxy* GetActiveWindow(); + scoped_refptr<WindowProxy> GetActiveWindow(); // Tells the browser to enable or disable network request filtering. Returns // false if the message fails to send to the browser. @@ -192,9 +192,9 @@ class AutomationProxy : public IPC::Channel::Listener, // Creates a tab that can hosted in an external process. The function // returns a TabProxy representing the tab as well as a window handle // that can be reparented in another process. - TabProxy* CreateExternalTab(HWND parent, const gfx::Rect& dimensions, - unsigned int style, bool incognito, - HWND* external_tab_container); + scoped_refptr<TabProxy> CreateExternalTab(HWND parent, + const gfx::Rect& dimensions, unsigned int style, bool incognito, + HWND* external_tab_container); #endif // defined(OS_WIN) int command_execution_timeout_ms() const { @@ -216,6 +216,7 @@ class AutomationProxy : public IPC::Channel::Listener, } private: + template <class T> scoped_refptr<T> ProxyObjectFromHandle(int handle); void InitializeChannelID(); void InitializeThread(); void InitializeChannel(); diff --git a/chrome/test/automation/automation_proxy_uitest.cc b/chrome/test/automation/automation_proxy_uitest.cc index ef7001c..cefef1fd 100644 --- a/chrome/test/automation/automation_proxy_uitest.cc +++ b/chrome/test/automation/automation_proxy_uitest.cc @@ -44,17 +44,17 @@ TEST_F(AutomationProxyTest, GetBrowserWindowCount) { TEST_F(AutomationProxyTest, GetBrowserWindow) { { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); } { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(-1)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(-1)); ASSERT_FALSE(window.get()); } { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(1)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(1)); ASSERT_FALSE(window.get()); } }; @@ -64,12 +64,12 @@ TEST_F(AutomationProxyTest, GetBrowserWindow) { #if defined(OS_WIN) TEST_F(AutomationProxyVisibleTest, WindowGetViewBounds) { { - scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); - scoped_ptr<WindowProxy> window(browser->GetWindow()); + scoped_refptr<WindowProxy> window(browser->GetWindow()); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab1(browser->GetTab(0)); + scoped_refptr<TabProxy> tab1(browser->GetTab(0)); ASSERT_TRUE(tab1.get()); GURL tab1_url; ASSERT_TRUE(tab1->GetCurrentURL(&tab1_url)); @@ -77,7 +77,7 @@ TEST_F(AutomationProxyVisibleTest, WindowGetViewBounds) { // Add another tab so we can simulate dragging. ASSERT_TRUE(browser->AppendTab(GURL("about:"))); - scoped_ptr<TabProxy> tab2(browser->GetTab(1)); + scoped_refptr<TabProxy> tab2(browser->GetTab(1)); ASSERT_TRUE(tab2.get()); GURL tab2_url; ASSERT_TRUE(tab2->GetCurrentURL(&tab2_url)); @@ -121,12 +121,12 @@ TEST_F(AutomationProxyVisibleTest, WindowGetViewBounds) { views::Event::EF_LEFT_BUTTON_DOWN)); // Check to see that the drag event successfully swapped the two tabs. - tab1.reset(browser->GetTab(0)); + tab1 = browser->GetTab(0); ASSERT_TRUE(tab1.get()); GURL tab1_new_url; ASSERT_TRUE(tab1->GetCurrentURL(&tab1_new_url)); - tab2.reset(browser->GetTab(1)); + tab2 = browser->GetTab(1); ASSERT_TRUE(tab2.get()); GURL tab2_new_url; ASSERT_TRUE(tab2->GetCurrentURL(&tab2_new_url)); @@ -140,7 +140,7 @@ TEST_F(AutomationProxyVisibleTest, WindowGetViewBounds) { #endif // defined(OS_WIN) TEST_F(AutomationProxyTest, GetTabCount) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); int tab_count = 0; @@ -149,7 +149,7 @@ TEST_F(AutomationProxyTest, GetTabCount) { } TEST_F(AutomationProxyTest, GetActiveTabIndex) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); int active_tab_index = -1; @@ -158,7 +158,7 @@ TEST_F(AutomationProxyTest, GetActiveTabIndex) { } TEST_F(AutomationProxyVisibleTest, AppendTab) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); int original_tab_count; @@ -187,7 +187,7 @@ TEST_F(AutomationProxyVisibleTest, AppendTab) { // Append tab will also be active tab ASSERT_TRUE(window->GetActiveTabIndex(&appended_tab_index)); - scoped_ptr<TabProxy> tab(window->GetTab(appended_tab_index)); + scoped_refptr<TabProxy> tab(window->GetTab(appended_tab_index)); ASSERT_TRUE(tab.get()); std::wstring title; ASSERT_TRUE(tab->GetTabTitle(&title)); @@ -195,7 +195,7 @@ TEST_F(AutomationProxyVisibleTest, AppendTab) { } TEST_F(AutomationProxyTest, ActivateTab) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); ASSERT_TRUE(window->AppendTab(GURL("about:blank"))); @@ -214,10 +214,10 @@ TEST_F(AutomationProxyTest, ActivateTab) { TEST_F(AutomationProxyTest, GetTab) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); { - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); std::wstring title; ASSERT_TRUE(tab->GetTabTitle(&title)); @@ -230,16 +230,15 @@ TEST_F(AutomationProxyTest, GetTab) { } { - scoped_ptr<TabProxy> tab; - tab.reset(window->GetTab(1)); + scoped_refptr<TabProxy> tab(window->GetTab(1)); ASSERT_FALSE(tab.get()); } }; TEST_F(AutomationProxyTest, NavigateToURL) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); std::wstring title; @@ -258,9 +257,9 @@ TEST_F(AutomationProxyTest, NavigateToURL) { } TEST_F(AutomationProxyTest, NavigateToURLWithTimeout1) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); FilePath filename(test_data_directory_); @@ -281,10 +280,9 @@ TEST_F(AutomationProxyTest, NavigateToURLWithTimeout1) { } TEST_F(AutomationProxyTest, NavigateToURLWithTimeout2) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); - tab.reset(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); FilePath filename1(test_data_directory_); @@ -303,9 +301,9 @@ TEST_F(AutomationProxyTest, NavigateToURLWithTimeout2) { } TEST_F(AutomationProxyTest, GoBackForward) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); std::wstring title; @@ -338,9 +336,9 @@ TEST_F(AutomationProxyTest, GoBackForward) { } TEST_F(AutomationProxyTest, GetCurrentURL) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); GURL url; ASSERT_TRUE(tab->GetCurrentURL(&url)); @@ -371,7 +369,7 @@ class AutomationProxyTest2 : public AutomationProxyVisibleTest { }; TEST_F(AutomationProxyTest2, GetActiveTabIndex) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); int active_tab_index = -1; @@ -386,15 +384,15 @@ TEST_F(AutomationProxyTest2, GetActiveTabIndex) { } TEST_F(AutomationProxyTest2, GetTabTitle) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); std::wstring title; ASSERT_TRUE(tab->GetTabTitle(&title)); ASSERT_STREQ(L"title1.html", title.c_str()); - tab.reset(window->GetTab(1)); + tab = window->GetTab(1); ASSERT_TRUE(tab.get()); ASSERT_TRUE(tab->GetTabTitle(&title)); ASSERT_STREQ(L"Title Of Awesomeness", title.c_str()); @@ -404,10 +402,10 @@ TEST_F(AutomationProxyTest, Cookies) { GURL url("http://mojo.jojo.google.com"); std::string value_result; - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); // test setting the cookie: @@ -436,9 +434,9 @@ TEST_F(AutomationProxyTest, Cookies) { // TODO(port): Determine what tests need this and port. #if defined(OS_WIN) TEST_F(AutomationProxyTest, GetHWND) { - scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); - scoped_ptr<WindowProxy> window(browser->GetWindow()); + scoped_refptr<WindowProxy> window(browser->GetWindow()); ASSERT_TRUE(window.get()); HWND handle; @@ -449,9 +447,9 @@ TEST_F(AutomationProxyTest, GetHWND) { TEST_F(AutomationProxyTest, NavigateToURLAsync) { AutomationProxy* automation_object = automation(); - scoped_ptr<BrowserProxy> window(automation_object->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation_object->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); FilePath filename(test_data_directory_); @@ -465,7 +463,7 @@ TEST_F(AutomationProxyTest, NavigateToURLAsync) { } TEST_F(AutomationProxyTest, AcceleratorNewTab) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); int tab_count = -1; ASSERT_TRUE(window->GetTabCount(&tab_count)); @@ -474,7 +472,7 @@ TEST_F(AutomationProxyTest, AcceleratorNewTab) { ASSERT_TRUE(window->RunCommand(IDC_NEW_TAB)); ASSERT_TRUE(window->GetTabCount(&tab_count)); EXPECT_EQ(2, tab_count); - scoped_ptr<TabProxy> tab(window->GetTab(tab_count - 1)); + scoped_refptr<TabProxy> tab(window->GetTab(tab_count - 1)); ASSERT_TRUE(tab.get()); } @@ -494,10 +492,10 @@ std::wstring CreateJSString(const std::wstring& value) { } TEST_F(AutomationProxyTest4, StringValueIsEchoedByDomAutomationController) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); std::wstring expected(L"string"); @@ -516,10 +514,10 @@ std::wstring BooleanToString(bool bool_value) { } TEST_F(AutomationProxyTest4, BooleanValueIsEchoedByDomAutomationController) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); bool expected = true; @@ -530,10 +528,10 @@ TEST_F(AutomationProxyTest4, BooleanValueIsEchoedByDomAutomationController) { } TEST_F(AutomationProxyTest4, NumberValueIsEchoedByDomAutomationController) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); int expected = 1; @@ -571,10 +569,10 @@ std::wstring CreateJSStringForDOMQuery(const std::wstring& id) { } TEST_F(AutomationProxyTest3, FrameDocumentCanBeAccessed) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); std::wstring actual; @@ -600,7 +598,7 @@ TEST_F(AutomationProxyTest3, FrameDocumentCanBeAccessed) { #if 0 // Open a new Destinations tab to execute script inside. window->RunCommand(IDC_NEWTAB); - tab.reset(window->GetTab(1)); + tab = window->GetTab(1); ASSERT_TRUE(tab.get()); ASSERT_TRUE(window->ActivateTab(1)); @@ -611,11 +609,10 @@ TEST_F(AutomationProxyTest3, FrameDocumentCanBeAccessed) { // TODO(port): Need to port constrained_window_proxy.* first. #if defined(OS_WIN) TEST_F(AutomationProxyTest, ConstrainedWindowTest) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); - tab.reset(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); FilePath filename(test_data_directory_); @@ -629,22 +626,20 @@ TEST_F(AutomationProxyTest, ConstrainedWindowTest) { ASSERT_EQ(1, count); - ConstrainedWindowProxy* cwindow = tab->GetConstrainedWindow(0); - ASSERT_TRUE(cwindow); + scoped_refptr<ConstrainedWindowProxy> cwindow = tab->GetConstrainedWindow(0); + ASSERT_TRUE(cwindow.get()); std::wstring title; ASSERT_TRUE(cwindow->GetTitle(&title)); std::wstring window_title = L"Pop-ups Blocked: 2"; ASSERT_STREQ(window_title.c_str(), title.c_str()); - delete cwindow; } TEST_F(AutomationProxyTest, CantEscapeByOnloadMoveto) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); - tab.reset(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); FilePath filename(test_data_directory_); @@ -658,8 +653,8 @@ TEST_F(AutomationProxyTest, CantEscapeByOnloadMoveto) { ASSERT_EQ(1, count); - ConstrainedWindowProxy* cwindow = tab->GetConstrainedWindow(0); - ASSERT_TRUE(cwindow); + scoped_refptr<ConstrainedWindowProxy> cwindow = tab->GetConstrainedWindow(0); + ASSERT_TRUE(cwindow.get()); gfx::Rect rect; bool is_timeout = false; @@ -803,7 +798,7 @@ void AutomationProxyForExternalTab::OnForwardMessageToExternalHost( TEST_F(ExternalTabTestType, CreateExternalTab) { HWND external_tab_container = NULL; - scoped_ptr<TabProxy> tab(automation()->CreateExternalTab(NULL, gfx::Rect(), + scoped_refptr<TabProxy> tab(automation()->CreateExternalTab(NULL, gfx::Rect(), WS_POPUP, false, &external_tab_container)); EXPECT_TRUE(tab != NULL); EXPECT_NE(FALSE, ::IsWindow(external_tab_container)); @@ -822,21 +817,21 @@ TEST_F(ExternalTabTestType, IncognitoMode) { std::string value_result; // Create incognito tab - scoped_ptr<TabProxy> tab(automation()->CreateExternalTab(NULL, gfx::Rect(), + scoped_refptr<TabProxy> tab(automation()->CreateExternalTab(NULL, gfx::Rect(), WS_POPUP, true, &external_tab_container)); EXPECT_TRUE(tab->SetCookie(url, "robert=burton; " "expires=Thu, 13 Oct 2011 05:04:03 UTC;")); EXPECT_TRUE(tab->GetCookieByName(url, "robert", &value_result)); EXPECT_EQ("burton", value_result); - tab.reset(NULL); + tab = NULL; CloseBrowserAndServer(); value_result.empty(); clear_profile_ = false; external_tab_container = NULL; LaunchBrowserAndServer(); - tab.reset(automation()->CreateExternalTab(NULL, gfx::Rect(), - WS_POPUP, false, &external_tab_container)); + tab = automation()->CreateExternalTab(NULL, gfx::Rect(), + WS_POPUP, false, &external_tab_container); EXPECT_TRUE(tab->GetCookieByName(url, "robert", &value_result)); EXPECT_EQ("", value_result); } @@ -846,7 +841,7 @@ TEST_F(ExternalTabTestType, ExternalTabPostMessage) { static_cast<AutomationProxyForExternalTab*>(automation()); HWND external_tab_container = NULL; - scoped_ptr<TabProxy> tab(proxy->CreateExternalTab(NULL, gfx::Rect(), + scoped_refptr<TabProxy> tab(proxy->CreateExternalTab(NULL, gfx::Rect(), WS_POPUP, false, &external_tab_container)); EXPECT_TRUE(tab != NULL); EXPECT_NE(FALSE, ::IsWindow(external_tab_container)); @@ -880,9 +875,9 @@ TEST_F(ExternalTabTestType, ExternalTabPostMessage) { // TODO(port): Need to port autocomplete_edit_proxy.* first. #if defined(OS_WIN) || defined(OS_LINUX) TEST_F(AutomationProxyTest, AutocompleteGetSetText) { - scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); - scoped_ptr<AutocompleteEditProxy> edit( + scoped_refptr<AutocompleteEditProxy> edit( browser->GetAutocompleteEdit()); ASSERT_TRUE(edit.get()); EXPECT_TRUE(edit->is_valid()); @@ -891,22 +886,22 @@ TEST_F(AutomationProxyTest, AutocompleteGetSetText) { EXPECT_TRUE(edit->SetText(text_to_set)); EXPECT_TRUE(edit->GetText(&actual_text)); EXPECT_EQ(text_to_set, actual_text); - scoped_ptr<AutocompleteEditProxy> edit2( + scoped_refptr<AutocompleteEditProxy> edit2( browser->GetAutocompleteEdit()); EXPECT_TRUE(edit2->GetText(&actual_text)); EXPECT_EQ(text_to_set, actual_text); } TEST_F(AutomationProxyTest, AutocompleteParallelProxy) { - scoped_ptr<BrowserProxy> browser1(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> browser1(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser1.get()); - scoped_ptr<AutocompleteEditProxy> edit1( + scoped_refptr<AutocompleteEditProxy> edit1( browser1->GetAutocompleteEdit()); ASSERT_TRUE(edit1.get()); EXPECT_TRUE(browser1->RunCommand(IDC_NEW_WINDOW)); - scoped_ptr<BrowserProxy> browser2(automation()->GetBrowserWindow(1)); + scoped_refptr<BrowserProxy> browser2(automation()->GetBrowserWindow(1)); ASSERT_TRUE(browser2.get()); - scoped_ptr<AutocompleteEditProxy> edit2( + scoped_refptr<AutocompleteEditProxy> edit2( browser2->GetAutocompleteEdit()); ASSERT_TRUE(edit2.get()); EXPECT_TRUE(browser2->GetTab(0)->WaitForTabToBeRestored( @@ -923,9 +918,9 @@ TEST_F(AutomationProxyTest, AutocompleteParallelProxy) { } TEST_F(AutomationProxyVisibleTest, AutocompleteMatchesTest) { - scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); - scoped_ptr<AutocompleteEditProxy> edit( + scoped_refptr<AutocompleteEditProxy> edit( browser->GetAutocompleteEdit()); ASSERT_TRUE(edit.get()); EXPECT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION)); @@ -943,10 +938,9 @@ TEST_F(AutomationProxyVisibleTest, AutocompleteMatchesTest) { // Disabled because flaky see bug #5314. TEST_F(AutomationProxyTest, DISABLED_AppModalDialogTest) { - scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); - scoped_ptr<TabProxy> tab(browser->GetTab(0)); - tab.reset(browser->GetTab(0)); + scoped_refptr<TabProxy> tab(browser->GetTab(0)); ASSERT_TRUE(tab.get()); bool modal_dialog_showing = false; @@ -1039,10 +1033,10 @@ class AutomationProxyTest5 : public UITest { }; TEST_F(AutomationProxyTest5, TestLifetimeOfDomAutomationController) { - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); ASSERT_TRUE(window.get()); - scoped_ptr<TabProxy> tab(window->GetTab(0)); + scoped_refptr<TabProxy> tab(window->GetTab(0)); ASSERT_TRUE(tab.get()); FilePath filename(test_data_directory_); diff --git a/chrome/test/automation/browser_proxy.cc b/chrome/test/automation/browser_proxy.cc index 03a1e51..28dd022 100644 --- a/chrome/test/automation/browser_proxy.cc +++ b/chrome/test/automation/browser_proxy.cc @@ -112,25 +112,34 @@ bool BrowserProxy::GetActiveTabIndexWithTimeout(int* active_tab_index, return succeeded; } -TabProxy* BrowserProxy::GetTab(int tab_index) const { +scoped_refptr<TabProxy> BrowserProxy::GetTab(int tab_index) const { if (!is_valid()) return NULL; - int handle = 0; + int tab_handle = 0; - sender_->Send(new AutomationMsg_Tab(0, handle_, tab_index, &handle)); - if (!handle) + sender_->Send(new AutomationMsg_Tab(0, handle_, tab_index, &tab_handle)); + if (!tab_handle) return NULL; - return new TabProxy(sender_, tracker_, handle); + TabProxy* tab = static_cast<TabProxy*>(tracker_->GetResource(tab_handle)); + if (!tab) { + tab = new TabProxy(sender_, tracker_, tab_handle); + tab->AddRef(); + } + + // Since there is no scoped_refptr::attach. + scoped_refptr<TabProxy> result; + result.swap(&tab); + return result; } -TabProxy* BrowserProxy::GetActiveTab() const { +scoped_refptr<TabProxy> BrowserProxy::GetActiveTab() const { return GetActiveTabWithTimeout(base::kNoTimeout, NULL); } -TabProxy* BrowserProxy::GetActiveTabWithTimeout(uint32 timeout_ms, - bool* is_timeout) const { +scoped_refptr<TabProxy> BrowserProxy::GetActiveTabWithTimeout(uint32 timeout_ms, + bool* is_timeout) const { int active_tab_index; if (!GetActiveTabIndexWithTimeout(&active_tab_index, timeout_ms, is_timeout)) return NULL; @@ -365,9 +374,9 @@ bool BrowserProxy::SetBooleanPreference(const std::wstring& name, return result; } -WindowProxy* BrowserProxy::GetWindow() const { +scoped_refptr<WindowProxy> BrowserProxy::GetWindow() const { if (!is_valid()) - return false; + return NULL; bool handle_ok = false; int window_handle = 0; @@ -377,10 +386,20 @@ WindowProxy* BrowserProxy::GetWindow() const { if (!handle_ok) return NULL; - return new WindowProxy(sender_, tracker_, window_handle); + WindowProxy* window = + static_cast<WindowProxy*>(tracker_->GetResource(window_handle)); + if (!window) { + window = new WindowProxy(sender_, tracker_, window_handle); + window->AddRef(); + } + + // Since there is no scoped_refptr::attach. + scoped_refptr<WindowProxy> result; + result.swap(&window); + return result; } -AutocompleteEditProxy* BrowserProxy::GetAutocompleteEdit() { +scoped_refptr<AutocompleteEditProxy> BrowserProxy::GetAutocompleteEdit() { if (!is_valid()) return NULL; @@ -393,5 +412,16 @@ AutocompleteEditProxy* BrowserProxy::GetAutocompleteEdit() { if (!handle_ok) return NULL; - return new AutocompleteEditProxy(sender_, tracker_, autocomplete_edit_handle); + AutocompleteEditProxy* p = static_cast<AutocompleteEditProxy*>( + tracker_->GetResource(autocomplete_edit_handle)); + + if (!p) { + p = new AutocompleteEditProxy(sender_, tracker_, autocomplete_edit_handle); + p->AddRef(); + } + + // Since there is no scoped_refptr::attach. + scoped_refptr<AutocompleteEditProxy> result; + result.swap(&p); + return result; } diff --git a/chrome/test/automation/browser_proxy.h b/chrome/test/automation/browser_proxy.h index 7f69681..98e64de 100644 --- a/chrome/test/automation/browser_proxy.h +++ b/chrome/test/automation/browser_proxy.h @@ -34,7 +34,6 @@ class BrowserProxy : public AutomationResourceProxy { AutomationHandleTracker* tracker, int handle) : AutomationResourceProxy(tracker, sender, handle) {} - virtual ~BrowserProxy() {} // Activates the tab corresponding to (zero-based) tab_index. Returns true if // successful. @@ -89,26 +88,27 @@ class BrowserProxy : public AutomationResourceProxy { // // Use GetTabCount to see how many windows you can ask for. Tab numbers // are 0-based. - TabProxy* GetTab(int tab_index) const; + scoped_refptr<TabProxy> GetTab(int tab_index) const; // Returns the TabProxy for the currently active tab, transferring // ownership of the pointer to the caller. On failure, returns NULL. - TabProxy* GetActiveTab() const; + scoped_refptr<TabProxy> GetActiveTab() const; // Like GetActiveTab, but returns NULL if no response is received before // the specified timout. - TabProxy* GetActiveTabWithTimeout(uint32 timeout_ms, bool* is_timeout) const; + scoped_refptr<TabProxy> GetActiveTabWithTimeout(uint32 timeout_ms, + bool* is_timeout) const; // Returns the WindowProxy for this browser's window. It can be used to // retreive view bounds, simulate clicks and key press events. The caller // owns the returned WindowProxy. // On failure, returns NULL. - WindowProxy* GetWindow() const; + scoped_refptr<WindowProxy> GetWindow() const; // Returns an AutocompleteEdit for this browser's window. It can be used to // manipulate the omnibox. The caller owns the returned pointer. // On failure, returns NULL. - AutocompleteEditProxy* GetAutocompleteEdit(); + scoped_refptr<AutocompleteEditProxy> GetAutocompleteEdit(); // Apply the accelerator with given id (IDC_BACK, IDC_NEWTAB ...) // The list can be found at chrome/app/chrome_dll_resource.h @@ -198,6 +198,8 @@ class BrowserProxy : public AutomationResourceProxy { // Sets the boolean value of the specified preference. bool SetBooleanPreference(const std::wstring& name, bool value); + protected: + virtual ~BrowserProxy() {} private: DISALLOW_COPY_AND_ASSIGN(BrowserProxy); }; diff --git a/chrome/test/automation/tab_proxy.cc b/chrome/test/automation/tab_proxy.cc index 2b27e0d..207efac 100644 --- a/chrome/test/automation/tab_proxy.cc +++ b/chrome/test/automation/tab_proxy.cc @@ -337,19 +337,31 @@ bool TabProxy::GetConstrainedWindowCount(int* count) const { 0, handle_, count)); } -ConstrainedWindowProxy* TabProxy::GetConstrainedWindow( +scoped_refptr<ConstrainedWindowProxy> TabProxy::GetConstrainedWindow( int window_index) const { if (!is_valid()) return NULL; int handle = 0; - if (sender_->Send(new AutomationMsg_ConstrainedWindow(0, handle_, + if (!sender_->Send(new AutomationMsg_ConstrainedWindow(0, handle_, window_index, - &handle))) { - return new ConstrainedWindowProxy(sender_, tracker_, handle); + &handle))) + return NULL; + + if (handle == 0) + return NULL; + + ConstrainedWindowProxy* w = static_cast<ConstrainedWindowProxy*>( + tracker_->GetResource(handle)); + if (!w) { + w = new ConstrainedWindowProxy(sender_, tracker_, handle); + w->AddRef(); } - return NULL; + // Since there is no scoped_refptr::attach. + scoped_refptr<ConstrainedWindowProxy> result; + result.swap(&w); + return result; } bool TabProxy::WaitForChildWindowCountToChange(int count, int* new_count, @@ -637,3 +649,20 @@ void TabProxy::Reposition(HWND window, HWND window_insert_after, int left, } #endif // defined(OS_WIN) + +void TabProxy::AddObserver(TabProxyDelegate* observer) { + AutoLock lock(list_lock_); + observers_list_.AddObserver(observer); +} + +void TabProxy::RemoveObserver(TabProxyDelegate* observer) { + AutoLock lock(list_lock_); + observers_list_.RemoveObserver(observer); +} + +// Called on Channel background thread, if TabMessages filter is installed. +void TabProxy::OnMessageReceived(const IPC::Message& message) { + AutoLock lock(list_lock_); + FOR_EACH_OBSERVER(TabProxyDelegate, observers_list_, + OnMessageReceived(this, message)); +} diff --git a/chrome/test/automation/tab_proxy.h b/chrome/test/automation/tab_proxy.h index 8f071bb..81c72a8 100644 --- a/chrome/test/automation/tab_proxy.h +++ b/chrome/test/automation/tab_proxy.h @@ -14,6 +14,7 @@ #include <string> #include <vector> +#include "base/observer_list.h" #include "chrome/browser/download/save_package.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/security_style.h" @@ -23,19 +24,23 @@ class ConstrainedWindowProxy; class GURL; class Value; +class IPC::Message; enum FindInPageDirection { BACK = 0, FWD = 1 }; enum FindInPageCase { IGNORE_CASE = 0, CASE_SENSITIVE = 1 }; class TabProxy : public AutomationResourceProxy { public: + class TabProxyDelegate { + public: + virtual void OnMessageReceived(TabProxy* tab, const IPC::Message& msg) {} + }; + TabProxy(AutomationMessageSender* sender, AutomationHandleTracker* tracker, int handle) : AutomationResourceProxy(tracker, sender, handle) {} - virtual ~TabProxy() {} - // Gets the current url of the tab. bool GetCurrentURL(GURL* url) const; @@ -51,7 +56,8 @@ class TabProxy : public AutomationResourceProxy { // Gets the proxy object for constrained window within this tab. Ownership // for the returned object is transfered to the caller. Returns NULL on // failure. - ConstrainedWindowProxy* GetConstrainedWindow(int window_index) const; + scoped_refptr<ConstrainedWindowProxy> GetConstrainedWindow( + int window_index) const; // Executes a javascript in a frame's context whose xpath is provided as the // first parameter and extract the values from the resulting json string. @@ -295,7 +301,15 @@ class TabProxy : public AutomationResourceProxy { int width, int height, int flags, HWND parent_window); #endif // defined(OS_WIN) + // Calls delegates + void AddObserver(TabProxyDelegate* observer); + void RemoveObserver(TabProxyDelegate* observer); + void OnMessageReceived(const IPC::Message& message); + protected: + virtual ~TabProxy() {} private: + Lock list_lock_; // Protects the observers_list_. + ObserverList<TabProxyDelegate> observers_list_; DISALLOW_COPY_AND_ASSIGN(TabProxy); }; diff --git a/chrome/test/automation/window_proxy.cc b/chrome/test/automation/window_proxy.cc index 7288595..6cced64 100644 --- a/chrome/test/automation/window_proxy.cc +++ b/chrome/test/automation/window_proxy.cc @@ -118,14 +118,14 @@ bool WindowProxy::GetFocusedViewID(int* view_id) { view_id)); } -BrowserProxy* WindowProxy::GetBrowser() { +scoped_refptr<BrowserProxy> WindowProxy::GetBrowser() { return GetBrowserWithTimeout(base::kNoTimeout, NULL); } -BrowserProxy* WindowProxy::GetBrowserWithTimeout(uint32 timeout_ms, - bool* is_timeout) { +scoped_refptr<BrowserProxy> WindowProxy::GetBrowserWithTimeout( + uint32 timeout_ms, bool* is_timeout) { if (!is_valid()) - return false; + return NULL; bool handle_ok = false; int browser_handle = 0; @@ -135,5 +135,15 @@ BrowserProxy* WindowProxy::GetBrowserWithTimeout(uint32 timeout_ms, if (!handle_ok) return NULL; - return new BrowserProxy(sender_, tracker_, browser_handle); + BrowserProxy* browser = + static_cast<BrowserProxy*>(tracker_->GetResource(browser_handle)); + if (!browser) { + browser = new BrowserProxy(sender_, tracker_, browser_handle); + browser->AddRef(); + } + + // Since there is no scoped_refptr::attach. + scoped_refptr<BrowserProxy> result; + result.swap(&browser); + return result; } diff --git a/chrome/test/automation/window_proxy.h b/chrome/test/automation/window_proxy.h index 2935480..8beb158 100644 --- a/chrome/test/automation/window_proxy.h +++ b/chrome/test/automation/window_proxy.h @@ -34,7 +34,6 @@ class WindowProxy : public AutomationResourceProxy { AutomationHandleTracker* tracker, int handle) : AutomationResourceProxy(tracker, sender, handle) {} - virtual ~WindowProxy() {} #if defined(OS_WIN) // TODO(port): Use portable replacements for windowsisms. @@ -89,12 +88,14 @@ class WindowProxy : public AutomationResourceProxy { // Returns the browser this window corresponds to, or NULL if this window // is not a browser. The caller owns the returned BrowserProxy. - BrowserProxy* GetBrowser(); + scoped_refptr<BrowserProxy> GetBrowser(); // Same as GetWindow except return NULL if response isn't received // before the specified timeout. - BrowserProxy* GetBrowserWithTimeout(uint32 timeout_ms, bool* is_timeout); - + scoped_refptr<BrowserProxy> GetBrowserWithTimeout(uint32 timeout_ms, + bool* is_timeout); + protected: + virtual ~WindowProxy() {} private: DISALLOW_COPY_AND_ASSIGN(WindowProxy); }; diff --git a/chrome/test/interactive_ui/npapi_interactive_test.cc b/chrome/test/interactive_ui/npapi_interactive_test.cc index 95be3f6..24aa5d1 100644 --- a/chrome/test/interactive_ui/npapi_interactive_test.cc +++ b/chrome/test/interactive_ui/npapi_interactive_test.cc @@ -45,7 +45,7 @@ const int kShortWaitTimeout = 5 * 1000; // a synchronous mousemove works correctly TEST_F(NPAPIVisiblePluginTester, SelfDeletePluginInvokeInSynchronousMouseMove) { if (!UITest::in_process_renderer()) { - scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); + scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); HWND tab_window = NULL; tab_proxy->GetHWND(&tab_window); diff --git a/chrome/test/memory_test/memory_test.cc b/chrome/test/memory_test/memory_test.cc index ffddf51..e06727d 100644 --- a/chrome/test/memory_test/memory_test.cc +++ b/chrome/test/memory_test/memory_test.cc @@ -213,8 +213,8 @@ class MemoryTest : public UITest { size_t start_size = GetSystemCommitCharge(); // Cycle through the URLs. - scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); - scoped_ptr<TabProxy> tab(window->GetActiveTab()); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + scoped_refptr<TabProxy> tab(window->GetActiveTab()); int expected_tab_count = 1; for (unsigned counter = 0; counter < arraysize(urls); ++counter) { std::string url = urls[counter]; @@ -233,12 +233,12 @@ class MemoryTest : public UITest { EXPECT_TRUE(window->AppendTab(GURL(url))); expected_tab_count++; WaitUntilTabCount(expected_tab_count); - tab.reset(window->GetActiveTab()); + tab = window->GetActiveTab(); continue; } int tab_index = counter % num_target_tabs; // A pseudo-random tab. - tab.reset(window->GetTab(tab_index)); + tab = window->GetTab(tab_index); } const int kMaxWaitTime = 5000; diff --git a/chrome/test/page_cycler/page_cycler_test.cc b/chrome/test/page_cycler/page_cycler_test.cc index 1158248..34bafe6 100644 --- a/chrome/test/page_cycler/page_cycler_test.cc +++ b/chrome/test/page_cycler/page_cycler_test.cc @@ -67,7 +67,7 @@ class PageCyclerTest : public UITest { url_parse::Component(0, arraysize(query_string) - 1)); test_url = test_url.ReplaceComponents(replacements); - scoped_ptr<TabProxy> tab(GetActiveTab()); + scoped_refptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(test_url); // Wait for the test to finish. diff --git a/chrome/test/plugin/plugin_test.cpp b/chrome/test/plugin/plugin_test.cpp index 0faf2ca..5a5b844 100644 --- a/chrome/test/plugin/plugin_test.cpp +++ b/chrome/test/plugin/plugin_test.cpp @@ -116,7 +116,7 @@ class PluginTest : public UITest { const int kMaxIntervals = wait_time / kSleepTime; GURL url = GetTestUrl(L"done"); - scoped_ptr<TabProxy> tab(GetActiveTab()); + scoped_refptr<TabProxy> tab(GetActiveTab()); std::string done_str; for (int i = 0; i < kMaxIntervals; ++i) { diff --git a/chrome/test/reliability/page_load_test.cc b/chrome/test/reliability/page_load_test.cc index 277d6ca..774b7f0 100644 --- a/chrome/test/reliability/page_load_test.cc +++ b/chrome/test/reliability/page_load_test.cc @@ -168,7 +168,7 @@ class PageLoadTest : public UITest { // assertion when page loading fails. We log the result instead. { // TabProxy should be released before Browser is closed. - scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); + scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); if (tab_proxy.get()) { result = tab_proxy->NavigateToURLWithTimeout(url, timeout_ms, &is_timeout); @@ -177,9 +177,9 @@ class PageLoadTest : public UITest { if (!is_timeout && result == AUTOMATION_MSG_NAVIGATION_SUCCESS) { if (page_down) { // Page down twice. - scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); if (browser.get()) { - scoped_ptr<WindowProxy> window(browser->GetWindow()); + scoped_refptr<WindowProxy> window(browser->GetWindow()); if (window.get()) { bool activation_timeout; browser->BringToFrontWithTimeout(action_max_timeout_ms(), @@ -372,7 +372,7 @@ class PageLoadTest : public UITest { LaunchBrowserAndServer(); { // TabProxy should be released before Browser is closed. - scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); + scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); if (tab_proxy.get()) { tab_proxy->NavigateToURL(GURL(test_url_1)); } diff --git a/chrome/test/selenium/selenium_test.cc b/chrome/test/selenium/selenium_test.cc index 590d996..bf0be73 100644 --- a/chrome/test/selenium/selenium_test.cc +++ b/chrome/test/selenium/selenium_test.cc @@ -103,7 +103,7 @@ class SeleniumTest : public UITest { file_util::AppendToPath(&test_path, L"TestRunner.html"); GURL test_url(net::FilePathToFileURL(FilePath::FromWStringHack(test_path))); - scoped_ptr<TabProxy> tab(GetActiveTab()); + scoped_refptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(test_url); // Wait for the test to finish. diff --git a/chrome/test/startup/feature_startup_test.cc b/chrome/test/startup/feature_startup_test.cc index e1cd0a7..6862d6a 100644 --- a/chrome/test/startup/feature_startup_test.cc +++ b/chrome/test/startup/feature_startup_test.cc @@ -59,8 +59,8 @@ class NewTabUIStartupTest : public UITest { // Switch to the "new tab" tab, which should be any new tab after the // first (the first is about:blank). - BrowserProxy* window = automation()->GetBrowserWindow(0); - ASSERT_TRUE(window); + scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(window.get()); int tab_count = -1; ASSERT_TRUE(window->GetTabCount(&tab_count)); ASSERT_EQ(1, tab_count); @@ -80,7 +80,7 @@ class NewTabUIStartupTest : public UITest { timings[i] = TimeDelta::FromMilliseconds(load_time); } - delete window; + window = NULL; UITest::TearDown(); } diff --git a/chrome/test/tab_switching/tab_switching_test.cc b/chrome/test/tab_switching/tab_switching_test.cc index d56be38..91423a6 100644 --- a/chrome/test/tab_switching/tab_switching_test.cc +++ b/chrome/test/tab_switching/tab_switching_test.cc @@ -39,7 +39,7 @@ class TabSwitchingUITest : public UITest { void RunTabSwitchingUITest() { // Create a browser proxy. - browser_proxy_.reset(automation()->GetBrowserWindow(0)); + browser_proxy_ = automation()->GetBrowserWindow(0); // Open all the tabs. int initial_tab_count = 0; @@ -128,7 +128,7 @@ class TabSwitchingUITest : public UITest { std::wstring path_prefix_; int number_of_tabs_to_open_; - scoped_ptr<BrowserProxy> browser_proxy_; + scoped_refptr<BrowserProxy> browser_proxy_; private: DISALLOW_EVIL_CONSTRUCTORS(TabSwitchingUITest); diff --git a/chrome/test/ui/dom_checker_uitest.cc b/chrome/test/ui/dom_checker_uitest.cc index aa8c49a..3342a29 100644 --- a/chrome/test/ui/dom_checker_uitest.cc +++ b/chrome/test/ui/dom_checker_uitest.cc @@ -199,7 +199,7 @@ class DomCheckerTest : public UITest { test_url = net::FilePathToFileURL(test_path); } - scoped_ptr<TabProxy> tab(GetActiveTab()); + scoped_refptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(test_url); // Wait for the test to finish. diff --git a/chrome/test/ui/inspector_controller_uitest.cc b/chrome/test/ui/inspector_controller_uitest.cc index 6bf9664..9f9cf0a 100644 --- a/chrome/test/ui/inspector_controller_uitest.cc +++ b/chrome/test/ui/inspector_controller_uitest.cc @@ -12,8 +12,8 @@ class InspectorControllerTest : public UITest { protected: - TabProxy* GetActiveTabProxy() { - scoped_ptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0)); + scoped_refptr<TabProxy> GetActiveTabProxy() { + scoped_refptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0)); EXPECT_TRUE(window_proxy.get()); int active_tab_index = 0; @@ -36,7 +36,7 @@ TEST_F(InspectorControllerTest, DISABLED_InspectElement) { HTTPTestServer::CreateServer(L"chrome/test/data", NULL); ASSERT_TRUE(NULL != server.get()); - ::scoped_ptr<TabProxy> tab(GetActiveTabProxy()); + scoped_refptr<TabProxy> tab(GetActiveTabProxy()); // We don't track resources until we've opened the inspector. NavigateTab(tab.get(), server->TestServerPageW( L"files/inspector/test1.html")); diff --git a/chrome/test/ui/layout_plugin_uitest.cc b/chrome/test/ui/layout_plugin_uitest.cc index 3f4ba9d..e5c10f4 100644 --- a/chrome/test/ui/layout_plugin_uitest.cc +++ b/chrome/test/ui/layout_plugin_uitest.cc @@ -63,7 +63,7 @@ TEST_F(LayoutPluginTester, UnloadNoCrash) { NavigateToURL(net::FilePathToFileURL(path)); std::wstring title; - TabProxy* tab = GetActiveTab(); + scoped_refptr<TabProxy> tab = GetActiveTab(); ASSERT_TRUE(tab); EXPECT_TRUE(tab->GetTabTitle(&title)); EXPECT_EQ(L"Layout Test Plugin Test", title); @@ -71,6 +71,4 @@ TEST_F(LayoutPluginTester, UnloadNoCrash) { ASSERT_TRUE(tab->GoBack()); EXPECT_TRUE(tab->GetTabTitle(&title)); EXPECT_EQ(L"", title); - - delete tab; } diff --git a/chrome/test/ui/npapi_uitest.cc b/chrome/test/ui/npapi_uitest.cc index f8d5f47..76176a9 100644 --- a/chrome/test/ui/npapi_uitest.cc +++ b/chrome/test/ui/npapi_uitest.cc @@ -136,7 +136,7 @@ TEST_F(NPAPITester, DISABLED_SelfDeletePluginInvokeAlert) { // Wait for the alert dialog and then close it. automation()->WaitForAppModalDialog(5000); - scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); + scoped_refptr<WindowProxy> window(automation()->GetActiveWindow()); ASSERT_TRUE(window.get()); ASSERT_TRUE(window->SimulateOSKeyPress(VK_ESCAPE, 0)); diff --git a/chrome/test/ui/omnibox_uitest.cc b/chrome/test/ui/omnibox_uitest.cc index 4620418..c5b27c3 100644 --- a/chrome/test/ui/omnibox_uitest.cc +++ b/chrome/test/ui/omnibox_uitest.cc @@ -74,9 +74,9 @@ bool OmniboxTest::IsMatch(const std::wstring& input_text, void OmniboxTest::RunQueryChain(const std::wstring& input_text) { // Get a handle on the omnibox and give it focus. - scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); - scoped_ptr<WindowProxy> window(browser->GetWindow()); - scoped_ptr<AutocompleteEditProxy> autocomplete_edit( + scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); + scoped_refptr<WindowProxy> window(browser->GetWindow()); + scoped_refptr<AutocompleteEditProxy> autocomplete_edit( browser->GetAutocompleteEdit()); ASSERT_TRUE(browser->ApplyAccelerator(IDC_FOCUS_LOCATION)); diff --git a/chrome/test/ui/sunspider_uitest.cc b/chrome/test/ui/sunspider_uitest.cc index 6ec89d6..6e7f510 100644 --- a/chrome/test/ui/sunspider_uitest.cc +++ b/chrome/test/ui/sunspider_uitest.cc @@ -38,7 +38,7 @@ class SunSpiderTest : public UITest { test_path = test_path.Append(start_file); GURL test_url(net::FilePathToFileURL(test_path)); - scoped_ptr<TabProxy> tab(GetActiveTab()); + scoped_refptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(test_url); // Wait for the test to finish. diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index 85e97b0..1b15116 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -391,7 +391,7 @@ void UITest::LaunchBrowser(const CommandLine& arguments, bool clear_profile) { } void UITest::QuitBrowser() { - typedef std::vector<BrowserProxy*> BrowserVector; + typedef std::vector<scoped_refptr<BrowserProxy> > BrowserVector; // There's nothing to do here if the browser is not running. if (IsBrowserRunning()) { @@ -404,7 +404,8 @@ void UITest::QuitBrowser() { EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); for (int i = 0; i < window_count; ++i) { - BrowserProxy* browser_proxy = automation()->GetBrowserWindow(i); + scoped_refptr<BrowserProxy> browser_proxy = + automation()->GetBrowserWindow(i); browsers.push_back(browser_proxy); } @@ -415,10 +416,11 @@ void UITest::QuitBrowser() { iter != browsers.end(); ++iter) { // Use ApplyAccelerator since it doesn't wait (*iter)->ApplyAccelerator(IDC_CLOSE_WINDOW); - delete (*iter); } #endif + browsers.clear(); + // Now, drop the automation IPC channel so that the automation provider in // the browser notices and drops its reference to the browser process. server_->Disconnect(); @@ -455,13 +457,13 @@ void UITest::CleanupAppProcesses() { AssertAppNotRunning(L"Unable to quit all browser processes."); } -TabProxy* UITest::GetActiveTab(int window_index) { +scoped_refptr<TabProxy> UITest::GetActiveTab(int window_index) { EXPECT_GE(window_index, 0); int window_count; // Use EXPECT rather than ASSERT here because ASSERT_* returns void. EXPECT_TRUE(automation()->GetBrowserWindowCount(&window_count)); EXPECT_GT(window_count, window_index); - scoped_ptr<BrowserProxy> window_proxy(automation()-> + scoped_refptr<BrowserProxy> window_proxy(automation()-> GetBrowserWindow(window_index)); if (!window_proxy.get()) return NULL; @@ -474,8 +476,12 @@ TabProxy* UITest::GetActiveTab(int window_index) { return window_proxy->GetTab(active_tab_index); } +scoped_refptr<TabProxy> UITest::GetActiveTab() { + return GetActiveTab(0); +} + void UITest::NavigateToURLAsync(const GURL& url) { - scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); + scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); ASSERT_TRUE(tab_proxy.get()); if (!tab_proxy.get()) return; @@ -484,7 +490,7 @@ void UITest::NavigateToURLAsync(const GURL& url) { } void UITest::NavigateToURL(const GURL& url) { - scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); + scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); ASSERT_TRUE(tab_proxy.get()); if (!tab_proxy.get()) return; @@ -549,7 +555,7 @@ bool UITest::WaitForBookmarkBarVisibilityChange(BrowserProxy* browser, #endif // defined(OS_WIN) GURL UITest::GetActiveTabURL(int window_index) { - scoped_ptr<TabProxy> tab_proxy(GetActiveTab(window_index)); + scoped_refptr<TabProxy> tab_proxy(GetActiveTab(window_index)); if (!tab_proxy.get()) return GURL(); @@ -561,7 +567,7 @@ GURL UITest::GetActiveTabURL(int window_index) { std::wstring UITest::GetActiveTabTitle(int window_index) { std::wstring title; - scoped_ptr<TabProxy> tab_proxy(GetActiveTab(window_index)); + scoped_refptr<TabProxy> tab_proxy(GetActiveTab(window_index)); if (!tab_proxy.get()) return title; @@ -570,7 +576,7 @@ std::wstring UITest::GetActiveTabTitle(int window_index) { } int UITest::GetActiveTabIndex(int window_index) { - scoped_ptr<TabProxy> tab_proxy(GetActiveTab(window_index)); + scoped_refptr<TabProxy> tab_proxy(GetActiveTab(window_index)); if (!tab_proxy.get()) return -1; @@ -624,7 +630,7 @@ DictionaryValue* UITest::GetDefaultProfilePreferences() { #endif // OS_WIN int UITest::GetTabCount() { - scoped_ptr<BrowserProxy> first_window(automation()->GetBrowserWindow(0)); + scoped_refptr<BrowserProxy> first_window(automation()->GetBrowserWindow(0)); if (!first_window.get()) return 0; @@ -728,7 +734,7 @@ void UITest::WaitUntilTabCount(int tab_count) { } std::wstring UITest::GetDownloadDirectory() { - scoped_ptr<TabProxy> tab_proxy(GetActiveTab()); + scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); if (!tab_proxy.get()) return false; @@ -792,7 +798,7 @@ void UITest::WaitForFinish(const std::string &name, cookie_name.append("."); cookie_name.append(test_complete_cookie); - scoped_ptr<TabProxy> tab(GetActiveTab()); + scoped_refptr<TabProxy> tab(GetActiveTab()); bool test_result = WaitUntilCookieValue(tab.get(), url, cookie_name.c_str(), diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h index 543f1fd..69e3c507 100644 --- a/chrome/test/ui/ui_test.h +++ b/chrome/test/ui/ui_test.h @@ -427,10 +427,10 @@ class UITest : public testing::Test { // tab or there was some kind of error. Only looks at the first window, for // backward compatibility. The returned pointer MUST be deleted by the // caller if non-NULL. - TabProxy* GetActiveTab() { return GetActiveTab(0); } + scoped_refptr<TabProxy> GetActiveTab(); // Like above, but looks at the window at the given index. - TabProxy* GetActiveTab(int window_index); + scoped_refptr<TabProxy> GetActiveTab(int window_index); // ********* Member variables ********* diff --git a/chrome/test/ui/v8_benchmark_uitest.cc b/chrome/test/ui/v8_benchmark_uitest.cc index 76deb22..5d16776 100644 --- a/chrome/test/ui/v8_benchmark_uitest.cc +++ b/chrome/test/ui/v8_benchmark_uitest.cc @@ -39,7 +39,7 @@ class V8BenchmarkTest : public UITest { test_path = test_path.Append(start_file); GURL test_url(net::FilePathToFileURL(test_path)); - scoped_ptr<TabProxy> tab(GetActiveTab()); + scoped_refptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(test_url); // Wait for the test to finish. diff --git a/chrome/test/url_fetch_test/url_fetch_test.cc b/chrome/test/url_fetch_test/url_fetch_test.cc index bb773a5..b48ff96 100644 --- a/chrome/test/url_fetch_test/url_fetch_test.cc +++ b/chrome/test/url_fetch_test/url_fetch_test.cc @@ -27,7 +27,7 @@ class UrlFetchTest : public UITest { void RunTest(const GURL& url, const char *waitCookieName, const char *waitCookieValue, const wchar_t *varToFetch, UrlFetchTestResult *result) { - scoped_ptr<TabProxy> tab(GetActiveTab()); + scoped_refptr<TabProxy> tab(GetActiveTab()); tab->NavigateToURL(url); if (waitCookieName) { |