Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5665)

Unified Diff: chrome/browser/extensions/active_tab_unittest.cc

Issue 2858013002: PS - Showing permission prompt for activeTab (Closed)
Patch Set: Changed permission prompt message Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..77b8e472aaa73a9c83e147b41cf361a513263b07 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"
@@ -32,6 +34,20 @@
#include "extensions/common/permissions/permissions_data.h"
#include "extensions/common/value_builder.h"
+#if defined(OS_CHROMEOS)
+#include "base/run_loop.h"
+#include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
+#include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h"
+#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
+#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#include "chrome/browser/chromeos/settings/device_settings_service.h"
+#include "chrome/test/base/scoped_testing_local_state.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "chromeos/login/scoped_test_public_session_login_state.h"
+#include "components/signin/core/account_id/account_id.h"
+#include "extensions/browser/extension_dialog_auto_confirm.h"
+#endif
+
using base::DictionaryValue;
using base::ListValue;
using content::BrowserThread;
@@ -67,6 +83,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 +418,81 @@ 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);
+}
+
+#if defined(OS_CHROMEOS)
+// Test that the platform delegate is being set and the permission is prompted
+// for.
+TEST_F(ActiveTabTest, DelegateIsSet) {
+ // Setup, login a public account user.
+ chromeos::ScopedTestPublicSessionLoginState login_state;
+ std::string user_id = "public@account.user";
+ std::string user_email = user_id;
+ AccountId account_id = AccountId::FromUserEmailGaiaId(user_email, user_id);
+ std::string user_id_hash = chromeos::ProfileHelper::Get()->
+ GetUserIdHashByUserIdForTesting(user_id);
+ chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
+ chromeos::ScopedTestCrosSettings test_cros_settings_;
+ ScopedTestingLocalState local_state(TestingBrowserProcess::GetGlobal());
+ chromeos::ScopedTestUserManager test_user_manager_;
+ chromeos::WallpaperManager::Initialize();
+ g_browser_process->local_state()->SetString(
+ "PublicAccountPendingDataRemoval", user_email);
+ user_manager::UserManager::Get()->UserLoggedIn(
+ account_id, user_id_hash, true);
+
+ GURL google("http://www.google.com");
+ NavigateAndCommit(google);
+
+ // Grant and verify.
+ {
+ ScopedTestDialogAutoConfirm auto_confirm(
+ ScopedTestDialogAutoConfirm::ACCEPT);
+ active_tab_permission_granter()->GrantIfRequested(extension.get());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(IsBlocked(extension, google));
+ active_tab_permission_granter()->GrantIfRequested(extension.get());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(IsAllowed(extension, google));
+ }
+
+ // Deny and verify. Use a different extension so it doesn't trigger the cache.
+ {
+ ScopedTestDialogAutoConfirm auto_confirm(
+ ScopedTestDialogAutoConfirm::CANCEL);
+ active_tab_permission_granter()->GrantIfRequested(another_extension.get());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(IsBlocked(another_extension, google));
+ active_tab_permission_granter()->GrantIfRequested(another_extension.get());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_TRUE(IsBlocked(another_extension, google));
+ }
+
+ // Cleanup.
+ chromeos::WallpaperManager::Shutdown();
+ free(ActiveTabPermissionGranter::SetPlatformDelegate(nullptr));
Lei Zhang 2017/05/27 01:19:42 This should be a delete. Have you considered uniqu
+}
+#endif
+
} // namespace
} // namespace extensions
« no previous file with comments | « chrome/browser/extensions/active_tab_permission_granter.cc ('k') | chrome/browser/extensions/extension_install_prompt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698