| 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/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
| 9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
| 10 #include "chrome/browser/extensions/extension_process_manager.h" | 10 #include "chrome/browser/extensions/extension_process_manager.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 return ((num_browsers == | 100 return ((num_browsers == |
| 101 chrome::GetBrowserCount(browser->profile(), | 101 chrome::GetBrowserCount(browser->profile(), |
| 102 browser->host_desktop_type())) && | 102 browser->host_desktop_type())) && |
| 103 (num_tabs == browser->tab_strip_model()->count()) && | 103 (num_tabs == browser->tab_strip_model()->count()) && |
| 104 (num_panels == GetPanelCount(browser)) && | 104 (num_panels == GetPanelCount(browser)) && |
| 105 (num_popups == num_popups_seen)); | 105 (num_popups == num_popups_seen)); |
| 106 } | 106 } |
| 107 | 107 |
| 108 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { | 108 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { |
| 109 host_resolver()->AddRule("a.com", "127.0.0.1"); | 109 host_resolver()->AddRule("a.com", "127.0.0.1"); |
| 110 ASSERT_TRUE(StartTestServer()); | 110 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 111 ASSERT_TRUE(LoadExtension( | 111 ASSERT_TRUE(LoadExtension( |
| 112 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); | 112 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); |
| 113 | 113 |
| 114 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0)); | 114 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2, 0)); |
| 115 | 115 |
| 116 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { | 116 for (chrome::BrowserIterator iter; !iter.done(); iter.Next()) { |
| 117 if (*iter == browser()) | 117 if (*iter == browser()) |
| 118 ASSERT_FALSE(iter->is_app()); | 118 ASSERT_FALSE(iter->is_app()); |
| 119 else | 119 else |
| 120 ASSERT_TRUE(iter->is_app()); | 120 ASSERT_TRUE(iter->is_app()); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) { | 124 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) { |
| 125 ASSERT_TRUE(StartTestServer()); | 125 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 126 ASSERT_TRUE(LoadExtension( | 126 ASSERT_TRUE(LoadExtension( |
| 127 test_data_dir_.AppendASCII("window_open").AppendASCII("popup"))); | 127 test_data_dir_.AppendASCII("window_open").AppendASCII("popup"))); |
| 128 | 128 |
| 129 const int num_tabs = 1; | 129 const int num_tabs = 1; |
| 130 const int num_popups = 0; | 130 const int num_popups = 0; |
| 131 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); | 131 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); |
| 132 } | 132 } |
| 133 | 133 |
| 134 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) { | 134 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) { |
| 135 ASSERT_TRUE(StartTestServer()); | 135 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 136 ASSERT_TRUE(LoadExtension( | 136 ASSERT_TRUE(LoadExtension( |
| 137 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large"))); | 137 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large"))); |
| 138 | 138 |
| 139 // On other systems this should open a new popup window. | 139 // On other systems this should open a new popup window. |
| 140 const int num_tabs = 0; | 140 const int num_tabs = 0; |
| 141 const int num_popups = 1; | 141 const int num_popups = 1; |
| 142 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); | 142 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); |
| 143 } | 143 } |
| 144 | 144 |
| 145 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) { | 145 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) { |
| 146 ASSERT_TRUE(StartTestServer()); | 146 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 147 ASSERT_TRUE(LoadExtension( | 147 ASSERT_TRUE(LoadExtension( |
| 148 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small"))); | 148 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small"))); |
| 149 | 149 |
| 150 // On ChromeOS this should open a new panel (acts like a new popup window). | 150 // On ChromeOS this should open a new panel (acts like a new popup window). |
| 151 // On other systems this should open a new popup window. | 151 // On other systems this should open a new popup window. |
| 152 const int num_tabs = 0; | 152 const int num_tabs = 0; |
| 153 const int num_popups = 1; | 153 const int num_popups = 1; |
| 154 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); | 154 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups, 0)); |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Disabled on Windows. Often times out or fails: crbug.com/177530 | 157 // Disabled on Windows. Often times out or fails: crbug.com/177530 |
| 158 #if defined(OS_WIN) | 158 #if defined(OS_WIN) |
| 159 #define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension | 159 #define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension |
| 160 #else | 160 #else |
| 161 #define MAYBE_PopupBlockingExtension PopupBlockingExtension | 161 #define MAYBE_PopupBlockingExtension PopupBlockingExtension |
| 162 #endif | 162 #endif |
| 163 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) { | 163 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) { |
| 164 host_resolver()->AddRule("*", "127.0.0.1"); | 164 host_resolver()->AddRule("*", "127.0.0.1"); |
| 165 ASSERT_TRUE(StartTestServer()); | 165 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 166 | 166 |
| 167 ASSERT_TRUE(LoadExtension( | 167 ASSERT_TRUE(LoadExtension( |
| 168 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") | 168 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 169 .AppendASCII("extension"))); | 169 .AppendASCII("extension"))); |
| 170 | 170 |
| 171 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0)); | 171 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3, 0)); |
| 172 } | 172 } |
| 173 | 173 |
| 174 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) { | 174 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) { |
| 175 host_resolver()->AddRule("*", "127.0.0.1"); | 175 host_resolver()->AddRule("*", "127.0.0.1"); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 num_popups = 2; | 257 num_popups = 2; |
| 258 num_panels = 2; | 258 num_panels = 2; |
| 259 } else { | 259 } else { |
| 260 num_popups = 4; | 260 num_popups = 4; |
| 261 num_panels = 0; | 261 num_panels = 0; |
| 262 } | 262 } |
| 263 #else | 263 #else |
| 264 int num_popups = 2; | 264 int num_popups = 2; |
| 265 int num_panels = 2; | 265 int num_panels = 2; |
| 266 #endif | 266 #endif |
| 267 ASSERT_TRUE(StartTestServer()); | 267 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 268 | 268 |
| 269 // Setup listeners to wait on strings we expect the extension pages to send. | 269 // Setup listeners to wait on strings we expect the extension pages to send. |
| 270 std::vector<std::string> test_strings; | 270 std::vector<std::string> test_strings; |
| 271 test_strings.push_back("content_tab"); | 271 test_strings.push_back("content_tab"); |
| 272 if (num_panels) | 272 if (num_panels) |
| 273 test_strings.push_back("content_panel"); | 273 test_strings.push_back("content_panel"); |
| 274 test_strings.push_back("content_popup"); | 274 test_strings.push_back("content_popup"); |
| 275 | 275 |
| 276 ScopedVector<ExtensionTestMessageListener> listeners; | 276 ScopedVector<ExtensionTestMessageListener> listeners; |
| 277 for (size_t i = 0; i < test_strings.size(); ++i) { | 277 for (size_t i = 0; i < test_strings.size(); ++i) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 #endif | 324 #endif |
| 325 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_ClosePanelsOnExtensionCrash) { | 325 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_ClosePanelsOnExtensionCrash) { |
| 326 #if defined(USE_ASH_PANELS) | 326 #if defined(USE_ASH_PANELS) |
| 327 // On Ash, new panel windows open as popup windows instead. | 327 // On Ash, new panel windows open as popup windows instead. |
| 328 int num_popups = 4; | 328 int num_popups = 4; |
| 329 int num_panels = 0; | 329 int num_panels = 0; |
| 330 #else | 330 #else |
| 331 int num_popups = 2; | 331 int num_popups = 2; |
| 332 int num_panels = 2; | 332 int num_panels = 2; |
| 333 #endif | 333 #endif |
| 334 ASSERT_TRUE(StartTestServer()); | 334 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 335 | 335 |
| 336 // Setup listeners to wait on strings we expect the extension pages to send. | 336 // Setup listeners to wait on strings we expect the extension pages to send. |
| 337 std::vector<std::string> test_strings; | 337 std::vector<std::string> test_strings; |
| 338 test_strings.push_back("content_tab"); | 338 test_strings.push_back("content_tab"); |
| 339 if (num_panels) | 339 if (num_panels) |
| 340 test_strings.push_back("content_panel"); | 340 test_strings.push_back("content_panel"); |
| 341 test_strings.push_back("content_popup"); | 341 test_strings.push_back("content_popup"); |
| 342 | 342 |
| 343 ScopedVector<ExtensionTestMessageListener> listeners; | 343 ScopedVector<ExtensionTestMessageListener> listeners; |
| 344 for (size_t i = 0; i < test_strings.size(); ++i) { | 344 for (size_t i = 0; i < test_strings.size(); ++i) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 374 } | 374 } |
| 375 | 375 |
| 376 #if defined(USE_ASH_PANELS) | 376 #if defined(USE_ASH_PANELS) |
| 377 // This test is not applicable on Ash. The modified window.open behavior only | 377 // This test is not applicable on Ash. The modified window.open behavior only |
| 378 // applies to non-Ash panel windows. | 378 // applies to non-Ash panel windows. |
| 379 #define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel | 379 #define MAYBE_WindowOpenFromPanel DISABLED_WindowOpenFromPanel |
| 380 #else | 380 #else |
| 381 #define MAYBE_WindowOpenFromPanel WindowOpenFromPanel | 381 #define MAYBE_WindowOpenFromPanel WindowOpenFromPanel |
| 382 #endif | 382 #endif |
| 383 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) { | 383 IN_PROC_BROWSER_TEST_F(WindowOpenPanelTest, MAYBE_WindowOpenFromPanel) { |
| 384 ASSERT_TRUE(StartTestServer()); | 384 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 385 | 385 |
| 386 // Load the extension that will open a panel which then calls window.open. | 386 // Load the extension that will open a panel which then calls window.open. |
| 387 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open"). | 387 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("window_open"). |
| 388 AppendASCII("panel_window_open"))); | 388 AppendASCII("panel_window_open"))); |
| 389 | 389 |
| 390 // Expect one panel (opened by extension) and one tab (from the panel calling | 390 // Expect one panel (opened by extension) and one tab (from the panel calling |
| 391 // window.open). Panels modify the WindowOpenDisposition in window.open | 391 // window.open). Panels modify the WindowOpenDisposition in window.open |
| 392 // to always open in a tab. | 392 // to always open in a tab. |
| 393 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1)); | 393 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 1, 0, 1)); |
| 394 } | 394 } |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), | 461 OpenWindow(browser()->tab_strip_model()->GetActiveWebContents(), |
| 462 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + | 462 GURL(std::string("chrome-extension://") + last_loaded_extension_id_ + |
| 463 "/newtab.html"), false, &newtab)); | 463 "/newtab.html"), false, &newtab)); |
| 464 | 464 |
| 465 // Extension API should succeed. | 465 // Extension API should succeed. |
| 466 bool result = false; | 466 bool result = false; |
| 467 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", | 467 ASSERT_TRUE(content::ExecuteScriptAndExtractBool(newtab, "testExtensionApi()", |
| 468 &result)); | 468 &result)); |
| 469 EXPECT_TRUE(result); | 469 EXPECT_TRUE(result); |
| 470 } | 470 } |
| OLD | NEW |