| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "app/l10n_util.h" | 5 #include "app/l10n_util.h" |
| 6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
| 7 #include "base/gfx/native_widget_types.h" | 7 #include "base/gfx/native_widget_types.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/sys_info.h" | 9 #include "base/sys_info.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #endif | 52 #endif |
| 53 | 53 |
| 54 std::wstring GetWindowTitle() { | 54 std::wstring GetWindowTitle() { |
| 55 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 55 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 56 scoped_refptr<WindowProxy> window(browser->GetWindow()); | 56 scoped_refptr<WindowProxy> window(browser->GetWindow()); |
| 57 | 57 |
| 58 string16 title; | 58 string16 title; |
| 59 EXPECT_TRUE(window->GetWindowTitle(&title)); | 59 EXPECT_TRUE(window->GetWindowTitle(&title)); |
| 60 return UTF16ToWide(title); | 60 return UTF16ToWide(title); |
| 61 } | 61 } |
| 62 |
| 63 // In RTL locales wrap the page title with RTL embedding characters so that it |
| 64 // matches the value returned by GetWindowTitle(). |
| 65 std::wstring LocaleWindowCaptionFromPageTitle( |
| 66 const std::wstring& expected_title) { |
| 67 std::wstring page_title = WindowCaptionFromPageTitle(expected_title); |
| 68 #if defined(OS_WIN) |
| 69 string16 browser_locale; |
| 70 |
| 71 EXPECT_TRUE(automation()->GetBrowserLocale(&browser_locale)); |
| 72 |
| 73 const std::string& locale_utf8 = UTF16ToUTF8(browser_locale); |
| 74 if (l10n_util::GetTextDirectionForLocale(locale_utf8.c_str()) == |
| 75 l10n_util::RIGHT_TO_LEFT) { |
| 76 l10n_util::WrapStringWithLTRFormatting(&page_title); |
| 77 } |
| 78 |
| 79 return page_title; |
| 80 #else |
| 81 // Do we need to use the above code on POSIX as well? |
| 82 return page_title; |
| 83 #endif |
| 84 } |
| 62 }; | 85 }; |
| 63 | 86 |
| 64 class VisibleBrowserTest : public UITest { | 87 class VisibleBrowserTest : public UITest { |
| 65 protected: | 88 protected: |
| 66 VisibleBrowserTest() : UITest() { | 89 VisibleBrowserTest() : UITest() { |
| 67 show_window_ = true; | 90 show_window_ = true; |
| 68 } | 91 } |
| 69 }; | 92 }; |
| 70 | 93 |
| 71 // Launch the app on a page with no title, check that the app title was set | 94 // Launch the app on a page with no title, check that the app title was set |
| 72 // correctly. | 95 // correctly. |
| 73 TEST_F(BrowserTest, NoTitle) { | 96 TEST_F(BrowserTest, NoTitle) { |
| 74 FilePath test_file(test_data_directory_); | 97 FilePath test_file(test_data_directory_); |
| 75 test_file = test_file.AppendASCII("title1.html"); | 98 test_file = test_file.AppendASCII("title1.html"); |
| 76 | 99 |
| 77 NavigateToURL(net::FilePathToFileURL(test_file)); | 100 NavigateToURL(net::FilePathToFileURL(test_file)); |
| 78 // The browser lazily updates the title. | 101 // The browser lazily updates the title. |
| 79 PlatformThread::Sleep(sleep_timeout_ms()); | 102 PlatformThread::Sleep(sleep_timeout_ms()); |
| 80 EXPECT_EQ(WindowCaptionFromPageTitle(L"title1.html"), GetWindowTitle()); | 103 |
| 104 EXPECT_EQ(LocaleWindowCaptionFromPageTitle(L"title1.html"), GetWindowTitle()); |
| 81 EXPECT_EQ(L"title1.html", GetActiveTabTitle()); | 105 EXPECT_EQ(L"title1.html", GetActiveTabTitle()); |
| 82 } | 106 } |
| 83 | 107 |
| 84 // Launch the app, navigate to a page with a title, check that the app title | 108 // Launch the app, navigate to a page with a title, check that the app title |
| 85 // was set correctly. | 109 // was set correctly. |
| 86 TEST_F(BrowserTest, Title) { | 110 TEST_F(BrowserTest, Title) { |
| 87 FilePath test_file(test_data_directory_); | 111 FilePath test_file(test_data_directory_); |
| 88 test_file = test_file.AppendASCII("title2.html"); | 112 test_file = test_file.AppendASCII("title2.html"); |
| 89 | 113 |
| 90 NavigateToURL(net::FilePathToFileURL(test_file)); | 114 NavigateToURL(net::FilePathToFileURL(test_file)); |
| 91 // The browser lazily updates the title. | 115 // The browser lazily updates the title. |
| 92 PlatformThread::Sleep(sleep_timeout_ms()); | 116 PlatformThread::Sleep(sleep_timeout_ms()); |
| 93 | 117 |
| 94 const std::wstring test_title(L"Title Of Awesomeness"); | 118 const std::wstring test_title(L"Title Of Awesomeness"); |
| 95 EXPECT_EQ(WindowCaptionFromPageTitle(test_title), GetWindowTitle()); | 119 EXPECT_EQ(LocaleWindowCaptionFromPageTitle(test_title), GetWindowTitle()); |
| 96 EXPECT_EQ(test_title, GetActiveTabTitle()); | 120 EXPECT_EQ(test_title, GetActiveTabTitle()); |
| 97 } | 121 } |
| 98 | 122 |
| 99 // Create 34 tabs and verify that a lot of processes have been created. The | 123 // Create 34 tabs and verify that a lot of processes have been created. The |
| 100 // exact number of processes depends on the amount of memory. Previously we | 124 // exact number of processes depends on the amount of memory. Previously we |
| 101 // had a hard limit of 31 processes and this test is mainly directed at | 125 // had a hard limit of 31 processes and this test is mainly directed at |
| 102 // verifying that we don't crash when we pass this limit. | 126 // verifying that we don't crash when we pass this limit. |
| 103 TEST_F(BrowserTest, ThirtyFourTabs) { | 127 TEST_F(BrowserTest, ThirtyFourTabs) { |
| 104 FilePath test_file(test_data_directory_); | 128 FilePath test_file(test_data_directory_); |
| 105 test_file = test_file.AppendASCII("title2.html"); | 129 test_file = test_file.AppendASCII("title2.html"); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 break; | 319 break; |
| 296 } | 320 } |
| 297 } | 321 } |
| 298 | 322 |
| 299 if (i == 10) | 323 if (i == 10) |
| 300 FAIL() << "failed to get error page title"; | 324 FAIL() << "failed to get error page title"; |
| 301 } | 325 } |
| 302 #endif | 326 #endif |
| 303 | 327 |
| 304 } // namespace | 328 } // namespace |
| OLD | NEW |