[email protected] | d4db6c70 | 2011-03-28 21:49:14 | [diff] [blame^] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 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] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 6 | #include "chrome/browser/extensions/extension_apitest.h" |
[email protected] | 2ad4a90 | 2010-11-17 06:05:13 | [diff] [blame] | 7 | #include "chrome/browser/ui/browser.h" |
| 8 | #include "chrome/browser/ui/browser_list.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 9 | #include "chrome/common/chrome_switches.h" |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 10 | #include "chrome/test/ui_test_utils.h" |
| 11 | #include "net/base/mock_host_resolver.h" |
[email protected] | 32b7c49 | 2010-09-01 04:15:00 | [diff] [blame] | 12 | |
[email protected] | e78eb29 | 2010-12-22 08:35:39 | [diff] [blame] | 13 | // Disabled, http://crbug.com/64899. |
| 14 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_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"); |
[email protected] | e18a19b | 2010-10-19 20:32:30 | [diff] [blame] | 54 | ASSERT_TRUE(StartTestServer()); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 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 | |
[email protected] | fe304887 | 2010-10-18 14:58:59 | [diff] [blame] | 71 | // The app being tested owns the domain a.com . The test URLs we navigate |
| 72 | // to below must be within that domain, so that they fall within the app's |
| 73 | // web extent. |
| 74 | GURL::Replacements replace_host; |
| 75 | std::string a_dot_com = "a.com"; |
| 76 | replace_host.SetHostStr(a_dot_com); |
| 77 | |
| 78 | const std::string popup_app_contents_path( |
| 79 | "files/extensions/api_test/window_open/popup_blocking/hosted_app/"); |
| 80 | |
| 81 | GURL open_tab = |
| 82 | test_server()->GetURL(popup_app_contents_path + "open_tab.html") |
| 83 | .ReplaceComponents(replace_host); |
| 84 | GURL open_popup = |
| 85 | test_server()->GetURL(popup_app_contents_path + "open_popup.html") |
| 86 | .ReplaceComponents(replace_host); |
| 87 | |
| 88 | browser()->OpenURL(open_tab, GURL(), NEW_FOREGROUND_TAB, |
| 89 | PageTransition::TYPED); |
| 90 | browser()->OpenURL(open_popup, GURL(), NEW_FOREGROUND_TAB, |
| 91 | PageTransition::TYPED); |
[email protected] | 4026ce1e | 2010-09-14 19:35:04 | [diff] [blame] | 92 | |
| 93 | WaitForTabsAndPopups(browser(), 3, 1); |
| 94 | } |
[email protected] | d4db6c70 | 2011-03-28 21:49:14 | [diff] [blame^] | 95 | |
| 96 | #if defined(OS_MACOSX) || defined(OS_WIN) |
| 97 | // Focus test fails if there is no window manager on Linux. |
| 98 | IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenFocus) { |
| 99 | ASSERT_TRUE(RunExtensionTest("window_open/focus")) << message_; |
| 100 | } |
| 101 | #endif |