| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/chromeos/extensions/active_tab_permission_granter_deleg
ate_chromeos.h" | 5 #include "chrome/browser/chromeos/extensions/active_tab_permission_granter_deleg
ate_chromeos.h" |
| 6 | 6 |
| 7 #include <memory> | |
| 8 #include <string> | 7 #include <string> |
| 9 | 8 |
| 10 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 11 #include "chrome/browser/chromeos/extensions/public_session_permission_helper.h" | 10 #include "chrome/browser/chromeos/extensions/public_session_permission_helper.h" |
| 12 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 11 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 13 #include "chromeos/login/scoped_test_public_session_login_state.h" | 12 #include "chromeos/login/scoped_test_public_session_login_state.h" |
| 14 #include "extensions/browser/extension_dialog_auto_confirm.h" | 13 #include "extensions/browser/extension_dialog_auto_confirm.h" |
| 15 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
| 16 #include "extensions/common/extension_builder.h" | 15 #include "extensions/common/extension_builder.h" |
| 17 #include "extensions/common/value_builder.h" | 16 #include "extensions/common/value_builder.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 35 | 34 |
| 36 } // namespace | 35 } // namespace |
| 37 | 36 |
| 38 class ActiveTabPermissionGranterDelegateChromeOSTest | 37 class ActiveTabPermissionGranterDelegateChromeOSTest |
| 39 : public ChromeRenderViewHostTestHarness { | 38 : public ChromeRenderViewHostTestHarness { |
| 40 protected: | 39 protected: |
| 41 void SetUp() override; | 40 void SetUp() override; |
| 42 void TearDown() override; | 41 void TearDown() override; |
| 43 | 42 |
| 44 ActiveTabPermissionGranterDelegateChromeOS delegate_; | 43 ActiveTabPermissionGranterDelegateChromeOS delegate_; |
| 45 std::unique_ptr<chromeos::ScopedTestPublicSessionLoginState> login_state_; | 44 chromeos::ScopedTestPublicSessionLoginState login_state_; |
| 46 }; | 45 }; |
| 47 | 46 |
| 48 void ActiveTabPermissionGranterDelegateChromeOSTest::SetUp() { | 47 void ActiveTabPermissionGranterDelegateChromeOSTest::SetUp() { |
| 49 ChromeRenderViewHostTestHarness::SetUp(); | 48 ChromeRenderViewHostTestHarness::SetUp(); |
| 50 login_state_.reset(new chromeos::ScopedTestPublicSessionLoginState()); | |
| 51 } | 49 } |
| 52 | 50 |
| 53 void ActiveTabPermissionGranterDelegateChromeOSTest::TearDown() { | 51 void ActiveTabPermissionGranterDelegateChromeOSTest::TearDown() { |
| 54 login_state_.reset(); | |
| 55 permission_helper::ResetPermissionsForTesting(); | 52 permission_helper::ResetPermissionsForTesting(); |
| 56 ChromeRenderViewHostTestHarness::TearDown(); | 53 ChromeRenderViewHostTestHarness::TearDown(); |
| 57 } | 54 } |
| 58 | 55 |
| 59 TEST_F(ActiveTabPermissionGranterDelegateChromeOSTest, GrantedForWhitelisted) { | 56 TEST_F(ActiveTabPermissionGranterDelegateChromeOSTest, GrantedForWhitelisted) { |
| 60 auto extension = CreateExtension(kWhitelistedId); | 57 auto extension = CreateExtension(kWhitelistedId); |
| 61 EXPECT_TRUE(delegate_.ShouldGrantActiveTab(extension.get(), nullptr)); | 58 EXPECT_TRUE(delegate_.ShouldGrantActiveTab(extension.get(), nullptr)); |
| 62 } | 59 } |
| 63 | 60 |
| 64 TEST_F(ActiveTabPermissionGranterDelegateChromeOSTest, | 61 TEST_F(ActiveTabPermissionGranterDelegateChromeOSTest, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 79 auto extension = CreateExtension(kNonWhitelistedId); | 76 auto extension = CreateExtension(kNonWhitelistedId); |
| 80 // Allow the permission request. | 77 // Allow the permission request. |
| 81 ScopedTestDialogAutoConfirm auto_confirm(ScopedTestDialogAutoConfirm::ACCEPT); | 78 ScopedTestDialogAutoConfirm auto_confirm(ScopedTestDialogAutoConfirm::ACCEPT); |
| 82 EXPECT_FALSE(delegate_.ShouldGrantActiveTab(extension.get(), nullptr)); | 79 EXPECT_FALSE(delegate_.ShouldGrantActiveTab(extension.get(), nullptr)); |
| 83 base::RunLoop().RunUntilIdle(); | 80 base::RunLoop().RunUntilIdle(); |
| 84 // The permission request is granted now. | 81 // The permission request is granted now. |
| 85 EXPECT_TRUE(delegate_.ShouldGrantActiveTab(extension.get(), nullptr)); | 82 EXPECT_TRUE(delegate_.ShouldGrantActiveTab(extension.get(), nullptr)); |
| 86 } | 83 } |
| 87 | 84 |
| 88 } // namespace extensions | 85 } // namespace extensions |
| OLD | NEW |