Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(656)

Side by Side Diff: chrome/common/extensions/extension_unittest.cc

Issue 4687005: Track permissions granted to extensions in prefs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/common/extensions/extension.h" 5 #include "chrome/common/extensions/extension.h"
6 6
7 #if defined(TOOLKIT_GTK) 7 #if defined(TOOLKIT_GTK)
8 #include <gtk/gtk.h> 8 #include <gtk/gtk.h>
9 #endif 9 #endif
10 10
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 input_value->Set(keys::kPermissions, Value::CreateIntegerValue(9)); 245 input_value->Set(keys::kPermissions, Value::CreateIntegerValue(9));
246 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 246 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
247 EXPECT_TRUE(MatchPattern(error, errors::kInvalidPermissions)); 247 EXPECT_TRUE(MatchPattern(error, errors::kInvalidPermissions));
248 248
249 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); 249 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
250 input_value->GetList(keys::kPermissions, &permissions); 250 input_value->GetList(keys::kPermissions, &permissions);
251 permissions->Set(0, Value::CreateIntegerValue(24)); 251 permissions->Set(0, Value::CreateIntegerValue(24));
252 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 252 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error));
253 EXPECT_TRUE(MatchPattern(error, errors::kInvalidPermission)); 253 EXPECT_TRUE(MatchPattern(error, errors::kInvalidPermission));
254 254
255 // We now allow unknown permissions, so this will be valid.
Aaron Boodman 2010/11/12 00:05:24 In general don't say things like "we now do xyz" i
jstritar 2010/11/19 21:38:36 Done.
255 permissions->Set(0, Value::CreateStringValue("www.google.com")); 256 permissions->Set(0, Value::CreateStringValue("www.google.com"));
256 EXPECT_FALSE(extension.InitFromValue(*input_value, true, &error)); 257 EXPECT_TRUE(extension.InitFromValue(*input_value, true, &error));
257 EXPECT_TRUE(MatchPattern(error, errors::kInvalidPermission));
258 258
259 // Multiple page actions are not allowed. 259 // Multiple page actions are not allowed.
260 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy())); 260 input_value.reset(static_cast<DictionaryValue*>(valid_value->DeepCopy()));
261 DictionaryValue* action = new DictionaryValue; 261 DictionaryValue* action = new DictionaryValue;
262 action->SetString(keys::kPageActionId, "MyExtensionActionId"); 262 action->SetString(keys::kPageActionId, "MyExtensionActionId");
263 action->SetString(keys::kName, "MyExtensionActionName"); 263 action->SetString(keys::kName, "MyExtensionActionName");
264 ListValue* action_list = new ListValue; 264 ListValue* action_list = new ListValue;
265 action_list->Append(action->DeepCopy()); 265 action_list->Append(action->DeepCopy());
266 action_list->Append(action); 266 action_list->Append(action);
267 input_value->Set(keys::kPageActions, action_list); 267 input_value->Set(keys::kPageActions, action_list);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 EXPECT_TRUE(Extension::IdIsValid(extension.id())); 320 EXPECT_TRUE(Extension::IdIsValid(extension.id()));
321 EXPECT_EQ("1.0.0.0", extension.VersionString()); 321 EXPECT_EQ("1.0.0.0", extension.VersionString());
322 EXPECT_EQ("my extension", extension.name()); 322 EXPECT_EQ("my extension", extension.name());
323 EXPECT_EQ(extension.id(), extension.url().host()); 323 EXPECT_EQ(extension.id(), extension.url().host());
324 EXPECT_EQ(path.value(), extension.path().value()); 324 EXPECT_EQ(path.value(), extension.path().value());
325 325
326 // Test permissions scheme. 326 // Test permissions scheme.
327 ListValue* permissions = new ListValue; 327 ListValue* permissions = new ListValue;
328 permissions->Set(0, Value::CreateStringValue("file:///C:/foo.txt")); 328 permissions->Set(0, Value::CreateStringValue("file:///C:/foo.txt"));
329 input_value.Set(keys::kPermissions, permissions); 329 input_value.Set(keys::kPermissions, permissions);
330 EXPECT_FALSE(extension.InitFromValue(input_value, false, &error)); 330 // This will no longer throw an error message for invalid permissions.
Aaron Boodman 2010/11/12 00:05:24 Same here.
331 EXPECT_TRUE(MatchPattern(error, errors::kInvalidPermission)); 331 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
332 input_value.Remove(keys::kPermissions, NULL); 332 input_value.Remove(keys::kPermissions, NULL);
333 error.clear();
334 333
335 // Test with an options page. 334 // Test with an options page.
336 input_value.SetString(keys::kOptionsPage, "options.html"); 335 input_value.SetString(keys::kOptionsPage, "options.html");
337 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error)); 336 EXPECT_TRUE(extension.InitFromValue(input_value, false, &error));
338 EXPECT_EQ("", error); 337 EXPECT_EQ("", error);
339 EXPECT_EQ("chrome-extension", extension.options_url().scheme()); 338 EXPECT_EQ("chrome-extension", extension.options_url().scheme());
340 EXPECT_EQ("/options.html", extension.options_url().path()); 339 EXPECT_EQ("/options.html", extension.options_url().path());
341 340
342 // Test that an empty list of page actions does not stop a browser action 341 // Test that an empty list of page actions does not stop a browser action
343 // from being loaded. 342 // from being loaded.
(...skipping 816 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 EXPECT_TRUE(Extension::GenerateId("test", &result)); 1159 EXPECT_TRUE(Extension::GenerateId("test", &result));
1161 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf"); 1160 EXPECT_EQ(result, "jpignaibiiemhngfjkcpokkamffknabf");
1162 1161
1163 EXPECT_TRUE(Extension::GenerateId("_", &result)); 1162 EXPECT_TRUE(Extension::GenerateId("_", &result));
1164 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd"); 1163 EXPECT_EQ(result, "ncocknphbhhlhkikpnnlmbcnbgdempcd");
1165 1164
1166 EXPECT_TRUE(Extension::GenerateId( 1165 EXPECT_TRUE(Extension::GenerateId(
1167 "this_string_is_longer_than_a_single_sha256_hash_digest", &result)); 1166 "this_string_is_longer_than_a_single_sha256_hash_digest", &result));
1168 EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi"); 1167 EXPECT_EQ(result, "jimneklojkjdibfkgiiophfhjhbdgcfi");
1169 } 1168 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698