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

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

Issue 99203: Second attempt at cleaning up handling of --disable-popup-blocking. I didn't... (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
« no previous file with comments | « chrome/browser/tab_contents/tab_contents.cc ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/platform_thread.h" 6 #include "base/platform_thread.h"
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/common/message_box_flags.h" 9 #include "chrome/common/message_box_flags.h"
10 #include "chrome/test/automation/browser_proxy.h" 10 #include "chrome/test/automation/browser_proxy.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const std::string TWO_SECOND_BEFORE_UNLOAD_ALERT_HTML = 67 const std::string TWO_SECOND_BEFORE_UNLOAD_ALERT_HTML =
68 "<html><head><title>twosecondbeforeunloadalert</title></head><body>" 68 "<html><head><title>twosecondbeforeunloadalert</title></head><body>"
69 "<script>window.onbeforeunload=function(e){" 69 "<script>window.onbeforeunload=function(e){"
70 "var start = new Date().getTime();" 70 "var start = new Date().getTime();"
71 "while(new Date().getTime() - start < 2000){}" 71 "while(new Date().getTime() - start < 2000){}"
72 "alert('foo');" 72 "alert('foo');"
73 "}</script></body></html>"; 73 "}</script></body></html>";
74 74
75 const std::string CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER = 75 const std::string CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER =
76 "<html><head><title>only_one_unload</title></head>" 76 "<html><head><title>only_one_unload</title></head>"
77 "<body onload=\"window.open('data:text/html,<html><head><title>second_tab</t itle></head></body>')\" " 77 "<body onload=\"window.open('data:text/html,<html><head><title>popup</title> </head></body>')\" "
78 "onbeforeunload='return;'" 78 "onbeforeunload='return;'"
79 "</body></html>"; 79 "</body></html>";
80 80
81 class UnloadTest : public UITest { 81 class UnloadTest : public UITest {
82 public: 82 public:
83 virtual void SetUp() { 83 virtual void SetUp() {
84 const testing::TestInfo* const test_info = 84 const testing::TestInfo* const test_info =
85 testing::UnitTest::GetInstance()->current_test_info(); 85 testing::UnitTest::GetInstance()->current_test_info();
86 if (strcmp(test_info->name(), 86 if (strcmp(test_info->name(),
87 "BrowserCloseTabWhenOtherTabHasListener") == 0) { 87 "BrowserCloseTabWhenOtherTabHasListener") == 0) {
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 // two seconds to run then pops up an alert. 330 // two seconds to run then pops up an alert.
331 TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnloadAlert) { 331 TEST_F(UnloadTest, BrowserCloseTwoSecondBeforeUnloadAlert) {
332 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_ALERT_HTML, 332 LoadUrlAndQuitBrowser(TWO_SECOND_BEFORE_UNLOAD_ALERT_HTML,
333 L"twosecondbeforeunloadalert"); 333 L"twosecondbeforeunloadalert");
334 } 334 }
335 335
336 // Tests that if there's a renderer process with two tabs, one of which has an 336 // Tests that if there's a renderer process with two tabs, one of which has an
337 // unload handler, and the other doesn't, the tab that doesn't have an unload 337 // unload handler, and the other doesn't, the tab that doesn't have an unload
338 // handler can be closed. If this test fails, the Close() call will hang. 338 // handler can be closed. If this test fails, the Close() call will hang.
339 TEST_F(UnloadTest, BrowserCloseTabWhenOtherTabHasListener) { 339 TEST_F(UnloadTest, BrowserCloseTabWhenOtherTabHasListener) {
340 NavigateToDataURL(CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER, L"second_tab"); 340 NavigateToDataURL(CLOSE_TAB_WHEN_OTHER_TAB_HAS_LISTENER, L"only_one_unload");
341 int window_count;
342 automation()->GetBrowserWindowCount(&window_count);
343 ASSERT_EQ(2, window_count);
341 344
342 scoped_ptr<BrowserProxy> browser_proxy(automation()->GetBrowserWindow(0)); 345 scoped_ptr<BrowserProxy> popup_browser_proxy(
343 EXPECT_TRUE(browser_proxy.get()); 346 automation()->GetBrowserWindow(1));
347 ASSERT_TRUE(popup_browser_proxy.get());
348 int popup_tab_count;
349 EXPECT_TRUE(popup_browser_proxy->GetTabCount(&popup_tab_count));
350 EXPECT_EQ(1, popup_tab_count);
351 scoped_ptr<TabProxy> popup_tab(popup_browser_proxy->GetActiveTab());
352 std::wstring popup_title;
353 ASSERT_TRUE(popup_tab.get() != NULL);
354 EXPECT_TRUE(popup_tab->GetTabTitle(&popup_title));
355 EXPECT_EQ(std::wstring(L"popup"), popup_title);
356 EXPECT_TRUE(popup_tab->Close(true));
344 357
345 int tab_count; 358 scoped_ptr<BrowserProxy> main_browser_proxy(
346 EXPECT_TRUE(browser_proxy->GetTabCount(&tab_count)); 359 automation()->GetBrowserWindow(0));
347 EXPECT_EQ(tab_count, 2); 360 ASSERT_TRUE(main_browser_proxy.get());
348 361 int main_tab_count;
349 scoped_ptr<TabProxy> second_tab(browser_proxy->GetActiveTab()); 362 EXPECT_TRUE(main_browser_proxy->GetTabCount(&main_tab_count));
350 EXPECT_TRUE(second_tab.get()!= NULL); 363 EXPECT_EQ(1, main_tab_count);
351 EXPECT_TRUE(second_tab->Close(true)); 364 scoped_ptr<TabProxy> main_tab(main_browser_proxy->GetActiveTab());
352 365 std::wstring main_title;
353 scoped_ptr<TabProxy> first_tab(browser_proxy->GetActiveTab()); 366 ASSERT_TRUE(main_tab.get() != NULL);
354 std::wstring title; 367 EXPECT_TRUE(main_tab->GetTabTitle(&main_title));
355 EXPECT_TRUE(first_tab.get() != NULL); 368 EXPECT_EQ(std::wstring(L"only_one_unload"), main_title);
356 EXPECT_TRUE(first_tab->GetTabTitle(&title));
357 EXPECT_EQ(title, L"only_one_unload");
358 } 369 }
359 370
360 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs 371 // TODO(ojan): Add tests for unload/beforeunload that have multiple tabs
361 // and multiple windows. 372 // and multiple windows.
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/tab_contents.cc ('k') | chrome/renderer/render_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698