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

Side by Side Diff: chrome/common/extensions/api/extension_api_unittest.cc

Issue 9403006: Extensions: run "custom bindings" v8-extensions in content scripts. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: final comments Created 8 years, 10 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/api/extension_api.h" 5 #include "chrome/common/extensions/api/extension_api.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 13 matching lines...) Expand all
24 EXPECT_TRUE(extension_api->IsPrivileged("extension.lastError")); 24 EXPECT_TRUE(extension_api->IsPrivileged("extension.lastError"));
25 25
26 // Default unknown names to privileged for paranoia's sake. 26 // Default unknown names to privileged for paranoia's sake.
27 EXPECT_TRUE(extension_api->IsPrivileged("")); 27 EXPECT_TRUE(extension_api->IsPrivileged(""));
28 EXPECT_TRUE(extension_api->IsPrivileged("<unknown-namespace>")); 28 EXPECT_TRUE(extension_api->IsPrivileged("<unknown-namespace>"));
29 EXPECT_TRUE(extension_api->IsPrivileged("extension.<unknown-member>")); 29 EXPECT_TRUE(extension_api->IsPrivileged("extension.<unknown-member>"));
30 30
31 // Exists, but privileged. 31 // Exists, but privileged.
32 EXPECT_TRUE(extension_api->IsPrivileged("extension.getViews")); 32 EXPECT_TRUE(extension_api->IsPrivileged("extension.getViews"));
33 EXPECT_TRUE(extension_api->IsPrivileged("history.search")); 33 EXPECT_TRUE(extension_api->IsPrivileged("history.search"));
34
35 // Whole APIs that are unprivileged.
36 EXPECT_FALSE(extension_api->IsPrivileged("storage.local"));
37 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.onChanged"));
38 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.set"));
39 EXPECT_FALSE(extension_api->IsPrivileged("storage.local.MAX_ITEMS"));
40 EXPECT_FALSE(extension_api->IsPrivileged("storage.set"));
41 }
42
43 TEST(ExtensionAPI, IsWholeAPIPrivileged) {
44 ExtensionAPI* extension_api = ExtensionAPI::GetInstance();
45
46 // Completely unprivileged.
47 EXPECT_FALSE(extension_api->IsWholeAPIPrivileged("storage"));
48
49 // Partially unprivileged.
50 EXPECT_FALSE(extension_api->IsWholeAPIPrivileged("extension"));
51 EXPECT_FALSE(extension_api->IsWholeAPIPrivileged("test"));
52
53 // Nothing unprivileged.
54 EXPECT_TRUE(extension_api->IsWholeAPIPrivileged("history"));
55
56 // Paranoid above... paranoid here, too.
57 EXPECT_TRUE(extension_api->IsWholeAPIPrivileged(""));
58 EXPECT_TRUE(extension_api->IsWholeAPIPrivileged("<unknown-namespace>"));
34 } 59 }
35 60
36 TEST(ExtensionAPI, Depends) { 61 TEST(ExtensionAPI, Depends) {
37 // Fake extension with the "ttsEngine" permission but not the "tts" 62 // Fake extension with the "ttsEngine" permission but not the "tts"
38 // permission; it must load TTS. 63 // permission; it must load TTS.
39 DictionaryValue manifest; 64 DictionaryValue manifest;
40 manifest.SetString("name", "test extension"); 65 manifest.SetString("name", "test extension");
41 manifest.SetString("version", "1.0"); 66 manifest.SetString("version", "1.0");
42 { 67 {
43 scoped_ptr<ListValue> permissions(new ListValue()); 68 scoped_ptr<ListValue> permissions(new ListValue());
44 permissions->Append(Value::CreateStringValue("ttsEngine")); 69 permissions->Append(Value::CreateStringValue("ttsEngine"));
45 manifest.Set("permissions", permissions.release()); 70 manifest.Set("permissions", permissions.release());
46 } 71 }
47 72
48 std::string error; 73 std::string error;
49 scoped_refptr<Extension> extension(Extension::Create( 74 scoped_refptr<Extension> extension(Extension::Create(
50 FilePath(), Extension::LOAD, manifest, Extension::NO_FLAGS, "x", &error)); 75 FilePath(), Extension::LOAD, manifest, Extension::NO_FLAGS, &error));
51 CHECK(extension.get()); 76 CHECK(extension.get());
52 CHECK(error.empty()); 77 CHECK(error.empty());
53 78
54 ExtensionAPI::SchemaMap schemas; 79 ExtensionAPI::SchemaMap schemas;
55 ExtensionAPI::GetInstance()->GetSchemasForExtension(*extension, &schemas); 80 ExtensionAPI::GetInstance()->GetSchemasForExtension(*extension, &schemas);
56 EXPECT_EQ(1u, schemas.count("tts")); 81 EXPECT_EQ(1u, schemas.count("tts"));
57 } 82 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/api/extension_api.cc ('k') | chrome/common/extensions/api/storage.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698