Index: chrome/browser/extensions/active_tab_unittest.cc |
diff --git a/chrome/browser/extensions/active_tab_unittest.cc b/chrome/browser/extensions/active_tab_unittest.cc |
index 908d366a92c7e4d6202824b1f8f6dc558e03b4ea..8b27e6970c897853d165c3990cfe4e8b7164db58 100644 |
--- a/chrome/browser/extensions/active_tab_unittest.cc |
+++ b/chrome/browser/extensions/active_tab_unittest.cc |
@@ -7,6 +7,8 @@ |
#include <utility> |
#include "base/compiler_specific.h" |
+#include "base/macros.h" |
+#include "base/memory/ptr_util.h" |
#include "base/message_loop/message_loop.h" |
#include "base/values.h" |
#include "chrome/browser/chrome_notification_types.h" |
@@ -67,6 +69,28 @@ enum PermittedFeature { |
PERMITTED_BOTH |
}; |
+class ActiveTabPermissionGranterTestDelegate |
+ : public ActiveTabPermissionGranter::Delegate { |
+ public: |
+ ActiveTabPermissionGranterTestDelegate() {} |
+ ~ActiveTabPermissionGranterTestDelegate() override {} |
+ |
+ // ActiveTabPermissionGranterTestDelegate::Delegate |
+ bool ShouldGrantActiveTab(const Extension* extension, |
+ content::WebContents* contents) override { |
+ return should_grant_; |
+ } |
+ |
+ void SetShouldGrant(bool should_grant) { |
+ should_grant_ = should_grant; |
+ } |
+ |
+ private: |
+ bool should_grant_ = false; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ActiveTabPermissionGranterTestDelegate); |
+}; |
+ |
class ActiveTabTest : public ChromeRenderViewHostTestHarness { |
protected: |
ActiveTabTest() |
@@ -380,5 +404,27 @@ TEST_F(ActiveTabTest, ChromeUrlGrants) { |
tab_id() + 1, APIPermission::kTabCaptureForTab)); |
} |
+// Test that the custom platform delegate works as expected. |
+TEST_F(ActiveTabTest, Delegate) { |
+ auto test_delegate = |
+ base::MakeUnique<ActiveTabPermissionGranterTestDelegate>(); |
+ ActiveTabPermissionGranter::SetPlatformDelegate(test_delegate.get()); |
+ |
+ GURL google("http://www.google.com"); |
+ NavigateAndCommit(google); |
+ |
+ // Not granted because the delegate denies grant. |
+ active_tab_permission_granter()->GrantIfRequested(extension.get()); |
+ EXPECT_TRUE(IsBlocked(extension, google)); |
+ |
+ // This time it's granted because the delegate allows it. |
+ test_delegate->SetShouldGrant(true); |
+ active_tab_permission_granter()->GrantIfRequested(extension.get()); |
+ EXPECT_TRUE(IsAllowed(extension, google)); |
+ |
+ // Cleanup :). |
+ ActiveTabPermissionGranter::SetPlatformDelegate(nullptr); |
+} |
+ |
} // namespace |
} // namespace extensions |