| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/macros.h" | 5 #include "base/macros.h" |
| 6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" | 10 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 DISALLOW_COPY_AND_ASSIGN(WebUIWebViewBrowserTest); | 133 DISALLOW_COPY_AND_ASSIGN(WebUIWebViewBrowserTest); |
| 134 }; | 134 }; |
| 135 | 135 |
| 136 // Checks that hiding and showing the WebUI host page doesn't break guests in | 136 // Checks that hiding and showing the WebUI host page doesn't break guests in |
| 137 // it. | 137 // it. |
| 138 // Regression test for http://crbug.com/515268 | 138 // Regression test for http://crbug.com/515268 |
| 139 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, DisplayNone) { | 139 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, DisplayNone) { |
| 140 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 140 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 141 | 141 |
| 142 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 142 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 143 "testDisplayNone", | 143 "testDisplayNone", new base::Value(GetTestUrl("empty.html").spec()))); |
| 144 new base::StringValue(GetTestUrl("empty.html").spec()))); | |
| 145 } | 144 } |
| 146 | 145 |
| 147 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, ExecuteScriptCode) { | 146 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, ExecuteScriptCode) { |
| 148 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 147 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 149 | 148 |
| 150 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 149 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 151 "testExecuteScriptCode", | 150 "testExecuteScriptCode", |
| 152 new base::StringValue(GetTestUrl("empty.html").spec()))); | 151 new base::Value(GetTestUrl("empty.html").spec()))); |
| 153 } | 152 } |
| 154 | 153 |
| 155 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, ExecuteScriptCodeFromFile) { | 154 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, ExecuteScriptCodeFromFile) { |
| 156 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 155 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 157 | 156 |
| 158 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 157 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 159 "testExecuteScriptCodeFromFile", | 158 "testExecuteScriptCodeFromFile", |
| 160 new base::StringValue(GetTestUrl("empty.html").spec()))); | 159 new base::Value(GetTestUrl("empty.html").spec()))); |
| 161 } | 160 } |
| 162 | 161 |
| 163 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddContentScript) { | 162 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddContentScript) { |
| 164 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 163 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 165 | 164 |
| 166 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 165 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 167 "testAddContentScript", | 166 "testAddContentScript", |
| 168 new base::StringValue(GetTestUrl("empty.html").spec()))); | 167 new base::Value(GetTestUrl("empty.html").spec()))); |
| 169 } | 168 } |
| 170 | 169 |
| 171 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddMultiContentScripts) { | 170 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddMultiContentScripts) { |
| 172 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 171 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 173 | 172 |
| 174 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 173 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 175 "testAddMultiContentScripts", | 174 "testAddMultiContentScripts", |
| 176 new base::StringValue(GetTestUrl("empty.html").spec()))); | 175 new base::Value(GetTestUrl("empty.html").spec()))); |
| 177 } | 176 } |
| 178 | 177 |
| 179 IN_PROC_BROWSER_TEST_F( | 178 IN_PROC_BROWSER_TEST_F( |
| 180 WebUIWebViewBrowserTest, | 179 WebUIWebViewBrowserTest, |
| 181 AddContentScriptWithSameNameShouldOverwriteTheExistingOne) { | 180 AddContentScriptWithSameNameShouldOverwriteTheExistingOne) { |
| 182 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 181 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 183 | 182 |
| 184 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 183 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 185 "testAddContentScriptWithSameNameShouldOverwriteTheExistingOne", | 184 "testAddContentScriptWithSameNameShouldOverwriteTheExistingOne", |
| 186 new base::StringValue(GetTestUrl("empty.html").spec()))); | 185 new base::Value(GetTestUrl("empty.html").spec()))); |
| 187 } | 186 } |
| 188 | 187 |
| 189 IN_PROC_BROWSER_TEST_F( | 188 IN_PROC_BROWSER_TEST_F( |
| 190 WebUIWebViewBrowserTest, | 189 WebUIWebViewBrowserTest, |
| 191 AddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView) { | 190 AddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView) { |
| 192 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 191 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 193 | 192 |
| 194 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 193 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 195 "testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView", | 194 "testAddContentScriptToOneWebViewShouldNotInjectToTheOtherWebView", |
| 196 new base::StringValue(GetTestUrl("empty.html").spec()))); | 195 new base::Value(GetTestUrl("empty.html").spec()))); |
| 197 } | 196 } |
| 198 | 197 |
| 199 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddAndRemoveContentScripts) { | 198 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddAndRemoveContentScripts) { |
| 200 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 199 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 201 | 200 |
| 202 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 201 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 203 "testAddAndRemoveContentScripts", | 202 "testAddAndRemoveContentScripts", |
| 204 new base::StringValue(GetTestUrl("empty.html").spec()))); | 203 new base::Value(GetTestUrl("empty.html").spec()))); |
| 205 } | 204 } |
| 206 | 205 |
| 207 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, | 206 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, |
| 208 AddContentScriptsWithNewWindowAPI) { | 207 AddContentScriptsWithNewWindowAPI) { |
| 209 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 208 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 210 | 209 |
| 211 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 210 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 212 "testAddContentScriptsWithNewWindowAPI", | 211 "testAddContentScriptsWithNewWindowAPI", |
| 213 new base::StringValue(GetTestUrl("guest_from_opener.html").spec()))); | 212 new base::Value(GetTestUrl("guest_from_opener.html").spec()))); |
| 214 } | 213 } |
| 215 | 214 |
| 216 // https://crbug.com/665512. | 215 // https://crbug.com/665512. |
| 217 IN_PROC_BROWSER_TEST_F( | 216 IN_PROC_BROWSER_TEST_F( |
| 218 WebUIWebViewBrowserTest, | 217 WebUIWebViewBrowserTest, |
| 219 DISABLED_ContentScriptIsInjectedAfterTerminateAndReloadWebView) { | 218 DISABLED_ContentScriptIsInjectedAfterTerminateAndReloadWebView) { |
| 220 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 219 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 221 | 220 |
| 222 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 221 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 223 "testContentScriptIsInjectedAfterTerminateAndReloadWebView", | 222 "testContentScriptIsInjectedAfterTerminateAndReloadWebView", |
| 224 new base::StringValue(GetTestUrl("empty.html").spec()))); | 223 new base::Value(GetTestUrl("empty.html").spec()))); |
| 225 } | 224 } |
| 226 | 225 |
| 227 // TODO(crbug.com/662673) Flaky on CrOS trybots. | 226 // TODO(crbug.com/662673) Flaky on CrOS trybots. |
| 228 #if defined(OS_CHROMEOS) | 227 #if defined(OS_CHROMEOS) |
| 229 #define MAYBE_ContentScriptExistsAsLongAsWebViewTagExists \ | 228 #define MAYBE_ContentScriptExistsAsLongAsWebViewTagExists \ |
| 230 DISABLED_ContentScriptExistsAsLongAsWebViewTagExists | 229 DISABLED_ContentScriptExistsAsLongAsWebViewTagExists |
| 231 #else | 230 #else |
| 232 #define MAYBE_ContentScriptExistsAsLongAsWebViewTagExists \ | 231 #define MAYBE_ContentScriptExistsAsLongAsWebViewTagExists \ |
| 233 ContentScriptExistsAsLongAsWebViewTagExists | 232 ContentScriptExistsAsLongAsWebViewTagExists |
| 234 #endif | 233 #endif |
| 235 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, | 234 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, |
| 236 MAYBE_ContentScriptExistsAsLongAsWebViewTagExists) { | 235 MAYBE_ContentScriptExistsAsLongAsWebViewTagExists) { |
| 237 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 236 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 238 | 237 |
| 239 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 238 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 240 "testContentScriptExistsAsLongAsWebViewTagExists", | 239 "testContentScriptExistsAsLongAsWebViewTagExists", |
| 241 new base::StringValue(GetTestUrl("empty.html").spec()))); | 240 new base::Value(GetTestUrl("empty.html").spec()))); |
| 242 } | 241 } |
| 243 | 242 |
| 244 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddContentScriptWithCode) { | 243 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddContentScriptWithCode) { |
| 245 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 244 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 246 | 245 |
| 247 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 246 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 248 "testAddContentScriptWithCode", | 247 "testAddContentScriptWithCode", |
| 249 new base::StringValue(GetTestUrl("empty.html").spec()))); | 248 new base::Value(GetTestUrl("empty.html").spec()))); |
| 250 } | 249 } |
| 251 | 250 |
| 252 #if defined(OS_CHROMEOS) | 251 #if defined(OS_CHROMEOS) |
| 253 // Right now we only have incognito WebUI on CrOS, but this should | 252 // Right now we only have incognito WebUI on CrOS, but this should |
| 254 // theoretically work for all platforms. | 253 // theoretically work for all platforms. |
| 255 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddContentScriptIncognito) { | 254 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, AddContentScriptIncognito) { |
| 256 Browser* incognito_browser = | 255 Browser* incognito_browser = |
| 257 OpenURLOffTheRecord(browser()->profile(), GetWebViewEnabledWebUIURL()); | 256 OpenURLOffTheRecord(browser()->profile(), GetWebViewEnabledWebUIURL()); |
| 258 | 257 |
| 259 SetWebUIInstance( | 258 SetWebUIInstance( |
| 260 incognito_browser->tab_strip_model()->GetActiveWebContents()->GetWebUI()); | 259 incognito_browser->tab_strip_model()->GetActiveWebContents()->GetWebUI()); |
| 261 | 260 |
| 262 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | 261 ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( |
| 263 "testAddContentScript", | 262 "testAddContentScript", |
| 264 new base::StringValue(GetTestUrl("empty.html").spec()))); | 263 new base::Value(GetTestUrl("empty.html").spec()))); |
| 265 } | 264 } |
| 266 #endif | 265 #endif |
| 267 | 266 |
| 268 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, ContextMenuInspectElement) { | 267 IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, ContextMenuInspectElement) { |
| 269 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | 268 ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); |
| 270 content::ContextMenuParams params; | 269 content::ContextMenuParams params; |
| 271 TestRenderViewContextMenu menu( | 270 TestRenderViewContextMenu menu( |
| 272 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), | 271 browser()->tab_strip_model()->GetActiveWebContents()->GetMainFrame(), |
| 273 params); | 272 params); |
| 274 EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); | 273 EXPECT_FALSE(menu.IsItemPresent(IDC_CONTENT_CONTEXT_INSPECTELEMENT)); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 dropdata, client_pt, screen_pt, 0); | 365 dropdata, client_pt, screen_pt, 0); |
| 367 ASSERT_TRUE(listener.Wait()); | 366 ASSERT_TRUE(listener.Wait()); |
| 368 // Confirm no navigation | 367 // Confirm no navigation |
| 369 EXPECT_FALSE(observer.Navigated()); | 368 EXPECT_FALSE(observer.Navigated()); |
| 370 EXPECT_EQ(GetWebViewEnabledWebUIURL(), embedder_web_contents->GetURL()); | 369 EXPECT_EQ(GetWebViewEnabledWebUIURL(), embedder_web_contents->GetURL()); |
| 371 } | 370 } |
| 372 } | 371 } |
| 373 #endif | 372 #endif |
| 374 | 373 |
| 375 #endif // !defined(OS_MACOSX) | 374 #endif // !defined(OS_MACOSX) |
| OLD | NEW |