blob: 4be4b937d474bc4a0d95ff6439b444bb0841e799 [file] [log] [blame]
[email protected]d4db6c702011-03-28 21:49:141// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]32b7c492010-09-01 04:15:002// 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]32b7c492010-09-01 04:15:006#include "chrome/browser/extensions/extension_apitest.h"
[email protected]2ad4a902010-11-17 06:05:137#include "chrome/browser/ui/browser.h"
8#include "chrome/browser/ui/browser_list.h"
[email protected]32b7c492010-09-01 04:15:009#include "chrome/common/chrome_switches.h"
[email protected]4026ce1e2010-09-14 19:35:0410#include "chrome/test/ui_test_utils.h"
11#include "net/base/mock_host_resolver.h"
[email protected]32b7c492010-09-01 04:15:0012
[email protected]e78eb292010-12-22 08:35:3913// Disabled, http://crbug.com/64899.
14IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) {
[email protected]32b7c492010-09-01 04:15:0015 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]4026ce1e2010-09-14 19:35:0423
24void 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]1b74d2122010-10-06 16:49:1644 // Check for TYPE_POPUP or TYPE_APP_POPUP/PANEL.
45 ASSERT_TRUE((*iter)->type() & Browser::TYPE_POPUP);
[email protected]4026ce1e2010-09-14 19:35:0446 }
47
48 break;
49 }
50}
51
52IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingExtension) {
53 host_resolver()->AddRule("*", "127.0.0.1");
[email protected]e18a19b2010-10-19 20:32:3054 ASSERT_TRUE(StartTestServer());
[email protected]4026ce1e2010-09-14 19:35:0455
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
63IN_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]fe3048872010-10-18 14:58:5971 // 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]4026ce1e2010-09-14 19:35:0492
93 WaitForTabsAndPopups(browser(), 3, 1);
94}
[email protected]d4db6c702011-03-28 21:49:1495
96#if defined(OS_MACOSX) || defined(OS_WIN)
97// Focus test fails if there is no window manager on Linux.
98IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenFocus) {
99 ASSERT_TRUE(RunExtensionTest("window_open/focus")) << message_;
100}
101#endif