diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-07 19:28:16 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-07 19:28:16 +0000 |
commit | 6e4dea5b594cdd042b087ae4fc6343ab63d4af3c (patch) | |
tree | 68c896dedec2b7bade7d18cb45e2c702b82cc988 /chrome/browser/views | |
parent | c3506860d782d0e647ff213d9be89e2d0cfe93e3 (diff) | |
download | chromium_src-6e4dea5b594cdd042b087ae4fc6343ab63d4af3c.zip chromium_src-6e4dea5b594cdd042b087ae4fc6343ab63d4af3c.tar.gz chromium_src-6e4dea5b594cdd042b087ae4fc6343ab63d4af3c.tar.bz2 |
Updates one of the unit tests I disabled when I rewrote the popup blocker UI.
Review URL: http://codereview.chromium.org/10206
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r-- | chrome/browser/views/constrained_window_impl_interactive_uitest.cc | 75 |
1 files changed, 61 insertions, 14 deletions
diff --git a/chrome/browser/views/constrained_window_impl_interactive_uitest.cc b/chrome/browser/views/constrained_window_impl_interactive_uitest.cc index 5f672a3..58e504b 100644 --- a/chrome/browser/views/constrained_window_impl_interactive_uitest.cc +++ b/chrome/browser/views/constrained_window_impl_interactive_uitest.cc @@ -7,14 +7,18 @@ #include "base/file_util.h" #include "chrome/browser/view_ids.h" #include "chrome/common/chrome_constants.h" -#include "chrome/test/automation/constrained_window_proxy.h" +#include "chrome/common/l10n_util.h" +#include "chrome/test/automation/automation_constants.h" #include "chrome/test/automation/browser_proxy.h" +#include "chrome/test/automation/constrained_window_proxy.h" #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/automation/window_proxy.h" #include "chrome/test/ui/ui_test.h" #include "chrome/views/event.h" #include "net/base/net_util.h" +#include "generated_resources.h" + const int kRightCloseButtonOffset = 55; const int kBottomCloseButtonOffset = 20; @@ -92,9 +96,30 @@ TEST_F(InteractiveConstrainedWindowTest, TestOpenAndResizeTo) { ASSERT_LT(rect.height(), 200); } +// Helper function used to get the number of blocked popups out of the window +// title. +bool ParseCountOutOfTitle(const std::wstring& title, int* output) +{ + // Since we will be reading the number of popup windows open by grabbing the + // number out of the window title, and that format string is localized, we + // need to find out the offset into that string. + const wchar_t* placeholder = L"XXXX"; + size_t offset = + l10n_util::GetStringF(IDS_POPUPS_BLOCKED_COUNT, placeholder). + find(placeholder); + + std::wstring number; + while (offset < title.size() && iswdigit(title[offset])) { + number += title[offset]; + offset++; + } + + return StringToInt(number, output); +} + // Tests that in the window.open() equivalent of a fork bomb, we stop building // windows. -TEST_F(InteractiveConstrainedWindowTest, DISABLED_DontSpawnEndlessPopups) { +TEST_F(InteractiveConstrainedWindowTest, DontSpawnEndlessPopups) { scoped_ptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); ASSERT_TRUE(browser.get()); @@ -129,20 +154,42 @@ TEST_F(InteractiveConstrainedWindowTest, DISABLED_DontSpawnEndlessPopups) { scoped_ptr<TabProxy> popup_tab(popup_browser->GetTab(0)); ASSERT_TRUE(popup_tab.get()); - // And now we spin on this, waiting to make sure that we don't spawn popup + int constrained_window_count = 0; + ASSERT_TRUE(popup_tab->WaitForChildWindowCountToChange( + 0, &constrained_window_count, 10000)); + ASSERT_EQ(1, constrained_window_count); + scoped_ptr<ConstrainedWindowProxy> constrained_window( + popup_tab->GetConstrainedWindow(0)); + ASSERT_TRUE(constrained_window.get()); + + // And now we spin, waiting to make sure that we don't spawn popup // windows endlessly. The current limit is 25, so allowing for possible race - // conditions and one off errors, don't break out until we go over 35 popup + // conditions and one off errors, don't break out until we go over 30 popup // windows (in which case we are bork bork bork). - const int kMaxPopupWindows = 35; - int constrained_window_count = 0; - int new_constrained_window_count; + const int kMaxPopupWindows = 30; + + int popup_window_count = 0; + int new_popup_window_count = 0; + int times_slept = 0; bool continuing = true; - while (continuing && constrained_window_count < kMaxPopupWindows) { - continuing = popup_tab->WaitForChildWindowCountToChange( - constrained_window_count, &new_constrained_window_count, - 100000); - EXPECT_GE(new_constrained_window_count, constrained_window_count); - EXPECT_LE(new_constrained_window_count, kMaxPopupWindows); - constrained_window_count = new_constrained_window_count; + while (continuing && popup_window_count < kMaxPopupWindows) { + std::wstring title; + ASSERT_TRUE(constrained_window->GetTitle(&title)); + ASSERT_TRUE(ParseCountOutOfTitle(title, &new_popup_window_count)); + if (new_popup_window_count == popup_window_count) { + if (times_slept == 10) { + continuing = false; + } else { + // Nothing intereseting is going on wait it out. + Sleep(automation::kSleepTime); + times_slept++; + } + } else { + times_slept = 0; + } + + EXPECT_GE(new_popup_window_count, popup_window_count); + EXPECT_LE(new_popup_window_count, kMaxPopupWindows); + popup_window_count = new_popup_window_count; } } |