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

Side by Side Diff: chrome/browser/extensions/active_tab_unittest.cc

Issue 2858013002: PS - Showing permission prompt for activeTab (Closed)
Patch Set: Added permission message for activeTab; partial tests 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 unified diff | Download patch
OLDNEW
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 <memory> 5 #include <memory>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/macros.h"
11 #include "base/memory/ptr_util.h"
10 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
11 #include "base/values.h" 13 #include "base/values.h"
12 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
13 #include "chrome/browser/extensions/active_tab_permission_granter.h" 15 #include "chrome/browser/extensions/active_tab_permission_granter.h"
14 #include "chrome/browser/extensions/tab_helper.h" 16 #include "chrome/browser/extensions/tab_helper.h"
15 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/sessions/session_tab_helper.h" 18 #include "chrome/browser/sessions/session_tab_helper.h"
17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 19 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
18 #include "components/version_info/version_info.h" 20 #include "components/version_info/version_info.h"
19 #include "content/public/browser/browser_thread.h" 21 #include "content/public/browser/browser_thread.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 .Build(); 62 .Build();
61 } 63 }
62 64
63 enum PermittedFeature { 65 enum PermittedFeature {
64 PERMITTED_NONE, 66 PERMITTED_NONE,
65 PERMITTED_SCRIPT_ONLY, 67 PERMITTED_SCRIPT_ONLY,
66 PERMITTED_CAPTURE_ONLY, 68 PERMITTED_CAPTURE_ONLY,
67 PERMITTED_BOTH 69 PERMITTED_BOTH
68 }; 70 };
69 71
72 class ActiveTabPermissionGranterTestDelegate
73 : public ActiveTabPermissionGranter::Delegate {
74 public:
75 ActiveTabPermissionGranterTestDelegate() {}
76 ~ActiveTabPermissionGranterTestDelegate() override {}
77
78 // ActiveTabPermissionGranterTestDelegate::Delegate
79 bool ShouldGrantActiveTab(const Extension* extension,
80 content::WebContents* contents) override {
81 return should_grant_;
82 }
83
84 void SetShouldGrant(bool should_grant) {
85 should_grant_ = should_grant;
86 }
87
88 private:
89 bool should_grant_ = false;
90
91 DISALLOW_COPY_AND_ASSIGN(ActiveTabPermissionGranterTestDelegate);
92 };
93
70 class ActiveTabTest : public ChromeRenderViewHostTestHarness { 94 class ActiveTabTest : public ChromeRenderViewHostTestHarness {
71 protected: 95 protected:
72 ActiveTabTest() 96 ActiveTabTest()
73 : current_channel(version_info::Channel::DEV), 97 : current_channel(version_info::Channel::DEV),
74 extension(CreateTestExtension("deadbeef", true, false)), 98 extension(CreateTestExtension("deadbeef", true, false)),
75 another_extension(CreateTestExtension("feedbeef", true, false)), 99 another_extension(CreateTestExtension("feedbeef", true, false)),
76 extension_without_active_tab(CreateTestExtension("badbeef", 100 extension_without_active_tab(CreateTestExtension("badbeef",
77 false, 101 false,
78 false)), 102 false)),
79 extension_with_tab_capture(CreateTestExtension("cafebeef", 103 extension_with_tab_capture(CreateTestExtension("cafebeef",
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 const PermissionsData* permissions_data = 397 const PermissionsData* permissions_data =
374 extension_with_tab_capture->permissions_data(); 398 extension_with_tab_capture->permissions_data();
375 EXPECT_TRUE(permissions_data->HasAPIPermissionForTab( 399 EXPECT_TRUE(permissions_data->HasAPIPermissionForTab(
376 tab_id(), APIPermission::kTabCaptureForTab)); 400 tab_id(), APIPermission::kTabCaptureForTab));
377 401
378 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1)); 402 EXPECT_TRUE(IsBlocked(extension_with_tab_capture, internal, tab_id() + 1));
379 EXPECT_FALSE(permissions_data->HasAPIPermissionForTab( 403 EXPECT_FALSE(permissions_data->HasAPIPermissionForTab(
380 tab_id() + 1, APIPermission::kTabCaptureForTab)); 404 tab_id() + 1, APIPermission::kTabCaptureForTab));
381 } 405 }
382 406
407 // Test that the custom platform delegate works as expected.
408 TEST_F(ActiveTabTest, Delegate) {
409 auto test_delegate =
410 base::MakeUnique<ActiveTabPermissionGranterTestDelegate>();
411 ActiveTabPermissionGranter::SetPlatformDelegate(test_delegate.get());
412
413 GURL google("http://www.google.com");
414 NavigateAndCommit(google);
415
416 // Not granted because the delegate denies grant.
417 active_tab_permission_granter()->GrantIfRequested(extension.get());
418 EXPECT_TRUE(IsBlocked(extension, google));
419
420 // This time it's granted because the delegate allows it.
421 test_delegate->SetShouldGrant(true);
422 active_tab_permission_granter()->GrantIfRequested(extension.get());
423 EXPECT_TRUE(IsAllowed(extension, google));
424
425 // Cleanup :).
426 ActiveTabPermissionGranter::SetPlatformDelegate(nullptr);
427 }
428
383 } // namespace 429 } // namespace
384 } // namespace extensions 430 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698