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

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

Issue 113722: Make automation proxy objects to ref_counted. That allows to process async no... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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-2009 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 "app/message_box_flags.h" 5 #include "app/message_box_flags.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/platform_thread.h" 7 #include "base/platform_thread.h"
8 #include "chrome/browser/automation/url_request_mock_http_job.h" 8 #include "chrome/browser/automation/url_request_mock_http_job.h"
9 #include "chrome/common/chrome_switches.h" 9 #include "chrome/common/chrome_switches.h"
10 #include "chrome/test/automation/browser_proxy.h" 10 #include "chrome/test/automation/browser_proxy.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); 139 URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
140 PlatformThread::Sleep(400); 140 PlatformThread::Sleep(400);
141 NavigateToURL( 141 NavigateToURL(
142 URLRequestMockHTTPJob::GetMockUrl(L"title2.html")); 142 URLRequestMockHTTPJob::GetMockUrl(L"title2.html"));
143 143
144 CheckTitle(L"Title Of Awesomeness"); 144 CheckTitle(L"Title Of Awesomeness");
145 } 145 }
146 146
147 void LoadUrlAndQuitBrowser(const std::string& html_content, 147 void LoadUrlAndQuitBrowser(const std::string& html_content,
148 const std::wstring& expected_title = L"") { 148 const std::wstring& expected_title = L"") {
149 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 149 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
150 NavigateToDataURL(html_content, expected_title); 150 NavigateToDataURL(html_content, expected_title);
151 bool application_closed = false; 151 bool application_closed = false;
152 EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed)); 152 EXPECT_TRUE(CloseBrowser(browser.get(), &application_closed));
153 } 153 }
154 154
155 void ClickModalDialogButton(MessageBoxFlags::DialogButton button) { 155 void ClickModalDialogButton(MessageBoxFlags::DialogButton button) {
156 #if defined(OS_WIN) || defined(OS_LINUX) 156 #if defined(OS_WIN) || defined(OS_LINUX)
157 bool modal_dialog_showing = false; 157 bool modal_dialog_showing = false;
158 MessageBoxFlags::DialogButton available_buttons; 158 MessageBoxFlags::DialogButton available_buttons;
159 EXPECT_TRUE(automation()->WaitForAppModalDialog(3000)); 159 EXPECT_TRUE(automation()->WaitForAppModalDialog(3000));
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 } 232 }
233 233
234 // Tests closing the browser on a page with an unload listener registered. 234 // Tests closing the browser on a page with an unload listener registered.
235 TEST_F(UnloadTest, BrowserCloseUnload) { 235 TEST_F(UnloadTest, BrowserCloseUnload) {
236 LoadUrlAndQuitBrowser(UNLOAD_HTML, L"unload"); 236 LoadUrlAndQuitBrowser(UNLOAD_HTML, L"unload");
237 } 237 }
238 238
239 // Tests closing the browser with a beforeunload handler and clicking 239 // Tests closing the browser with a beforeunload handler and clicking
240 // OK in the beforeunload confirm dialog. 240 // OK in the beforeunload confirm dialog.
241 TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) { 241 TEST_F(UnloadTest, BrowserCloseBeforeUnloadOK) {
242 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 242 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
243 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); 243 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload");
244 244
245 CloseBrowserAsync(browser.get()); 245 CloseBrowserAsync(browser.get());
246 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); 246 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK);
247 WaitForBrowserClosed(); 247 WaitForBrowserClosed();
248 EXPECT_FALSE(IsBrowserRunning()); 248 EXPECT_FALSE(IsBrowserRunning());
249 } 249 }
250 250
251 // Tests closing the browser with a beforeunload handler and clicking 251 // Tests closing the browser with a beforeunload handler and clicking
252 // CANCEL in the beforeunload confirm dialog. 252 // CANCEL in the beforeunload confirm dialog.
253 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) { 253 TEST_F(UnloadTest, BrowserCloseBeforeUnloadCancel) {
254 scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 254 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
255 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload"); 255 NavigateToDataURL(BEFORE_UNLOAD_HTML, L"beforeunload");
256 256
257 CloseBrowserAsync(browser.get()); 257 CloseBrowserAsync(browser.get());
258 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_CANCEL); 258 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_CANCEL);
259 WaitForBrowserClosed(); 259 WaitForBrowserClosed();
260 EXPECT_TRUE(IsBrowserRunning()); 260 EXPECT_TRUE(IsBrowserRunning());
261 261
262 CloseBrowserAsync(browser.get()); 262 CloseBrowserAsync(browser.get());
263 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK); 263 ClickModalDialogButton(MessageBoxFlags::DIALOGBUTTON_OK);
264 WaitForBrowserClosed(); 264 WaitForBrowserClosed();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 329
330 // Tests that if there's a renderer process with two tabs, one of which has an 330 // Tests that if there's a renderer process with two tabs, one of which has an
331 // unload handler, and the other doesn't, the tab that doesn't have an unload 331 // unload handler, and the other doesn't, the tab that doesn't have an unload
332 // handler can be closed. If this test fails, the Close() call will hang. 332 // handler can be closed. If this test fails, the Close() call will hang.
333 TEST_F(UnloadTest, BrowserCloseTabWhenOtherTabHasListener) { 333 TEST_F(UnloadTest, BrowserCloseTabWhenOtherTabHasListener) {
334 NavigateToDataURL(CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER, L"only_one_unload"); 334 NavigateToDataURL(CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER, L"only_one_unload");
335 int window_count; 335 int window_count;
336 automation()->GetBrowserWindowCount(&window_count); 336 automation()->GetBrowserWindowCount(&window_count);
337 ASSERT_EQ(2, window_count); 337 ASSERT_EQ(2, window_count);
338 338
339 scoped_ptr<BrowserProxy> popup_browser_proxy( 339 scoped_refptr<BrowserProxy> popup_browser_proxy(
340 automation()->GetBrowserWindow(1)); 340 automation()->GetBrowserWindow(1));
341 ASSERT_TRUE(popup_browser_proxy.get()); 341 ASSERT_TRUE(popup_browser_proxy.get());
342 int popup_tab_count; 342 int popup_tab_count;
343 EXPECT_TRUE(popup_browser_proxy->GetTabCount(&popup_tab_count)); 343 EXPECT_TRUE(popup_browser_proxy->GetTabCount(&popup_tab_count));
344 EXPECT_EQ(1, popup_tab_count); 344 EXPECT_EQ(1, popup_tab_count);
345 scoped_ptr<TabProxy> popup_tab(popup_browser_proxy->GetActiveTab()); 345 scoped_refptr<TabProxy> popup_tab(popup_browser_proxy->GetActiveTab());
346 std::wstring popup_title; 346 std::wstring popup_title;
347 ASSERT_TRUE(popup_tab.get() != NULL); 347 ASSERT_TRUE(popup_tab.get() != NULL);
348 EXPECT_TRUE(popup_tab->GetTabTitle(&popup_title)); 348 EXPECT_TRUE(popup_tab->GetTabTitle(&popup_title));
349 EXPECT_EQ(std::wstring(L"popup"), popup_title); 349 EXPECT_EQ(std::wstring(L"popup"), popup_title);
350 EXPECT_TRUE(popup_tab->Close(true)); 350 EXPECT_TRUE(popup_tab->Close(true));
351 351
352 scoped_ptr<BrowserProxy> main_browser_proxy( 352 scoped_refptr<BrowserProxy> main_browser_proxy(
353 automation()->GetBrowserWindow(0)); 353 automation()->GetBrowserWindow(0));
354 ASSERT_TRUE(main_browser_proxy.get()); 354 ASSERT_TRUE(main_browser_proxy.get());
355 int main_tab_count; 355 int main_tab_count;
356 EXPECT_TRUE(main_browser_proxy->GetTabCount(&main_tab_count)); 356 EXPECT_TRUE(main_browser_proxy->GetTabCount(&main_tab_count));
357 EXPECT_EQ(1, main_tab_count); 357 EXPECT_EQ(1, main_tab_count);
358 scoped_ptr<TabProxy> main_tab(main_browser_proxy->GetActiveTab()); 358 scoped_refptr<TabProxy> main_tab(main_browser_proxy->GetActiveTab());
359 std::wstring main_title; 359 std::wstring main_title;
360 ASSERT_TRUE(main_tab.get() != NULL); 360 ASSERT_TRUE(main_tab.get() != NULL);
361 EXPECT_TRUE(main_tab->GetTabTitle(&main_title)); 361 EXPECT_TRUE(main_tab->GetTabTitle(&main_title));
362 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title); 362 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title);
363 } 363 }
364 364
365 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 365 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
366 // and multiple windows. 366 // and multiple windows.
OLDNEW
« no previous file with comments | « chrome/browser/tab_restore_uitest.cc ('k') | chrome/browser/views/constrained_window_impl_interactive_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698