summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_browsertest.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 17:41:31 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 17:41:31 +0000
commite1247af3110dc604221f24d3cfdab993688cc78b (patch)
treeeb971f1ac0904ec2f5e254aad0c323b2d15d9f69 /chrome/browser/browser_browsertest.cc
parentd29f9e18625ce6411cd8ad422b6a812d108756f0 (diff)
downloadchromium_src-e1247af3110dc604221f24d3cfdab993688cc78b.zip
chromium_src-e1247af3110dc604221f24d3cfdab993688cc78b.tar.gz
chromium_src-e1247af3110dc604221f24d3cfdab993688cc78b.tar.bz2
Convert most flakiness-prone Browser UI tests to browser_tests framework.
TEST=none BUG=http://crbug.com/16062 Review URL: http://codereview.chromium.org/149365 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20276 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_browsertest.cc')
-rw-r--r--chrome/browser/browser_browsertest.cc81
1 files changed, 81 insertions, 0 deletions
diff --git a/chrome/browser/browser_browsertest.cc b/chrome/browser/browser_browsertest.cc
new file mode 100644
index 0000000..8b29936
--- /dev/null
+++ b/chrome/browser/browser_browsertest.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2009 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 <string>
+
+#include "app/l10n_util.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_process.h"
+#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/test/in_process_browser_test.h"
+#include "chrome/test/ui_test_utils.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "grit/chromium_strings.h"
+#include "grit/generated_resources.h"
+
+namespace {
+
+// Given a page title, returns the expected window caption string.
+std::wstring WindowCaptionFromPageTitle(std::wstring page_title) {
+#if defined(OS_WIN) || defined(OS_LINUX)
+ if (page_title.empty())
+ return l10n_util::GetString(IDS_PRODUCT_NAME);
+
+ return l10n_util::GetStringF(IDS_BROWSER_WINDOW_TITLE_FORMAT, page_title);
+#elif defined(OS_MACOSX)
+ // On Mac, we don't want to suffix the page title with the application name.
+ if (page_title.empty())
+ return l10n_util::GetString(IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED);
+ return page_title;
+#endif
+}
+
+} // namespace
+
+class BrowserTest : public InProcessBrowserTest {
+ protected:
+ // In RTL locales wrap the page title with RTL embedding characters so that it
+ // matches the value returned by GetWindowTitle().
+ std::wstring LocaleWindowCaptionFromPageTitle(
+ const std::wstring& expected_title) {
+ std::wstring page_title = WindowCaptionFromPageTitle(expected_title);
+#if defined(OS_WIN)
+ std::string locale = g_browser_process->GetApplicationLocale();
+ if (l10n_util::GetTextDirectionForLocale(locale.c_str()) ==
+ l10n_util::RIGHT_TO_LEFT) {
+ l10n_util::WrapStringWithLTRFormatting(&page_title);
+ }
+
+ return page_title;
+#else
+ // Do we need to use the above code on POSIX as well?
+ return page_title;
+#endif
+ }
+};
+
+// Launch the app on a page with no title, check that the app title was set
+// correctly.
+IN_PROC_BROWSER_TEST_F(BrowserTest, NoTitle) {
+ ui_test_utils::NavigateToURL(browser(),
+ ui_test_utils::GetTestUrl(L".", L"title1.html"));
+ EXPECT_EQ(LocaleWindowCaptionFromPageTitle(L"title1.html"),
+ browser()->GetCurrentPageTitle());
+ string16 tab_title;
+ ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &tab_title));
+ EXPECT_EQ(ASCIIToUTF16("title1.html"), tab_title);
+}
+
+// Launch the app, navigate to a page with a title, check that the app title
+// was set correctly.
+IN_PROC_BROWSER_TEST_F(BrowserTest, Title) {
+ ui_test_utils::NavigateToURL(browser(),
+ ui_test_utils::GetTestUrl(L".", L"title2.html"));
+ const std::wstring test_title(L"Title Of Awesomeness");
+ EXPECT_EQ(LocaleWindowCaptionFromPageTitle(test_title),
+ browser()->GetCurrentPageTitle());
+ string16 tab_title;
+ ASSERT_TRUE(ui_test_utils::GetCurrentTabTitle(browser(), &tab_title));
+ EXPECT_EQ(WideToUTF16(test_title), tab_title);
+}