OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/extensions/active_tab_permission_granter_deleg
ate_chromeos.h" |
| 6 |
| 7 #include <string> |
| 8 |
| 9 #include "base/run_loop.h" |
| 10 #include "chrome/browser/chromeos/extensions/public_session_permission_helper.h" |
| 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 12 #include "chromeos/login/scoped_test_public_session_login_state.h" |
| 13 #include "extensions/browser/extension_dialog_auto_confirm.h" |
| 14 #include "extensions/common/extension.h" |
| 15 #include "extensions/common/extension_builder.h" |
| 16 #include "extensions/common/value_builder.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 namespace extensions { |
| 20 |
| 21 namespace { |
| 22 |
| 23 const char kWhitelistedId[] = "cbkkbcmdlboombapidmoeolnmdacpkch"; |
| 24 // Use an extension ID that will never be whitelisted. |
| 25 const char kNonWhitelistedId[] = "bogus"; |
| 26 |
| 27 scoped_refptr<Extension> CreateExtension(const std::string& id) { |
| 28 return ExtensionBuilder() |
| 29 .SetManifest( |
| 30 DictionaryBuilder().Set("name", "test").Set("version", "0.1").Build()) |
| 31 .SetID(id) |
| 32 .Build(); |
| 33 } |
| 34 |
| 35 } // namespace |
| 36 |
| 37 class ActiveTabPermissionGranterDelegateChromeOSTest |
| 38 : public ChromeRenderViewHostTestHarness { |
| 39 protected: |
| 40 void SetUp() override; |
| 41 void TearDown() override; |
| 42 |
| 43 ActiveTabPermissionGranterDelegateChromeOS delegate_; |
| 44 chromeos::ScopedTestPublicSessionLoginState login_state_; |
| 45 }; |
| 46 |
| 47 void ActiveTabPermissionGranterDelegateChromeOSTest::SetUp() { |
| 48 ChromeRenderViewHostTestHarness::SetUp(); |
| 49 } |
| 50 |
| 51 void ActiveTabPermissionGranterDelegateChromeOSTest::TearDown() { |
| 52 permission_helper::ResetPermissionsForTesting(); |
| 53 ChromeRenderViewHostTestHarness::TearDown(); |
| 54 } |
| 55 |
| 56 TEST_F(ActiveTabPermissionGranterDelegateChromeOSTest, GrantedForWhitelisted) { |
| 57 auto extension = CreateExtension(kWhitelistedId); |
| 58 EXPECT_TRUE(delegate_.ShouldGrantActiveTab(extension.get(), nullptr)); |
| 59 } |
| 60 |
| 61 TEST_F(ActiveTabPermissionGranterDelegateChromeOSTest, |
| 62 RejectedForNonWhitelisted) { |
| 63 auto extension = CreateExtension(kNonWhitelistedId); |
| 64 // Deny the permission request. |
| 65 ScopedTestDialogAutoConfirm auto_confirm(ScopedTestDialogAutoConfirm::CANCEL); |
| 66 // First request is always rejected (by design). |
| 67 EXPECT_FALSE(delegate_.ShouldGrantActiveTab(extension.get(), nullptr)); |
| 68 // Spin the loop, allowing the dialog to be resolved. |
| 69 base::RunLoop().RunUntilIdle(); |
| 70 // Dialog result is propagated here, permission request is rejected. |
| 71 EXPECT_FALSE(delegate_.ShouldGrantActiveTab(extension.get(), nullptr)); |
| 72 } |
| 73 |
| 74 TEST_F(ActiveTabPermissionGranterDelegateChromeOSTest, |
| 75 GrantedForNonWhitelisted) { |
| 76 auto extension = CreateExtension(kNonWhitelistedId); |
| 77 // Allow the permission request. |
| 78 ScopedTestDialogAutoConfirm auto_confirm(ScopedTestDialogAutoConfirm::ACCEPT); |
| 79 EXPECT_FALSE(delegate_.ShouldGrantActiveTab(extension.get(), nullptr)); |
| 80 base::RunLoop().RunUntilIdle(); |
| 81 // The permission request is granted now. |
| 82 EXPECT_TRUE(delegate_.ShouldGrantActiveTab(extension.get(), nullptr)); |
| 83 } |
| 84 |
| 85 } // namespace extensions |
OLD | NEW |