OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/json/json_file_value_serializer.h" | 5 #include "base/json/json_file_value_serializer.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "chrome/common/chrome_paths.h" | 8 #include "chrome/common/chrome_paths.h" |
9 #include "chrome/common/extensions/extension.h" | 9 #include "chrome/common/extensions/extension.h" |
10 #include "content/public/test/test_browser_thread.h" | 10 #include "content/public/test/test_browser_thread.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 | 83 |
84 // New extensions should have a single reference holding onto them. | 84 // New extensions should have a single reference holding onto them. |
85 scoped_refptr<Extension> extension1(CreateExtension("extension1")); | 85 scoped_refptr<Extension> extension1(CreateExtension("extension1")); |
86 scoped_refptr<Extension> extension2(CreateExtension("extension2")); | 86 scoped_refptr<Extension> extension2(CreateExtension("extension2")); |
87 scoped_refptr<Extension> extension3(CreateExtension("extension3")); | 87 scoped_refptr<Extension> extension3(CreateExtension("extension3")); |
88 EXPECT_TRUE(extension1->HasOneRef()); | 88 EXPECT_TRUE(extension1->HasOneRef()); |
89 EXPECT_TRUE(extension2->HasOneRef()); | 89 EXPECT_TRUE(extension2->HasOneRef()); |
90 EXPECT_TRUE(extension3->HasOneRef()); | 90 EXPECT_TRUE(extension3->HasOneRef()); |
91 | 91 |
92 // Add a ref to each extension and give it to the info map. | 92 // Add a ref to each extension and give it to the info map. |
93 info_map->AddExtension(extension1.get(), base::Time(), false); | 93 info_map->AddExtension(extension1.get(), base::Time(), false, false); |
94 info_map->AddExtension(extension2.get(), base::Time(), false); | 94 info_map->AddExtension(extension2.get(), base::Time(), false, false); |
95 info_map->AddExtension(extension3.get(), base::Time(), false); | 95 info_map->AddExtension(extension3.get(), base::Time(), false, false); |
96 | 96 |
97 // Release extension1, and the info map should have the only ref. | 97 // Release extension1, and the info map should have the only ref. |
98 const Extension* weak_extension1 = extension1.get(); | 98 const Extension* weak_extension1 = extension1.get(); |
99 extension1 = NULL; | 99 extension1 = NULL; |
100 EXPECT_TRUE(weak_extension1->HasOneRef()); | 100 EXPECT_TRUE(weak_extension1->HasOneRef()); |
101 | 101 |
102 // Remove extension2, and the extension2 object should have the only ref. | 102 // Remove extension2, and the extension2 object should have the only ref. |
103 info_map->RemoveExtension( | 103 info_map->RemoveExtension( |
104 extension2->id(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); | 104 extension2->id(), extensions::UnloadedExtensionInfo::REASON_UNINSTALL); |
105 EXPECT_TRUE(extension2->HasOneRef()); | 105 EXPECT_TRUE(extension2->HasOneRef()); |
106 | 106 |
107 // Delete the info map, and the extension3 object should have the only ref. | 107 // Delete the info map, and the extension3 object should have the only ref. |
108 info_map = NULL; | 108 info_map = NULL; |
109 EXPECT_TRUE(extension3->HasOneRef()); | 109 EXPECT_TRUE(extension3->HasOneRef()); |
110 } | 110 } |
111 | 111 |
112 // Tests that we can query a few extension properties from the InfoMap. | 112 // Tests that we can query a few extension properties from the InfoMap. |
113 TEST_F(InfoMapTest, Properties) { | 113 TEST_F(InfoMapTest, Properties) { |
114 scoped_refptr<InfoMap> info_map(new InfoMap()); | 114 scoped_refptr<InfoMap> info_map(new InfoMap()); |
115 | 115 |
116 scoped_refptr<Extension> extension1(CreateExtension("extension1")); | 116 scoped_refptr<Extension> extension1(CreateExtension("extension1")); |
117 scoped_refptr<Extension> extension2(CreateExtension("extension2")); | 117 scoped_refptr<Extension> extension2(CreateExtension("extension2")); |
118 | 118 |
119 info_map->AddExtension(extension1.get(), base::Time(), false); | 119 info_map->AddExtension(extension1.get(), base::Time(), false, false); |
120 info_map->AddExtension(extension2.get(), base::Time(), false); | 120 info_map->AddExtension(extension2.get(), base::Time(), false, false); |
121 | 121 |
122 EXPECT_EQ(2u, info_map->extensions().size()); | 122 EXPECT_EQ(2u, info_map->extensions().size()); |
123 EXPECT_EQ(extension1.get(), info_map->extensions().GetByID(extension1->id())); | 123 EXPECT_EQ(extension1.get(), info_map->extensions().GetByID(extension1->id())); |
124 EXPECT_EQ(extension2.get(), info_map->extensions().GetByID(extension2->id())); | 124 EXPECT_EQ(extension2.get(), info_map->extensions().GetByID(extension2->id())); |
125 } | 125 } |
126 | 126 |
127 // Tests CheckURLAccessToExtensionPermission given both extension and app URLs. | 127 // Tests CheckURLAccessToExtensionPermission given both extension and app URLs. |
128 TEST_F(InfoMapTest, CheckPermissions) { | 128 TEST_F(InfoMapTest, CheckPermissions) { |
129 scoped_refptr<InfoMap> info_map(new InfoMap()); | 129 scoped_refptr<InfoMap> info_map(new InfoMap()); |
130 | 130 |
131 scoped_refptr<Extension> app( | 131 scoped_refptr<Extension> app( |
132 LoadManifest("manifest_tests", "valid_app.json")); | 132 LoadManifest("manifest_tests", "valid_app.json")); |
133 scoped_refptr<Extension> extension( | 133 scoped_refptr<Extension> extension( |
134 LoadManifest("manifest_tests", "tabs_extension.json")); | 134 LoadManifest("manifest_tests", "tabs_extension.json")); |
135 | 135 |
136 GURL app_url("http://www.google.com/mail/foo.html"); | 136 GURL app_url("http://www.google.com/mail/foo.html"); |
137 ASSERT_TRUE(app->is_app()); | 137 ASSERT_TRUE(app->is_app()); |
138 ASSERT_TRUE(app->web_extent().MatchesURL(app_url)); | 138 ASSERT_TRUE(app->web_extent().MatchesURL(app_url)); |
139 | 139 |
140 info_map->AddExtension(app.get(), base::Time(), false); | 140 info_map->AddExtension(app.get(), base::Time(), false, false); |
141 info_map->AddExtension(extension.get(), base::Time(), false); | 141 info_map->AddExtension(extension.get(), base::Time(), false, false); |
142 | 142 |
143 // The app should have the notifications permission, either from a | 143 // The app should have the notifications permission, either from a |
144 // chrome-extension URL or from its web extent. | 144 // chrome-extension URL or from its web extent. |
145 const Extension* match = info_map->extensions().GetExtensionOrAppByURL( | 145 const Extension* match = info_map->extensions().GetExtensionOrAppByURL( |
146 app->GetResourceURL("a.html")); | 146 app->GetResourceURL("a.html")); |
147 EXPECT_TRUE(match && match->HasAPIPermission(APIPermission::kNotification)); | 147 EXPECT_TRUE(match && match->HasAPIPermission(APIPermission::kNotification)); |
148 match = info_map->extensions().GetExtensionOrAppByURL(app_url); | 148 match = info_map->extensions().GetExtensionOrAppByURL(app_url); |
149 EXPECT_TRUE(match && match->HasAPIPermission(APIPermission::kNotification)); | 149 EXPECT_TRUE(match && match->HasAPIPermission(APIPermission::kNotification)); |
150 EXPECT_FALSE(match && match->HasAPIPermission(APIPermission::kTab)); | 150 EXPECT_FALSE(match && match->HasAPIPermission(APIPermission::kTab)); |
151 | 151 |
152 // The extension should have the tabs permission. | 152 // The extension should have the tabs permission. |
153 match = info_map->extensions().GetExtensionOrAppByURL( | 153 match = info_map->extensions().GetExtensionOrAppByURL( |
154 extension->GetResourceURL("a.html")); | 154 extension->GetResourceURL("a.html")); |
155 EXPECT_TRUE(match && match->HasAPIPermission(APIPermission::kTab)); | 155 EXPECT_TRUE(match && match->HasAPIPermission(APIPermission::kTab)); |
156 EXPECT_FALSE(match && match->HasAPIPermission(APIPermission::kNotification)); | 156 EXPECT_FALSE(match && match->HasAPIPermission(APIPermission::kNotification)); |
157 | 157 |
158 // Random URL should not have any permissions. | 158 // Random URL should not have any permissions. |
159 GURL evil_url("http://evil.com/a.html"); | 159 GURL evil_url("http://evil.com/a.html"); |
160 match = info_map->extensions().GetExtensionOrAppByURL(evil_url); | 160 match = info_map->extensions().GetExtensionOrAppByURL(evil_url); |
161 EXPECT_FALSE(match); | 161 EXPECT_FALSE(match); |
162 } | 162 } |
163 | 163 |
| 164 TEST_F(InfoMapTest, TestNotificationsDisabled) { |
| 165 scoped_refptr<InfoMap> info_map(new InfoMap()); |
| 166 scoped_refptr<Extension> app(LoadManifest("manifest_tests", |
| 167 "valid_app.json")); |
| 168 info_map->AddExtension(app.get(), base::Time(), false, false); |
| 169 |
| 170 EXPECT_FALSE(info_map->AreNotificationsDisabled(app->id())); |
| 171 info_map->SetNotificationsDisabled(app->id(), true); |
| 172 EXPECT_TRUE(info_map->AreNotificationsDisabled(app->id())); |
| 173 info_map->SetNotificationsDisabled(app->id(), false); |
| 174 } |
| 175 |
164 } // namespace extensions | 176 } // namespace extensions |
OLD | NEW |