OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/memory/ref_counted.h" | 6 #include "base/memory/ref_counted.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "chrome/browser/extensions/extension_install_prompt.h" | 8 #include "chrome/browser/extensions/extension_install_prompt.h" |
9 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" | 9 #include "chrome/browser/extensions/extension_install_prompt_show_params.h" |
10 #include "content/public/test/test_browser_thread_bundle.h" | 10 #include "content/public/test/test_browser_thread_bundle.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 new PermissionSet(api_permissions, | 46 new PermissionSet(api_permissions, |
47 ManifestPermissionSet(), | 47 ManifestPermissionSet(), |
48 URLPatternSet(), | 48 URLPatternSet(), |
49 URLPatternSet()); | 49 URLPatternSet()); |
50 scoped_refptr<const Extension> extension = | 50 scoped_refptr<const Extension> extension = |
51 ExtensionBuilder().SetManifest( | 51 ExtensionBuilder().SetManifest( |
52 DictionaryBuilder().Set("name", "foo") | 52 DictionaryBuilder().Set("name", "foo") |
53 .Set("version", "1.0") | 53 .Set("version", "1.0") |
54 .Set("manifest_version", 2) | 54 .Set("manifest_version", 2) |
55 .Set("description", "Random Ext")).Build(); | 55 .Set("description", "Random Ext")).Build(); |
56 ExtensionInstallPrompt prompt(NULL /* no web contents in this test */); | 56 ExtensionInstallPrompt prompt(nullptr /* no web contents in this test */); |
57 base::RunLoop run_loop; | 57 base::RunLoop run_loop; |
58 prompt.set_callback_for_test( | 58 prompt.set_callback_for_test( |
59 base::Bind(&VerifyPromptPermissionsCallback, | 59 base::Bind(&VerifyPromptPermissionsCallback, |
60 run_loop.QuitClosure(), | 60 run_loop.QuitClosure(), |
61 1u, // |regular_permissions_count|. | 61 1u, // |regular_permissions_count|. |
62 0u)); // |withheld_permissions_count|. | 62 0u)); // |withheld_permissions_count|. |
63 prompt.ConfirmPermissions(NULL, // no delegate | 63 prompt.ConfirmPermissions(nullptr, // no delegate |
64 extension.get(), | 64 extension.get(), |
65 permission_set.get()); | 65 permission_set.get()); |
66 run_loop.Run(); | 66 run_loop.Run(); |
67 } | 67 } |
68 | 68 |
69 TEST(ExtensionInstallPromptUnittest, PromptShowsWithheldPermissions) { | 69 TEST(ExtensionInstallPromptUnittest, PromptShowsWithheldPermissions) { |
70 content::TestBrowserThreadBundle thread_bundle; | 70 content::TestBrowserThreadBundle thread_bundle; |
71 | 71 |
72 // Enable consent flag so that <all_hosts> permissions get withheld. | 72 // Enable consent flag so that <all_hosts> permissions get withheld. |
73 FeatureSwitch::ScopedOverride enable_scripts_switch( | 73 FeatureSwitch::ScopedOverride enable_scripts_switch( |
74 FeatureSwitch::scripts_require_action(), true); | 74 FeatureSwitch::scripts_require_action(), true); |
75 | 75 |
76 ListBuilder permissions; | |
77 permissions.Append("http://*/*"); | |
78 permissions.Append("http://www.google.com/"); | |
79 permissions.Append("tabs"); | |
80 scoped_refptr<const Extension> extension = | 76 scoped_refptr<const Extension> extension = |
81 ExtensionBuilder().SetManifest( | 77 ExtensionBuilder().SetManifest( |
82 DictionaryBuilder().Set("name", "foo") | 78 DictionaryBuilder().Set("name", "foo") |
83 .Set("version", "1.0") | 79 .Set("version", "1.0") |
84 .Set("manifest_version", 2) | 80 .Set("manifest_version", 2) |
85 .Set("description", "Random Ext") | 81 .Set("description", "Random Ext") |
86 .Set("permissions", permissions)).Build(); | 82 .Set("permissions", |
87 ExtensionInstallPrompt prompt(NULL /* no web contents in this test */); | 83 ListBuilder().Append("http://*/*") |
| 84 .Append("http://www.google.com/") |
| 85 .Append("tabs"))) |
| 86 .Build(); |
| 87 ExtensionInstallPrompt prompt(nullptr /* no web contents in this test */); |
88 base::RunLoop run_loop; | 88 base::RunLoop run_loop; |
89 | 89 |
90 // We expect <all_hosts> to be withheld, but http://www.google.com/ and tabs | 90 // We expect <all_hosts> to be withheld, but http://www.google.com/ and tabs |
91 // permissions should be granted as regular permissions. | 91 // permissions should be granted as regular permissions. |
92 prompt.ConfirmInstall( | 92 prompt.ConfirmInstall( |
93 NULL, | 93 nullptr, |
94 extension.get(), | 94 extension.get(), |
95 base::Bind(&VerifyPromptPermissionsCallback, | 95 base::Bind(&VerifyPromptPermissionsCallback, |
96 run_loop.QuitClosure(), | 96 run_loop.QuitClosure(), |
97 2u, // |regular_permissions_count|. | 97 2u, // |regular_permissions_count|. |
98 1u)); // |withheld_permissions_count|. | 98 1u)); // |withheld_permissions_count|. |
99 run_loop.Run(); | 99 run_loop.Run(); |
100 } | 100 } |
101 | 101 |
| 102 TEST(ExtensionInstallPromptUnittest, DelegatedPromptShowsOptionalPermissions) { |
| 103 content::TestBrowserThreadBundle thread_bundle; |
| 104 scoped_refptr<const Extension> extension = |
| 105 ExtensionBuilder().SetManifest( |
| 106 DictionaryBuilder().Set("name", "foo") |
| 107 .Set("version", "1.0") |
| 108 .Set("manifest_version", 2) |
| 109 .Set("description", "Random Ext") |
| 110 .Set("permissions", ListBuilder().Append("tabs")) |
| 111 .Set("optional_permissions", |
| 112 ListBuilder().Append("location"))) |
| 113 .Build(); |
| 114 ExtensionInstallPrompt prompt(nullptr /* no web contents in this test */); |
| 115 base::RunLoop run_loop; |
| 116 prompt.set_callback_for_test( |
| 117 base::Bind(&VerifyPromptPermissionsCallback, |
| 118 run_loop.QuitClosure(), |
| 119 2u, // |regular_permissions_count|. |
| 120 0u)); // |withheld_permissions_count|. |
| 121 prompt.ConfirmPermissionsForDelegatedInstall(nullptr, // no delegate |
| 122 extension.get(), |
| 123 "Username", |
| 124 nullptr); // no icon |
| 125 run_loop.Run(); |
| 126 } |
| 127 |
102 } // namespace extensions | 128 } // namespace extensions |
OLD | NEW |