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 "chrome/browser/ui/views/apps/app_info_dialog/app_info_permissions_pane
l.h" | 5 #include "chrome/browser/ui/views/apps/app_info_dialog/app_info_permissions_pane
l.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "apps/saved_files_service.h" | 9 #include "apps/saved_files_service.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 | 37 |
38 class AppInfoPermissionsPanelTest : public testing::Test { | 38 class AppInfoPermissionsPanelTest : public testing::Test { |
39 protected: | 39 protected: |
40 AppInfoPermissionsPanelTest() {} | 40 AppInfoPermissionsPanelTest() {} |
41 | 41 |
42 scoped_ptr<base::DictionaryValue> ValidAppManifest() { | 42 scoped_ptr<base::DictionaryValue> ValidAppManifest() { |
43 return extensions::DictionaryBuilder() | 43 return extensions::DictionaryBuilder() |
44 .Set("name", "Test App Name") | 44 .Set("name", "Test App Name") |
45 .Set("version", "2.0") | 45 .Set("version", "2.0") |
46 .Set("manifest_version", 2) | 46 .Set("manifest_version", 2) |
47 .Set("app", | 47 .Set("app", extensions::DictionaryBuilder() |
48 std::move(extensions::DictionaryBuilder().Set( | 48 .Set("background", |
49 "background", | 49 extensions::DictionaryBuilder() |
50 std::move(extensions::DictionaryBuilder().Set( | 50 .Set("scripts", extensions::ListBuilder() |
51 "scripts", std::move(extensions::ListBuilder().Append( | 51 .Append("background.js") |
52 "background.js"))))))) | 52 .Build()) |
| 53 .Build()) |
| 54 .Build()) |
53 .Build(); | 55 .Build(); |
54 } | 56 } |
55 | 57 |
56 // We need the UI thread in order to construct UI elements in the view. | 58 // We need the UI thread in order to construct UI elements in the view. |
57 content::TestBrowserThreadBundle thread_bundle_; | 59 content::TestBrowserThreadBundle thread_bundle_; |
58 TestingProfile profile_; | 60 TestingProfile profile_; |
59 }; | 61 }; |
60 | 62 |
61 // Tests that an app with no permissions is treated correctly. | 63 // Tests that an app with no permissions is treated correctly. |
62 TEST_F(AppInfoPermissionsPanelTest, NoPermissionsObtainedCorrectly) { | 64 TEST_F(AppInfoPermissionsPanelTest, NoPermissionsObtainedCorrectly) { |
63 scoped_refptr<const extensions::Extension> app = | 65 scoped_refptr<const extensions::Extension> app = |
64 extensions::ExtensionBuilder() | 66 extensions::ExtensionBuilder() |
65 .SetManifest(ValidAppManifest()) | 67 .SetManifest(ValidAppManifest()) |
66 .SetID(kTestExtensionId) | 68 .SetID(kTestExtensionId) |
67 .Build(); | 69 .Build(); |
68 AppInfoPermissionsPanel panel(&profile_, app.get()); | 70 AppInfoPermissionsPanel panel(&profile_, app.get()); |
69 | 71 |
70 EXPECT_TRUE(VerifyNoPermissionMessages(panel.app_->permissions_data())); | 72 EXPECT_TRUE(VerifyNoPermissionMessages(panel.app_->permissions_data())); |
71 EXPECT_TRUE(panel.GetRetainedFilePaths().empty()); | 73 EXPECT_TRUE(panel.GetRetainedFilePaths().empty()); |
72 } | 74 } |
73 | 75 |
74 // Tests that an app's required permissions are detected and converted to | 76 // Tests that an app's required permissions are detected and converted to |
75 // messages correctly. | 77 // messages correctly. |
76 TEST_F(AppInfoPermissionsPanelTest, RequiredPermissionsObtainedCorrectly) { | 78 TEST_F(AppInfoPermissionsPanelTest, RequiredPermissionsObtainedCorrectly) { |
77 scoped_refptr<const extensions::Extension> app = | 79 scoped_refptr<const extensions::Extension> app = |
78 extensions::ExtensionBuilder() | 80 extensions::ExtensionBuilder() |
79 .SetManifest(ValidAppManifest()) | 81 .SetManifest(ValidAppManifest()) |
80 .MergeManifest(extensions::DictionaryBuilder().Set( | 82 .MergeManifest( |
81 "permissions", | 83 extensions::DictionaryBuilder() |
82 std::move( | 84 .Set("permissions", extensions::ListBuilder() |
83 extensions::ListBuilder() | 85 // A valid permission with a message |
84 .Append("desktopCapture") // A valid permission with a | 86 .Append("desktopCapture") |
85 // message | 87 // An invalid permission |
86 .Append("bad_perm") // An invalid permission | 88 .Append("bad_perm") |
87 .Append("cookies") // An valid permission with | 89 // An valid permission with no message |
88 // no message | 90 .Append("cookies") |
89 .Append("serial")))) // A valid permission with a | 91 // A valid permission with a message |
90 // message | 92 .Append("serial") |
| 93 .Build()) |
| 94 .Build()) |
91 .SetID(kTestExtensionId) | 95 .SetID(kTestExtensionId) |
92 .Build(); | 96 .Build(); |
93 AppInfoPermissionsPanel panel(&profile_, app.get()); | 97 AppInfoPermissionsPanel panel(&profile_, app.get()); |
94 | 98 |
95 EXPECT_TRUE(VerifyTwoPermissionMessages( | 99 EXPECT_TRUE(VerifyTwoPermissionMessages( |
96 panel.app_->permissions_data(), | 100 panel.app_->permissions_data(), |
97 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_WARNING_DESKTOP_CAPTURE), | 101 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_WARNING_DESKTOP_CAPTURE), |
98 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_WARNING_SERIAL), | 102 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_WARNING_SERIAL), |
99 false)); | 103 false)); |
100 } | 104 } |
101 | 105 |
102 // Tests that an app's optional permissions are detected and converted to | 106 // Tests that an app's optional permissions are detected and converted to |
103 // messages correctly. | 107 // messages correctly. |
104 TEST_F(AppInfoPermissionsPanelTest, OptionalPermissionsObtainedCorrectly) { | 108 TEST_F(AppInfoPermissionsPanelTest, OptionalPermissionsObtainedCorrectly) { |
105 scoped_refptr<const extensions::Extension> app = | 109 scoped_refptr<const extensions::Extension> app = |
106 extensions::ExtensionBuilder() | 110 extensions::ExtensionBuilder() |
107 .SetManifest(ValidAppManifest()) | 111 .SetManifest(ValidAppManifest()) |
108 .MergeManifest(extensions::DictionaryBuilder().Set( | 112 .MergeManifest(extensions::DictionaryBuilder() |
109 "optional_permissions", | 113 .Set("optional_permissions", |
110 std::move( | 114 extensions::ListBuilder() |
111 extensions::ListBuilder() | 115 // A valid permission with a message |
112 .Append("clipboardRead") // A valid permission with a | 116 .Append("clipboardRead") |
113 // message | 117 // An invalid permission |
114 .Append("bad_perm") // An invalid permission | 118 .Append("bad_perm") |
115 .Append("idle") // A valid permission with | 119 // A valid permission with no message |
116 // no message | 120 .Append("idle") |
117 .Append("serial")))) // Another valid permission with | 121 // Another valid permission with a message |
118 // a message | 122 .Append("serial") |
| 123 .Build()) |
| 124 .Build()) |
119 .SetID(kTestExtensionId) | 125 .SetID(kTestExtensionId) |
120 .Build(); | 126 .Build(); |
121 AppInfoPermissionsPanel panel(&profile_, app.get()); | 127 AppInfoPermissionsPanel panel(&profile_, app.get()); |
122 | 128 |
123 // Optional permissions don't appear until they are 'activated' at runtime. | 129 // Optional permissions don't appear until they are 'activated' at runtime. |
124 // TODO(sashab): Activate the optional permissions and ensure they are | 130 // TODO(sashab): Activate the optional permissions and ensure they are |
125 // successfully added to the dialog. | 131 // successfully added to the dialog. |
126 EXPECT_TRUE(VerifyNoPermissionMessages(panel.app_->permissions_data())); | 132 EXPECT_TRUE(VerifyNoPermissionMessages(panel.app_->permissions_data())); |
127 EXPECT_TRUE(panel.GetRetainedFilePaths().empty()); | 133 EXPECT_TRUE(panel.GetRetainedFilePaths().empty()); |
128 } | 134 } |
129 | 135 |
130 // Tests that an app's retained files are detected and converted to paths | 136 // Tests that an app's retained files are detected and converted to paths |
131 // correctly. | 137 // correctly. |
132 TEST_F(AppInfoPermissionsPanelTest, RetainedFilePermissionsObtainedCorrectly) { | 138 TEST_F(AppInfoPermissionsPanelTest, RetainedFilePermissionsObtainedCorrectly) { |
133 scoped_refptr<const extensions::Extension> app = | 139 scoped_refptr<const extensions::Extension> app = |
134 extensions::ExtensionBuilder() | 140 extensions::ExtensionBuilder() |
135 .SetManifest(ValidAppManifest()) | 141 .SetManifest(ValidAppManifest()) |
136 .MergeManifest(extensions::DictionaryBuilder().Set( | 142 .MergeManifest( |
137 "permissions", | 143 extensions::DictionaryBuilder() |
138 std::move(extensions::ListBuilder().Append( | 144 .Set("permissions", |
139 std::move(extensions::DictionaryBuilder().Set( | 145 extensions::ListBuilder() |
140 "fileSystem", std::move(extensions::ListBuilder().Append( | 146 .Append(extensions::DictionaryBuilder() |
141 "retainEntries")))))))) | 147 .Set("fileSystem", |
| 148 extensions::ListBuilder() |
| 149 .Append("retainEntries") |
| 150 .Build()) |
| 151 .Build()) |
| 152 .Build()) |
| 153 .Build()) |
142 .SetID(kTestExtensionId) | 154 .SetID(kTestExtensionId) |
143 .Build(); | 155 .Build(); |
144 AppInfoPermissionsPanel panel(&profile_, app.get()); | 156 AppInfoPermissionsPanel panel(&profile_, app.get()); |
145 apps::SavedFilesService* files_service = | 157 apps::SavedFilesService* files_service = |
146 apps::SavedFilesService::Get(&profile_); | 158 apps::SavedFilesService::Get(&profile_); |
147 files_service->RegisterFileEntry( | 159 files_service->RegisterFileEntry( |
148 app->id(), "file_id_1", FilePath(FILE_PATH_LITERAL("file_1.ext")), false); | 160 app->id(), "file_id_1", FilePath(FILE_PATH_LITERAL("file_1.ext")), false); |
149 files_service->RegisterFileEntry( | 161 files_service->RegisterFileEntry( |
150 app->id(), "file_id_2", FilePath(FILE_PATH_LITERAL("file_2.ext")), false); | 162 app->id(), "file_id_2", FilePath(FILE_PATH_LITERAL("file_2.ext")), false); |
151 files_service->RegisterFileEntry( | 163 files_service->RegisterFileEntry( |
152 app->id(), "file_id_3", FilePath(FILE_PATH_LITERAL("file_3.ext")), false); | 164 app->id(), "file_id_3", FilePath(FILE_PATH_LITERAL("file_3.ext")), false); |
153 | 165 |
154 ASSERT_TRUE(VerifyNoPermissionMessages(panel.app_->permissions_data())); | 166 ASSERT_TRUE(VerifyNoPermissionMessages(panel.app_->permissions_data())); |
155 | 167 |
156 // Since we have no guarantees on the order of retained files, make sure the | 168 // Since we have no guarantees on the order of retained files, make sure the |
157 // list is the expected length and all required entries are present. | 169 // list is the expected length and all required entries are present. |
158 const std::vector<base::string16> retained_file_paths = | 170 const std::vector<base::string16> retained_file_paths = |
159 panel.GetRetainedFilePaths(); | 171 panel.GetRetainedFilePaths(); |
160 ASSERT_EQ(3U, retained_file_paths.size()); | 172 ASSERT_EQ(3U, retained_file_paths.size()); |
161 EXPECT_THAT(retained_file_paths, | 173 EXPECT_THAT(retained_file_paths, |
162 Contains(Eq(base::UTF8ToUTF16("file_1.ext")))); | 174 Contains(Eq(base::UTF8ToUTF16("file_1.ext")))); |
163 EXPECT_THAT(retained_file_paths, | 175 EXPECT_THAT(retained_file_paths, |
164 Contains(Eq(base::UTF8ToUTF16("file_2.ext")))); | 176 Contains(Eq(base::UTF8ToUTF16("file_2.ext")))); |
165 EXPECT_THAT(retained_file_paths, | 177 EXPECT_THAT(retained_file_paths, |
166 Contains(Eq(base::UTF8ToUTF16("file_3.ext")))); | 178 Contains(Eq(base::UTF8ToUTF16("file_3.ext")))); |
167 } | 179 } |
OLD | NEW |