| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 38 | 38 |
| 39 #if defined(USE_ASH) | 39 #if defined(USE_ASH) |
| 40 #include "extensions/browser/app_window/app_window_registry.h" | 40 #include "extensions/browser/app_window/app_window_registry.h" |
| 41 #endif | 41 #endif |
| 42 | 42 |
| 43 using content::OpenURLParams; | 43 using content::OpenURLParams; |
| 44 using content::Referrer; | 44 using content::Referrer; |
| 45 using content::WebContents; | 45 using content::WebContents; |
| 46 | 46 |
| 47 class WindowOpenApiTest : public ExtensionApiTest { |
| 48 void SetUpOnMainThread() override { |
| 49 ExtensionApiTest::SetUpOnMainThread(); |
| 50 host_resolver()->AddRule("*", "127.0.0.1"); |
| 51 } |
| 52 }; |
| 53 |
| 47 // The test uses the chrome.browserAction.openPopup API, which requires that the | 54 // The test uses the chrome.browserAction.openPopup API, which requires that the |
| 48 // window can automatically be activated. | 55 // window can automatically be activated. |
| 49 // See comments at BrowserActionInteractiveTest::ShouldRunPopupTest | 56 // See comments at BrowserActionInteractiveTest::ShouldRunPopupTest |
| 50 // Fails flakily on all platforms. https://crbug.com/477691 | 57 // Fails flakily on all platforms. https://crbug.com/477691 |
| 51 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpen) { | 58 IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, DISABLED_WindowOpen) { |
| 52 extensions::ResultCatcher catcher; | 59 extensions::ResultCatcher catcher; |
| 53 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ | 60 ASSERT_TRUE(LoadExtensionIncognito(test_data_dir_ |
| 54 .AppendASCII("window_open").AppendASCII("spanning"))); | 61 .AppendASCII("window_open").AppendASCII("spanning"))); |
| 55 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 62 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 56 } | 63 } |
| 57 | 64 |
| 58 bool WaitForTabsAndPopups(Browser* browser, | 65 bool WaitForTabsAndPopups(Browser* browser, |
| 59 int num_tabs, | 66 int num_tabs, |
| 60 int num_popups) { | 67 int num_popups) { |
| 61 SCOPED_TRACE( | 68 SCOPED_TRACE( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 86 EXPECT_TRUE(b->is_type_popup()); | 93 EXPECT_TRUE(b->is_type_popup()); |
| 87 ++num_popups_seen; | 94 ++num_popups_seen; |
| 88 } | 95 } |
| 89 EXPECT_EQ(num_popups, num_popups_seen); | 96 EXPECT_EQ(num_popups, num_popups_seen); |
| 90 | 97 |
| 91 return ((num_browsers == chrome::GetBrowserCount(browser->profile())) && | 98 return ((num_browsers == chrome::GetBrowserCount(browser->profile())) && |
| 92 (num_tabs == browser->tab_strip_model()->count()) && | 99 (num_tabs == browser->tab_strip_model()->count()) && |
| 93 (num_popups == num_popups_seen)); | 100 (num_popups == num_popups_seen)); |
| 94 } | 101 } |
| 95 | 102 |
| 96 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, BrowserIsApp) { | 103 IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, BrowserIsApp) { |
| 97 host_resolver()->AddRule("a.com", "127.0.0.1"); | |
| 98 ASSERT_TRUE(StartEmbeddedTestServer()); | 104 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 99 ASSERT_TRUE(LoadExtension( | 105 ASSERT_TRUE(LoadExtension( |
| 100 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); | 106 test_data_dir_.AppendASCII("window_open").AppendASCII("browser_is_app"))); |
| 101 | 107 |
| 102 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2)); | 108 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 2)); |
| 103 | 109 |
| 104 for (auto* b : *BrowserList::GetInstance()) { | 110 for (auto* b : *BrowserList::GetInstance()) { |
| 105 if (b == browser()) | 111 if (b == browser()) |
| 106 ASSERT_FALSE(b->is_app()); | 112 ASSERT_FALSE(b->is_app()); |
| 107 else | 113 else |
| 108 ASSERT_TRUE(b->is_app()); | 114 ASSERT_TRUE(b->is_app()); |
| 109 } | 115 } |
| 110 } | 116 } |
| 111 | 117 |
| 112 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupDefault) { | 118 IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, WindowOpenPopupDefault) { |
| 113 ASSERT_TRUE(StartEmbeddedTestServer()); | 119 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 114 ASSERT_TRUE(LoadExtension( | 120 ASSERT_TRUE(LoadExtension( |
| 115 test_data_dir_.AppendASCII("window_open").AppendASCII("popup"))); | 121 test_data_dir_.AppendASCII("window_open").AppendASCII("popup"))); |
| 116 | 122 |
| 117 const int num_tabs = 1; | 123 const int num_tabs = 1; |
| 118 const int num_popups = 0; | 124 const int num_popups = 0; |
| 119 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); | 125 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); |
| 120 } | 126 } |
| 121 | 127 |
| 122 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupIframe) { | 128 IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, WindowOpenPopupIframe) { |
| 123 base::FilePath test_data_dir; | 129 base::FilePath test_data_dir; |
| 124 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | 130 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); |
| 125 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | 131 embedded_test_server()->ServeFilesFromDirectory(test_data_dir); |
| 126 ASSERT_TRUE(StartEmbeddedTestServer()); | 132 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 127 ASSERT_TRUE(LoadExtension( | 133 ASSERT_TRUE(LoadExtension( |
| 128 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_iframe"))); | 134 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_iframe"))); |
| 129 | 135 |
| 130 const int num_tabs = 1; | 136 const int num_tabs = 1; |
| 131 const int num_popups = 0; | 137 const int num_popups = 0; |
| 132 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); | 138 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); |
| 133 } | 139 } |
| 134 | 140 |
| 135 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupLarge) { | 141 IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, WindowOpenPopupLarge) { |
| 136 ASSERT_TRUE(StartEmbeddedTestServer()); | 142 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 137 ASSERT_TRUE(LoadExtension( | 143 ASSERT_TRUE(LoadExtension( |
| 138 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large"))); | 144 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_large"))); |
| 139 | 145 |
| 140 // On other systems this should open a new popup window. | 146 // On other systems this should open a new popup window. |
| 141 const int num_tabs = 0; | 147 const int num_tabs = 0; |
| 142 const int num_popups = 1; | 148 const int num_popups = 1; |
| 143 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); | 149 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); |
| 144 } | 150 } |
| 145 | 151 |
| 146 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowOpenPopupSmall) { | 152 IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, WindowOpenPopupSmall) { |
| 147 ASSERT_TRUE(StartEmbeddedTestServer()); | 153 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 148 ASSERT_TRUE(LoadExtension( | 154 ASSERT_TRUE(LoadExtension( |
| 149 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small"))); | 155 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_small"))); |
| 150 | 156 |
| 151 // On ChromeOS this should open a new panel (acts like a new popup window). | 157 // On ChromeOS this should open a new panel (acts like a new popup window). |
| 152 // On other systems this should open a new popup window. | 158 // On other systems this should open a new popup window. |
| 153 const int num_tabs = 0; | 159 const int num_tabs = 0; |
| 154 const int num_popups = 1; | 160 const int num_popups = 1; |
| 155 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); | 161 EXPECT_TRUE(WaitForTabsAndPopups(browser(), num_tabs, num_popups)); |
| 156 } | 162 } |
| 157 | 163 |
| 158 // Disabled on Windows. Often times out or fails: crbug.com/177530 | 164 // Disabled on Windows. Often times out or fails: crbug.com/177530 |
| 159 #if defined(OS_WIN) | 165 #if defined(OS_WIN) |
| 160 #define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension | 166 #define MAYBE_PopupBlockingExtension DISABLED_PopupBlockingExtension |
| 161 #else | 167 #else |
| 162 #define MAYBE_PopupBlockingExtension PopupBlockingExtension | 168 #define MAYBE_PopupBlockingExtension PopupBlockingExtension |
| 163 #endif | 169 #endif |
| 164 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_PopupBlockingExtension) { | 170 IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, MAYBE_PopupBlockingExtension) { |
| 165 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 166 ASSERT_TRUE(StartEmbeddedTestServer()); | 171 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 167 | 172 |
| 168 ASSERT_TRUE(LoadExtension( | 173 ASSERT_TRUE(LoadExtension( |
| 169 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") | 174 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 170 .AppendASCII("extension"))); | 175 .AppendASCII("extension"))); |
| 171 | 176 |
| 172 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3)); | 177 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 5, 3)); |
| 173 } | 178 } |
| 174 | 179 |
| 175 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PopupBlockingHostedApp) { | 180 IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, PopupBlockingHostedApp) { |
| 176 host_resolver()->AddRule("*", "127.0.0.1"); | |
| 177 ASSERT_TRUE(embedded_test_server()->Start()); | 181 ASSERT_TRUE(embedded_test_server()->Start()); |
| 178 | 182 |
| 179 ASSERT_TRUE(LoadExtension( | 183 ASSERT_TRUE(LoadExtension( |
| 180 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") | 184 test_data_dir_.AppendASCII("window_open").AppendASCII("popup_blocking") |
| 181 .AppendASCII("hosted_app"))); | 185 .AppendASCII("hosted_app"))); |
| 182 | 186 |
| 183 // The app being tested owns the domain a.com . The test URLs we navigate | 187 // The app being tested owns the domain a.com . The test URLs we navigate |
| 184 // to below must be within that domain, so that they fall within the app's | 188 // to below must be within that domain, so that they fall within the app's |
| 185 // web extent. | 189 // web extent. |
| 186 GURL::Replacements replace_host; | 190 GURL::Replacements replace_host; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 199 browser()->OpenURL(OpenURLParams(open_tab, Referrer(), | 203 browser()->OpenURL(OpenURLParams(open_tab, Referrer(), |
| 200 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 204 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 201 ui::PAGE_TRANSITION_TYPED, false)); | 205 ui::PAGE_TRANSITION_TYPED, false)); |
| 202 browser()->OpenURL(OpenURLParams(open_popup, Referrer(), | 206 browser()->OpenURL(OpenURLParams(open_popup, Referrer(), |
| 203 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 207 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 204 ui::PAGE_TRANSITION_TYPED, false)); | 208 ui::PAGE_TRANSITION_TYPED, false)); |
| 205 | 209 |
| 206 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1)); | 210 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 3, 1)); |
| 207 } | 211 } |
| 208 | 212 |
| 209 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, WindowArgumentsOverflow) { | 213 IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, WindowArgumentsOverflow) { |
| 210 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_; | 214 ASSERT_TRUE(RunExtensionTest("window_open/argument_overflow")) << message_; |
| 211 } | 215 } |
| 212 | 216 |
| 213 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, DISABLED_WindowOpener) { | 217 IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, DISABLED_WindowOpener) { |
| 214 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_; | 218 ASSERT_TRUE(RunExtensionTest("window_open/opener")) << message_; |
| 215 } | 219 } |
| 216 | 220 |
| 217 #if defined(OS_MACOSX) | 221 #if defined(OS_MACOSX) |
| 218 // Extension popup windows are incorrectly sized on OSX, crbug.com/225601 | 222 // Extension popup windows are incorrectly sized on OSX, crbug.com/225601 |
| 219 #define MAYBE_WindowOpenSized DISABLED_WindowOpenSized | 223 #define MAYBE_WindowOpenSized DISABLED_WindowOpenSized |
| 220 #else | 224 #else |
| 221 #define MAYBE_WindowOpenSized WindowOpenSized | 225 #define MAYBE_WindowOpenSized WindowOpenSized |
| 222 #endif | 226 #endif |
| 223 // Ensure that the width and height properties of a window opened with | 227 // Ensure that the width and height properties of a window opened with |
| 224 // chrome.windows.create match the creation parameters. See crbug.com/173831. | 228 // chrome.windows.create match the creation parameters. See crbug.com/173831. |
| 225 IN_PROC_BROWSER_TEST_F(ExtensionApiTest, MAYBE_WindowOpenSized) { | 229 IN_PROC_BROWSER_TEST_F(WindowOpenApiTest, MAYBE_WindowOpenSized) { |
| 226 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_; | 230 ASSERT_TRUE(RunExtensionTest("window_open/window_size")) << message_; |
| 227 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1)); | 231 EXPECT_TRUE(WaitForTabsAndPopups(browser(), 0, 1)); |
| 228 } | 232 } |
| 229 | 233 |
| 230 // Tests that an extension page can call window.open to an extension URL and | 234 // Tests that an extension page can call window.open to an extension URL and |
| 231 // the new window has extension privileges. | 235 // the new window has extension privileges. |
| 232 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { | 236 IN_PROC_BROWSER_TEST_F(ExtensionBrowserTest, WindowOpenExtension) { |
| 233 ASSERT_TRUE(LoadExtension( | 237 ASSERT_TRUE(LoadExtension( |
| 234 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); | 238 test_data_dir_.AppendASCII("uitest").AppendASCII("window_open"))); |
| 235 | 239 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 ASSERT_TRUE(content::ExecuteScript( | 362 ASSERT_TRUE(content::ExecuteScript( |
| 359 tab, "location.href = '" + extension_url.spec() + "';")); | 363 tab, "location.href = '" + extension_url.spec() + "';")); |
| 360 observer.Wait(); | 364 observer.Wait(); |
| 361 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL()); | 365 EXPECT_EQ(extension_url, tab->GetMainFrame()->GetLastCommittedURL()); |
| 362 std::string result; | 366 std::string result; |
| 363 ASSERT_TRUE(content::ExecuteScriptAndExtractString( | 367 ASSERT_TRUE(content::ExecuteScriptAndExtractString( |
| 364 tab, "domAutomationController.send(document.body.innerText)", &result)); | 368 tab, "domAutomationController.send(document.body.innerText)", &result)); |
| 365 EXPECT_EQ("HOWDIE!!!", result); | 369 EXPECT_EQ("HOWDIE!!!", result); |
| 366 } | 370 } |
| 367 } | 371 } |
| OLD | NEW |