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

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

Issue 63113: Convert Windows Sleep to PlatformThread::Sleep... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/crash_recovery_uitest.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-2009 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"
11 #include "chrome/common/l10n_util.h" 11 #include "chrome/common/l10n_util.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 std::wstring test_file = test_data_directory_;
65 file_util::AppendToPath(&test_file, L"title1.html"); 65 file_util::AppendToPath(&test_file, L"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
69 // The browser lazily updates the title.
70 PlatformThread::Sleep(sleep_timeout_ms());
69 71
70 EXPECT_EQ(WindowCaptionFromPageTitle(L"title1.html"), GetWindowTitle()); 72 EXPECT_EQ(WindowCaptionFromPageTitle(L"title1.html"), GetWindowTitle());
71 EXPECT_EQ(L"title1.html", GetActiveTabTitle()); 73 EXPECT_EQ(L"title1.html", GetActiveTabTitle());
72 } 74 }
73 75
74 // Launch the app, navigate to a page with a title, check that the app title 76 // Launch the app, navigate to a page with a title, check that the app title
75 // was set correctly. 77 // was set correctly.
76 TEST_F(BrowserTest, Title) { 78 TEST_F(BrowserTest, Title) {
77 std::wstring test_file = test_data_directory_; 79 std::wstring test_file = test_data_directory_;
78 file_util::AppendToPath(&test_file, L"title2.html"); 80 file_util::AppendToPath(&test_file, L"title2.html");
79 81
80 NavigateToURL(net::FilePathToFileURL(test_file)); 82 NavigateToURL(net::FilePathToFileURL(test_file));
81 Sleep(sleep_timeout_ms()); // The browser lazily updates the title. 83
84 // The browser lazily updates the title.
85 PlatformThread::Sleep(sleep_timeout_ms());
82 86
83 const std::wstring test_title(L"Title Of Awesomeness"); 87 const std::wstring test_title(L"Title Of Awesomeness");
84 EXPECT_EQ(WindowCaptionFromPageTitle(test_title), GetWindowTitle()); 88 EXPECT_EQ(WindowCaptionFromPageTitle(test_title), GetWindowTitle());
85 EXPECT_EQ(test_title, GetActiveTabTitle()); 89 EXPECT_EQ(test_title, GetActiveTabTitle());
86 } 90 }
87 91
88 // Create 34 tabs and verify that a lot of processes have been created. The 92 // 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 93 // 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 94 // 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. 95 // verifying that we don't crash when we pass this limit.
(...skipping 21 matching lines...) Expand all
113 EXPECT_LE(process_count, 23); 117 EXPECT_LE(process_count, 23);
114 } 118 }
115 } 119 }
116 120
117 // The browser should quit quickly if it receives a WM_ENDSESSION message. 121 // The browser should quit quickly if it receives a WM_ENDSESSION message.
118 TEST_F(BrowserTest, WindowsSessionEnd) { 122 TEST_F(BrowserTest, WindowsSessionEnd) {
119 std::wstring test_file = test_data_directory_; 123 std::wstring test_file = test_data_directory_;
120 file_util::AppendToPath(&test_file, L"title1.html"); 124 file_util::AppendToPath(&test_file, L"title1.html");
121 125
122 NavigateToURL(net::FilePathToFileURL(test_file)); 126 NavigateToURL(net::FilePathToFileURL(test_file));
123 Sleep(action_timeout_ms()); 127 PlatformThread::Sleep(action_timeout_ms());
124 128
125 // Simulate an end of session. Normally this happens when the user 129 // Simulate an end of session. Normally this happens when the user
126 // shuts down the pc or logs off. 130 // shuts down the pc or logs off.
127 HWND window_handle = GetMainWindow(); 131 HWND window_handle = GetMainWindow();
128 ASSERT_TRUE(::PostMessageW(window_handle, WM_ENDSESSION, 0, 0)); 132 ASSERT_TRUE(::PostMessageW(window_handle, WM_ENDSESSION, 0, 0));
129 133
130 Sleep(action_timeout_ms()); 134 PlatformThread::Sleep(action_timeout_ms());
131 ASSERT_FALSE(IsBrowserRunning()); 135 ASSERT_FALSE(IsBrowserRunning());
132 136
133 // Make sure the UMA metrics say we didn't crash. 137 // Make sure the UMA metrics say we didn't crash.
134 scoped_ptr<DictionaryValue> local_prefs(GetLocalState()); 138 scoped_ptr<DictionaryValue> local_prefs(GetLocalState());
135 bool exited_cleanly; 139 bool exited_cleanly;
136 ASSERT_TRUE(local_prefs.get()); 140 ASSERT_TRUE(local_prefs.get());
137 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilityExitedCleanly, 141 ASSERT_TRUE(local_prefs->GetBoolean(prefs::kStabilityExitedCleanly,
138 &exited_cleanly)); 142 &exited_cleanly));
139 ASSERT_TRUE(exited_cleanly); 143 ASSERT_TRUE(exited_cleanly);
140 144
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 204
201 // Use JavaScript URL to "fork" a new tab, just like Gmail. (Open tab to a 205 // 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.) 206 // blank page, set its opener to null, and redirect it cross-site.)
203 std::wstring url_prefix(L"javascript:(function(){w=window.open();"); 207 std::wstring url_prefix(L"javascript:(function(){w=window.open();");
204 GURL fork_url(url_prefix + 208 GURL fork_url(url_prefix +
205 L"w.opener=null;w.document.location=\"http://localhost:1337\";})()"); 209 L"w.opener=null;w.document.location=\"http://localhost:1337\";})()");
206 210
207 // Make sure that a new tab has been created and that we have a new renderer 211 // Make sure that a new tab has been created and that we have a new renderer
208 // process for it. 212 // process for it.
209 tab->NavigateToURLAsync(fork_url); 213 tab->NavigateToURLAsync(fork_url);
210 Sleep(action_timeout_ms()); 214 PlatformThread::Sleep(action_timeout_ms());
211 ASSERT_EQ(orig_process_count + 1, GetBrowserProcessCount()); 215 ASSERT_EQ(orig_process_count + 1, GetBrowserProcessCount());
212 int new_tab_count = -1; 216 int new_tab_count = -1;
213 ASSERT_TRUE(window->GetTabCount(&new_tab_count)); 217 ASSERT_TRUE(window->GetTabCount(&new_tab_count));
214 ASSERT_EQ(orig_tab_count + 1, new_tab_count); 218 ASSERT_EQ(orig_tab_count + 1, new_tab_count);
215 } 219 }
216 #endif 220 #endif
217 221
218 // Tests that non-Gmail-like script redirects (i.e., non-null window.opener) or 222 // Tests that non-Gmail-like script redirects (i.e., non-null window.opener) or
219 // a same-page-redirect) will not fork a new process. 223 // a same-page-redirect) will not fork a new process.
220 TEST_F(BrowserTest, OtherRedirectsDontForkProcess) { 224 TEST_F(BrowserTest, OtherRedirectsDontForkProcess) {
(...skipping 18 matching lines...) Expand all
239 ASSERT_GE(orig_process_count, 1); 243 ASSERT_GE(orig_process_count, 1);
240 244
241 // Use JavaScript URL to almost fork a new tab, but not quite. (Leave the 245 // Use JavaScript URL to almost fork a new tab, but not quite. (Leave the
242 // opener non-null.) Should not fork a process. 246 // opener non-null.) Should not fork a process.
243 std::wstring url_prefix(L"javascript:(function(){w=window.open();"); 247 std::wstring url_prefix(L"javascript:(function(){w=window.open();");
244 GURL dont_fork_url(url_prefix + 248 GURL dont_fork_url(url_prefix +
245 L"w.document.location=\"http://localhost:1337\";})()"); 249 L"w.document.location=\"http://localhost:1337\";})()");
246 250
247 // Make sure that a new tab but not new process has been created. 251 // Make sure that a new tab but not new process has been created.
248 tab->NavigateToURLAsync(dont_fork_url); 252 tab->NavigateToURLAsync(dont_fork_url);
249 Sleep(action_timeout_ms()); 253 PlatformThread::Sleep(action_timeout_ms());
250 ASSERT_EQ(orig_process_count, GetBrowserProcessCount()); 254 ASSERT_EQ(orig_process_count, GetBrowserProcessCount());
251 int new_tab_count = -1; 255 int new_tab_count = -1;
252 ASSERT_TRUE(window->GetTabCount(&new_tab_count)); 256 ASSERT_TRUE(window->GetTabCount(&new_tab_count));
253 ASSERT_EQ(orig_tab_count + 1, new_tab_count); 257 ASSERT_EQ(orig_tab_count + 1, new_tab_count);
254 258
255 // Same thing if the current tab tries to redirect itself. 259 // Same thing if the current tab tries to redirect itself.
256 GURL dont_fork_url2(url_prefix + 260 GURL dont_fork_url2(url_prefix +
257 L"document.location=\"http://localhost:1337\";})()"); 261 L"document.location=\"http://localhost:1337\";})()");
258 262
259 // Make sure that no new process has been created. 263 // Make sure that no new process has been created.
260 tab->NavigateToURLAsync(dont_fork_url2); 264 tab->NavigateToURLAsync(dont_fork_url2);
261 Sleep(action_timeout_ms()); 265 PlatformThread::Sleep(action_timeout_ms());
262 ASSERT_EQ(orig_process_count, GetBrowserProcessCount()); 266 ASSERT_EQ(orig_process_count, GetBrowserProcessCount());
263 } 267 }
264 268
265 TEST_F(VisibleBrowserTest, WindowOpenClose) { 269 TEST_F(VisibleBrowserTest, WindowOpenClose) {
266 std::wstring test_file(test_data_directory_); 270 std::wstring test_file(test_data_directory_);
267 file_util::AppendToPath(&test_file, L"window.close.html"); 271 file_util::AppendToPath(&test_file, L"window.close.html");
268 272
269 NavigateToURL(net::FilePathToFileURL(test_file)); 273 NavigateToURL(net::FilePathToFileURL(test_file));
270 274
271 int i; 275 int i;
272 for (i = 0; i < 10; ++i) { 276 for (i = 0; i < 10; ++i) {
273 Sleep(action_max_timeout_ms() / 10); 277 PlatformThread::Sleep(action_max_timeout_ms() / 10);
274 std::wstring title = GetActiveTabTitle(); 278 std::wstring title = GetActiveTabTitle();
275 if (title == L"PASSED") { 279 if (title == L"PASSED") {
276 // Success, bail out. 280 // Success, bail out.
277 break; 281 break;
278 } 282 }
279 } 283 }
280 284
281 if (i == 10) 285 if (i == 10)
282 FAIL() << "failed to get error page title"; 286 FAIL() << "failed to get error page title";
283 } 287 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/crash_recovery_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698