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

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

Issue 9233018: Convert use of int ms to TimeDelta in files owned by brettw. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase onto master. 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
OLDNEW
1 // Copyright (c) 2011 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
19 const std::string NOLISTENERS_HTML = 21 const std::string NOLISTENERS_HTML =
20 "<html><head><title>nolisteners</title></head><body></body></html>"; 22 "<html><head><title>nolisteners</title></head><body></body></html>";
21 23
22 const std::string UNLOAD_HTML = 24 const std::string UNLOAD_HTML =
23 "<html><head><title>unload</title></head><body>" 25 "<html><head><title>unload</title></head><body>"
24 "<script>window.onunload=function(e){}</script></body></html>"; 26 "<script>window.onunload=function(e){}</script></body></html>";
25 27
26 const std::string BEFORE_UNLOAD_HTML = 28 const std::string BEFORE_UNLOAD_HTML =
27 "<html><head><title>beforeunload</title></head><body>" 29 "<html><head><title>beforeunload</title></head><body>"
28 "<script>window.onbeforeunload=function(e){return 'foo'}</script>" 30 "<script>window.onbeforeunload=function(e){return 'foo'}</script>"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 testing::UnitTest::GetInstance()->current_test_info(); 100 testing::UnitTest::GetInstance()->current_test_info();
99 if (strcmp(test_info->name(), 101 if (strcmp(test_info->name(),
100 "BrowserCloseTabWhenOtherTabHasListener") == 0) { 102 "BrowserCloseTabWhenOtherTabHasListener") == 0) {
101 launch_arguments_.AppendSwitch(switches::kDisablePopupBlocking); 103 launch_arguments_.AppendSwitch(switches::kDisablePopupBlocking);
102 } 104 }
103 105
104 UITest::SetUp(); 106 UITest::SetUp();
105 } 107 }
106 108
107 void CheckTitle(const std::wstring& expected_title) { 109 void CheckTitle(const std::wstring& expected_title) {
108 const int kCheckDelayMs = 100; 110 const TimeDelta kCheckDelay = TimeDelta::FromMilliseconds(100);
109 for (int max_wait_time = TestTimeouts::action_max_timeout_ms(); 111 for (TimeDelta max_wait_time = TestTimeouts::action_max_timeout();
110 max_wait_time > 0; max_wait_time -= kCheckDelayMs) { 112 max_wait_time > TimeDelta(); max_wait_time -= kCheckDelay) {
111 if (expected_title == GetActiveTabTitle()) 113 if (expected_title == GetActiveTabTitle())
112 break; 114 break;
113 base::PlatformThread::Sleep(kCheckDelayMs); 115 base::PlatformThread::Sleep(kCheckDelay);
114 } 116 }
115 117
116 EXPECT_EQ(expected_title, GetActiveTabTitle()); 118 EXPECT_EQ(expected_title, GetActiveTabTitle());
117 } 119 }
118 120
119 void NavigateToDataURL(const std::string& html_content, 121 void NavigateToDataURL(const std::string& html_content,
120 const std::wstring& expected_title) { 122 const std::wstring& expected_title) {
121 NavigateToURL(GURL("data:text/html," + html_content)); 123 NavigateToURL(GURL("data:text/html," + html_content));
122 CheckTitle(expected_title); 124 CheckTitle(expected_title);
123 } 125 }
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { 299 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
298 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 300 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
299 ASSERT_TRUE(browser.get()); 301 ASSERT_TRUE(browser.get());
300 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); 302 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload");
301 303
302 CloseBrowserAsync(browser.get()); 304 CloseBrowserAsync(browser.get());
303 ClickModalDialogButton(ui::DIALOG_BUTTON_CANCEL); 305 ClickModalDialogButton(ui::DIALOG_BUTTON_CANCEL);
304 306
305 // There's no real graceful way to wait for something _not_ to happen, so 307 // There's no real graceful way to wait for something _not_ to happen, so
306 // we just wait a short period. 308 // we just wait a short period.
307 base::PlatformThread::Sleep(TestTimeouts::action_timeout_ms()); 309 base::PlatformThread::Sleep(TestTimeouts::action_timeout());
308 310
309 CloseBrowserAsync(browser.get()); 311 CloseBrowserAsync(browser.get());
310 ClickModalDialogButton(ui::DIALOG_BUTTON_OK); 312 ClickModalDialogButton(ui::DIALOG_BUTTON_OK);
311 313
312 int exit_code = -1; 314 int exit_code = -1;
313 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit( 315 ASSERT_TRUE(launcher_->WaitForBrowserProcessToQuit(
314 TestTimeouts::action_max_timeout_ms(), &exit_code)); 316 TestTimeouts::action_max_timeout_ms(), &exit_code));
315 EXPECT_EQ(0, exit_code); // Expect a clean shutdown. 317 EXPECT_EQ(0, exit_code); // Expect a clean shutdown.
316 } 318 }
317 319
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 ASSERT_TRUE(browser->WaitForTabCountToBecome(1)); 478 ASSERT_TRUE(browser->WaitForTabCountToBecome(1));
477 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab()); 479 scoped_refptr<TabProxy> main_tab(browser->GetActiveTab());
478 ASSERT_TRUE(main_tab.get()); 480 ASSERT_TRUE(main_tab.get());
479 std::wstring main_title; 481 std::wstring main_title;
480 EXPECT_TRUE(main_tab->GetTabTitle(&main_title)); 482 EXPECT_TRUE(main_tab->GetTabTitle(&main_title));
481 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title); 483 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title);
482 } 484 }
483 485
484 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 486 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
485 // and multiple windows. 487 // 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