diff options
author | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-07 20:51:42 +0000 |
---|---|---|
committer | huanr@chromium.org <huanr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-07 20:51:42 +0000 |
commit | d79ffea9554887c2a8866731634a91614c19d454 (patch) | |
tree | 55a422eef3a7150d1205de3115d36d0932bc87a1 /chrome/test/automated_ui_tests | |
parent | 1d33670da500d061e670e810a223ed9aa0acc2d9 (diff) | |
download | chromium_src-d79ffea9554887c2a8866731634a91614c19d454.zip chromium_src-d79ffea9554887c2a8866731634a91614c19d454.tar.gz chromium_src-d79ffea9554887c2a8866731634a91614c19d454.tar.bz2 |
Consolidate notifiers used by different automation
IPC messages.
Make OpenIncognito synchronuous.
Review URL: http://codereview.chromium.org/115092
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15579 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/automated_ui_tests')
5 files changed, 106 insertions, 42 deletions
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 5820275..2a16b9b 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_base.cc +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.cc @@ -39,9 +39,7 @@ bool AutomatedUITestBase::CloseActiveTab() { } if (tab_count > 1) { - scoped_ptr<TabProxy> tab(GetActiveTab()); - // Wait until tab is closed. - return tab->Close(true); + return RunCommand(IDC_CLOSE_TAB); } else if (tab_count == 1) { // Synchronously close the window if it is not the last window. return CloseActiveWindow(); @@ -77,6 +75,10 @@ bool AutomatedUITestBase::DuplicateTab() { return RunCommand(IDC_DUPLICATE_TAB); } +bool AutomatedUITestBase::GoOffTheRecord() { + return RunCommand(IDC_NEW_INCOGNITO_WINDOW); +} + bool AutomatedUITestBase::OpenAndActivateNewBrowserWindow( BrowserProxy** previous_browser) { if (!automation()->OpenNewBrowserWindow(SW_SHOWNORMAL)) { 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 e454bec..80268bc 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_base.h +++ b/chrome/test/automated_ui_tests/automated_ui_test_base.h @@ -38,6 +38,9 @@ class AutomatedUITestBase : public UITest { // Returns true if a duplicated tab is added. bool DuplicateTab(); + // Opens an OffTheRecord browser window. + bool GoOffTheRecord(); + // Opens a new tab in the active window using an accelerator. // Returns true if a new tab is successfully opened. bool NewTab(); 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 afaa97a..e09996f 100644 --- a/chrome/test/automated_ui_tests/automated_ui_test_test.cc +++ b/chrome/test/automated_ui_tests/automated_ui_test_test.cc @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#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" #include "chrome/test/automation/tab_proxy.h" @@ -48,6 +49,50 @@ TEST_F(AutomatedUITestBase, RestoreTab) { ASSERT_EQ(2, tab_count); } +TEST_F(AutomatedUITestBase, CloseTab) { + int num_browser_windows; + int tab_count; + NewTab(); + automation()->GetBrowserWindowCount(&num_browser_windows); + ASSERT_EQ(1, num_browser_windows); + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(2, tab_count); + + ASSERT_TRUE(OpenAndActivateNewBrowserWindow(NULL)); + NewTab(); + NewTab(); + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(3, tab_count); + automation()->GetBrowserWindowCount(&num_browser_windows); + ASSERT_EQ(2, num_browser_windows); + + ASSERT_TRUE(CloseActiveTab()); + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(2, tab_count); + ASSERT_TRUE(CloseActiveTab()); + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(1, tab_count); + num_browser_windows = 0; + automation()->GetBrowserWindowCount(&num_browser_windows); + ASSERT_EQ(2, num_browser_windows); + + // The browser window is closed by closing this tab. + ASSERT_TRUE(CloseActiveTab()); + automation()->GetBrowserWindowCount(&num_browser_windows); + ASSERT_EQ(1, num_browser_windows); + // Active_browser_ is now the first created window. + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(2, tab_count); + ASSERT_TRUE(CloseActiveTab()); + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(1, tab_count); + + // The last tab should not be closed. + ASSERT_FALSE(CloseActiveTab()); + active_browser()->GetTabCount(&tab_count); + ASSERT_EQ(1, tab_count); +} + TEST_F(AutomatedUITestBase, OpenBrowserWindow) { int num_browser_windows; int tab_count; @@ -131,46 +176,68 @@ TEST_F(AutomatedUITestBase, CloseBrowserWindow) { ASSERT_FALSE(CloseActiveWindow()); } -TEST_F(AutomatedUITestBase, CloseTab) { +TEST_F(AutomatedUITestBase, IncognitoWindow) { int num_browser_windows; - int tab_count; - NewTab(); + int num_normal_browser_windows; automation()->GetBrowserWindowCount(&num_browser_windows); ASSERT_EQ(1, num_browser_windows); - active_browser()->GetTabCount(&tab_count); - ASSERT_EQ(2, tab_count); + automation()->GetNormalBrowserWindowCount(&num_normal_browser_windows); + ASSERT_EQ(1, num_normal_browser_windows); - ASSERT_TRUE(OpenAndActivateNewBrowserWindow(NULL)); - NewTab(); - NewTab(); - active_browser()->GetTabCount(&tab_count); - ASSERT_EQ(3, tab_count); + ASSERT_TRUE(GoOffTheRecord()); + ASSERT_TRUE(GoOffTheRecord()); automation()->GetBrowserWindowCount(&num_browser_windows); - ASSERT_EQ(2, num_browser_windows); + ASSERT_EQ(3, num_browser_windows); + automation()->GetNormalBrowserWindowCount(&num_normal_browser_windows); + ASSERT_EQ(1, num_normal_browser_windows); - ASSERT_TRUE(CloseActiveTab()); - active_browser()->GetTabCount(&tab_count); - ASSERT_EQ(2, tab_count); - ASSERT_TRUE(CloseActiveTab()); - active_browser()->GetTabCount(&tab_count); - ASSERT_EQ(1, tab_count); - num_browser_windows = 0; + // There is only one normal window so it will not be closed. + ASSERT_FALSE(CloseActiveWindow()); automation()->GetBrowserWindowCount(&num_browser_windows); - ASSERT_EQ(2, num_browser_windows); + ASSERT_EQ(3, num_browser_windows); + automation()->GetNormalBrowserWindowCount(&num_normal_browser_windows); + ASSERT_EQ(1, num_normal_browser_windows); - // The browser window is closed by closing this tab. - ASSERT_TRUE(CloseActiveTab()); + set_active_browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(RunCommand(IDC_CLOSE_WINDOW)); + set_active_browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(RunCommand(IDC_CLOSE_WINDOW)); automation()->GetBrowserWindowCount(&num_browser_windows); ASSERT_EQ(1, num_browser_windows); - // Active_browser_ is now the first created window. - active_browser()->GetTabCount(&tab_count); - ASSERT_EQ(2, tab_count); - ASSERT_TRUE(CloseActiveTab()); - active_browser()->GetTabCount(&tab_count); - ASSERT_EQ(1, tab_count); +} - // The last tab should not be closed. - ASSERT_FALSE(CloseActiveTab()); - active_browser()->GetTabCount(&tab_count); - ASSERT_EQ(1, tab_count); +TEST_F(AutomatedUITestBase, OpenCloseBrowserWindowWithAccelerator) { + // Note: we don't use RunCommand(IDC_OPEN/CLOSE_WINDOW) to open/close + // browser window in automated ui tests. Instead we use + // OpenAndActivateNewBrowserWindow and CloseActiveWindow. + // There are other parts of UI test that use the accelerators. This is + // a unit test for those usage. + ASSERT_TRUE(RunCommand(IDC_NEW_WINDOW)); + int num_browser_windows; + automation()->GetBrowserWindowCount(&num_browser_windows); + ASSERT_EQ(2, num_browser_windows); + ASSERT_TRUE(RunCommand(IDC_NEW_WINDOW)); + ASSERT_TRUE(RunCommand(IDC_NEW_WINDOW)); + ASSERT_TRUE(RunCommand(IDC_NEW_WINDOW)); + ASSERT_TRUE(RunCommand(IDC_NEW_WINDOW)); + ASSERT_TRUE(RunCommand(IDC_NEW_WINDOW)); + automation()->GetBrowserWindowCount(&num_browser_windows); + ASSERT_EQ(7, num_browser_windows); + + set_active_browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(RunCommand(IDC_CLOSE_WINDOW)); + automation()->GetBrowserWindowCount(&num_browser_windows); + ASSERT_EQ(6, num_browser_windows); + set_active_browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(RunCommand(IDC_CLOSE_WINDOW)); + set_active_browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(RunCommand(IDC_CLOSE_WINDOW)); + set_active_browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(RunCommand(IDC_CLOSE_WINDOW)); + set_active_browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(RunCommand(IDC_CLOSE_WINDOW)); + set_active_browser(automation()->GetBrowserWindow(0)); + ASSERT_TRUE(RunCommand(IDC_CLOSE_WINDOW)); + automation()->GetBrowserWindowCount(&num_browser_windows); + ASSERT_EQ(1, num_browser_windows); } diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.cc b/chrome/test/automated_ui_tests/automated_ui_tests.cc index 35d8dca..bd66201 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.cc +++ b/chrome/test/automated_ui_tests/automated_ui_tests.cc @@ -426,10 +426,6 @@ bool AutomatedUITest::ForwardButton() { return RunCommandAsync(IDC_FORWARD); } -bool AutomatedUITest::GoOffTheRecord() { - return RunCommandAsync(IDC_NEW_INCOGNITO_WINDOW); -} - bool AutomatedUITest::Home() { return RunCommandAsync(IDC_HOME); } diff --git a/chrome/test/automated_ui_tests/automated_ui_tests.h b/chrome/test/automated_ui_tests/automated_ui_tests.h index c6b847d..a58b2dc 100644 --- a/chrome/test/automated_ui_tests/automated_ui_tests.h +++ b/chrome/test/automated_ui_tests/automated_ui_tests.h @@ -154,10 +154,6 @@ class AutomatedUITest : public AutomatedUITestBase { // XML element: <Forward/> bool ForwardButton(); - // Opens and focuses an OffTheRecord browser window. - // XML element: <GoOffTheRecord/> - bool GoOffTheRecord(); - // Navigates to the Home page. // Returns true if call to activate the accelerator is successful. // XML element: <Home/> |