diff options
author | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-25 02:02:46 +0000 |
---|---|---|
committer | jcampan@chromium.org <jcampan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-25 02:02:46 +0000 |
commit | 1e187afa75fe66d8525651c1f395c40e8227844d (patch) | |
tree | 28a2f0ea9a7c27305af52e8382b471a321a9af8b | |
parent | 67a54912d23c2a0c87065e9a876971fda54edf70 (diff) | |
download | chromium_src-1e187afa75fe66d8525651c1f395c40e8227844d.zip chromium_src-1e187afa75fe66d8525651c1f395c40e8227844d.tar.gz chromium_src-1e187afa75fe66d8525651c1f395c40e8227844d.tar.bz2 |
Reverting 10318.
Reverting again...
Review URL: http://codereview.chromium.org/28106
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@10321 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/scoped_ole_initializer.h | 5 | ||||
-rw-r--r-- | chrome/browser/browser_focus_uitest.cc | 526 | ||||
-rw-r--r-- | chrome/browser/views/find_bar_win_unittest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/views/frame/browser_view.h | 1 | ||||
-rw-r--r-- | chrome/test/in_process_browser_test.cc | 16 | ||||
-rw-r--r-- | chrome/test/in_process_browser_test.h | 14 | ||||
-rw-r--r-- | chrome/test/interactive_ui/interactive_ui.vcproj | 113 | ||||
-rw-r--r-- | chrome/test/ui_test_utils.cc | 4 | ||||
-rw-r--r-- | chrome/test/unit/chrome_test_suite.h | 4 | ||||
-rw-r--r-- | chrome/test/unit/unittests.vcproj | 4 |
10 files changed, 247 insertions, 443 deletions
diff --git a/chrome/app/scoped_ole_initializer.h b/chrome/app/scoped_ole_initializer.h index 1dcc0d5..3560374 100644 --- a/chrome/app/scoped_ole_initializer.h +++ b/chrome/app/scoped_ole_initializer.h @@ -6,7 +6,6 @@ #define CHROME_APP_SCOPED_OLE_INITIALIZER_H_ #include "base/logging.h" -#include "base/message_loop.h" #include "build/build_config.h" // Wraps OLE initialization in a cross-platform class meant to be used on the @@ -20,16 +19,12 @@ class ScopedOleInitializer { public: ScopedOleInitializer() { - msg_loop_ = MessageLoop::current(); int ole_result = OleInitialize(NULL); DCHECK(ole_result == S_OK); } ~ScopedOleInitializer() { - DCHECK(msg_loop_ == MessageLoop::current()); OleUninitialize(); } - - MessageLoop* msg_loop_; }; #else diff --git a/chrome/browser/browser_focus_uitest.cc b/chrome/browser/browser_focus_uitest.cc index 6ff0f35..ca68034 100644 --- a/chrome/browser/browser_focus_uitest.cc +++ b/chrome/browser/browser_focus_uitest.cc @@ -2,183 +2,157 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "base/message_loop.h" -#include "chrome/browser/automation/ui_controls.h" -#include "chrome/browser/browser.h" -#include "chrome/browser/dom_operation_notification_details.h" -#include "chrome/browser/tab_contents/web_contents.h" #include "chrome/browser/view_ids.h" -#include "chrome/browser/views/frame/browser_view.h" -#include "chrome/browser/views/location_bar_view.h" -#include "chrome/common/notification_details.h" -#include "chrome/common/notification_observer.h" -#include "chrome/common/notification_service.h" -#include "chrome/common/notification_source.h" -#include "chrome/common/notification_type.h" -#include "chrome/views/focus_manager.h" #include "chrome/views/view.h" -#include "chrome/views/window.h" -#include "chrome/test/in_process_browser_test.h" -#include "chrome/test/ui_test_utils.h" - +#include "chrome/test/automation/browser_proxy.h" +#include "chrome/test/automation/window_proxy.h" +#include "chrome/test/automation/tab_proxy.h" +#include "chrome/test/ui/ui_test.h" +#include "net/url_request/url_request_unittest.h" namespace { -// The delay waited in some cases where we don't have a notifications for an -// action we take. +// The delay waited after sending an OS simulated event. const int kActionDelayMs = 500; +const wchar_t kDocRoot[] = L"chrome/test/data"; + const wchar_t kSimplePage[] = L"files/focus/page_with_focus.html"; const wchar_t kStealFocusPage[] = L"files/focus/page_steals_focus.html"; const wchar_t kTypicalPage[] = L"files/focus/typical_page.html"; -class BrowserFocusTest : public InProcessBrowserTest { +class BrowserFocusTest : public UITest { public: BrowserFocusTest() { - set_show_window(true); - EnableDOMAutomation(); + show_window_ = true; + dom_automation_enabled_ = true; } }; -class JavaScriptRunner : public NotificationObserver { - public: - JavaScriptRunner(WebContents* web_contents, - const std::wstring& frame_xpath, - const std::wstring& jscript) - : web_contents_(web_contents), - frame_xpath_(frame_xpath), - jscript_(jscript) { - NotificationService::current()-> - AddObserver(this, NotificationType::DOM_OPERATION_RESPONSE, - Source<WebContents>(web_contents)); - } - - virtual void Observe(NotificationType type, - const NotificationSource& source, - const NotificationDetails& details) { - Details<DomOperationNotificationDetails> dom_op_details(details); - result_ = dom_op_details->json(); - // The Jasonified response has quotes, remove them. - if (result_.length() > 1 && result_[0] == '"') - result_ = result_.substr(1, result_.length() - 2); - - NotificationService::current()-> - RemoveObserver(this, NotificationType::DOM_OPERATION_RESPONSE, - Source<WebContents>(web_contents_)); - MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); - } +// Activate a tab by clicking on it. Returns true if the call was successful +// (meaning the messages were correctly sent, but does not guarantee the tab +// has been changed). +bool ActivateTabByClick(AutomationProxy* automation, + WindowProxy* browser_window, + int tab_index) { + // Click on the tab. + gfx::Rect bounds; - std::string Run() { - // The DOMAutomationController requires an automation ID, eventhough we are - // not using it in this case. - web_contents_->render_view_host()->ExecuteJavascriptInWebFrame( - frame_xpath_, L"window.domAutomationController.setAutomationId(0);"); + if (!browser_window->GetViewBounds(VIEW_ID_TAB_0 + tab_index, &bounds, true)) + return false; - web_contents_->render_view_host()->ExecuteJavascriptInWebFrame(frame_xpath_, - jscript_); - ui_test_utils::RunMessageLoop(); - return result_; - } + POINT click(bounds.CenterPoint().ToPOINT()); + if (!browser_window->SimulateOSClick(click, + views::Event::EF_LEFT_BUTTON_DOWN)) + return false; - private: - WebContents* web_contents_; - std::wstring frame_xpath_; - std::wstring jscript_; - std::string result_; + // Wait a bit to let the click be processed. + ::Sleep(kActionDelayMs); - DISALLOW_COPY_AND_ASSIGN(JavaScriptRunner); -}; + return true; +} } // namespace -IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BrowsersRememberFocus) { - HTTPTestServer* server = StartHTTPServer(); +TEST_F(BrowserFocusTest, BrowsersRememberFocus) { + scoped_refptr<HTTPTestServer> server = + HTTPTestServer::CreateServer(kDocRoot, NULL); + ASSERT_TRUE(NULL != server.get()); // First we navigate to our test page. GURL url = server->TestServerPageW(kSimplePage); - ui_test_utils::NavigateToURL(browser(), url); + scoped_ptr<TabProxy> tab(GetActiveTab()); + EXPECT_NE(AUTOMATION_MSG_NAVIGATION_ERROR, tab->NavigateToURL(url)); // The focus should be on the Tab contents. - HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); - BrowserView* browser_view = BrowserView::GetBrowserViewForHWND(hwnd); - ASSERT_TRUE(browser_view); - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManager(hwnd); - ASSERT_TRUE(focus_manager); + scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); + ASSERT_TRUE(window.get() != NULL); - EXPECT_EQ(browser_view->GetContentsView(), focus_manager->GetFocusedView()); + scoped_ptr<BrowserProxy> browser(window->GetBrowser()); + ASSERT_TRUE(browser.get() != NULL); + + int focused_view_id; + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_TAB_CONTAINER, focused_view_id); // Now hide the window, show it again, the focus should not have changed. - // TODO(jcampan): retrieve the WidgetWin and show/hide on it instead of - // using Windows API. - ::ShowWindow(hwnd, SW_HIDE); - ::ShowWindow(hwnd, SW_SHOW); - EXPECT_EQ(browser_view->GetContentsView(), focus_manager->GetFocusedView()); + EXPECT_TRUE(window->SetVisible(false)); + EXPECT_TRUE(window->SetVisible(true)); + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_TAB_CONTAINER, focused_view_id); // Click on the location bar. - LocationBarView* location_bar = browser_view->GetLocationBarView(); - ui_controls::MoveMouseToCenterAndPress(location_bar, - ui_controls::LEFT, - ui_controls::DOWN | ui_controls::UP, - new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); - // Location bar should have focus. - EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); + gfx::Rect bounds; + EXPECT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &bounds, false)); + POINT click(bounds.CenterPoint().ToPOINT()); + + EXPECT_TRUE(window->SimulateOSClick(click, + views::Event::EF_LEFT_BUTTON_DOWN)); + ::Sleep(kActionDelayMs); + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id); // Hide the window, show it again, the focus should not have changed. - ::ShowWindow(hwnd, SW_HIDE); - ::ShowWindow(hwnd, SW_SHOW); - EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); + EXPECT_TRUE(window->SetVisible(false)); + EXPECT_TRUE(window->SetVisible(true)); + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id); // Open a new browser window. - Browser* browser2 = Browser::Create(browser()->profile()); - ASSERT_TRUE(browser2); - browser2->AddBlankTab(true); - browser2->window()->Show(); - ui_test_utils::NavigateToURL(browser2, url); - - HWND hwnd2 = reinterpret_cast<HWND>(browser2->window()->GetNativeHandle()); - BrowserView* browser_view2 = BrowserView::GetBrowserViewForHWND(hwnd2); - ASSERT_TRUE(browser_view2); - views::FocusManager* focus_manager2 = - views::FocusManager::GetFocusManager(hwnd2); - ASSERT_TRUE(focus_manager2); - EXPECT_EQ(browser_view2->GetContentsView(), focus_manager2->GetFocusedView()); + EXPECT_TRUE(automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)); + scoped_ptr<WindowProxy> new_window(automation()->GetActiveWindow()); + ASSERT_TRUE(new_window.get() != NULL); + scoped_ptr<BrowserProxy> new_browser(new_window->GetBrowser()); + ASSERT_TRUE(new_browser.get() != NULL); + + // Let's make sure we have 2 different browser windows. + EXPECT_TRUE(browser->handle() != new_browser->handle()); + + tab.reset(new_browser->GetActiveTab()); + EXPECT_TRUE(tab.get()); + tab->NavigateToURL(url); // Switch to the 1st browser window, focus should still be on the location // bar and the second browser should have nothing focused. - browser()->window()->Activate(); - EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); - EXPECT_EQ(NULL, focus_manager2->GetFocusedView()); + EXPECT_TRUE(window->Activate()); + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id); + EXPECT_TRUE(new_window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(-1, focused_view_id); // Switch back to the second browser, focus should still be on the page. - browser2->window()->Activate(); - EXPECT_EQ(NULL, focus_manager->GetFocusedView()); - EXPECT_EQ(browser_view2->GetContentsView(), focus_manager2->GetFocusedView()); - - // Close the 2nd browser to avoid a DCHECK(). - browser_view2->Close(); + EXPECT_TRUE(new_window->Activate()); + EXPECT_TRUE(new_window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_TAB_CONTAINER, focused_view_id); + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(-1, focused_view_id); } // Tabs remember focus. -IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) { - HTTPTestServer* server = StartHTTPServer(); +TEST_F(BrowserFocusTest, TabsRememberFocus) { + scoped_refptr<HTTPTestServer> server = + HTTPTestServer::CreateServer(kDocRoot, NULL); + ASSERT_TRUE(NULL != server.get()); + + scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); + ASSERT_TRUE(window.get() != NULL); + scoped_ptr<BrowserProxy> browser(window->GetBrowser()); + ASSERT_TRUE(browser.get() != NULL); // First we navigate to our test page. GURL url = server->TestServerPageW(kSimplePage); - ui_test_utils::NavigateToURL(browser(), url); - - HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); - BrowserView* browser_view = BrowserView::GetBrowserViewForHWND(hwnd); - ASSERT_TRUE(browser_view); - - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManager(hwnd); - ASSERT_TRUE(focus_manager); + scoped_ptr<TabProxy> tab(GetActiveTab()); + tab->NavigateToURL(url); // Create several tabs. - for (int i = 0; i < 4; ++i) - browser()->AddTabWithURL(url, GURL(), PageTransition::TYPED, true, NULL); + EXPECT_TRUE(browser->AppendTab(url)); + EXPECT_TRUE(browser->AppendTab(url)); + EXPECT_TRUE(browser->AppendTab(url)); + EXPECT_TRUE(browser->AppendTab(url)); + + int tab_count; + EXPECT_TRUE(browser->GetTabCount(&tab_count)); + ASSERT_EQ(5, tab_count); // Alternate focus for the tab. const bool kFocusPage[3][5] = { @@ -189,256 +163,234 @@ IN_PROC_BROWSER_TEST_F(BrowserFocusTest, TabsRememberFocus) { for (int i = 1; i < 3; i++) { for (int j = 0; j < 5; j++) { - // Activate the tab. - browser()->SelectTabContentsAt(j, true); + // Click on the tab. + ActivateTabByClick(automation(), window.get(), j); // Activate the location bar or the page. - views::View* view_to_focus = kFocusPage[i][j] ? - browser_view->GetContentsView() : - browser_view->GetLocationBarView(); - - ui_controls::MoveMouseToCenterAndPress(view_to_focus, - ui_controls::LEFT, - ui_controls::DOWN | - ui_controls::UP, - new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); + int view_id = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER : + VIEW_ID_LOCATION_BAR; + + gfx::Rect bounds; + EXPECT_TRUE(window->GetViewBounds(view_id, &bounds, true)); + POINT click(bounds.CenterPoint().ToPOINT()); + EXPECT_TRUE(window->SimulateOSClick(click, + views::Event::EF_LEFT_BUTTON_DOWN)); + ::Sleep(kActionDelayMs); } // Now come back to the tab and check the right view is focused. for (int j = 0; j < 5; j++) { - // Activate the tab. - browser()->SelectTabContentsAt(j, true); + // Click on the tab. + ActivateTabByClick(automation(), window.get(), j); // Activate the location bar or the page. - views::View* view = kFocusPage[i][j] ? - browser_view->GetContentsView() : - browser_view->GetLocationBarView(); - EXPECT_EQ(view, focus_manager->GetFocusedView()); + int exp_view_id = kFocusPage[i][j] ? VIEW_ID_TAB_CONTAINER : + VIEW_ID_LOCATION_BAR; + int focused_view_id; + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(exp_view_id, focused_view_id); } } } // Background window does not steal focus. -IN_PROC_BROWSER_TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { - HTTPTestServer* server = StartHTTPServer(); +TEST_F(BrowserFocusTest, BackgroundBrowserDontStealFocus) { + scoped_refptr<HTTPTestServer> server = + HTTPTestServer::CreateServer(kDocRoot, NULL); + ASSERT_TRUE(NULL != server.get()); // First we navigate to our test page. - GURL url = server->TestServerPageW(kSimplePage); - ui_test_utils::NavigateToURL(browser(), url); + GURL simple_page_url = server->TestServerPageW(kSimplePage); + scoped_ptr<TabProxy> tab(GetActiveTab()); + tab->NavigateToURL(simple_page_url); + + scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); + ASSERT_TRUE(window.get() != NULL); + scoped_ptr<BrowserProxy> browser(window->GetBrowser()); + ASSERT_TRUE(browser.get() != NULL); // Open a new browser window. - Browser* browser2 = Browser::Create(browser()->profile()); - ASSERT_TRUE(browser2); - browser2->AddBlankTab(true); - browser2->window()->Show(); + EXPECT_TRUE(automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)); + scoped_ptr<WindowProxy> new_window(automation()->GetActiveWindow()); + ASSERT_TRUE(window.get() != NULL); + scoped_ptr<BrowserProxy> new_browser(new_window->GetBrowser()); + ASSERT_TRUE(new_browser.get() != NULL); + GURL steal_focus_url = server->TestServerPageW(kStealFocusPage); - ui_test_utils::NavigateToURL(browser2, steal_focus_url); + new_browser->AppendTab(steal_focus_url); - // Activate the first browser. - browser()->window()->Activate(); + // Make the first browser active + EXPECT_TRUE(window->Activate()); // Wait for the focus to be stolen by the other browser. ::Sleep(2000); - // Make sure the first browser is still active. - HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); - BrowserView* browser_view = BrowserView::GetBrowserViewForHWND(hwnd); - ASSERT_TRUE(browser_view); - EXPECT_TRUE(browser_view->frame()->GetWindow()->IsActive()); - - // Close the 2nd browser to avoid a DCHECK(). - HWND hwnd2 = reinterpret_cast<HWND>(browser2->window()->GetNativeHandle()); - BrowserView* browser_view2 = BrowserView::GetBrowserViewForHWND(hwnd2); - browser_view2->Close(); + // Make sure the 1st browser window is still active. + bool is_active = false; + EXPECT_TRUE(window->IsActive(&is_active)); + EXPECT_TRUE(is_active); } // Page cannot steal focus when focus is on location bar. -IN_PROC_BROWSER_TEST_F(BrowserFocusTest, LocationBarLockFocus) { - HTTPTestServer* server = StartHTTPServer(); +TEST_F(BrowserFocusTest, LocationBarLockFocus) { + scoped_refptr<HTTPTestServer> server = + HTTPTestServer::CreateServer(kDocRoot, NULL); + ASSERT_TRUE(NULL != server.get()); // Open the page that steals focus. GURL url = server->TestServerPageW(kStealFocusPage); - ui_test_utils::NavigateToURL(browser(), url); + scoped_ptr<TabProxy> tab(GetActiveTab()); + tab->NavigateToURL(url); - HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); - BrowserView* browser_view = BrowserView::GetBrowserViewForHWND(hwnd); - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManager(hwnd); + scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); + ASSERT_TRUE(window.get() != NULL); + scoped_ptr<BrowserProxy> browser(window->GetBrowser()); + ASSERT_TRUE(browser.get() != NULL); // Click on the location bar. - LocationBarView* location_bar = browser_view->GetLocationBarView(); - ui_controls::MoveMouseToCenterAndPress(location_bar, - ui_controls::LEFT, - ui_controls::DOWN | ui_controls::UP, - new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); + gfx::Rect bounds; + EXPECT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &bounds, true)); + POINT click(bounds.CenterPoint().ToPOINT()); + EXPECT_TRUE(window->SimulateOSClick(click, + views::Event::EF_LEFT_BUTTON_DOWN)); + ::Sleep(kActionDelayMs); // Wait for the page to steal focus. ::Sleep(2000); // Make sure the location bar is still focused. - EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); + int focused_view_id; + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id); } // Focus traversal -IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FocusTraversal) { - HTTPTestServer* server = StartHTTPServer(); +TEST_F(BrowserFocusTest, FocusTraversal) { + scoped_refptr<HTTPTestServer> server = + HTTPTestServer::CreateServer(kDocRoot, NULL); + ASSERT_TRUE(NULL != server.get()); - // First we navigate to our test page. + // Open the page the test page. GURL url = server->TestServerPageW(kTypicalPage); - ui_test_utils::NavigateToURL(browser(), url); + scoped_ptr<TabProxy> tab(GetActiveTab()); + tab->NavigateToURL(url); - HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); - BrowserView* browser_view = BrowserView::GetBrowserViewForHWND(hwnd); - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManager(hwnd); + scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); + ASSERT_TRUE(window.get() != NULL); + scoped_ptr<BrowserProxy> browser(window->GetBrowser()); + ASSERT_TRUE(browser.get() != NULL); // Click on the location bar. - LocationBarView* location_bar = browser_view->GetLocationBarView(); - ui_controls::MoveMouseToCenterAndPress(location_bar, - ui_controls::LEFT, - ui_controls::DOWN | ui_controls::UP, - new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); - - const char* kExpElementIDs[] = { - "", // Initially no element in the page should be focused - // (the location bar is focused). - "textEdit", "searchButton", "luckyButton", "googleLink", "gmailLink", - "gmapLink" + gfx::Rect bounds; + EXPECT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &bounds, true)); + POINT click(bounds.CenterPoint().ToPOINT()); + EXPECT_TRUE(window->SimulateOSClick(click, + views::Event::EF_LEFT_BUTTON_DOWN)); + ::Sleep(kActionDelayMs); + + const wchar_t* kExpElementIDs[] = { + L"", // Initially no element in the page should be focused + // (the location bar is focused). + L"textEdit", L"searchButton", L"luckyButton", L"googleLink", L"gmailLink", + L"gmapLink" }; // Test forward focus traversal. for (int i = 0; i < 3; ++i) { // Location bar should be focused. - EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); + int focused_view_id; + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id); // Now let's press tab to move the focus. for (int j = 0; j < 7; ++j) { // Let's make sure the focus is on the expected element in the page. - JavaScriptRunner js_runner( - browser()->GetSelectedTabContents()->AsWebContents(), - L"", - L"window.domAutomationController.send(getFocusedElement());"); - std::string actual = js_runner.Run(); + std::wstring actual; + ASSERT_TRUE(tab->ExecuteAndExtractString(L"", + L"window.domAutomationController.send(getFocusedElement());", + &actual)); ASSERT_STREQ(kExpElementIDs[j], actual.c_str()); - ui_controls::SendKeyPressNotifyWhenDone(L'\t', false, false, false, - new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); - // Ideally, we wouldn't sleep here and instead would use the event - // processed ack nofification from the renderer. I am reluctant to create - // a new notification/callback for that purpose just for this test. + window->SimulateOSKeyPress(L'\t', 0); ::Sleep(kActionDelayMs); } - - // At this point the renderer has sent us a message asking to advance the - // focus (as the end of the focus loop was reached in the renderer). - // We need to run the message loop to process it. - MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); } // Now let's try reverse focus traversal. for (int i = 0; i < 3; ++i) { // Location bar should be focused. - EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); + int focused_view_id; + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id); - // Now let's press shift-tab to move the focus in reverse. + // Now let's press tab to move the focus. for (int j = 0; j < 7; ++j) { - ui_controls::SendKeyPressNotifyWhenDone(L'\t', false, true, false, - new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); + window->SimulateOSKeyPress(L'\t', views::Event::EF_SHIFT_DOWN); ::Sleep(kActionDelayMs); // Let's make sure the focus is on the expected element in the page. - JavaScriptRunner js_runner( - browser()->GetSelectedTabContents()->AsWebContents(), - L"", - L"window.domAutomationController.send(getFocusedElement());"); - std::string actual = js_runner.Run(); + std::wstring actual; + ASSERT_TRUE(tab->ExecuteAndExtractString(L"", + L"window.domAutomationController.send(getFocusedElement());", + &actual)); ASSERT_STREQ(kExpElementIDs[6 - j], actual.c_str()); } - - // At this point the renderer has sent us a message asking to advance the - // focus (as the end of the focus loop was reached in the renderer). - // We need to run the message loop to process it. - MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); } } // Make sure Find box can request focus, even when it is already open. -IN_PROC_BROWSER_TEST_F(BrowserFocusTest, FindFocusTest) { - HTTPTestServer* server = StartHTTPServer(); +TEST_F(BrowserFocusTest, FindFocusTest) { + scoped_refptr<HTTPTestServer> server = + HTTPTestServer::CreateServer(kDocRoot, NULL); + ASSERT_TRUE(NULL != server.get()); // Open some page (any page that doesn't steal focus). GURL url = server->TestServerPageW(kTypicalPage); - ui_test_utils::NavigateToURL(browser(), url); + scoped_ptr<TabProxy> tab(GetActiveTab()); + tab->NavigateToURL(url); - HWND hwnd = reinterpret_cast<HWND>(browser()->window()->GetNativeHandle()); - BrowserView* browser_view = BrowserView::GetBrowserViewForHWND(hwnd); - views::FocusManager* focus_manager = - views::FocusManager::GetFocusManager(hwnd); - LocationBarView* location_bar = browser_view->GetLocationBarView(); + scoped_ptr<WindowProxy> window(automation()->GetActiveWindow()); + ASSERT_TRUE(window.get() != NULL); + scoped_ptr<BrowserProxy> browser(window->GetBrowser()); + ASSERT_TRUE(browser.get() != NULL); // Press Ctrl+F, which will make the Find box open and request focus. static const int VK_F = 0x46; - ui_controls::SendKeyPressNotifyWhenDone(L'F', true, false, false, - new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); - - // Ideally, we wouldn't sleep here and instead would intercept the - // RenderViewHostDelegate::HandleKeyboardEvent() callback. To do that, we - // could create a RenderViewHostDelegate wrapper and hook-it up by either: - // - creating a factory used to create the delegate - // - making the test a private and overwriting the delegate member directly. + EXPECT_TRUE(window->SimulateOSKeyPress(VK_F, views::Event::EF_CONTROL_DOWN)); ::Sleep(kActionDelayMs); - MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); - - views::View* focused_view = focus_manager->GetFocusedView(); - ASSERT_TRUE(focused_view != NULL); - EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); + int focused_view_id; + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view_id); // Click on the location bar. - ui_controls::MoveMouseToCenterAndPress(location_bar, - ui_controls::LEFT, - ui_controls::DOWN | ui_controls::UP, - new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); - + gfx::Rect bounds; + EXPECT_TRUE(window->GetViewBounds(VIEW_ID_LOCATION_BAR, &bounds, true)); + POINT click(bounds.CenterPoint().ToPOINT()); + EXPECT_TRUE(window->SimulateOSClick(click, + views::Event::EF_LEFT_BUTTON_DOWN)); + ::Sleep(kActionDelayMs); // Make sure the location bar is focused. - EXPECT_EQ(location_bar, focus_manager->GetFocusedView()); + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_LOCATION_BAR, focused_view_id); // Now press Ctrl+F again and focus should move to the Find box. - ui_controls::SendKeyPressNotifyWhenDone(L'F', true, false, false, - new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); - focused_view = focus_manager->GetFocusedView(); - ASSERT_TRUE(focused_view != NULL); - EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); + EXPECT_TRUE(window->SimulateOSKeyPress(VK_F, views::Event::EF_CONTROL_DOWN)); + ::Sleep(kActionDelayMs); + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view_id); // Set focus to the page. - ui_controls::MoveMouseToCenterAndPress(browser_view->GetContentsView(), - ui_controls::LEFT, - ui_controls::DOWN | ui_controls::UP, - new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); - EXPECT_EQ(browser_view->GetContentsView(), focus_manager->GetFocusedView()); + EXPECT_TRUE(window->GetViewBounds(VIEW_ID_TAB_CONTAINER, &bounds, true)); + click = bounds.CenterPoint().ToPOINT(); + EXPECT_TRUE(window->SimulateOSClick(click, + views::Event::EF_LEFT_BUTTON_DOWN)); + ::Sleep(kActionDelayMs); + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_TAB_CONTAINER, focused_view_id); // Now press Ctrl+F again and focus should move to the Find box. - ui_controls::SendKeyPressNotifyWhenDone(VK_F, true, false, false, - new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); - - // See remark above on why we wait. + EXPECT_TRUE(window->SimulateOSKeyPress(VK_F, views::Event::EF_CONTROL_DOWN)); ::Sleep(kActionDelayMs); - MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask()); - ui_test_utils::RunMessageLoop(); - - focused_view = focus_manager->GetFocusedView(); - ASSERT_TRUE(focused_view != NULL); - EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view->GetID()); + EXPECT_TRUE(window->GetFocusedViewID(&focused_view_id)); + EXPECT_EQ(VIEW_ID_FIND_IN_PAGE_TEXT_FIELD, focused_view_id); } diff --git a/chrome/browser/views/find_bar_win_unittest.cc b/chrome/browser/views/find_bar_win_unittest.cc index 87d93e0..4ef345c 100644 --- a/chrome/browser/views/find_bar_win_unittest.cc +++ b/chrome/browser/views/find_bar_win_unittest.cc @@ -144,6 +144,3 @@ IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, FindInPageFrames) { EXPECT_EQ(1, FindInPage(L"Hreggvi\u00F0ur", FWD, CASE_SENSITIVE, false)); EXPECT_EQ(0, FindInPage(L"hreggvi\u00F0ur", FWD, CASE_SENSITIVE, false)); } - -IN_PROC_BROWSER_TEST_F(FindInPageControllerTest, OtherTest) { -}
\ No newline at end of file diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index b1f70a8..c228246 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -53,7 +53,6 @@ class BrowserView : public BrowserWindow, virtual ~BrowserView(); void set_frame(BrowserFrame* frame) { frame_ = frame; } - BrowserFrame* frame() const { return frame_; } // Returns a pointer to the BrowserView* interface implementation (an // instance of this object, typically) for a given HWND, or NULL if there is diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc index aae695b..dd1f919 100644 --- a/chrome/test/in_process_browser_test.cc +++ b/chrome/test/in_process_browser_test.cc @@ -12,7 +12,6 @@ #include "chrome/browser/browser_shutdown.h" #include "chrome/browser/profile.h" #include "chrome/browser/profile_manager.h" -#include "chrome/browser/renderer_host/render_process_host.h" #include "chrome/browser/views/frame/browser_view.h" #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" @@ -44,10 +43,7 @@ bool DieFileDie(const std::wstring& file, bool recurse) { } // namespace -InProcessBrowserTest::InProcessBrowserTest() - : browser_(NULL), - show_window_(false), - dom_automation_enabled_(false) { +InProcessBrowserTest::InProcessBrowserTest() : browser_(NULL) { } void InProcessBrowserTest::SetUp() { @@ -72,23 +68,15 @@ void InProcessBrowserTest::SetUp() { CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); // Hide windows on show. - if (!command_line->HasSwitch(kUnitTestShowWindows) && !show_window_) + if (!command_line->HasSwitch(kUnitTestShowWindows)) BrowserView::SetShowState(SW_HIDE); - if (dom_automation_enabled_) - command_line->AppendSwitch(switches::kDomAutomationController); - command_line->AppendSwitchWithValue(switches::kUserDataDir, user_data_dir); // For some reason the sandbox wasn't happy running in test mode. These // tests aren't intended to test the sandbox, so we turn it off. command_line->AppendSwitch(switches::kNoSandbox); - // Single-process mode is not set in BrowserMain so it needs to be processed - // explicitlty. - if (command_line->HasSwitch(switches::kSingleProcess)) - RenderProcessHost::set_run_renderer_in_process(true); - // Explicitly set the path of the exe used for the renderer, otherwise it'll // try to use unit_test.exe. std::wstring renderer_path; diff --git a/chrome/test/in_process_browser_test.h b/chrome/test/in_process_browser_test.h index 90dcdc9..230b8df 100644 --- a/chrome/test/in_process_browser_test.h +++ b/chrome/test/in_process_browser_test.h @@ -5,6 +5,7 @@ #ifndef CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ #define CHROME_TEST_IN_PROCESS_BROWSER_TEST_H_ +#include "chrome/app/scoped_ole_initializer.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_observer.h" #include "net/url_request/url_request_unittest.h" @@ -73,11 +74,6 @@ class InProcessBrowserTest : public testing::Test, public NotificationObserver { // This is invoked from Setup. virtual Browser* CreateBrowser(Profile* profile); - // Sets some test states (see below for comments). Call this in your test - // constructor. - void set_show_window(bool show) { show_window_ = show; } - void EnableDOMAutomation() { dom_automation_enabled_ = true; } - private: // Invokes CreateBrowser to create a browser, then RunTestOnMainThread, and // destroys the browser. @@ -92,13 +88,7 @@ class InProcessBrowserTest : public testing::Test, public NotificationObserver { // HTTPServer, created when StartHTTPServer is invoked. scoped_refptr<HTTPTestServer> http_server_; - // Whether this test requires the browser windows to be shown (interactive - // tests for example need the windows shown). - bool show_window_; - - // Whether the JavaScript can access the DOMAutomationController (a JS object - // that can send messages back to the browser). - bool dom_automation_enabled_; + ScopedOleInitializer ole_initializer_; DISALLOW_COPY_AND_ASSIGN(InProcessBrowserTest); }; diff --git a/chrome/test/interactive_ui/interactive_ui.vcproj b/chrome/test/interactive_ui/interactive_ui.vcproj index ee5907e..a4863ee 100644 --- a/chrome/test/interactive_ui/interactive_ui.vcproj +++ b/chrome/test/interactive_ui/interactive_ui.vcproj @@ -12,16 +12,12 @@ /> </Platforms> <ToolFiles> - <ToolFile - RelativePath="..\..\tools\build\win\version.rules" - /> </ToolFiles> <Configurations> <Configuration Name="Debug|Win32" - OutputDirectory="$(SolutionDir)$(ConfigurationName)" ConfigurationType="1" - InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\debug.vsprops;..\..\tools\build\win\precompiled_wtl.vsprops;..\..\tools\build\win\unit_test.vsprops;$(SolutionDir)..\third_party\libpng\using_libpng.vsprops;$(SolutionDir)..\third_party\zlib\using_zlib.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;$(SolutionDir)..\third_party\icu38\build\using_icu.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops;..\..\third_party\hunspell\using_hunspell.vsprops;..\..\installer\util\using_util.vsprops;..\..\..\third_party\npapi\using_npapi.vsprops" + InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\debug.vsprops;..\..\tools\build\win\precompiled_wtl.vsprops;..\..\tools\build\win\unit_test.vsprops;$(SolutionDir)..\third_party\libpng\using_libpng.vsprops;$(SolutionDir)..\third_party\zlib\using_zlib.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;..\..\..\third_party\icu38\build\using_icu.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops;..\..\third_party\hunspell\using_hunspell.vsprops" > <Tool Name="VCPreBuildEventTool" @@ -30,9 +26,6 @@ Name="VCCustomBuildTool" /> <Tool - Name="Version" - /> - <Tool Name="VCXMLDataGeneratorTool" /> <Tool @@ -49,14 +42,12 @@ /> <Tool Name="VCResourceCompilerTool" - AdditionalIncludeDirectories="$(SolutionDir)..;"$(IntDir)";"$(IntDir)";"$(SolutionDir)";"$(IntDir)\..\"" /> <Tool Name="VCPreLinkEventTool" /> <Tool Name="VCLinkerTool" - AdditionalDependencies="winmm.lib" /> <Tool Name="VCALinkTool" @@ -86,7 +77,7 @@ <Configuration Name="Release|Win32" ConfigurationType="1" - InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\release.vsprops;..\..\tools\build\win\unit_test.vsprops;$(SolutionDir)..\third_party\libpng\using_libpng.vsprops;$(SolutionDir)..\third_party\zlib\using_zlib.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;$(SolutionDir)..\third_party\icu38\build\using_icu.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops;..\..\third_party\hunspell\using_hunspell.vsprops;..\..\installer\util\using_util.vsprops;..\..\..\third_party\npapi\using_npapi.vsprops" + InheritedPropertySheets="$(SolutionDir)..\build\common.vsprops;$(SolutionDir)..\build\release.vsprops;..\..\tools\build\win\unit_test.vsprops;$(SolutionDir)..\third_party\libpng\using_libpng.vsprops;$(SolutionDir)..\third_party\zlib\using_zlib.vsprops;$(SolutionDir)..\skia\using_skia.vsprops;$(SolutionDir)..\third_party\libxml\build\using_libxml.vsprops;..\..\..\third_party\icu38\build\using_icu.vsprops;$(SolutionDir)..\testing\using_gtest.vsprops;..\..\third_party\hunspell\using_hunspell.vsprops" > <Tool Name="VCPreBuildEventTool" @@ -95,9 +86,6 @@ Name="VCCustomBuildTool" /> <Tool - Name="Version" - /> - <Tool Name="VCXMLDataGeneratorTool" /> <Tool @@ -114,7 +102,6 @@ /> <Tool Name="VCResourceCompilerTool" - AdditionalIncludeDirectories="$(SolutionDir)..;"$(IntDir)";"$(IntDir)";"$(SolutionDir)";"$(IntDir)\..\"" /> <Tool Name="VCPreLinkEventTool" @@ -156,14 +143,6 @@ Name="Common" > <File - RelativePath="..\in_process_browser_test.cc" - > - </File> - <File - RelativePath="..\in_process_browser_test.h" - > - </File> - <File RelativePath="..\ui\npapi_test_helper.cc" > </File> @@ -212,14 +191,6 @@ > </File> <File - RelativePath="..\ui_test_utils.cc" - > - </File> - <File - RelativePath="..\ui_test_utils.h" - > - </File> - <File RelativePath=".\view_event_test_base.cc" > </File> @@ -229,86 +200,6 @@ </File> </Filter> <Filter - Name="resources" - > - <File - RelativePath="..\..\..\webkit\glue\resources\aliasb.cur" - > - </File> - <File - RelativePath="$(OutDir)\grit_derived_sources\browser_resources.rc" - > - </File> - <File - RelativePath="..\..\..\webkit\glue\resources\cell.cur" - > - </File> - <File - RelativePath="..\..\app\chrome_dll.rc" - > - </File> - <File - RelativePath="..\..\app\chrome_dll_resource.h" - > - </File> - <File - RelativePath="..\..\app\chrome_dll_version.rc.version" - > - </File> - <File - RelativePath="..\..\..\webkit\glue\resources\col_resize.cur" - > - </File> - <File - RelativePath="$(OutDir)\grit_derived_sources\common_resources.rc" - > - </File> - <File - RelativePath="..\..\..\webkit\glue\resources\copy.cur" - > - </File> - <File - RelativePath="$(OutDir)\grit_derived_sources\debugger_resources.rc" - > - </File> - <File - RelativePath="$(OutDir)\grit_derived_sources\net_resources.rc" - > - </File> - <File - RelativePath="$(OutDir)\grit_derived_sources\renderer_resources.rc" - > - </File> - <File - RelativePath="..\data\resource.h" - > - </File> - <File - RelativePath="..\data\resource.rc" - > - </File> - <File - RelativePath="..\..\..\webkit\glue\resources\row_resize.cur" - > - </File> - <File - RelativePath="..\..\..\webkit\glue\resources\vertical_text.cur" - > - </File> - <File - RelativePath="$(OutDir)\grit_derived_sources\webkit_resources.rc" - > - </File> - <File - RelativePath="..\..\..\webkit\glue\resources\zoom_in.cur" - > - </File> - <File - RelativePath="..\..\..\webkit\glue\resources\zoom_out.cur" - > - </File> - </Filter> - <Filter Name="TestBookmarkBarView" > <File diff --git a/chrome/test/ui_test_utils.cc b/chrome/test/ui_test_utils.cc index 7471711..1293f72 100644 --- a/chrome/test/ui_test_utils.cc +++ b/chrome/test/ui_test_utils.cc @@ -10,7 +10,6 @@ #include "chrome/browser/tab_contents/web_contents.h" #include "chrome/common/notification_registrar.h" #include "chrome/common/notification_service.h" -#include "chrome/views/accelerator_handler.h" #include "googleurl/src/gurl.h" namespace ui_test_utils { @@ -60,8 +59,7 @@ void RunMessageLoop() { MessageLoopForUI* loop = MessageLoopForUI::current(); bool did_allow_task_nesting = loop->NestableTasksAllowed(); loop->SetNestableTasksAllowed(true); - views::AcceleratorHandler handler; - loop->Run(&handler); + loop->Run(NULL); loop->SetNestableTasksAllowed(did_allow_task_nesting); } diff --git a/chrome/test/unit/chrome_test_suite.h b/chrome/test/unit/chrome_test_suite.h index 3382d972..79c5e19 100644 --- a/chrome/test/unit/chrome_test_suite.h +++ b/chrome/test/unit/chrome_test_suite.h @@ -12,7 +12,6 @@ #include "base/path_service.h" #include "base/scoped_nsautorelease_pool.h" #include "base/test_suite.h" -#include "chrome/app/scoped_ole_initializer.h" #include "chrome/browser/browser_process.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" @@ -79,12 +78,11 @@ protected: // Tear down shared StatsTable; prevents unit_tests from leaking it. StatsTable::set_current(NULL); delete stats_table_; - + TestSuite::Shutdown(); } StatsTable* stats_table_; - ScopedOleInitializer ole_initializer_; }; #endif // CHROME_TEST_UNIT_CHROME_TEST_SUITE_H_ diff --git a/chrome/test/unit/unittests.vcproj b/chrome/test/unit/unittests.vcproj index fbc182b..3011530 100644 --- a/chrome/test/unit/unittests.vcproj +++ b/chrome/test/unit/unittests.vcproj @@ -999,10 +999,6 @@ > </File> </Filter> - <File - RelativePath="..\..\browser\browser_focus_uitest.cc" - > - </File> </Files> <Globals> </Globals> |