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