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 "apps/saved_files_service.h" | 7 #include "apps/saved_files_service.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 content::TestBrowserThreadBundle thread_bundle_; | 56 content::TestBrowserThreadBundle thread_bundle_; |
57 }; | 57 }; |
58 | 58 |
59 // Tests that an app with no permissions is treated correctly. | 59 // Tests that an app with no permissions is treated correctly. |
60 TEST_F(AppInfoPermissionsPanelTest, NoPermissionsObtainedCorrectly) { | 60 TEST_F(AppInfoPermissionsPanelTest, NoPermissionsObtainedCorrectly) { |
61 scoped_refptr<const extensions::Extension> app = | 61 scoped_refptr<const extensions::Extension> app = |
62 extensions::ExtensionBuilder() | 62 extensions::ExtensionBuilder() |
63 .SetManifest(ValidAppManifest()) | 63 .SetManifest(ValidAppManifest()) |
64 .SetID(kTestExtensionId) | 64 .SetID(kTestExtensionId) |
65 .Build(); | 65 .Build(); |
66 AppInfoPermissionsPanel panel(&profile_, app); | 66 AppInfoPermissionsPanel panel(&profile_, app.get()); |
67 | 67 |
68 EXPECT_TRUE(panel.GetActivePermissionMessages().empty()); | 68 EXPECT_TRUE(panel.GetActivePermissionMessages().empty()); |
69 EXPECT_TRUE(panel.GetRetainedFilePaths().empty()); | 69 EXPECT_TRUE(panel.GetRetainedFilePaths().empty()); |
70 } | 70 } |
71 | 71 |
72 // Tests that an app's required permissions are detected and converted to | 72 // Tests that an app's required permissions are detected and converted to |
73 // messages correctly. | 73 // messages correctly. |
74 TEST_F(AppInfoPermissionsPanelTest, RequiredPermissionsObtainedCorrectly) { | 74 TEST_F(AppInfoPermissionsPanelTest, RequiredPermissionsObtainedCorrectly) { |
75 scoped_refptr<const extensions::Extension> app = | 75 scoped_refptr<const extensions::Extension> app = |
76 extensions::ExtensionBuilder() | 76 extensions::ExtensionBuilder() |
77 .SetManifest(ValidAppManifest()) | 77 .SetManifest(ValidAppManifest()) |
78 .MergeManifest(extensions::DictionaryBuilder().Set( | 78 .MergeManifest(extensions::DictionaryBuilder().Set( |
79 "permissions", | 79 "permissions", |
80 extensions::ListBuilder() | 80 extensions::ListBuilder() |
81 .Append("desktopCapture") // A valid permission with a | 81 .Append("desktopCapture") // A valid permission with a |
82 // message | 82 // message |
83 .Append("bad_perm") // An invalid permission | 83 .Append("bad_perm") // An invalid permission |
84 .Append("notifications") // An valid permission with | 84 .Append("notifications") // An valid permission with |
85 // no message | 85 // no message |
86 .Append("serial"))) // Another valid permission with | 86 .Append("serial"))) // Another valid permission with |
87 // a message | 87 // a message |
88 .SetID(kTestExtensionId) | 88 .SetID(kTestExtensionId) |
89 .Build(); | 89 .Build(); |
90 AppInfoPermissionsPanel panel(&profile_, app); | 90 AppInfoPermissionsPanel panel(&profile_, app.get()); |
91 | 91 |
92 const std::vector<base::string16> permission_messages = | 92 const std::vector<base::string16> permission_messages = |
93 panel.GetActivePermissionMessages(); | 93 panel.GetActivePermissionMessages(); |
94 ASSERT_EQ(2U, permission_messages.size()); | 94 ASSERT_EQ(2U, permission_messages.size()); |
95 EXPECT_EQ( | 95 EXPECT_EQ( |
96 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_WARNING_DESKTOP_CAPTURE), | 96 l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_WARNING_DESKTOP_CAPTURE), |
97 base::UTF16ToUTF8(permission_messages[0])); | 97 base::UTF16ToUTF8(permission_messages[0])); |
98 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_WARNING_SERIAL), | 98 EXPECT_EQ(l10n_util::GetStringUTF8(IDS_EXTENSION_PROMPT_WARNING_SERIAL), |
99 base::UTF16ToUTF8(permission_messages[1])); | 99 base::UTF16ToUTF8(permission_messages[1])); |
100 } | 100 } |
101 | 101 |
102 // Tests that an app's optional permissions are detected and converted to | 102 // Tests that an app's optional permissions are detected and converted to |
103 // messages correctly. | 103 // messages correctly. |
104 TEST_F(AppInfoPermissionsPanelTest, OptionalPermissionsObtainedCorrectly) { | 104 TEST_F(AppInfoPermissionsPanelTest, OptionalPermissionsObtainedCorrectly) { |
105 scoped_refptr<const extensions::Extension> app = | 105 scoped_refptr<const extensions::Extension> app = |
106 extensions::ExtensionBuilder() | 106 extensions::ExtensionBuilder() |
107 .SetManifest(ValidAppManifest()) | 107 .SetManifest(ValidAppManifest()) |
108 .MergeManifest(extensions::DictionaryBuilder().Set( | 108 .MergeManifest(extensions::DictionaryBuilder().Set( |
109 "optional_permissions", | 109 "optional_permissions", |
110 extensions::ListBuilder() | 110 extensions::ListBuilder() |
111 .Append("clipboardRead") // A valid permission with a | 111 .Append("clipboardRead") // A valid permission with a |
112 // message | 112 // message |
113 .Append("bad_perm") // An invalid permission | 113 .Append("bad_perm") // An invalid permission |
114 .Append("idle") // A valid permission with | 114 .Append("idle") // A valid permission with |
115 // no message | 115 // no message |
116 .Append("serial"))) // Another valid permission with | 116 .Append("serial"))) // Another valid permission with |
117 // a message | 117 // a message |
118 .SetID(kTestExtensionId) | 118 .SetID(kTestExtensionId) |
119 .Build(); | 119 .Build(); |
120 AppInfoPermissionsPanel panel(&profile_, app); | 120 AppInfoPermissionsPanel panel(&profile_, app.get()); |
121 | 121 |
122 // Optional permissions don't appear until they are 'activated' at runtime. | 122 // Optional permissions don't appear until they are 'activated' at runtime. |
123 // TODO(sashab): Activate the optional permissions and ensure they are | 123 // TODO(sashab): Activate the optional permissions and ensure they are |
124 // successfully added to the dialog. | 124 // successfully added to the dialog. |
125 EXPECT_TRUE(panel.GetActivePermissionMessages().empty()); | 125 EXPECT_TRUE(panel.GetActivePermissionMessages().empty()); |
126 EXPECT_TRUE(panel.GetRetainedFilePaths().empty()); | 126 EXPECT_TRUE(panel.GetRetainedFilePaths().empty()); |
127 } | 127 } |
128 | 128 |
129 // Tests that an app's retained files are detected and converted to paths | 129 // Tests that an app's retained files are detected and converted to paths |
130 // correctly. | 130 // correctly. |
131 TEST_F(AppInfoPermissionsPanelTest, RetainedFilePermissionsObtainedCorrectly) { | 131 TEST_F(AppInfoPermissionsPanelTest, RetainedFilePermissionsObtainedCorrectly) { |
132 scoped_refptr<const extensions::Extension> app = | 132 scoped_refptr<const extensions::Extension> app = |
133 extensions::ExtensionBuilder() | 133 extensions::ExtensionBuilder() |
134 .SetManifest(ValidAppManifest()) | 134 .SetManifest(ValidAppManifest()) |
135 .MergeManifest(extensions::DictionaryBuilder().Set( | 135 .MergeManifest(extensions::DictionaryBuilder().Set( |
136 "permissions", | 136 "permissions", |
137 extensions::ListBuilder().Append( | 137 extensions::ListBuilder().Append( |
138 extensions::DictionaryBuilder().Set( | 138 extensions::DictionaryBuilder().Set( |
139 "fileSystem", | 139 "fileSystem", |
140 extensions::ListBuilder().Append("retainEntries"))))) | 140 extensions::ListBuilder().Append("retainEntries"))))) |
141 .SetID(kTestExtensionId) | 141 .SetID(kTestExtensionId) |
142 .Build(); | 142 .Build(); |
143 AppInfoPermissionsPanel panel(&profile_, app); | 143 AppInfoPermissionsPanel panel(&profile_, app.get()); |
144 apps::SavedFilesService* files_service = | 144 apps::SavedFilesService* files_service = |
145 apps::SavedFilesService::Get(&profile_); | 145 apps::SavedFilesService::Get(&profile_); |
146 files_service->RegisterFileEntry( | 146 files_service->RegisterFileEntry( |
147 app->id(), "file_id_1", FilePath(FILE_PATH_LITERAL("file_1.ext")), false); | 147 app->id(), "file_id_1", FilePath(FILE_PATH_LITERAL("file_1.ext")), false); |
148 files_service->RegisterFileEntry( | 148 files_service->RegisterFileEntry( |
149 app->id(), "file_id_2", FilePath(FILE_PATH_LITERAL("file_2.ext")), false); | 149 app->id(), "file_id_2", FilePath(FILE_PATH_LITERAL("file_2.ext")), false); |
150 files_service->RegisterFileEntry( | 150 files_service->RegisterFileEntry( |
151 app->id(), "file_id_3", FilePath(FILE_PATH_LITERAL("file_3.ext")), false); | 151 app->id(), "file_id_3", FilePath(FILE_PATH_LITERAL("file_3.ext")), false); |
152 | 152 |
153 const std::vector<base::string16> permission_messages = | 153 const std::vector<base::string16> permission_messages = |
154 panel.GetActivePermissionMessages(); | 154 panel.GetActivePermissionMessages(); |
155 ASSERT_TRUE(permission_messages.empty()); | 155 ASSERT_TRUE(permission_messages.empty()); |
156 | 156 |
157 // Since we have no guarantees on the order of retained files, make sure the | 157 // Since we have no guarantees on the order of retained files, make sure the |
158 // list is the expected length and all required entries are present. | 158 // list is the expected length and all required entries are present. |
159 const std::vector<base::string16> retained_file_paths = | 159 const std::vector<base::string16> retained_file_paths = |
160 panel.GetRetainedFilePaths(); | 160 panel.GetRetainedFilePaths(); |
161 ASSERT_EQ(3U, retained_file_paths.size()); | 161 ASSERT_EQ(3U, retained_file_paths.size()); |
162 EXPECT_THAT(retained_file_paths, | 162 EXPECT_THAT(retained_file_paths, |
163 Contains(Eq(base::UTF8ToUTF16("file_1.ext")))); | 163 Contains(Eq(base::UTF8ToUTF16("file_1.ext")))); |
164 EXPECT_THAT(retained_file_paths, | 164 EXPECT_THAT(retained_file_paths, |
165 Contains(Eq(base::UTF8ToUTF16("file_2.ext")))); | 165 Contains(Eq(base::UTF8ToUTF16("file_2.ext")))); |
166 EXPECT_THAT(retained_file_paths, | 166 EXPECT_THAT(retained_file_paths, |
167 Contains(Eq(base::UTF8ToUTF16("file_3.ext")))); | 167 Contains(Eq(base::UTF8ToUTF16("file_3.ext")))); |
168 } | 168 } |
OLD | NEW |