diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-03 23:35:43 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-03 23:35:43 +0000 |
commit | 940126a74172ceda71c753ab3c1aa59b1003d8aa (patch) | |
tree | e6add7225df7196e9cc153db11f0645b1f1022bc | |
parent | 7af17654fdd641aa9924892cd9f5e2f36529ecea (diff) | |
download | chromium_src-940126a74172ceda71c753ab3c1aa59b1003d8aa.zip chromium_src-940126a74172ceda71c753ab3c1aa59b1003d8aa.tar.gz chromium_src-940126a74172ceda71c753ab3c1aa59b1003d8aa.tar.bz2 |
Convert the last remaining UI test to a browser_test.
BUG=121574
Review URL: https://chromiumcodereview.appspot.com/10368003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135237 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/browser_browsertest.cc | 165 | ||||
-rw-r--r-- | chrome/browser/ui/tests/browser_uitest.cc | 236 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/test/data/fileurl_universalaccess.html | 2 |
4 files changed, 166 insertions, 238 deletions
diff --git a/chrome/browser/ui/browser_browsertest.cc b/chrome/browser/ui/browser_browsertest.cc index 43dc0b3..197841c 100644 --- a/chrome/browser/ui/browser_browsertest.cc +++ b/chrome/browser/ui/browser_browsertest.cc @@ -22,6 +22,7 @@ #include "chrome/browser/first_run/first_run.h" #include "chrome/browser/prefs/incognito_mode_prefs.h" #include "chrome/browser/profiles/profile.h" +#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/tabs/pinned_tab_codec.h" #include "chrome/browser/tabs/tab_strip_model.h" #include "chrome/browser/translate/translate_tab_helper.h" @@ -1745,3 +1746,167 @@ IN_PROC_BROWSER_TEST_F(BrowserTest2, NoTabsInPopups) { app_popup_browser->CloseAllTabs(); } #endif + +IN_PROC_BROWSER_TEST_F(BrowserTest, WindowOpenClose) { + GURL url = ui_test_utils::GetTestUrl( + FilePath(), FilePath().AppendASCII("window.close.html")); + + string16 title = ASCIIToUTF16("Title Of Awesomeness"); + ui_test_utils::TitleWatcher title_watcher( + browser()->GetSelectedWebContents(), title); + ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(), url, 2); + EXPECT_EQ(title, title_watcher.WaitAndGetTitle()); +} + +class ShowModalDialogTest : public BrowserTest { + public: + ShowModalDialogTest() {} + + virtual void SetUpCommandLine(CommandLine* command_line) { + command_line->AppendSwitch(switches::kDisablePopupBlocking); + } +}; + +IN_PROC_BROWSER_TEST_F(ShowModalDialogTest, BasicTest) { + // This navigation should show a modal dialog that will be immediately + // closed, but the fact that it was shown should be recorded. + GURL url = ui_test_utils::GetTestUrl( + FilePath(), FilePath().AppendASCII("showmodaldialog.html")); + + string16 expected_title(ASCIIToUTF16("SUCCESS")); + ui_test_utils::TitleWatcher title_watcher( + browser()->GetSelectedWebContents(), expected_title); + ui_test_utils::NavigateToURL(browser(), url); + + // Verify that we set a mark on successful dialog show. + ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); +} + +IN_PROC_BROWSER_TEST_F(BrowserTest, DisallowFileUrlUniversalAccessTest) { + GURL url = ui_test_utils::GetTestUrl( + FilePath(), FilePath().AppendASCII("fileurl_universalaccess.html")); + + string16 expected_title(ASCIIToUTF16("Disallowed")); + ui_test_utils::TitleWatcher title_watcher( + browser()->GetSelectedWebContents(), expected_title); + title_watcher.AlsoWaitForTitle(ASCIIToUTF16("Allowed")); + ui_test_utils::NavigateToURL(browser(), url); + ASSERT_EQ(expected_title, title_watcher.WaitAndGetTitle()); +} + +#if !defined(OS_MACOSX) +class KioskModeTest : public BrowserTest { + public: + KioskModeTest() {} + + virtual void SetUpCommandLine(CommandLine* command_line) { + command_line->AppendSwitch(switches::kKioskMode); + } +}; + +IN_PROC_BROWSER_TEST_F(KioskModeTest, EnableKioskModeTest) { + // Check if browser is in fullscreen mode. + ASSERT_TRUE(browser()->window()->IsFullscreen()); + ASSERT_FALSE(browser()->window()->IsFullscreenBubbleVisible()); +} +#endif // !defined(OS_MACOSX) + +#if defined(OS_WIN) +// This test verifies that Chrome can be launched with a user-data-dir path +// which contains non ASCII characters. +class LaunchBrowserWithNonAsciiUserDatadir : public BrowserTest { + public: + LaunchBrowserWithNonAsciiUserDatadir() {} + + virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); + FilePath tmp_profile = temp_dir_.path().AppendASCII("tmp_profile"); + tmp_profile = tmp_profile.Append(L"Test Chrome G�raldine"); + + ASSERT_TRUE(file_util::CreateDirectory(tmp_profile)); + command_line->AppendSwitchPath(switches::kUserDataDir, tmp_profile); + } + + ScopedTempDir temp_dir_; +}; + +IN_PROC_BROWSER_TEST_F(LaunchBrowserWithNonAsciiUserDatadir, + TestNonAsciiUserDataDir) { + // Verify that the window is present. + ASSERT_TRUE(browser()); +} +#endif // defined(OS_WIN) + +// Tests to ensure that the browser continues running in the background after +// the last window closes. +class RunInBackgroundTest : public BrowserTest { + public: + RunInBackgroundTest() {} + + virtual void SetUpCommandLine(CommandLine* command_line) { + command_line->AppendSwitch(switches::kKeepAliveForTest); + } +}; + +IN_PROC_BROWSER_TEST_F(RunInBackgroundTest, RunInBackgroundBasicTest) { + // Close the browser window, then open a new one - the browser should keep + // running. + Profile* profile = browser()->profile(); + EXPECT_EQ(1u, BrowserList::size()); + ui_test_utils::WindowedNotificationObserver observer( + chrome::NOTIFICATION_BROWSER_CLOSED, + content::Source<Browser>(browser())); + browser()->CloseWindow(); + observer.Wait(); + EXPECT_EQ(0u, BrowserList::size()); + + ui_test_utils::BrowserAddedObserver browser_added_observer; + Browser::NewEmptyWindow(profile); + browser_added_observer.WaitForSingleNewBrowser(); + + EXPECT_EQ(1u, BrowserList::size()); +} + +// Tests to ensure that the browser continues running in the background after +// the last window closes. +class NoStartupWindowTest : public BrowserTest { + public: + NoStartupWindowTest() {} + + virtual void SetUpCommandLine(CommandLine* command_line) { + command_line->AppendSwitch(switches::kNoStartupWindow); + command_line->AppendSwitch(switches::kKeepAliveForTest); + } +}; + +IN_PROC_BROWSER_TEST_F(NoStartupWindowTest, NoStartupWindowBasicTest) { + // No browser window should be started by default. + EXPECT_EQ(0u, BrowserList::size()); + + // Starting a browser window should work just fine. + ui_test_utils::BrowserAddedObserver browser_added_observer; + CreateBrowser(ProfileManager::GetDefaultProfile()); + browser_added_observer.WaitForSingleNewBrowser(); + + EXPECT_EQ(1u, BrowserList::size()); +} + +// This test needs to be placed outside the anonymouse namespace because we +// need to access private type of Browser. +class AppModeTest : public BrowserTest { + public: + AppModeTest() {} + + virtual void SetUpCommandLine(CommandLine* command_line) { + GURL url = ui_test_utils::GetTestUrl( + FilePath(), FilePath().AppendASCII("title1.html")); + command_line->AppendSwitchASCII(switches::kApp, url.spec()); + } +}; + +IN_PROC_BROWSER_TEST_F(AppModeTest, EnableAppModeTest) { + // Test that an application browser window loads correctly. + + // Verify the browser is in application mode. + EXPECT_TRUE(browser()->IsApplication()); +} diff --git a/chrome/browser/ui/tests/browser_uitest.cc b/chrome/browser/ui/tests/browser_uitest.cc deleted file mode 100644 index ac30eee..0000000 --- a/chrome/browser/ui/tests/browser_uitest.cc +++ /dev/null @@ -1,236 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "base/base_paths.h" -#include "base/file_path.h" -#include "base/file_util.h" -#include "base/path_service.h" -#include "base/string_util.h" -#include "base/sys_info.h" -#include "base/test/test_file_util.h" -#include "base/test/test_timeouts.h" -#include "base/values.h" -#include "chrome/app/chrome_command_ids.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/common/chrome_constants.h" -#include "chrome/common/chrome_switches.h" -#include "chrome/test/automation/automation_proxy.h" -#include "chrome/test/automation/browser_proxy.h" -#include "chrome/test/automation/tab_proxy.h" -#include "chrome/test/automation/window_proxy.h" -#include "chrome/test/ui/ui_test.h" -#include "grit/chromium_strings.h" -#include "grit/generated_resources.h" -#include "net/base/net_util.h" -#include "net/test/test_server.h" -#include "ui/gfx/native_widget_types.h" - -namespace { - -class BrowserUITestEnd : public UITest { -}; - -class VisibleBrowserTest : public UITest { - protected: - VisibleBrowserTest() : UITest() { - show_window_ = true; - } -}; - -} // namespace - -// The browser should quit quickly if it receives a WM_ENDSESSION message -// on Windows, or SIGTERM on posix. -TEST_F(BrowserUITestEnd, SessionEnd) { - FilePath test_file(test_data_directory_); - test_file = test_file.AppendASCII("title1.html"); - - NavigateToURL(net::FilePathToFileURL(test_file)); - TerminateBrowser(); -} - -TEST_F(VisibleBrowserTest, WindowOpenClose) { - FilePath test_file(test_data_directory_); - test_file = test_file.AppendASCII("window.close.html"); - - NavigateToURLBlockUntilNavigationsComplete( - net::FilePathToFileURL(test_file), 2); - EXPECT_EQ(L"Title Of Awesomeness", GetActiveTabTitle()); -} - -class ShowModalDialogTest : public UITest { - public: - ShowModalDialogTest() { - launch_arguments_.AppendSwitch(switches::kDisablePopupBlocking); - } -}; - -TEST_F(ShowModalDialogTest, BasicTest) { - FilePath test_file(test_data_directory_); - test_file = test_file.AppendASCII("showmodaldialog.html"); - - // This navigation should show a modal dialog that will be immediately - // closed, but the fact that it was shown should be recorded. - NavigateToURL(net::FilePathToFileURL(test_file)); - ASSERT_TRUE(automation()->WaitForWindowCountToBecome(1)); - - // Verify that we set a mark on successful dialog show. - scoped_refptr<BrowserProxy> browser = automation()->GetBrowserWindow(0); - ASSERT_TRUE(browser.get()); - scoped_refptr<TabProxy> tab = browser->GetActiveTab(); - ASSERT_TRUE(tab.get()); - std::wstring title; - ASSERT_TRUE(tab->GetTabTitle(&title)); - ASSERT_EQ(L"SUCCESS", title); -} - -class SecurityTest : public UITest { -}; - -TEST_F(SecurityTest, DisallowFileUrlUniversalAccessTest) { - scoped_refptr<TabProxy> tab(GetActiveTab()); - ASSERT_TRUE(tab.get()); - - FilePath test_file(test_data_directory_); - test_file = test_file.AppendASCII("fileurl_universalaccess.html"); - - GURL url = net::FilePathToFileURL(test_file); - ASSERT_TRUE(tab->NavigateToURL(url)); - - std::string value = WaitUntilCookieNonEmpty(tab.get(), url, - "status", TestTimeouts::action_max_timeout_ms()); - ASSERT_STREQ("Disallowed", value.c_str()); -} - -#if !defined(OS_MACOSX) -class KioskModeTest : public UITest { - public: - KioskModeTest() { - launch_arguments_.AppendSwitch(switches::kKioskMode); - } -}; - -TEST_F(KioskModeTest, EnableKioskModeTest) { - // Verify that the window is present. - scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); - ASSERT_TRUE(browser.get()); - - // Check if browser is in fullscreen mode. - bool is_visible; - ASSERT_TRUE(browser->IsFullscreen(&is_visible)); - EXPECT_TRUE(is_visible); - ASSERT_TRUE(browser->IsFullscreenBubbleVisible(&is_visible)); - EXPECT_FALSE(is_visible); -} -#endif // !defined(OS_MACOSX) - -#if defined(OS_WIN) -// This test verifies that Chrome can be launched with a user-data-dir path -// which contains non ASCII characters. -class LaunchBrowserWithNonAsciiUserDatadir : public UITest { - public: - void SetUp() { - ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); - FilePath tmp_profile = temp_dir_.path().AppendASCII("tmp_profile"); - tmp_profile = tmp_profile.Append(L"Test Chrome G�raldine"); - - ASSERT_TRUE(file_util::CreateDirectory(tmp_profile)); - - launch_arguments_.AppendSwitchPath(switches::kUserDataDir, tmp_profile); - } - - bool LaunchAppWithProfile() { - UITest::SetUp(); - return true; - } - - private: - ScopedTempDir temp_dir_; -}; - -TEST_F(LaunchBrowserWithNonAsciiUserDatadir, TestNonAsciiUserDataDir) { - ASSERT_TRUE(LaunchAppWithProfile()); - // Verify that the window is present. - scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); - ASSERT_TRUE(browser.get()); -} -#endif // defined(OS_WIN) - -// Tests to ensure that the browser continues running in the background after -// the last window closes. -class RunInBackgroundTest : public UITest { - public: - RunInBackgroundTest() { - launch_arguments_.AppendSwitch(switches::kKeepAliveForTest); - } -}; - -TEST_F(RunInBackgroundTest, RunInBackgroundBasicTest) { - // Close the browser window, then open a new one - the browser should keep - // running. - scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); - ASSERT_TRUE(browser.get()); - int window_count; - ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); - EXPECT_EQ(1, window_count); - ASSERT_TRUE(browser->RunCommand(IDC_CLOSE_WINDOW)); - ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); - EXPECT_EQ(0, window_count); - ASSERT_TRUE(automation()->OpenNewBrowserWindow(Browser::TYPE_TABBED, true)); - ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); - EXPECT_EQ(1, window_count); - // Set the shutdown type to 'SESSION_ENDING' since we are running in - // background mode and neither closing all the windows nor quitting will - // shut down the browser. - set_shutdown_type(ProxyLauncher::SESSION_ENDING); -} - -// Tests to ensure that the browser continues running in the background after -// the last window closes. -class NoStartupWindowTest : public UITest { - public: - NoStartupWindowTest() { - launch_arguments_.AppendSwitch(switches::kNoStartupWindow); - launch_arguments_.AppendSwitch(switches::kKeepAliveForTest); - } -}; - -TEST_F(NoStartupWindowTest, NoStartupWindowBasicTest) { - // No browser window should be started by default. - int window_count; - ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); - EXPECT_EQ(0, window_count); - - // Starting a browser window should work just fine. - ASSERT_TRUE(automation()->OpenNewBrowserWindow(Browser::TYPE_TABBED, true)); - ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count)); - EXPECT_EQ(1, window_count); -} - -// This test needs to be placed outside the anonymouse namespace because we -// need to access private type of Browser. -class AppModeTest : public UITest { - public: - AppModeTest() { - // Load a local file. - FilePath test_file(test_data_directory_); - test_file = test_file.AppendASCII("title1.html"); - GURL test_file_url(net::FilePathToFileURL(test_file)); - - launch_arguments_.AppendSwitchASCII(switches::kApp, test_file_url.spec()); - } -}; - -TEST_F(AppModeTest, EnableAppModeTest) { - // Test that an application browser window loads correctly. - - // Verify that the window is present. - scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); - ASSERT_TRUE(browser.get()); - - // Verify the browser is in application mode. - bool is_application; - ASSERT_TRUE(browser->IsApplication(&is_application)); - EXPECT_TRUE(is_application); -} diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 0325393..b7eb96f 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -716,7 +716,6 @@ # NOTE: DON'T ADD NEW TESTS HERE! # New tests should be browser_tests. browser_tests are sharded and are # less flakier. - 'browser/ui/tests/browser_uitest.cc', 'test/automation/automation_proxy_uitest.cc', 'test/automation/automation_proxy_uitest.h', 'test/base/chrome_process_util_uitest.cc', diff --git a/chrome/test/data/fileurl_universalaccess.html b/chrome/test/data/fileurl_universalaccess.html index a419fef..5b7400d 100644 --- a/chrome/test/data/fileurl_universalaccess.html +++ b/chrome/test/data/fileurl_universalaccess.html @@ -10,7 +10,7 @@ function test() { } catch (e) { status = "Disallowed"; } - document.cookie = "status=" + status; + document.title = status; } </script> <div id=result></div> |