| 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/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
| 10 #include "chrome/browser/extensions/active_tab_permission_granter.h" | 10 #include "chrome/browser/extensions/active_tab_permission_granter.h" |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 | 520 |
| 521 // The extension shouldn't have currently received any webRequest events, | 521 // The extension shouldn't have currently received any webRequest events, |
| 522 // since it doesn't have permission (and shouldn't receive any from an XHR). | 522 // since it doesn't have permission (and shouldn't receive any from an XHR). |
| 523 EXPECT_EQ(0, GetWebRequestCountFromBackgroundPage(extension, profile())); | 523 EXPECT_EQ(0, GetWebRequestCountFromBackgroundPage(extension, profile())); |
| 524 PerformXhrInPage(web_contents, kHost, port, kXhrPath); | 524 PerformXhrInPage(web_contents, kHost, port, kXhrPath); |
| 525 EXPECT_EQ(0, GetWebRequestCountFromBackgroundPage(extension, profile())); | 525 EXPECT_EQ(0, GetWebRequestCountFromBackgroundPage(extension, profile())); |
| 526 | 526 |
| 527 // Grant activeTab permission, and perform another XHR. The extension should | 527 // Grant activeTab permission, and perform another XHR. The extension should |
| 528 // receive the event. | 528 // receive the event. |
| 529 EXPECT_EQ(BLOCKED_ACTION_WEB_REQUEST, runner->GetBlockedActions(extension)); | 529 EXPECT_EQ(BLOCKED_ACTION_WEB_REQUEST, runner->GetBlockedActions(extension)); |
| 530 runner->set_default_bubble_close_action_for_testing( |
| 531 make_scoped_ptr(new ToolbarActionsBarBubbleDelegate::CloseAction( |
| 532 ToolbarActionsBarBubbleDelegate::CLOSE_EXECUTE))); |
| 530 runner->RunAction(extension, true); | 533 runner->RunAction(extension, true); |
| 534 base::RunLoop().RunUntilIdle(); |
| 535 EXPECT_TRUE(content::WaitForLoadStop(web_contents)); |
| 536 // The runner will have refreshed the page... |
| 531 EXPECT_EQ(BLOCKED_ACTION_NONE, runner->GetBlockedActions(extension)); | 537 EXPECT_EQ(BLOCKED_ACTION_NONE, runner->GetBlockedActions(extension)); |
| 538 int xhr_count = GetWebRequestCountFromBackgroundPage(extension, profile()); |
| 539 // ... which means that we should have a non-zero xhr count. |
| 540 EXPECT_GT(xhr_count, 0); |
| 541 // And the extension should receive future events. |
| 532 PerformXhrInPage(web_contents, kHost, port, kXhrPath); | 542 PerformXhrInPage(web_contents, kHost, port, kXhrPath); |
| 533 EXPECT_EQ(1, GetWebRequestCountFromBackgroundPage(extension, profile())); | 543 ++xhr_count; |
| 544 EXPECT_EQ(xhr_count, |
| 545 GetWebRequestCountFromBackgroundPage(extension, profile())); |
| 534 | 546 |
| 535 // If we revoke the extension's tab permissions, it should no longer receive | 547 // If we revoke the extension's tab permissions, it should no longer receive |
| 536 // webRequest events. | 548 // webRequest events. |
| 537 ActiveTabPermissionGranter* granter = | 549 ActiveTabPermissionGranter* granter = |
| 538 TabHelper::FromWebContents(web_contents)->active_tab_permission_granter(); | 550 TabHelper::FromWebContents(web_contents)->active_tab_permission_granter(); |
| 539 ASSERT_TRUE(granter); | 551 ASSERT_TRUE(granter); |
| 540 granter->RevokeForTesting(); | 552 granter->RevokeForTesting(); |
| 541 base::RunLoop().RunUntilIdle(); | 553 base::RunLoop().RunUntilIdle(); |
| 542 PerformXhrInPage(web_contents, kHost, port, kXhrPath); | 554 PerformXhrInPage(web_contents, kHost, port, kXhrPath); |
| 543 EXPECT_EQ(1, GetWebRequestCountFromBackgroundPage(extension, profile())); | 555 EXPECT_EQ(xhr_count, |
| 556 GetWebRequestCountFromBackgroundPage(extension, profile())); |
| 544 EXPECT_EQ(BLOCKED_ACTION_WEB_REQUEST, runner->GetBlockedActions(extension)); | 557 EXPECT_EQ(BLOCKED_ACTION_WEB_REQUEST, runner->GetBlockedActions(extension)); |
| 545 } | 558 } |
| 546 | 559 |
| 547 } // namespace extensions | 560 } // namespace extensions |
| OLD | NEW |