| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_test_message_listener.h" | 9 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
| 12 #include "chrome/browser/ui/browser_list.h" | 12 #include "chrome/browser/ui/browser_list.h" |
| 13 #include "chrome/browser/ui/browser_tabstrip.h" | 13 #include "chrome/browser/ui/browser_tabstrip.h" |
| 14 #include "chrome/browser/ui/panels/panel_manager.h" |
| 14 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
| 16 #include "chrome/test/base/ui_test_utils.h" | 17 #include "chrome/test/base/ui_test_utils.h" |
| 17 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
| 18 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "net/base/mock_host_resolver.h" | 21 #include "net/base/mock_host_resolver.h" |
| 21 | 22 |
| 22 using content::OpenURLParams; | 23 using content::OpenURLParams; |
| 23 using content::Referrer; | 24 using content::Referrer; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 36 | 37 |
| 37 void WaitForTabsAndPopups(Browser* browser, | 38 void WaitForTabsAndPopups(Browser* browser, |
| 38 int num_tabs, | 39 int num_tabs, |
| 39 int num_popups, | 40 int num_popups, |
| 40 int num_panels) { | 41 int num_panels) { |
| 41 SCOPED_TRACE( | 42 SCOPED_TRACE( |
| 42 StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d", | 43 StringPrintf("WaitForTabsAndPopups tabs:%d, popups:%d, panels:%d", |
| 43 num_tabs, num_popups, num_panels)); | 44 num_tabs, num_popups, num_panels)); |
| 44 // We start with one tab and one browser already open. | 45 // We start with one tab and one browser already open. |
| 45 ++num_tabs; | 46 ++num_tabs; |
| 46 size_t num_browsers = static_cast<size_t>(num_popups + num_panels) + 1; | 47 size_t num_browsers = static_cast<size_t>(num_popups) + 1; |
| 47 | 48 |
| 48 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(15); | 49 const base::TimeDelta kWaitTime = base::TimeDelta::FromSeconds(15); |
| 49 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime; | 50 base::TimeTicks end_time = base::TimeTicks::Now() + kWaitTime; |
| 50 while (base::TimeTicks::Now() < end_time) { | 51 while (base::TimeTicks::Now() < end_time) { |
| 51 if (browser::GetBrowserCount(browser->profile()) == num_browsers && | 52 if (browser::GetBrowserCount(browser->profile()) == num_browsers && |
| 52 browser->tab_count() == num_tabs) | 53 browser->tab_count() == num_tabs && |
| 54 PanelManager::GetInstance()->num_panels() == num_panels) |
| 53 break; | 55 break; |
| 54 | 56 |
| 55 content::RunAllPendingInMessageLoop(); | 57 content::RunAllPendingInMessageLoop(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 EXPECT_EQ(num_browsers, browser::GetBrowserCount(browser->profile())); | 60 EXPECT_EQ(num_browsers, browser::GetBrowserCount(browser->profile())); |
| 59 EXPECT_EQ(num_tabs, browser->tab_count()); | 61 EXPECT_EQ(num_tabs, browser->tab_count()); |
| 62 EXPECT_EQ(num_panels, PanelManager::GetInstance()->num_panels()); |
| 60 | 63 |
| 61 int num_popups_seen = 0; | 64 int num_popups_seen = 0; |
| 62 int num_panels_seen = 0; | |
| 63 for (BrowserList::const_iterator iter = BrowserList::begin(); | 65 for (BrowserList::const_iterator iter = BrowserList::begin(); |
| 64 iter != BrowserList::end(); ++iter) { | 66 iter != BrowserList::end(); ++iter) { |
| 65 if (*iter == browser) | 67 if (*iter == browser) |
| 66 continue; | 68 continue; |
| 67 | 69 |
| 68 // Check for TYPE_POPUP or TYPE_PANEL. | 70 // Check for TYPE_POPUP. |
| 69 EXPECT_TRUE((*iter)->is_type_popup() || (*iter)->is_type_panel()); | 71 EXPECT_TRUE((*iter)->is_type_popup()); |
| 70 if ((*iter)->is_type_popup()) | 72 ++num_popups_seen; |
| 71 ++num_popups_seen; | |
| 72 else | |
| 73 ++num_panels_seen; | |
| 74 } | 73 } |
| 75 EXPECT_EQ(num_popups, num_popups_seen); | 74 EXPECT_EQ(num_popups, num_popups_seen); |
| 76 EXPECT_EQ(num_panels, num_panels_seen); | |
| 77 } | 75 } |
| 78 | 76 |
| 79 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { | 77 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { |
| 80 host_resolver()->AddRule("a.com", "127.0.0.1"); | 78 host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 81 ASSERT_TRUE(StartTestServer()); | 79 ASSERT_TRUE(StartTestServer()); |
| 82 ASSERT_TRUE(LoadExtension( | 80 ASSERT_TRUE(LoadExtension( |
| 83 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); | 81 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); |
| 84 | 82 |
| 85 WaitForTabsAndPopups(browser(), 0, 2, 0); | 83 WaitForTabsAndPopups(browser(), 0, 2, 0); |
| 86 | 84 |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 }; | 195 }; |
| 198 | 196 |
| 199 #if defined(USE_ASH) | 197 #if defined(USE_ASH) |
| 200 // On Ash, this currently fails because we're currently opening new panel | 198 // On Ash, this currently fails because we're currently opening new panel |
| 201 // windows as popup windows instead. | 199 // windows as popup windows instead. |
| 202 #define MAYBE_WindowOpenPanel FAILS_WindowOpenPanel | 200 #define MAYBE_WindowOpenPanel FAILS_WindowOpenPanel |
| 203 #else | 201 #else |
| 204 #define MAYBE_WindowOpenPanel WindowOpenPanel | 202 #define MAYBE_WindowOpenPanel WindowOpenPanel |
| 205 #endif | 203 #endif |
| 206 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) { | 204 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenPanel) { |
| 205 if (!PanelManager::UseBrowserlessPanels()) |
| 206 return; |
| 207 ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_; | 207 ASSERT_TRUE(RunExtensionTest("window_open/panel")) << message_; |
| 208 } | 208 } |
| 209 | 209 |
| 210 #if defined(OS_MACOSX) || defined(OS_WIN) | 210 #if defined(OS_MACOSX) || defined(OS_WIN) |
| 211 // Focus test fails if there is no window manager on Linux. | 211 // Focus test fails if there is no window manager on Linux. |
| 212 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, WindowOpenFocus) { | 212 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, WindowOpenFocus) { |
| 213 if (!PanelManager::UseBrowserlessPanels()) |
| 214 return; |
| 213 ASSERT_TRUE(RunExtensionTest("window_open/focus")) << message_; | 215 ASSERT_TRUE(RunExtensionTest("window_open/focus")) << message_; |
| 214 } | 216 } |
| 215 #endif | 217 #endif |
| 216 | 218 |
| 217 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, | 219 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, |
| 218 CloseNonExtensionPanelsOnUninstall) { | 220 CloseNonExtensionPanelsOnUninstall) { |
| 221 if (!PanelManager::UseBrowserlessPanels()) |
| 222 return; |
| 219 #if defined(USE_ASH) | 223 #if defined(USE_ASH) |
| 220 int num_popups = 4; | 224 int num_popups = 4; |
| 221 int num_panels = 0; | 225 int num_panels = 0; |
| 222 #else | 226 #else |
| 223 int num_popups = 2; | 227 int num_popups = 2; |
| 224 int num_panels = 2; | 228 int num_panels = 2; |
| 225 #endif | 229 #endif |
| 226 ASSERT_TRUE(StartTestServer()); | 230 ASSERT_TRUE(StartTestServer()); |
| 227 | 231 |
| 228 // Setup listeners to wait on strings we expect the extension pages to send. | 232 // Setup listeners to wait on strings we expect the extension pages to send. |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 ASSERT_NO_FATAL_FAILURE(OpenWindow(chrome::GetActiveWebContents(browser()), | 321 ASSERT_NO_FATAL_FAILURE(OpenWindow(chrome::GetActiveWebContents(browser()), |
| 318 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + | 322 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + |
| 319 "/newtab.html"), false, &newtab)); | 323 "/newtab.html"), false, &newtab)); |
| 320 | 324 |
| 321 // Extension API should succeed. | 325 // Extension API should succeed. |
| 322 bool result = false; | 326 bool result = false; |
| 323 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( | 327 ASSERT_TRUE(content::ExecuteJavaScriptAndExtractBool( |
| 324 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); | 328 newtab->GetRenderViewHost(), L"", L"testExtensionApi()", &result)); |
| 325 EXPECT_TRUE(result); | 329 EXPECT_TRUE(result); |
| 326 } | 330 } |
| OLD | NEW |