Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: chrome/browser/browser_uitest.cc

Issue 63011: Monster FilePath patch! (Closed)
Patch Set: sync with trunk Created 11 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/chrome_plugin_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/string_util.h" 6 #include "base/string_util.h"
7 #include "base/sys_info.h" 7 #include "base/sys_info.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/app/chrome_dll_resource.h" 9 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/common/chrome_constants.h" 10 #include "chrome/common/chrome_constants.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 VisibleBrowserTest() : UITest() { 54 VisibleBrowserTest() : UITest() {
55 show_window_ = true; 55 show_window_ = true;
56 } 56 }
57 }; 57 };
58 58
59 } // namespace 59 } // namespace
60 60
61 // Launch the app on a page with no title, check that the app title was set 61 // Launch the app on a page with no title, check that the app title was set
62 // correctly. 62 // correctly.
63 TEST_F(BrowserTest, NoTitle) { 63 TEST_F(BrowserTest, NoTitle) {
64 std::wstring test_file = test_data_directory_; 64 FilePath test_file(FilePath::FromWStringHack(test_data_directory_));
65 file_util::AppendToPath(&test_file, L"title1.html"); 65 test_file = test_file.AppendASCII("title1.html");
66 66
67 NavigateToURL(net::FilePathToFileURL(test_file)); 67 NavigateToURL(net::FilePathToFileURL(test_file));
68 Sleep(sleep_timeout_ms()); // The browser lazily updates the title. 68 Sleep(sleep_timeout_ms()); // The browser lazily updates the title.
69 69
70 EXPECT_EQ(WindowCaptionFromPageTitle(L"title1.html"), GetWindowTitle()); 70 EXPECT_EQ(WindowCaptionFromPageTitle(L"title1.html"), GetWindowTitle());
71 EXPECT_EQ(L"title1.html", GetActiveTabTitle()); 71 EXPECT_EQ(L"title1.html", GetActiveTabTitle());
72 } 72 }
73 73
74 // Launch the app, navigate to a page with a title, check that the app title 74 // Launch the app, navigate to a page with a title, check that the app title
75 // was set correctly. 75 // was set correctly.
76 TEST_F(BrowserTest, Title) { 76 TEST_F(BrowserTest, Title) {
77 std::wstring test_file = test_data_directory_; 77 FilePath test_file(FilePath::FromWStringHack(test_data_directory_));
78 file_util::AppendToPath(&test_file, L"title2.html"); 78 test_file = test_file.AppendASCII("title2.html");
79 79
80 NavigateToURL(net::FilePathToFileURL(test_file)); 80 NavigateToURL(net::FilePathToFileURL(test_file));
81 Sleep(sleep_timeout_ms()); // The browser lazily updates the title. 81 Sleep(sleep_timeout_ms()); // The browser lazily updates the title.
82 82
83 const std::wstring test_title(L"Title Of Awesomeness"); 83 const std::wstring test_title(L"Title Of Awesomeness");
84 EXPECT_EQ(WindowCaptionFromPageTitle(test_title), GetWindowTitle()); 84 EXPECT_EQ(WindowCaptionFromPageTitle(test_title), GetWindowTitle());
85 EXPECT_EQ(test_title, GetActiveTabTitle()); 85 EXPECT_EQ(test_title, GetActiveTabTitle());
86 } 86 }
87 87
88 // Create 34 tabs and verify that a lot of processes have been created. The 88 // Create 34 tabs and verify that a lot of processes have been created. The
89 // exact number of processes depends on the amount of memory. Previously we 89 // exact number of processes depends on the amount of memory. Previously we
90 // had a hard limit of 31 processes and this test is mainly directed at 90 // had a hard limit of 31 processes and this test is mainly directed at
91 // verifying that we don't crash when we pass this limit. 91 // verifying that we don't crash when we pass this limit.
92 TEST_F(BrowserTest, ThirtyFourTabs) { 92 TEST_F(BrowserTest, ThirtyFourTabs) {
93 std::wstring test_file = test_data_directory_; 93 FilePath test_file(FilePath::FromWStringHack(test_data_directory_));
94 file_util::AppendToPath(&test_file, L"title2.html"); 94 test_file = test_file.AppendASCII("title2.html");
95 GURL url(net::FilePathToFileURL(test_file)); 95 GURL url(net::FilePathToFileURL(test_file));
96 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); 96 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
97 // There is one initial tab. 97 // There is one initial tab.
98 for (int ix = 0; ix != 33; ++ix) { 98 for (int ix = 0; ix != 33; ++ix) {
99 EXPECT_TRUE(window->AppendTab(url)); 99 EXPECT_TRUE(window->AppendTab(url));
100 } 100 }
101 int tab_count = 0; 101 int tab_count = 0;
102 EXPECT_TRUE(window->GetTabCount(&tab_count)); 102 EXPECT_TRUE(window->GetTabCount(&tab_count));
103 EXPECT_EQ(34, tab_count); 103 EXPECT_EQ(34, tab_count);
104 // Do not test the rest in single process mode. 104 // Do not test the rest in single process mode.
105 if (in_process_renderer()) 105 if (in_process_renderer())
106 return; 106 return;
107 // See browser\renderer_host\render_process_host.cc for the algorithm to 107 // See browser\renderer_host\render_process_host.cc for the algorithm to
108 // decide how many processes to create. 108 // decide how many processes to create.
109 int process_count = GetBrowserProcessCount(); 109 int process_count = GetBrowserProcessCount();
110 if (base::SysInfo::AmountOfPhysicalMemoryMB() >= 2048) { 110 if (base::SysInfo::AmountOfPhysicalMemoryMB() >= 2048) {
111 EXPECT_GE(process_count, 24); 111 EXPECT_GE(process_count, 24);
112 } else { 112 } else {
113 EXPECT_LE(process_count, 23); 113 EXPECT_LE(process_count, 23);
114 } 114 }
115 } 115 }
116 116
117 // The browser should quit quickly if it receives a WM_ENDSESSION message. 117 // The browser should quit quickly if it receives a WM_ENDSESSION message.
118 TEST_F(BrowserTest, WindowsSessionEnd) { 118 TEST_F(BrowserTest, WindowsSessionEnd) {
119 std::wstring test_file = test_data_directory_; 119 FilePath test_file(FilePath::FromWStringHack(test_data_directory_));
120 file_util::AppendToPath(&test_file, L"title1.html"); 120 test_file = test_file.AppendASCII("title1.html");
121 121
122 NavigateToURL(net::FilePathToFileURL(test_file)); 122 NavigateToURL(net::FilePathToFileURL(test_file));
123 Sleep(action_timeout_ms()); 123 Sleep(action_timeout_ms());
124 124
125 // Simulate an end of session. Normally this happens when the user 125 // Simulate an end of session. Normally this happens when the user
126 // shuts down the pc or logs off. 126 // shuts down the pc or logs off.
127 HWND window_handle = GetMainWindow(); 127 HWND window_handle = GetMainWindow();
128 ASSERT_TRUE(::PostMessageW(window_handle, WM_ENDSESSION, 0, 0)); 128 ASSERT_TRUE(::PostMessageW(window_handle, WM_ENDSESSION, 0, 0));
129 129
130 Sleep(action_timeout_ms()); 130 Sleep(action_timeout_ms());
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 #ifdef CHROME_V8 179 #ifdef CHROME_V8
180 TEST_F(BrowserTest, NullOpenerRedirectForksProcess) { 180 TEST_F(BrowserTest, NullOpenerRedirectForksProcess) {
181 // This test only works in multi-process mode 181 // This test only works in multi-process mode
182 if (in_process_renderer()) 182 if (in_process_renderer())
183 return; 183 return;
184 184
185 const wchar_t kDocRoot[] = L"chrome/test/data"; 185 const wchar_t kDocRoot[] = L"chrome/test/data";
186 scoped_refptr<HTTPTestServer> server = 186 scoped_refptr<HTTPTestServer> server =
187 HTTPTestServer::CreateServer(kDocRoot, NULL); 187 HTTPTestServer::CreateServer(kDocRoot, NULL);
188 ASSERT_TRUE(NULL != server.get()); 188 ASSERT_TRUE(NULL != server.get());
189 std::wstring test_file(test_data_directory_); 189 FilePath test_file(FilePath::FromWStringHack(test_data_directory_));
190 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); 190 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
191 scoped_ptr<TabProxy> tab(window->GetActiveTab()); 191 scoped_ptr<TabProxy> tab(window->GetActiveTab());
192 192
193 // Start with a file:// url 193 // Start with a file:// url
194 file_util::AppendToPath(&test_file, L"title2.html"); 194 test_file = test_file.AppendASCII("title2.html");
195 tab->NavigateToURL(net::FilePathToFileURL(test_file)); 195 tab->NavigateToURL(net::FilePathToFileURL(test_file));
196 int orig_tab_count = -1; 196 int orig_tab_count = -1;
197 ASSERT_TRUE(window->GetTabCount(&orig_tab_count)); 197 ASSERT_TRUE(window->GetTabCount(&orig_tab_count));
198 int orig_process_count = GetBrowserProcessCount(); 198 int orig_process_count = GetBrowserProcessCount();
199 ASSERT_GE(orig_process_count, 1); 199 ASSERT_GE(orig_process_count, 1);
200 200
201 // Use JavaScript URL to "fork" a new tab, just like Gmail. (Open tab to a 201 // Use JavaScript URL to "fork" a new tab, just like Gmail. (Open tab to a
202 // blank page, set its opener to null, and redirect it cross-site.) 202 // blank page, set its opener to null, and redirect it cross-site.)
203 std::wstring url_prefix(L"javascript:(function(){w=window.open();"); 203 std::wstring url_prefix(L"javascript:(function(){w=window.open();");
204 GURL fork_url(url_prefix + 204 GURL fork_url(url_prefix +
(...skipping 14 matching lines...) Expand all
219 // a same-page-redirect) will not fork a new process. 219 // a same-page-redirect) will not fork a new process.
220 TEST_F(BrowserTest, OtherRedirectsDontForkProcess) { 220 TEST_F(BrowserTest, OtherRedirectsDontForkProcess) {
221 // This test only works in multi-process mode 221 // This test only works in multi-process mode
222 if (in_process_renderer()) 222 if (in_process_renderer())
223 return; 223 return;
224 224
225 const wchar_t kDocRoot[] = L"chrome/test/data"; 225 const wchar_t kDocRoot[] = L"chrome/test/data";
226 scoped_refptr<HTTPTestServer> server = 226 scoped_refptr<HTTPTestServer> server =
227 HTTPTestServer::CreateServer(kDocRoot, NULL); 227 HTTPTestServer::CreateServer(kDocRoot, NULL);
228 ASSERT_TRUE(NULL != server.get()); 228 ASSERT_TRUE(NULL != server.get());
229 std::wstring test_file(test_data_directory_); 229 FilePath test_file(FilePath::FromWStringHack(test_data_directory_));
230 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); 230 scoped_ptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
231 scoped_ptr<TabProxy> tab(window->GetActiveTab()); 231 scoped_ptr<TabProxy> tab(window->GetActiveTab());
232 232
233 // Start with a file:// url 233 // Start with a file:// url
234 file_util::AppendToPath(&test_file, L"title2.html"); 234 test_file = test_file.AppendASCII("title2.html");
235 tab->NavigateToURL(net::FilePathToFileURL(test_file)); 235 tab->NavigateToURL(net::FilePathToFileURL(test_file));
236 int orig_tab_count = -1; 236 int orig_tab_count = -1;
237 ASSERT_TRUE(window->GetTabCount(&orig_tab_count)); 237 ASSERT_TRUE(window->GetTabCount(&orig_tab_count));
238 int orig_process_count = GetBrowserProcessCount(); 238 int orig_process_count = GetBrowserProcessCount();
239 ASSERT_GE(orig_process_count, 1); 239 ASSERT_GE(orig_process_count, 1);
240 240
241 // Use JavaScript URL to almost fork a new tab, but not quite. (Leave the 241 // Use JavaScript URL to almost fork a new tab, but not quite. (Leave the
242 // opener non-null.) Should not fork a process. 242 // opener non-null.) Should not fork a process.
243 std::wstring url_prefix(L"javascript:(function(){w=window.open();"); 243 std::wstring url_prefix(L"javascript:(function(){w=window.open();");
244 GURL dont_fork_url(url_prefix + 244 GURL dont_fork_url(url_prefix +
(...skipping 11 matching lines...) Expand all
256 GURL dont_fork_url2(url_prefix + 256 GURL dont_fork_url2(url_prefix +
257 L"document.location=\"http://localhost:1337\";})()"); 257 L"document.location=\"http://localhost:1337\";})()");
258 258
259 // Make sure that no new process has been created. 259 // Make sure that no new process has been created.
260 tab->NavigateToURLAsync(dont_fork_url2); 260 tab->NavigateToURLAsync(dont_fork_url2);
261 Sleep(action_timeout_ms()); 261 Sleep(action_timeout_ms());
262 ASSERT_EQ(orig_process_count, GetBrowserProcessCount()); 262 ASSERT_EQ(orig_process_count, GetBrowserProcessCount());
263 } 263 }
264 264
265 TEST_F(VisibleBrowserTest, WindowOpenClose) { 265 TEST_F(VisibleBrowserTest, WindowOpenClose) {
266 std::wstring test_file(test_data_directory_); 266 FilePath test_file(FilePath::FromWStringHack(test_data_directory_));
267 file_util::AppendToPath(&test_file, L"window.close.html"); 267 test_file = test_file.AppendASCII("window.close.html");
268 268
269 NavigateToURL(net::FilePathToFileURL(test_file)); 269 NavigateToURL(net::FilePathToFileURL(test_file));
270 270
271 int i; 271 int i;
272 for (i = 0; i < 10; ++i) { 272 for (i = 0; i < 10; ++i) {
273 Sleep(action_max_timeout_ms() / 10); 273 Sleep(action_max_timeout_ms() / 10);
274 std::wstring title = GetActiveTabTitle(); 274 std::wstring title = GetActiveTabTitle();
275 if (title == L"PASSED") { 275 if (title == L"PASSED") {
276 // Success, bail out. 276 // Success, bail out.
277 break; 277 break;
278 } 278 }
279 } 279 }
280 280
281 if (i == 10) 281 if (i == 10)
282 FAIL() << "failed to get error page title"; 282 FAIL() << "failed to get error page title";
283 } 283 }
OLDNEW
« no previous file with comments | « chrome/browser/browser.cc ('k') | chrome/browser/chrome_plugin_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698