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

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

Issue 9215005: Revert 117824 - Convert use of int ms to TimeDelta in files owned by brettw. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 11 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/test/test_timeouts.h" 6 #include "base/test/test_timeouts.h"
7 #include "chrome/browser/ui/view_ids.h" 7 #include "chrome/browser/ui/view_ids.h"
8 #include "chrome/common/chrome_switches.h" 8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/test/automation/automation_proxy.h" 9 #include "chrome/test/automation/automation_proxy.h"
10 #include "chrome/test/automation/browser_proxy.h" 10 #include "chrome/test/automation/browser_proxy.h"
11 #include "chrome/test/automation/tab_proxy.h" 11 #include "chrome/test/automation/tab_proxy.h"
12 #include "chrome/test/automation/window_proxy.h" 12 #include "chrome/test/automation/window_proxy.h"
13 #include "chrome/test/ui/ui_test.h" 13 #include "chrome/test/ui/ui_test.h"
14 #include "content/browser/net/url_request_mock_http_job.h" 14 #include "content/browser/net/url_request_mock_http_job.h"
15 #include "net/url_request/url_request_test_util.h" 15 #include "net/url_request/url_request_test_util.h"
16 #include "ui/base/events.h" 16 #include "ui/base/events.h"
17 #include "ui/base/ui_base_types.h" 17 #include "ui/base/ui_base_types.h"
18 18
19 using base::TimeDelta;
20
21 const std::string NOLISTENERS_HTML = 19 const std::string NOLISTENERS_HTML =
22 "<html><head><title>nolisteners</title></head><body></body></html>"; 20 "<html><head><title>nolisteners</title></head><body></body></html>";
23 21
24 const std::string UNLOAD_HTML = 22 const std::string UNLOAD_HTML =
25 "<html><head><title>unload</title></head><body>" 23 "<html><head><title>unload</title></head><body>"
26 "<script>window.onunload=function(e){}</script></body></html>"; 24 "<script>window.onunload=function(e){}</script></body></html>";
27 25
28 const std::string BEFORE_UNLOAD_HTML = 26 const std::string BEFORE_UNLOAD_HTML =
29 "<html><head><title>beforeunload</title></head><body>" 27 "<html><head><title>beforeunload</title></head><body>"
30 "<script>window.onbeforeunload=function(e){return 'foo'}</script>" 28 "<script>window.onbeforeunload=function(e){return 'foo'}</script>"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 testing::UnitTest::GetInstance()->current_test_info(); 98 testing::UnitTest::GetInstance()->current_test_info();
101 if (strcmp(test_info->name(), 99 if (strcmp(test_info->name(),
102 "BrowserCloseTabWhenOtherTabHasListener") == 0) { 100 "BrowserCloseTabWhenOtherTabHasListener") == 0) {
103 launch_arguments_.AppendSwitch(switches::kDisablePopupBlocking); 101 launch_arguments_.AppendSwitch(switches::kDisablePopupBlocking);
104 } 102 }
105 103
106 UITest::SetUp(); 104 UITest::SetUp();
107 } 105 }
108 106
109 void CheckTitle(const std::wstring& expected_title) { 107 void CheckTitle(const std::wstring& expected_title) {
110 const TimeDelta kCheckDelay = TimeDelta::FromMilliseconds(100); 108 const int kCheckDelayMs = 100;
111 for (TimeDelta max_wait_time = TestTimeouts::action_max_timeout(); 109 for (int max_wait_time = TestTimeouts::action_max_timeout_ms();
112 max_wait_time > TimeDelta(); max_wait_time -= kCheckDelay) { 110 max_wait_time > 0; max_wait_time -= kCheckDelayMs) {
113 if (expected_title == GetActiveTabTitle()) 111 if (expected_title == GetActiveTabTitle())
114 break; 112 break;
115 base::PlatformThread::Sleep(kCheckDelay); 113 base::PlatformThread::Sleep(kCheckDelayMs);
116 } 114 }
117 115
118 EXPECT_EQ(expected_title, GetActiveTabTitle()); 116 EXPECT_EQ(expected_title, GetActiveTabTitle());
119 } 117 }
120 118
121 void NavigateToDataURL(const std::string& html_content, 119 void NavigateToDataURL(const std::string& html_content,
122 const std::wstring& expected_title) { 120 const std::wstring& expected_title) {
123 NavigateToURL(GURL("data:text/html," + html_content)); 121 NavigateToURL(GURL("data:text/html," + html_content));
124 CheckTitle(expected_title); 122 CheckTitle(expected_title);
125 } 123 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { 297 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
300 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 298 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
301 ASSERT_TRUE(browser.get()); 299 ASSERT_TRUE(browser.get());
302 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); 300 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload");
303 301
304 CloseBrowserAsync(browser.get()); 302 CloseBrowserAsync(browser.get());
305 ClickModalDialogButton(ui::DIALOG_BUTTON_CANCEL); 303 ClickModalDialogButton(ui::DIALOG_BUTTON_CANCEL);
306 304
307 // There's no real graceful way to wait for something _not_ to happen, so 305 // There's no real graceful way to wait for something _not_ to happen, so
308 // we just wait a short period. 306 // we just wait a short period.
309 base::PlatformThread::Sleep(TestTimeouts::action_timeout()); 307 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms());
310 308
311 CloseBrowserAsync(browser.get()); 309 CloseBrowserAsync(browser.get());
312 ClickModalDialogButton(ui::DIALOG_BUTTON_OK); 310 ClickModalDialogButton(ui::DIALOG_BUTTON_OK);
313 311
314 int exit_code = -1; 312 int exit_code = -1;
315 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit( 313 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit(
316 TestTimeouts::action_max_timeout_ms(), &exit_code)); 314 TestTimeouts::action_max_timeout_ms(), &exit_code));
317 EXPECT_EQ(0, exit_code); // Expect a clean shutdown. 315 EXPECT_EQ(0, exit_code); // Expect a clean shutdown.
318 } 316 }
319 317
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 ASSERT_TRUE(browser->WaitForTabCountToBecome(1)); 476 ASSERT_TRUE(browser->WaitForTabCountToBecome(1));
479 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab()); 477 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab());
480 ASSERT_TRUE(main_tab.get()); 478 ASSERT_TRUE(main_tab.get());
481 std::wstring main_title; 479 std::wstring main_title;
482 EXPECT_TRUE(main_tab->GetTabTitle(&main_title)); 480 EXPECT_TRUE(main_tab->GetTabTitle(&main_title));
483 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title); 481 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title);
484 } 482 }
485 483
486 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 484 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
487 // and multiple windows. 485 // and multiple windows.
OLDNEW
« no previous file with comments | « chrome/browser/translate/translate_manager.cc ('k') | chrome/browser/visitedlink/visitedlink_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698