base::Time multiplicative operator overloading
[chromium-blink-merge.git] / chrome / browser / extensions / extension_install_prompt_unittest.cc
blob75967dfb5a77e889e5cd606d48af3f8fc7b4e7a1
1 // Copyright 2014 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.
5 #include "base/bind.h"
6 #include "base/memory/ref_counted.h"
7 #include "base/run_loop.h"
8 #include "chrome/browser/extensions/extension_install_prompt.h"
9 #include "chrome/browser/extensions/extension_install_prompt_show_params.h"
10 #include "content/public/test/test_browser_thread_bundle.h"
11 #include "extensions/common/extension.h"
12 #include "extensions/common/extension_builder.h"
13 #include "extensions/common/feature_switch.h"
14 #include "extensions/common/permissions/api_permission.h"
15 #include "extensions/common/permissions/api_permission_set.h"
16 #include "extensions/common/permissions/manifest_permission_set.h"
17 #include "extensions/common/permissions/permission_set.h"
18 #include "extensions/common/url_pattern_set.h"
19 #include "extensions/common/value_builder.h"
20 #include "testing/gtest/include/gtest/gtest.h"
22 namespace extensions {
24 void VerifyPromptPermissionsCallback(
25 const base::Closure& quit_closure,
26 size_t regular_permissions_count,
27 size_t withheld_permissions_count,
28 ExtensionInstallPromptShowParams* params,
29 ExtensionInstallPrompt::Delegate* delegate,
30 scoped_refptr<ExtensionInstallPrompt::Prompt> install_prompt) {
31 ASSERT_TRUE(install_prompt.get());
32 EXPECT_EQ(regular_permissions_count,
33 install_prompt->GetPermissionCount(
34 ExtensionInstallPrompt::REGULAR_PERMISSIONS));
35 EXPECT_EQ(withheld_permissions_count,
36 install_prompt->GetPermissionCount(
37 ExtensionInstallPrompt::WITHHELD_PERMISSIONS));
38 quit_closure.Run();
41 TEST(ExtensionInstallPromptUnittest, PromptShowsPermissionWarnings) {
42 content::TestBrowserThreadBundle thread_bundle;
43 APIPermissionSet api_permissions;
44 api_permissions.insert(APIPermission::kTab);
45 scoped_refptr<PermissionSet> permission_set =
46 new PermissionSet(api_permissions,
47 ManifestPermissionSet(),
48 URLPatternSet(),
49 URLPatternSet());
50 scoped_refptr<const Extension> extension =
51 ExtensionBuilder().SetManifest(
52 DictionaryBuilder().Set("name", "foo")
53 .Set("version", "1.0")
54 .Set("manifest_version", 2)
55 .Set("description", "Random Ext")).Build();
56 ExtensionInstallPrompt prompt(NULL /* no web contents in this test */);
57 base::RunLoop run_loop;
58 prompt.set_callback_for_test(
59 base::Bind(&VerifyPromptPermissionsCallback,
60 run_loop.QuitClosure(),
61 1u, // |regular_permissions_count|.
62 0u)); // |withheld_permissions_count|.
63 prompt.ConfirmPermissions(NULL, // no delegate
64 extension.get(),
65 permission_set.get());
66 run_loop.Run();
69 TEST(ExtensionInstallPromptUnittest, PromptShowsWithheldPermissions) {
70 content::TestBrowserThreadBundle thread_bundle;
72 // Enable consent flag so that <all_hosts> permissions get withheld.
73 FeatureSwitch::ScopedOverride enable_scripts_switch(
74 FeatureSwitch::scripts_require_action(), true);
76 ListBuilder permissions;
77 permissions.Append("http://*/*");
78 permissions.Append("http://www.google.com/");
79 permissions.Append("tabs");
80 scoped_refptr<const Extension> extension =
81 ExtensionBuilder().SetManifest(
82 DictionaryBuilder().Set("name", "foo")
83 .Set("version", "1.0")
84 .Set("manifest_version", 2)
85 .Set("description", "Random Ext")
86 .Set("permissions", permissions)).Build();
87 ExtensionInstallPrompt prompt(NULL /* no web contents in this test */);
88 base::RunLoop run_loop;
90 // We expect <all_hosts> to be withheld, but http://www.google.com/ and tabs
91 // permissions should be granted as regular permissions.
92 prompt.ConfirmInstall(
93 NULL,
94 extension.get(),
95 base::Bind(&VerifyPromptPermissionsCallback,
96 run_loop.QuitClosure(),
97 2u, // |regular_permissions_count|.
98 1u)); // |withheld_permissions_count|.
99 run_loop.Run();
102 } // namespace extensions