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 "chrome/browser/chrome_notification_types.h" | 6 #include "chrome/browser/chrome_notification_types.h" |
7 #include "chrome/browser/extensions/extension_apitest.h" | 7 #include "chrome/browser/extensions/extension_apitest.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 // Reload extension and wait for rules to be set up again. This should not | 315 // Reload extension and wait for rules to be set up again. This should not |
316 // crash the browser. | 316 // crash the browser. |
317 ExtensionTestMessageListener listener2("done", true); | 317 ExtensionTestMessageListener listener2("done", true); |
318 ExtensionTestMessageListener listener_incognito2("done_incognito", true); | 318 ExtensionTestMessageListener listener_incognito2("done_incognito", true); |
319 | 319 |
320 ReloadExtension(extension->id()); | 320 ReloadExtension(extension->id()); |
321 | 321 |
322 EXPECT_TRUE(listener2.WaitUntilSatisfied()); | 322 EXPECT_TRUE(listener2.WaitUntilSatisfied()); |
323 EXPECT_TRUE(listener_incognito2.WaitUntilSatisfied()); | 323 EXPECT_TRUE(listener_incognito2.WaitUntilSatisfied()); |
324 } | 324 } |
| 325 |
| 326 IN_PROC_BROWSER_TEST_F(ExtensionWebRequestApiTest, ExtensionRequests) { |
| 327 ASSERT_TRUE(StartEmbeddedTestServer()); |
| 328 ExtensionTestMessageListener listener_main1("web_request_status1", true); |
| 329 ExtensionTestMessageListener listener_main2("web_request_status2", true); |
| 330 |
| 331 ExtensionTestMessageListener listener_app("app_done", false); |
| 332 ExtensionTestMessageListener listener_extension("extension_done", true); |
| 333 |
| 334 // Set up webRequest listener |
| 335 ASSERT_TRUE(LoadExtension( |
| 336 test_data_dir_.AppendASCII("webrequest_extensions/main"))); |
| 337 EXPECT_TRUE(listener_main1.WaitUntilSatisfied()); |
| 338 EXPECT_TRUE(listener_main2.WaitUntilSatisfied()); |
| 339 |
| 340 // Perform some network activity in an app and another extension. |
| 341 ASSERT_TRUE(LoadExtension( |
| 342 test_data_dir_.AppendASCII("webrequest_extensions/app"))); |
| 343 ASSERT_TRUE(LoadExtension( |
| 344 test_data_dir_.AppendASCII("webrequest_extensions/extension"))); |
| 345 |
| 346 EXPECT_TRUE(listener_app.WaitUntilSatisfied()); |
| 347 EXPECT_TRUE(listener_extension.WaitUntilSatisfied()); |
| 348 |
| 349 // Load a page, a content script will ping us when it is ready. |
| 350 ExtensionTestMessageListener listener_pageready("contentscript_ready", true); |
| 351 ui_test_utils::NavigateToURL(browser(), embedded_test_server()->GetURL( |
| 352 "/extensions/test_file.html?match_webrequest_test")); |
| 353 |
| 354 // The extension and app-generated requests should not have triggered any |
| 355 // webRequest event filtered by type 'xmlhttprequest'. |
| 356 // (check this here instead of before the navigation, in case the webRequest |
| 357 // event routing is slow for some reason). |
| 358 ExtensionTestMessageListener listener_result(false); |
| 359 listener_main1.Reply(""); |
| 360 EXPECT_TRUE(listener_result.WaitUntilSatisfied()); |
| 361 EXPECT_EQ("Did not intercept any requests.", listener_result.message()); |
| 362 |
| 363 // Proceed with the final tests: Let the content script fire a request. |
| 364 EXPECT_TRUE(listener_pageready.WaitUntilSatisfied()); |
| 365 listener_pageready.Reply(""); |
| 366 |
| 367 ExtensionTestMessageListener listener_contentscript("contentscript_done", |
| 368 true); |
| 369 ExtensionTestMessageListener listener_framescript("framescript_done", false); |
| 370 EXPECT_TRUE(listener_contentscript.WaitUntilSatisfied()); |
| 371 listener_contentscript.Reply(""); |
| 372 EXPECT_TRUE(listener_framescript.WaitUntilSatisfied()); |
| 373 |
| 374 // Collect the visited URLs. The content script and subframe does not run in |
| 375 // the extension's process, so the requests should be visible to the main |
| 376 // extension. |
| 377 listener_result.Reset(); |
| 378 listener_main2.Reply(""); |
| 379 EXPECT_TRUE(listener_result.WaitUntilSatisfied()); |
| 380 if (content::AreAllSitesIsolatedForTesting()) { |
| 381 // With --site-per-process, the extension frame does run in the extension's |
| 382 // process. |
| 383 EXPECT_EQ("Intercepted requests: ?contentscript", |
| 384 listener_result.message()); |
| 385 } else { |
| 386 EXPECT_EQ("Intercepted requests: ?contentscript, ?framescript", |
| 387 listener_result.message()); |
| 388 } |
| 389 } |
OLD | NEW |