diff options
author | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-14 19:35:04 +0000 |
---|---|---|
committer | aa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-14 19:35:04 +0000 |
commit | 4026ce1e61982fe637913ea59c66f16c5d9165ee (patch) | |
tree | fe76ee7ad7ee03c4eae14b8cd7b5a99a8f8097c2 /chrome/browser/extensions/window_open_apitest.cc | |
parent | 2958211007b5f2ac195b38346cbe9b3116792d13 (diff) | |
download | chromium_src-4026ce1e61982fe637913ea59c66f16c5d9165ee.zip chromium_src-4026ce1e61982fe637913ea59c66f16c5d9165ee.tar.gz chromium_src-4026ce1e61982fe637913ea59c66f16c5d9165ee.tar.bz2 |
Land implementation part of cl 3352009 (that cl was just data
files that had to be uploaded first for try runs to work).
This makes window.open() open a tab or popup window correctly from extensions, even when no user gesture is present.
BUG=54768
TEST=Added browser tests.
Review URL: http://codereview.chromium.org/3325024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59418 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/window_open_apitest.cc')
-rw-r--r-- | chrome/browser/extensions/window_open_apitest.cc | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/chrome/browser/extensions/window_open_apitest.cc b/chrome/browser/extensions/window_open_apitest.cc index a0b710b..931a83a 100644 --- a/chrome/browser/extensions/window_open_apitest.cc +++ b/chrome/browser/extensions/window_open_apitest.cc @@ -3,8 +3,13 @@ // found in the LICENSE file. #include "base/command_line.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/browser_list.h" #include "chrome/browser/extensions/extension_apitest.h" +#include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/chrome_switches.h" +#include "chrome/test/ui_test_utils.h" +#include "net/base/mock_host_resolver.h" IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FLAKY_WindowOpen) { CommandLine::ForCurrentProcess()->AppendSwitch( @@ -15,3 +20,59 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FLAKY_WindowOpen) { .AppendASCII("window_open").AppendASCII("spanning"))); EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); } + +void WaitForTabsAndPopups(Browser* browser, int num_tabs, int num_popups) { + // We start with one tab and one browser already open. + ++num_tabs; + size_t num_browsers = static_cast<size_t>(num_popups) + 1; + + while (true) { + if (BrowserList::GetBrowserCount(browser->profile()) < num_browsers || + browser->tab_count() < num_tabs) { + MessageLoopForUI::current()->RunAllPending(); + continue; + } + + ASSERT_EQ(num_browsers, BrowserList::GetBrowserCount(browser->profile())); + ASSERT_EQ(num_tabs, browser->tab_count()); + + for (BrowserList::const_iterator iter = BrowserList::begin(); + iter != BrowserList::end(); ++iter) { + if (*iter == browser) + continue; + + ASSERT_EQ(Browser::TYPE_POPUP, (*iter)->type()); + } + + break; + } +} + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingExtension) { + host_resolver()->AddRule("*", "127.0.0.1"); + ASSERT_TRUE(test_server()->Start()); + + ASSERT_TRUE(LoadExtension( + test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") + .AppendASCII("extension"))); + + WaitForTabsAndPopups(browser(), 5, 3); +} + +IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) { + host_resolver()->AddRule("*", "127.0.0.1"); + ASSERT_TRUE(test_server()->Start()); + + ASSERT_TRUE(LoadExtension( + test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") + .AppendASCII("hosted_app"))); + + std::string app_base("http://a.com:1337/files/extensions/api_test/" + "window_open/popup_blocking/hosted_app/"); + browser()->OpenURL(GURL(app_base + "open_tab.html"), GURL(), + NEW_FOREGROUND_TAB, PageTransition::TYPED); + browser()->OpenURL(GURL(app_base + "open_popup.html"), GURL(), + NEW_FOREGROUND_TAB, PageTransition::TYPED); + + WaitForTabsAndPopups(browser(), 3, 1); +} |