| OLD | NEW |
| 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 | 6 |
| 7 #include "chrome/browser/automation/url_request_mock_http_job.h" | 7 #include "chrome/browser/automation/url_request_mock_http_job.h" |
| 8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
| 9 #include "chrome/test/automation/browser_proxy.h" | 9 #include "chrome/test/automation/browser_proxy.h" |
| 10 #include "chrome/test/ui/ui_test.h" | 10 #include "chrome/test/ui/ui_test.h" |
| 11 #include "chrome/views/window/dialog_delegate.h" | 11 #include "chrome/views/window/dialog_delegate.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 "alert('foo');" | 71 "alert('foo');" |
| 72 "}</script></body></html>"; | 72 "}</script></body></html>"; |
| 73 | 73 |
| 74 class UnloadTest : public UITest { | 74 class UnloadTest : public UITest { |
| 75 public: | 75 public: |
| 76 void WaitForBrowserClosed() { | 76 void WaitForBrowserClosed() { |
| 77 const int kCheckDelayMs = 100; | 77 const int kCheckDelayMs = 100; |
| 78 int max_wait_time = 5000; | 78 int max_wait_time = 5000; |
| 79 while (max_wait_time > 0) { | 79 while (max_wait_time > 0) { |
| 80 max_wait_time -= kCheckDelayMs; | 80 max_wait_time -= kCheckDelayMs; |
| 81 Sleep(kCheckDelayMs); | 81 PlatformThread::Sleep(kCheckDelayMs); |
| 82 if (!IsBrowserRunning()) | 82 if (!IsBrowserRunning()) |
| 83 break; | 83 break; |
| 84 } | 84 } |
| 85 } | 85 } |
| 86 | 86 |
| 87 void CheckTitle(const std::wstring& expected_title) { | 87 void CheckTitle(const std::wstring& expected_title) { |
| 88 const int kCheckDelayMs = 100; | 88 const int kCheckDelayMs = 100; |
| 89 int max_wait_time = 5000; | 89 int max_wait_time = 5000; |
| 90 while (max_wait_time > 0) { | 90 while (max_wait_time > 0) { |
| 91 max_wait_time -= kCheckDelayMs; | 91 max_wait_time -= kCheckDelayMs; |
| 92 Sleep(kCheckDelayMs); | 92 PlatformThread::Sleep(kCheckDelayMs); |
| 93 if (expected_title == GetActiveTabTitle()) | 93 if (expected_title == GetActiveTabTitle()) |
| 94 break; | 94 break; |
| 95 } | 95 } |
| 96 | 96 |
| 97 EXPECT_EQ(expected_title, GetActiveTabTitle()); | 97 EXPECT_EQ(expected_title, GetActiveTabTitle()); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void NavigateToDataURL(const std::string& html_content, | 100 void NavigateToDataURL(const std::string& html_content, |
| 101 const std::wstring& expected_title) { | 101 const std::wstring& expected_title) { |
| 102 NavigateToURL(GURL("data:text/html," + html_content)); | 102 NavigateToURL(GURL("data:text/html," + html_content)); |
| 103 CheckTitle(expected_title); | 103 CheckTitle(expected_title); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void NavigateToNolistenersFileTwice() { | 106 void NavigateToNolistenersFileTwice() { |
| 107 NavigateToURL( | 107 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 108 URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | |
| 109 CheckTitle(L"Title Of Awesomeness"); | 108 CheckTitle(L"Title Of Awesomeness"); |
| 110 NavigateToURL( | 109 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 111 URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | |
| 112 CheckTitle(L"Title Of Awesomeness"); | 110 CheckTitle(L"Title Of Awesomeness"); |
| 113 } | 111 } |
| 114 | 112 |
| 115 // Navigates to a URL asynchronously, then again synchronously. The first | 113 // Navigates to a URL asynchronously, then again synchronously. The first |
| 116 // load is purposely async to test the case where the user loads another | 114 // load is purposely async to test the case where the user loads another |
| 117 // page without waiting for the first load to complete. | 115 // page without waiting for the first load to complete. |
| 118 void NavigateToNolistenersFileTwiceAsync() { | 116 void NavigateToNolistenersFileTwiceAsync() { |
| 119 // TODO(ojan): We hit a DCHECK in RenderViewHost::OnMsgShouldCloseACK | 117 // TODO(ojan): We hit a DCHECK in RenderViewHost::OnMsgShouldCloseACK |
| 120 // if we don't sleep here. | 118 // if we don't sleep here. |
| 121 Sleep(400); | 119 PlatformThread::Sleep(400); |
| 122 NavigateToURLAsync( | 120 NavigateToURLAsync(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 123 URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | 121 PlatformThread::Sleep(400); |
| 124 Sleep(400); | 122 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); |
| 125 NavigateToURL( | |
| 126 URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); | |
| 127 | 123 |
| 128 CheckTitle(L"Title Of Awesomeness"); | 124 CheckTitle(L"Title Of Awesomeness"); |
| 129 } | 125 } |
| 130 | 126 |
| 131 void LoadUrlAndQuitBrowser(const std::string& html_content, | 127 void LoadUrlAndQuitBrowser(const std::string& html_content, |
| 132 const std::wstring& expected_title = L"") { | 128 const std::wstring& expected_title = L"") { |
| 133 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | 129 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 134 NavigateToDataURL(html_content, expected_title); | 130 NavigateToDataURL(html_content, expected_title); |
| 135 bool application_closed = false; | 131 bool application_closed = false; |
| 136 EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed)); | 132 EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed)); |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 294 |
| 299 // Tests closing the browser with a beforeunload handler that takes | 295 // Tests closing the browser with a beforeunload handler that takes |
| 300 // two seconds to run then pops up an alert. | 296 // two seconds to run then pops up an alert. |
| 301 TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnloadAlert) { | 297 TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnloadAlert) { |
| 302 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_ALERT_HTML, | 298 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_ALERT_HTML, |
| 303 L"twosecondbeforeunloadalert"); | 299 L"twosecondbeforeunloadalert"); |
| 304 } | 300 } |
| 305 | 301 |
| 306 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs | 302 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs |
| 307 // and multiple windows. | 303 // and multiple windows. |
| OLD | NEW |