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

Side by Side Diff: chrome/browser/renderer_host/resource_dispatcher_host_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
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 <sstream> 5 #include <sstream>
6 #include <string> 6 #include <string>
7 7
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
(...skipping 10 matching lines...) Expand all
22 22
23 class ResourceDispatcherTest : public UITest { 23 class ResourceDispatcherTest : public UITest {
24 public: 24 public:
25 void CheckTitleTest(const std::wstring& file, 25 void CheckTitleTest(const std::wstring& file,
26 const std::wstring& expected_title) { 26 const std::wstring& expected_title) {
27 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file)); 27 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file));
28 const int kCheckDelayMs = 100; 28 const int kCheckDelayMs = 100;
29 int max_wait_time = 5000; 29 int max_wait_time = 5000;
30 while (max_wait_time > 0) { 30 while (max_wait_time > 0) {
31 max_wait_time -= kCheckDelayMs; 31 max_wait_time -= kCheckDelayMs;
32 Sleep(kCheckDelayMs); 32 PlatformThread::Sleep(kCheckDelayMs);
33 if (expected_title == GetActiveTabTitle()) 33 if (expected_title == GetActiveTabTitle())
34 break; 34 break;
35 } 35 }
36 36
37 EXPECT_EQ(expected_title, GetActiveTabTitle()); 37 EXPECT_EQ(expected_title, GetActiveTabTitle());
38 } 38 }
39 39
40 protected: 40 protected:
41 ResourceDispatcherTest() : UITest() { 41 ResourceDispatcherTest() : UITest() {
42 dom_automation_enabled_ = true; 42 dom_automation_enabled_ = true;
(...skipping 15 matching lines...) Expand all
58 CheckTitleTest(L"content-sniffer-test1.html", L""); 58 CheckTitleTest(L"content-sniffer-test1.html", L"");
59 } 59 }
60 60
61 TEST_F(ResourceDispatcherTest, DoNotSniffHTMLFromImageGIF) { 61 TEST_F(ResourceDispatcherTest, DoNotSniffHTMLFromImageGIF) {
62 CheckTitleTest(L"content-sniffer-test2.html", L""); 62 CheckTitleTest(L"content-sniffer-test2.html", L"");
63 } 63 }
64 64
65 TEST_F(ResourceDispatcherTest, SniffNoContentTypeNoData) { 65 TEST_F(ResourceDispatcherTest, SniffNoContentTypeNoData) {
66 CheckTitleTest(L"content-sniffer-test3.html", 66 CheckTitleTest(L"content-sniffer-test3.html",
67 L"Content Sniffer Test 3"); 67 L"Content Sniffer Test 3");
68 Sleep(sleep_timeout_ms() * 2); 68 PlatformThread::Sleep(sleep_timeout_ms() * 2);
69 EXPECT_EQ(1, GetTabCount()); 69 EXPECT_EQ(1, GetTabCount());
70 70
71 // Make sure the download shelf is not showing. 71 // Make sure the download shelf is not showing.
72 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 72 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
73 scoped_ptr<TabProxy> dl_tab(browser->GetTab(0)); 73 scoped_ptr<TabProxy> dl_tab(browser->GetTab(0));
74 ASSERT_TRUE(dl_tab.get()); 74 ASSERT_TRUE(dl_tab.get());
75 75
76 bool visible = false; 76 bool visible = false;
77 ASSERT_TRUE(dl_tab->IsShelfVisible(&visible)); 77 ASSERT_TRUE(dl_tab->IsShelfVisible(&visible));
78 EXPECT_FALSE(visible); 78 EXPECT_FALSE(visible);
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 if (in_process_renderer()) 203 if (in_process_renderer())
204 return; 204 return;
205 205
206 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 206 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0));
207 EXPECT_TRUE(browser_proxy.get()); 207 EXPECT_TRUE(browser_proxy.get());
208 scoped_ptr<TabProxy> tab(browser_proxy->GetActiveTab()); 208 scoped_ptr<TabProxy> tab(browser_proxy->GetActiveTab());
209 209
210 // Cause the renderer to crash. 210 // Cause the renderer to crash.
211 expected_crashes_ = 1; 211 expected_crashes_ = 1;
212 tab->NavigateToURLAsync(GURL("about:crash")); 212 tab->NavigateToURLAsync(GURL("about:crash"));
213 Sleep(sleep_timeout_ms()); // Wait for browser to notice the renderer crash. 213
214 // Wait for browser to notice the renderer crash.
215 PlatformThread::Sleep(sleep_timeout_ms());
214 216
215 // Navigate to a new cross-site page. The browser should not wait around for 217 // Navigate to a new cross-site page. The browser should not wait around for
216 // the old renderer's on{before}unload handlers to run. 218 // the old renderer's on{before}unload handlers to run.
217 CheckTitleTest(L"content-sniffer-test0.html", 219 CheckTitleTest(L"content-sniffer-test0.html",
218 L"Content Sniffer Test 0"); 220 L"Content Sniffer Test 0");
219 } 221 }
220 222
221 // Tests that cross-site navigations work when the new page does not go through 223 // Tests that cross-site navigations work when the new page does not go through
222 // the BufferedEventHandler (e.g., non-http{s} URLs). (Bug 1225872) 224 // the BufferedEventHandler (e.g., non-http{s} URLs). (Bug 1225872)
223 TEST_F(ResourceDispatcherTest, CrossSiteNavigationNonBuffered) { 225 TEST_F(ResourceDispatcherTest, CrossSiteNavigationNonBuffered) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 std::wstring tab_title; 263 std::wstring tab_title;
262 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); 264 EXPECT_TRUE(tab->GetTabTitle(&tab_title));
263 EXPECT_EQ(L"set cookie on unload", tab_title); 265 EXPECT_EQ(L"set cookie on unload", tab_title);
264 266
265 // Navigate to a new cross-site URL that results in an error page. We must 267 // Navigate to a new cross-site URL that results in an error page. We must
266 // wait for the error page to update the title. 268 // wait for the error page to update the title.
267 // TODO(creis): If this causes crashes or hangs, it might be for the same 269 // TODO(creis): If this causes crashes or hangs, it might be for the same
268 // reason as ErrorPageTest::DNSError. See bug 1199491. 270 // reason as ErrorPageTest::DNSError. See bug 1199491.
269 tab->NavigateToURL(GURL(URLRequestFailedDnsJob::kTestUrl)); 271 tab->NavigateToURL(GURL(URLRequestFailedDnsJob::kTestUrl));
270 for (int i = 0; i < 10; ++i) { 272 for (int i = 0; i < 10; ++i) {
271 Sleep(sleep_timeout_ms()); 273 PlatformThread::Sleep(sleep_timeout_ms());
272 if (GetActiveTabTitle() != L"set cookie on unload") { 274 if (GetActiveTabTitle() != L"set cookie on unload") {
273 // Success, bail out. 275 // Success, bail out.
274 break; 276 break;
275 } 277 }
276 } 278 }
277 EXPECT_NE(L"set cookie on unload", GetActiveTabTitle()); 279 EXPECT_NE(L"set cookie on unload", GetActiveTabTitle());
278 280
279 // Check that the cookie was set, meaning that the onunload handler ran. 281 // Check that the cookie was set, meaning that the onunload handler ran.
280 std::string value_result; 282 std::string value_result;
281 EXPECT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result)); 283 EXPECT_TRUE(tab->GetCookieByName(url, "onunloadCookie", &value_result));
282 EXPECT_FALSE(value_result.empty()); 284 EXPECT_FALSE(value_result.empty());
283 EXPECT_STREQ("foo", value_result.c_str()); 285 EXPECT_STREQ("foo", value_result.c_str());
284 286
285 // Check that renderer-initiated navigations still work. In a previous bug, 287 // Check that renderer-initiated navigations still work. In a previous bug,
286 // the ResourceDispatcherHost would think that such navigations were 288 // the ResourceDispatcherHost would think that such navigations were
287 // cross-site, because we didn't clean up from the previous request. Since 289 // cross-site, because we didn't clean up from the previous request. Since
288 // WebContents was in the NORMAL state, it would ignore the attempt to run 290 // WebContents was in the NORMAL state, it would ignore the attempt to run
289 // the onunload handler, and the navigation would fail. 291 // the onunload handler, and the navigation would fail.
290 // (Test by redirecting to javascript:window.location='someURL'.) 292 // (Test by redirecting to javascript:window.location='someURL'.)
291 GURL test_url(server->TestServerPageW(L"files/title2.html")); 293 GURL test_url(server->TestServerPageW(L"files/title2.html"));
292 std::wstring redirect_url = L"javascript:window.location='" + 294 std::wstring redirect_url = L"javascript:window.location='" +
293 ASCIIToWide(test_url.possibly_invalid_spec()) + L"'"; 295 ASCIIToWide(test_url.possibly_invalid_spec()) + L"'";
294 tab->NavigateToURLAsync(GURL(redirect_url)); 296 tab->NavigateToURLAsync(GURL(redirect_url));
295 Sleep(sleep_timeout_ms()); // Wait for JavaScript redirect to happen. 297
298 // Wait for JavaScript redirect to happen.
299 PlatformThread::Sleep(sleep_timeout_ms());
296 EXPECT_TRUE(tab->GetTabTitle(&tab_title)); 300 EXPECT_TRUE(tab->GetTabTitle(&tab_title));
297 EXPECT_EQ(L"Title Of Awesomeness", tab_title); 301 EXPECT_EQ(L"Title Of Awesomeness", tab_title);
298 } 302 }
OLDNEW
« no previous file with comments | « chrome/browser/printing/printing_layout_uitest.cc ('k') | chrome/browser/tab_contents/view_source_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698