[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "base/command_line.h" |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 6 | #include "chrome/browser/browser.h" |
| 7 | #include "chrome/browser/browser_list.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 8 | #include "chrome/browser/extensions/extension_apitest.h" |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 9 | #include "chrome/browser/tab_contents/tab_contents.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 10 | #include "chrome/common/chrome_switches.h" |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 11 | #include "chrome/test/ui_test_utils.h" |
| 12 | #include "net/base/mock_host_resolver.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 13 | |
[email protected] | dd3ea90 | 2010-09-01 05:10:48 | [diff] [blame] | 14 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, FLAKY_WindowOpen) { |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 15 | CommandLine::ForCurrentProcess()->AppendSwitch( |
| 16 | switches::kEnableExperimentalExtensionApis); |
| 17 | |
| 18 | ResultCatcher catcher; |
| 19 | ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
| 20 | .AppendASCII("window_open").AppendASCII("spanning"))); |
| 21 | EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 22 | } |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 23 | |
| 24 | void WaitForTabsAndPopups(Browser* browser, int num_tabs, int num_popups) { |
| 25 | // We start with one tab and one browser already open. |
| 26 | ++num_tabs; |
| 27 | size_t num_browsers = static_cast<size_t>(num_popups) + 1; |
| 28 | |
| 29 | while (true) { |
| 30 | if (BrowserList::GetBrowserCount(browser->profile()) < num_browsers || |
| 31 | browser->tab_count() < num_tabs) { |
| 32 | MessageLoopForUI::current()->RunAllPending(); |
| 33 | continue; |
| 34 | } |
| 35 | |
| 36 | ASSERT_EQ(num_browsers, BrowserList::GetBrowserCount(browser->profile())); |
| 37 | ASSERT_EQ(num_tabs, browser->tab_count()); |
| 38 | |
| 39 | for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 40 | iter != BrowserList::end(); ++iter) { |
| 41 | if (*iter == browser) |
| 42 | continue; |
| 43 | |
[email protected] | 1b74d212 | 2010-10-06 16:49:16 | [diff] [blame^] | 44 | // Check for TYPE_POPUP or TYPE_APP_POPUP/PANEL. |
| 45 | ASSERT_TRUE((*iter)->type() & Browser::TYPE_POPUP); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingExtension) { |
| 53 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 54 | ASSERT_TRUE(test_server()->Start()); |
| 55 | |
| 56 | ASSERT_TRUE(LoadExtension( |
| 57 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 58 | .AppendASCII("extension"))); |
| 59 | |
| 60 | WaitForTabsAndPopups(browser(), 5, 3); |
| 61 | } |
| 62 | |
| 63 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) { |
| 64 | host_resolver()->AddRule("*", "127.0.0.1"); |
| 65 | ASSERT_TRUE(test_server()->Start()); |
| 66 | |
| 67 | ASSERT_TRUE(LoadExtension( |
| 68 | test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 69 | .AppendASCII("hosted_app"))); |
| 70 | |
| 71 | std::string app_base("http://a.com:1337/files/extensions/api_test/" |
| 72 | "window_open/popup_blocking/hosted_app/"); |
| 73 | browser()->OpenURL(GURL(app_base + "open_tab.html"), GURL(), |
| 74 | NEW_FOREGROUND_TAB, PageTransition::TYPED); |
| 75 | browser()->OpenURL(GURL(app_base + "open_popup.html"), GURL(), |
| 76 | NEW_FOREGROUND_TAB, PageTransition::TYPED); |
| 77 | |
| 78 | WaitForTabsAndPopups(browser(), 3, 1); |
| 79 | } |